Skip to content

Commit aa675f1

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): Resolve project by new smart default provider.
fixes #788
1 parent fcde52a commit aa675f1

29 files changed

+55
-19
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,15 @@ export default function (options: ApplicationOptions): Rule {
346346
routingScope: 'Root',
347347
path: sourceDir,
348348
spec: false,
349+
project: options.name,
349350
}),
350351
schematic('component', {
351352
name: 'app',
352353
selector: appRootSelector,
353354
flat: true,
354355
path: sourceDir,
355356
skipImport: true,
357+
project: options.name,
356358
...componentOptions,
357359
}),
358360
mergeWith(

packages/schematics/angular/class/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
12+
SchematicsException,
1213
Tree,
1314
apply,
1415
branchAndMerge,
@@ -27,7 +28,7 @@ export default function (options: ClassOptions): Rule {
2728
return (host: Tree, context: SchematicContext) => {
2829
const workspace = getWorkspace(host);
2930
if (!options.project) {
30-
options.project = Object.keys(workspace.projects)[0];
31+
throw new SchematicsException('Option (project) is required.');
3132
}
3233
const project = workspace.projects[options.project];
3334

packages/schematics/angular/class/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Class Schematic', () => {
2121
name: 'foo',
2222
type: '',
2323
spec: false,
24+
project: 'bar',
2425
};
2526

2627

packages/schematics/angular/class/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"project": {
2222
"type": "string",
2323
"description": "The name of the project.",
24-
"visible": false
24+
"$default": {
25+
"$source": "projectName"
26+
}
2527
},
2628
"spec": {
2729
"type": "boolean",

packages/schematics/angular/component/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default function(options: ComponentOptions): Rule {
108108
return (host: Tree, context: SchematicContext) => {
109109
const workspace = getWorkspace(host);
110110
if (!options.project) {
111-
options.project = Object.keys(workspace.projects)[0];
111+
throw new SchematicsException('Option (project) is required.');
112112
}
113113
const project = workspace.projects[options.project];
114114

packages/schematics/angular/component/index_spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('Component Schematic', () => {
2828
spec: true,
2929
module: undefined,
3030
export: false,
31+
project: 'bar',
3132
};
3233

3334

@@ -253,7 +254,7 @@ describe('Component Schematic', () => {
253254
});
254255

255256
it('should handle a path in the name and module options', () => {
256-
appTree = schematicRunner.runSchematic('module', { name: 'admin/module' }, appTree);
257+
appTree = schematicRunner.runSchematic('module', { name: 'admin/module', project: 'bar' }, appTree);
257258

258259
const options = { ...defaultOptions, name: 'other/test-component', module: 'admin/module' };
259260
appTree = schematicRunner.runSchematic('component', options, appTree);

packages/schematics/angular/component/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"project": {
1414
"type": "string",
1515
"description": "The name of the project.",
16-
"visible": false
16+
"$default": {
17+
"$source": "projectName"
18+
}
1719
},
1820
"name": {
1921
"type": "string",

packages/schematics/angular/directive/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default function (options: DirectiveOptions): Rule {
105105
return (host: Tree, context: SchematicContext) => {
106106
const workspace = getWorkspace(host);
107107
if (!options.project) {
108-
options.project = Object.keys(workspace.projects)[0];
108+
throw new SchematicsException('Option (project) is required.');
109109
}
110110
const project = workspace.projects[options.project];
111111

packages/schematics/angular/directive/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('Directive Schematic', () => {
2424
export: false,
2525
prefix: 'app',
2626
flat: true,
27+
project: 'bar',
2728
};
2829

2930
const workspaceOptions: WorkspaceOptions = {

packages/schematics/angular/directive/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"project": {
2222
"type": "string",
2323
"description": "The name of the project.",
24-
"visible": false
24+
"$default": {
25+
"$source": "projectName"
26+
}
2527
},
2628
"prefix": {
2729
"type": "string",

packages/schematics/angular/enum/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
12+
SchematicsException,
1213
Tree,
1314
apply,
1415
branchAndMerge,
@@ -27,7 +28,7 @@ export default function (options: EnumOptions): Rule {
2728
return (host: Tree, context: SchematicContext) => {
2829
const workspace = getWorkspace(host);
2930
if (!options.project) {
30-
options.project = Object.keys(workspace.projects)[0];
31+
throw new SchematicsException('Option (project) is required.');
3132
}
3233
const project = workspace.projects[options.project];
3334

packages/schematics/angular/enum/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Enum Schematic', () => {
1919
);
2020
const defaultOptions: EnumOptions = {
2121
name: 'foo',
22+
project: 'bar',
2223
};
2324

2425
const workspaceOptions: WorkspaceOptions = {

packages/schematics/angular/enum/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"project": {
2222
"type": "string",
2323
"description": "The name of the project.",
24-
"visible": false
24+
"$default": {
25+
"$source": "projectName"
26+
}
2527
}
2628
},
2729
"required": []

packages/schematics/angular/guard/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default function (options: GuardOptions): Rule {
6969
return (host: Tree, context: SchematicContext) => {
7070
const workspace = getWorkspace(host);
7171
if (!options.project) {
72-
options.project = Object.keys(workspace.projects)[0];
72+
throw new SchematicsException('Option (project) is required.');
7373
}
7474
const project = workspace.projects[options.project];
7575

packages/schematics/angular/guard/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('Guard Schematic', () => {
2222
spec: true,
2323
module: undefined,
2424
flat: true,
25+
project: 'bar',
2526
};
2627
const workspaceOptions: WorkspaceOptions = {
2728
name: 'workspace',

packages/schematics/angular/guard/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"project": {
3737
"type": "string",
3838
"description": "The name of the project.",
39-
"visible": false
39+
"$default": {
40+
"$source": "projectName"
41+
}
4042
}
4143
},
4244
"required": []

packages/schematics/angular/interface/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
12+
SchematicsException,
1213
Tree,
1314
apply,
1415
branchAndMerge,
@@ -27,7 +28,7 @@ export default function (options: InterfaceOptions): Rule {
2728
return (host: Tree, context: SchematicContext) => {
2829
const workspace = getWorkspace(host);
2930
if (!options.project) {
30-
options.project = Object.keys(workspace.projects)[0];
31+
throw new SchematicsException('Option (project) is required.');
3132
}
3233
const project = workspace.projects[options.project];
3334

packages/schematics/angular/interface/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Interface Schematic', () => {
2121
name: 'foo',
2222
prefix: '',
2323
type: '',
24+
project: 'bar',
2425
};
2526

2627
const workspaceOptions: WorkspaceOptions = {

packages/schematics/angular/interface/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"project": {
2222
"type": "string",
2323
"description": "The name of the project.",
24-
"visible": false
24+
"$default": {
25+
"$source": "projectName"
26+
}
2527
},
2628
"prefix": {
2729
"type": "string",

packages/schematics/angular/library/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export default function (options: LibraryOptions): Rule {
225225
flat: true,
226226
path: sourceDir,
227227
spec: false,
228+
project: options.name,
228229
}),
229230
schematic('component', {
230231
name: options.name,
@@ -234,11 +235,13 @@ export default function (options: LibraryOptions): Rule {
234235
flat: true,
235236
path: sourceDir,
236237
export: true,
238+
project: options.name,
237239
}),
238240
schematic('service', {
239241
name: options.name,
240242
flat: true,
241243
path: sourceDir,
244+
project: options.name,
242245
}),
243246
(_tree: Tree, context: SchematicContext) => {
244247
context.addTask(new NodePackageInstallTask());

packages/schematics/angular/module/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function (options: ModuleOptions): Rule {
7474
return (host: Tree, context: SchematicContext) => {
7575
const workspace = getWorkspace(host);
7676
if (!options.project) {
77-
options.project = Object.keys(workspace.projects)[0];
77+
throw new SchematicsException('Option (project) is required.');
7878
}
7979
const project = workspace.projects[options.project];
8080

packages/schematics/angular/module/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('Module Schematic', () => {
2222
spec: true,
2323
module: undefined,
2424
flat: false,
25+
project: 'bar',
2526
};
2627

2728
const workspaceOptions: WorkspaceOptions = {

packages/schematics/angular/module/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"project": {
2222
"type": "string",
2323
"description": "The name of the project.",
24-
"visible": false
24+
"$default": {
25+
"$source": "projectName"
26+
}
2527
},
2628
"routing": {
2729
"type": "boolean",

packages/schematics/angular/pipe/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default function (options: PipeOptions): Rule {
8989
return (host: Tree, context: SchematicContext) => {
9090
const workspace = getWorkspace(host);
9191
if (!options.project) {
92-
options.project = Object.keys(workspace.projects)[0];
92+
throw new SchematicsException('Option (project) is required.');
9393
}
9494
const project = workspace.projects[options.project];
9595

packages/schematics/angular/pipe/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('Pipe Schematic', () => {
2424
module: undefined,
2525
export: false,
2626
flat: true,
27+
project: 'bar',
2728
};
2829

2930
const workspaceOptions: WorkspaceOptions = {

packages/schematics/angular/pipe/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"project": {
2222
"type": "string",
2323
"description": "The name of the project.",
24-
"visible": false
24+
"$default": {
25+
"$source": "projectName"
26+
}
2527
},
2628
"flat": {
2729
"type": "boolean",

packages/schematics/angular/service/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
12+
SchematicsException,
1213
Tree,
1314
apply,
1415
filter,
@@ -26,7 +27,7 @@ export default function (options: ServiceOptions): Rule {
2627
return (host: Tree, context: SchematicContext) => {
2728
const workspace = getWorkspace(host);
2829
if (!options.project) {
29-
options.project = Object.keys(workspace.projects)[0];
30+
throw new SchematicsException('Option (project) is required.');
3031
}
3132
const project = workspace.projects[options.project];
3233

packages/schematics/angular/service/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Service Schematic', () => {
2121
name: 'foo',
2222
spec: true,
2323
flat: false,
24+
project: 'bar',
2425
};
2526

2627
const workspaceOptions: WorkspaceOptions = {

packages/schematics/angular/service/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"project": {
2222
"type": "string",
2323
"description": "The name of the project.",
24-
"visible": false
24+
"$default": {
25+
"$source": "projectName"
26+
}
2527
},
2628
"flat": {
2729
"type": "boolean",

0 commit comments

Comments
 (0)