Skip to content

Commit 867b10e

Browse files
committed
feat(@schematics/angular): Add the option to create an empty workspace
Fixes #12216
1 parent 432fe97 commit 867b10e

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

packages/schematics/angular/ng-new/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
empty,
1616
mergeWith,
1717
move,
18+
noop,
1819
schematic,
1920
} from '@angular-devkit/schematics';
2021
import {
@@ -60,7 +61,7 @@ export default function (options: NgNewOptions): Rule {
6061
mergeWith(
6162
apply(empty(), [
6263
schematic('workspace', workspaceOptions),
63-
schematic('application', applicationOptions),
64+
options.empty ? noop : schematic('application', applicationOptions),
6465
move(options.directory || options.name),
6566
]),
6667
),

packages/schematics/angular/ng-new/index_spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,24 @@ describe('Ng New Schematic', () => {
5656
const moduleContent = tree.readContent('/foo/src/app/app.module.ts');
5757
expect(moduleContent).toMatch(/declarations:\s*\[\s*AppComponent\s*\]/m);
5858
});
59+
60+
fdescribe('empty option', () => {
61+
it('should create an empty workspace', () => {
62+
const options = { ...defaultOptions, empty: true };
63+
64+
const tree = schematicRunner.runSchematic('ng-new', options);
65+
const files = tree.files;
66+
expect(files.indexOf('/bar/angular.json')).toBeGreaterThanOrEqual(0);
67+
});
68+
69+
it('should not create a project', () => {
70+
const options = { ...defaultOptions, empty: true };
71+
72+
const tree = schematicRunner.runSchematic('ng-new', options);
73+
const files = tree.files;
74+
expect(files.indexOf('/bar/src')).toBe(-1);
75+
});
76+
77+
78+
});
5979
});

packages/schematics/angular/ng-new/schema.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@ export interface Schema {
7272
* Skip creating spec files.
7373
*/
7474
skipTests?: boolean;
75+
/**
76+
* Create an empty workspace with no projects.
77+
*/
78+
empty?: boolean;
7579
}

packages/schematics/angular/ng-new/schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@
131131
"type": "boolean",
132132
"default": false,
133133
"alias": "S"
134+
},
135+
"empty": {
136+
"description": "Create an empty workspace with no projects.",
137+
"type": "boolean",
138+
"default": false,
139+
"alias": "e"
134140
}
135141
},
136142
"required": [

0 commit comments

Comments
 (0)