Skip to content

Commit 8e98683

Browse files
committed
fix(@schematics/angular): the ng-new schematic should not prompt for style
closes #13383
1 parent 516a455 commit 8e98683

File tree

8 files changed

+72
-69
lines changed

8 files changed

+72
-69
lines changed

packages/schematics/angular/migrations/update-7/devkit-ng-packagr_spec.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,31 @@ describe('updateDevkitBuildNgPackagr', () => {
2828

2929
beforeEach(async () => {
3030
tree = new UnitTestTree(new EmptyTree());
31-
tree = await schematicRunner.runExternalSchematicAsync(
32-
require.resolve('../../collection.json'), 'ng-new',
33-
{
34-
name: 'migration-test',
35-
version: '1.2.3',
36-
directory: '.',
37-
},
38-
tree,
39-
).toPromise();
31+
tree = await schematicRunner
32+
.runExternalSchematicAsync(
33+
require.resolve('../../collection.json'),
34+
'ng-new',
35+
{
36+
name: 'migration-test',
37+
version: '1.2.3',
38+
directory: '.',
39+
style: 'css',
40+
},
41+
tree,
42+
)
43+
.toPromise();
4044
});
4145

4246
it('should work as expected', async () => {
4347
tree.overwrite('/package.json', oldPkg);
44-
const tree2 = await schematicRunner.runSchematicAsync('migration-06', {}, tree.branch())
48+
const tree2 = await schematicRunner
49+
.runSchematicAsync('migration-06', {}, tree.branch())
4550
.toPromise();
4651

4752
const content = tree2.readContent('/package.json');
4853
const pkg = JSON.parse(content);
49-
expect(pkg.devDependencies['@angular-devkit/build-ng-packagr'])
50-
.toBe(latestVersions.DevkitBuildNgPackagr);
54+
expect(pkg.devDependencies['@angular-devkit/build-ng-packagr']).toBe(
55+
latestVersions.DevkitBuildNgPackagr,
56+
);
5157
});
5258
});

