Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@schematics/angular): allow inlineTemplate/inlineStyle with minimal application #19101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/schematics/angular/application/index.ts
Expand Up @@ -103,10 +103,10 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
|| options.minimal
|| options.style !== Style.Css) {
const componentSchematicsOptions: JsonObject = {};
if (options.inlineTemplate || options.minimal) {
if (options.inlineTemplate ?? options.minimal) {
componentSchematicsOptions.inlineTemplate = true;
}
if (options.inlineStyle || options.minimal) {
if (options.inlineStyle ?? options.minimal) {
componentSchematicsOptions.inlineStyle = true;
}
if (options.style && options.style !== Style.Css) {
Expand Down Expand Up @@ -289,10 +289,11 @@ export default function (options: ApplicationOptions): Rule {
viewEncapsulation: options.viewEncapsulation,
} :
{
inlineStyle: true,
inlineTemplate: true,
inlineStyle: options.inlineStyle ?? true,
inlineTemplate: options.inlineTemplate ?? true,
skipTests: true,
style: options.style,
viewEncapsulation: options.viewEncapsulation,
};

const workspace = await getWorkspace(host);
Expand Down
84 changes: 82 additions & 2 deletions packages/schematics/angular/application/index_spec.ts
Expand Up @@ -32,8 +32,6 @@ describe('Application Schematic', () => {

const defaultOptions: ApplicationOptions = {
name: 'foo',
inlineStyle: false,
inlineTemplate: false,
routing: false,
skipPackageJson: false,
};
Expand Down Expand Up @@ -206,6 +204,30 @@ describe('Application Schematic', () => {
});
});

it('minimal=true allows inlineStyle=false when configuring the schematics options for components', async () => {
const options = { ...defaultOptions, minimal: true, inlineStyle: false };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const config = JSON.parse(tree.readContent('/angular.json'));
const schematics = config.projects.foo.schematics;
expect(schematics['@schematics/angular:component']).toEqual({
inlineTemplate: true,
skipTests: true,
});
});

it('minimal=true allows inlineTemplate=false when configuring the schematics options for components', async () => {
const options = { ...defaultOptions, minimal: true, inlineTemplate: false };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const config = JSON.parse(tree.readContent('/angular.json'));
const schematics = config.projects.foo.schematics;
expect(schematics['@schematics/angular:component']).toEqual({
inlineStyle: true,
skipTests: true,
});
});

it('should create correct files when using minimal', async () => {
const options = { ...defaultOptions, minimal: true };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
Expand Down Expand Up @@ -235,6 +257,64 @@ describe('Application Schematic', () => {
]));
});

it('should create correct files when using minimal and inlineStyle=false', async () => {
const options = { ...defaultOptions, minimal: true, inlineStyle: false };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const files = tree.files;
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/tslint.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.html',
'/projects/foo/src/app/app.component.spec.ts',
].forEach(x => expect(files).not.toContain(x));

expect(files).toEqual(jasmine.arrayContaining([
'/projects/foo/tsconfig.app.json',
'/projects/foo/src/environments/environment.ts',
'/projects/foo/src/environments/environment.prod.ts',
'/projects/foo/src/favicon.ico',
'/projects/foo/src/index.html',
'/projects/foo/src/main.ts',
'/projects/foo/src/polyfills.ts',
'/projects/foo/src/styles.css',
'/projects/foo/src/app/app.module.ts',
'/projects/foo/src/app/app.component.css',
'/projects/foo/src/app/app.component.ts',
]));
});

it('should create correct files when using minimal and inlineTemplate=false', async () => {
const options = { ...defaultOptions, minimal: true, inlineTemplate: false };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const files = tree.files;
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/tslint.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.css',
'/projects/foo/src/app/app.component.spec.ts',
].forEach(x => expect(files).not.toContain(x));

expect(files).toEqual(jasmine.arrayContaining([
'/projects/foo/tsconfig.app.json',
'/projects/foo/src/environments/environment.ts',
'/projects/foo/src/environments/environment.prod.ts',
'/projects/foo/src/favicon.ico',
'/projects/foo/src/index.html',
'/projects/foo/src/main.ts',
'/projects/foo/src/polyfills.ts',
'/projects/foo/src/styles.css',
'/projects/foo/src/app/app.module.ts',
'/projects/foo/src/app/app.component.html',
'/projects/foo/src/app/app.component.ts',
]));
});

describe(`update package.json`, () => {
it(`should add build-angular to devDependencies`, async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
Expand Down
2 changes: 0 additions & 2 deletions packages/schematics/angular/application/schema.json
Expand Up @@ -22,14 +22,12 @@
"inlineStyle": {
"description": "When true, includes styles inline in the root component.ts file. Only CSS styles can be included inline. Default is false, meaning that an external styles file is created and referenced in the root component.ts file.",
"type": "boolean",
"default": false,
"alias": "s",
"x-user-analytics": 9
},
"inlineTemplate": {
"description": "When true, includes template inline in the root component.ts file. Default is false, meaning that an external template file is created and referenced in the root component.ts file. ",
"type": "boolean",
"default": false,
"alias": "t",
"x-user-analytics": 10
},
Expand Down
2 changes: 0 additions & 2 deletions packages/schematics/angular/ng-new/schema.json
Expand Up @@ -66,14 +66,12 @@
"inlineStyle": {
"description": "When true, includes styles inline in the component TS file. By default, an external styles file is created and referenced in the component TS file.",
"type": "boolean",
"default": false,
"alias": "s",
"x-user-analytics": 9
},
"inlineTemplate": {
"description": "When true, includes template inline in the component TS file. By default, an external template file is created and referenced in the component TS file.",
"type": "boolean",
"default": false,
"alias": "t",
"x-user-analytics": 10
},
Expand Down