packages/schematics/angular/migrations/update-7/polyfill-metadata_spec.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
7070
import 'zone.js/dist/zone'; // Included with Angular CLI.
7171
`;
7272

73-
7473
describe('polyfillMetadataRule', () => {
7574
const schematicRunner = new SchematicTestRunner(
7675
'migrations',
@@ -81,26 +80,31 @@ describe('polyfillMetadataRule', () => {
8180

8281
beforeEach(async () => {
8382
tree = new UnitTestTree(new EmptyTree());
84-
tree = await schematicRunner.runExternalSchematicAsync(
85-
require.resolve('../../collection.json'), 'ng-new',
86-
{
87-
name: 'migration-test',
88-
version: '1.2.3',
89-
directory: '.',
90-
},
91-
tree,
92-
).toPromise();
83+
tree = await schematicRunner
84+
.runExternalSchematicAsync(
85+
require.resolve('../../collection.json'),
86+
'ng-new',
87+
{
88+
name: 'migration-test',
89+
version: '1.2.3',
90+
directory: '.',
91+
style: 'css',
92+
},
93+
tree,
94+
)
95+
.toPromise();
9396
});
9497

9598
it('is noop for new projects', async () => {
9699
const mapToIdem = (x: Action) => {
97-
const content = (x.kind == 'o' || x.kind == 'c') ? x.content.toString() : null;
100+
const content = x.kind == 'o' || x.kind == 'c' ? x.content.toString() : null;
98101

99102
return { ...x, content, id: -1 };
100103
};
101104

102105
const expected = [...tree.actions.map(mapToIdem)];
103-
const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch())
106+
const tree2 = await schematicRunner
107+
.runSchematicAsync('migration-03', {}, tree.branch())
104108
.toPromise();
105109

106110
expect(tree2.actions.map(mapToIdem)).toEqual(expected);
@@ -109,7 +113,8 @@ describe('polyfillMetadataRule', () => {
109113
it('should work as expected', async () => {
110114
const polyfillPath = '/src/polyfills.ts';
111115
tree.overwrite(polyfillPath, oldPolyfills);
112-
const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch())
116+
const tree2 = await schematicRunner
117+
.runSchematicAsync('migration-03', {}, tree.branch())
113118
.toPromise();
114119

115120
expect(tree2.readContent(polyfillPath)).toBe(newPolyfills);
@@ -121,7 +126,8 @@ describe('polyfillMetadataRule', () => {
121126
tree.overwrite('angular.json', JSON.stringify(originalContent));
122127
const polyfillPath = '/src/polyfills.ts';
123128
tree.overwrite(polyfillPath, oldPolyfills);
124-
const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch())
129+
const tree2 = await schematicRunner
130+
.runSchematicAsync('migration-03', {}, tree.branch())
125131
.toPromise();
126132

127133
expect(tree2.readContent(polyfillPath)).toBe(newPolyfills);

packages/schematics/angular/migrations/update-7/typescript-helpers_spec.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,26 @@ describe('typeScriptHelpersRule', () => {
4343

4444
beforeEach(async () => {
4545
tree = new UnitTestTree(new EmptyTree());
46-
tree = await schematicRunner.runExternalSchematicAsync(
47-
require.resolve('../../collection.json'), 'ng-new',
48-
{
49-
name: 'migration-test',
50-
version: '1.2.3',
51-
directory: '.',
52-
},
53-
tree,
54-
).toPromise();
46+
tree = await schematicRunner
47+
.runExternalSchematicAsync(
48+
require.resolve('../../collection.json'),
49+
'ng-new',
50+
{
51+
name: 'migration-test',
52+
version: '1.2.3',
53+
directory: '.',
54+
style: 'css',
55+
},
56+
tree,
57+
)
58+
.toPromise();
5559
});
5660

5761
it('should work as expected', async () => {
5862
const tsConfigPath = '/tsconfig.json';
5963
tree.overwrite(tsConfigPath, oldTsConfig);
60-
const tree2 = await schematicRunner.runSchematicAsync('migration-04', {}, tree.branch())
64+
const tree2 = await schematicRunner
65+
.runSchematicAsync('migration-04', {}, tree.branch())
6166
.toPromise();
6267

6368
const { importHelpers } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;

packages/schematics/angular/migrations/update-8/differential-loading_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('Migration to version 8', () => {
3838
name: 'migration-test',
3939
version: '1.2.3',
4040
directory: '.',
41+
style: 'css',
4142
},
4243
tree,
4344
)

packages/schematics/angular/migrations/update-8/drop-es6-polyfills_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import 'zone.js/dist/zone'; // Included with Angular CLI.
7070
name: 'migration-test',
7171
version: '1.2.3',
7272
directory: '.',
73+
style: 'css',
7374
},
7475
tree,
7576
).toPromise();

packages/schematics/angular/migrations/update-9/update-workspace-config_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { ANY_COMPONENT_STYLE_BUDGET } from './update-workspace-config';
1313

1414
// tslint:disable-next-line: no-any
1515
function getWorkspaceTargets(tree: UnitTestTree): any {
16-
return JSON.parse(tree.readContent(workspacePath))
17-
.projects['migration-test'].architect;
16+
return JSON.parse(tree.readContent(workspacePath)).projects['migration-test'].architect;
1817
}
1918

2019
function updateWorkspaceTargets(tree: UnitTestTree, workspaceTargets: WorkspaceTargets) {
@@ -73,6 +72,7 @@ describe('Migration to version 9', () => {
7372
name: 'migration-test',
7473
version: '1.2.3',
7574
directory: '.',
75+
style: 'css',
7676
},
7777
tree,
7878
)

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
9-
import { Schema as NgNewOptions } from './schema';
10-
9+
import { Schema as NgNewOptions, Style } from './schema';
1110

1211
describe('Ng New Schematic', () => {
1312
const schematicRunner = new SchematicTestRunner(
@@ -18,6 +17,7 @@ describe('Ng New Schematic', () => {
1817
name: 'foo',
1918
directory: 'bar',
2019
version: '6.0.0',
20+
style: Style.Css,
2121
};
2222

2323
it('should create files of a workspace', async () => {
@@ -33,15 +33,17 @@ describe('Ng New Schematic', () => {
3333

3434
const tree = await schematicRunner.runSchematicAsync('ng-new', options).toPromise();
3535
const files = tree.files;
36-
expect(files).toEqual(jasmine.arrayContaining([
37-
'/bar/tsconfig.app.json',
38-
'/bar/src/main.ts',
39-
'/bar/src/app/app.module.ts',
40-
'/bar/e2e/src/app.po.ts',
41-
'/bar/e2e/src/app.e2e-spec.ts',
42-
'/bar/e2e/tsconfig.json',
43-
'/bar/e2e/protractor.conf.js',
44-
]));
36+
expect(files).toEqual(
37+
jasmine.arrayContaining([
38+
'/bar/tsconfig.app.json',
39+
'/bar/src/main.ts',
40+
'/bar/src/app/app.module.ts',
41+
'/bar/e2e/src/app.po.ts',
42+
'/bar/e2e/src/app.e2e-spec.ts',
43+
'/bar/e2e/tsconfig.json',
44+
'/bar/e2e/protractor.conf.js',
45+
]),
46+
);
4547
});
4648

4749
it('should should set the prefix in angular.json and in app.component.ts', async () => {
@@ -56,6 +58,7 @@ describe('Ng New Schematic', () => {
5658
const options: NgNewOptions = {
5759
name: 'foo',
5860
version: '6.0.0',
61+
style: Style.Css,
5962
};
6063

6164
const tree = await schematicRunner.runSchematicAsync('ng-new', options).toPromise();

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,7 @@
114114
"style": {
115115
"description": "The file extension or preprocessor to use for style files.",
116116
"type": "string",
117-
"default": "css",
118-
"enum": [
119-
"css",
120-
"scss",
121-
"sass",
122-
"less",
123-
"styl"
124-
],
125-
"x-prompt": {
126-
"message": "Which stylesheet format would you like to use?",
127-
"type": "list",
128-
"items": [
129-
{ "value": "css", "label": "CSS" },
130-
{ "value": "scss", "label": "SCSS [ https://sass-lang.com/documentation/syntax#scss ]" },
131-
{ "value": "sass", "label": "Sass [ https://sass-lang.com/documentation/syntax#the-indented-syntax ]" },
132-
{ "value": "less", "label": "Less [ http://lesscss.org ]" },
133-
{ "value": "styl", "label": "Stylus [ http://stylus-lang.com ]" }
134-
]
135-
},
136-
"x-user-analytics": 5
117+
"enum": ["css", "scss", "sass", "less", "styl"]
137118
},
138119
"skipTests": {
139120
"description": "When true, does not generate \"spec.ts\" test files for the new project. ",

0 commit comments

Comments
 (0)