Skip to content

Commit 067dd19

Browse files
committed
refactor(ng-generate): use .template suffix for schematic template files
Switches all schematic template files to the `.template` file extension. This ensures that these files are not accidentally picked up in external projects (e.g. when building the summary files with ngc). Related to #16189
1 parent 5c51301 commit 067dd19

File tree

45 files changed

+340
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+340
-201
lines changed

src/cdk/schematics/ng-add/index.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ describe('CDK ng-add', () => {
1717
const dependencies = packageJson.dependencies;
1818

1919
expect(dependencies['@angular/cdk']).toBeDefined();
20-
expect(Object.keys(dependencies)).toEqual(Object.keys(dependencies).sort(),
21-
'Expected the modified "dependencies" to be sorted alphabetically.');
20+
expect(Object.keys(dependencies))
21+
.toEqual(
22+
Object.keys(dependencies).sort(),
23+
'Expected the modified "dependencies" to be sorted alphabetically.');
2224
});
2325
});

src/cdk/schematics/ng-add/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function(): Rule {
2929
}
3030

3131
/** Loads the full version from the given Angular package gracefully. */
32-
function loadPackageVersionGracefully(packageName: string): string | null {
32+
function loadPackageVersionGracefully(packageName: string): string|null {
3333
try {
3434
return require(`${packageName}/package.json`).version;
3535
} catch {

src/cdk/schematics/ng-generate/drag-drop/index.spec.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ describe('CDK drag-drop schematic', () => {
4444

4545
describe('style option', () => {
4646
it('should respect the option value', async () => {
47-
const tree = await runner.runSchematicAsync(
48-
'drag-drop', {style: 'scss', ...baseOptions}, await createTestApp(runner)).toPromise();
47+
const tree =
48+
await runner
49+
.runSchematicAsync(
50+
'drag-drop', {style: 'scss', ...baseOptions}, await createTestApp(runner))
51+
.toPromise();
4952

5053
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
5154
});
@@ -68,21 +71,30 @@ describe('CDK drag-drop schematic', () => {
6871
});
6972

7073
it('should not generate invalid stylesheets', async () => {
71-
const tree = await runner.runSchematicAsync(
72-
'drag-drop', {style: 'styl', ...baseOptions}, await createTestApp(runner)).toPromise();
74+
const tree =
75+
await runner
76+
.runSchematicAsync(
77+
'drag-drop', {style: 'styl', ...baseOptions}, await createTestApp(runner))
78+
.toPromise();
7379

7480
// In this case we expect the schematic to generate a plain "css" file because
7581
// the component schematics are using CSS style templates which are not compatible
7682
// with all CLI supported styles (e.g. Stylus or Sass)
77-
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.css',
78-
'Expected the schematic to generate a plain "css" file.');
79-
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.styl',
80-
'Expected the schematic to not generate a "stylus" file');
83+
expect(tree.files)
84+
.toContain(
85+
'/projects/material/src/app/foo/foo.component.css',
86+
'Expected the schematic to generate a plain "css" file.');
87+
expect(tree.files)
88+
.not.toContain(
89+
'/projects/material/src/app/foo/foo.component.styl',
90+
'Expected the schematic to not generate a "stylus" file');
8191
});
8292

8393
it('should fall back to the @schematics/angular:component option value', async () => {
84-
const tree = await runner.runSchematicAsync(
85-
'drag-drop', baseOptions, await createTestApp(runner, {style: 'less'})).toPromise();
94+
const tree = await runner
95+
.runSchematicAsync(
96+
'drag-drop', baseOptions, await createTestApp(runner, {style: 'less'}))
97+
.toPromise();
8698

8799
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.less');
88100
});
@@ -91,15 +103,19 @@ describe('CDK drag-drop schematic', () => {
91103
describe('inlineStyle option', () => {
92104
it('should respect the option value', async () => {
93105
const app = await createTestApp(runner);
94-
const tree = await runner.runSchematicAsync(
95-
'drag-drop', {inlineStyle: true, ...baseOptions}, app).toPromise();
106+
const tree =
107+
await runner.runSchematicAsync('drag-drop', {inlineStyle: true, ...baseOptions}, app)
108+
.toPromise();
96109

97110
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
98111
});
99112

100113
it('should fall back to the @schematics/angular:component option value', async () => {
101-
const tree = await runner.runSchematicAsync(
102-
'drag-drop', baseOptions, await createTestApp(runner, {inlineStyle: true})).toPromise();
114+
const tree =
115+
await runner
116+
.runSchematicAsync(
117+
'drag-drop', baseOptions, await createTestApp(runner, {inlineStyle: true}))
118+
.toPromise();
103119

104120
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
105121
});
@@ -108,8 +124,9 @@ describe('CDK drag-drop schematic', () => {
108124
describe('inlineTemplate option', () => {
109125
it('should respect the option value', async () => {
110126
const app = await createTestApp(runner);
111-
const tree = await runner.runSchematicAsync(
112-
'drag-drop', {inlineTemplate: true, ...baseOptions}, app).toPromise();
127+
const tree =
128+
await runner.runSchematicAsync('drag-drop', {inlineTemplate: true, ...baseOptions}, app)
129+
.toPromise();
113130

114131
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
115132
});
@@ -124,8 +141,11 @@ describe('CDK drag-drop schematic', () => {
124141

125142
describe('skipTests option', () => {
126143
it('should respect the option value', async () => {
127-
const tree = await runner.runSchematicAsync(
128-
'drag-drop', {skipTests: true, ...baseOptions}, await createTestApp(runner)).toPromise();
144+
const tree =
145+
await runner
146+
.runSchematicAsync(
147+
'drag-drop', {skipTests: true, ...baseOptions}, await createTestApp(runner))
148+
.toPromise();
129149

130150
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
131151
});
@@ -148,8 +168,10 @@ describe('CDK drag-drop schematic', () => {
148168
});
149169

150170
it('should fall back to the @schematics/angular:component option value', async () => {
151-
const tree = await runner.runSchematicAsync(
152-
'drag-drop', baseOptions, await createTestApp(runner, {skipTests: true})).toPromise();
171+
const tree = await runner
172+
.runSchematicAsync(
173+
'drag-drop', baseOptions, await createTestApp(runner, {skipTests: true}))
174+
.toPromise();
153175

154176
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
155177
});

src/cdk/schematics/ng-generate/drag-drop/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import {Schema} from './schema';
1414
export default function(options: Schema): Rule {
1515
return chain([
1616
buildComponent({...options}, {
17-
template: './__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html',
18-
stylesheet: './__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__style__',
17+
template: './__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template',
18+
stylesheet:
19+
'./__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__style__.template',
1920
}),
2021
options.skipImport ? noop() : addDragDropModulesToModule(options)
2122
]);

src/cdk/schematics/ng-update/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export function postUpdate(): Rule {
4646
console.log();
4747
console.log(green(' ✓ Angular CDK update complete'));
4848
console.log();
49-
console.log(yellow(' ⚠ Please check the output above for any issues that were detected ' +
50-
'but could not be automatically fixed.'));
49+
console.log(yellow(
50+
' ⚠ Please check the output above for any issues that were detected ' +
51+
'but could not be automatically fixed.'));
5152
};
5253
}

src/cdk/schematics/utils/build-component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {strings, template as interpolateTemplate} from '@angular-devkit/core';
1010
import {
1111
apply,
12+
applyTemplates,
1213
branchAndMerge,
1314
chain,
1415
filter,
@@ -17,7 +18,6 @@ import {
1718
noop,
1819
Rule,
1920
SchematicsException,
20-
template,
2121
Tree,
2222
url,
2323
} from '@angular-devkit/schematics';
@@ -238,12 +238,12 @@ export function buildComponent(options: ComponentOptions,
238238
}
239239

240240
const templateSource = apply(url(schematicFilesUrl), [
241-
options.skipTests ? filter(path => !path.endsWith('.spec.ts')) : noop(),
242-
options.inlineStyle ? filter(path => !path.endsWith('.__style__')) : noop(),
243-
options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
241+
options.skipTests ? filter(path => !path.endsWith('.spec.ts.template')) : noop(),
242+
options.inlineStyle ? filter(path => !path.endsWith('.__style__.template')) : noop(),
243+
options.inlineTemplate ? filter(path => !path.endsWith('.html.template')) : noop(),
244244
// Treat the template options as any, because the type definition for the template options
245245
// is made unnecessarily explicit. Every type of object can be used in the EJS template.
246-
template({indentTextContent, resolvedFiles, ...baseTemplateContext} as any),
246+
applyTemplates({indentTextContent, resolvedFiles, ...baseTemplateContext} as any),
247247
// TODO(devversion): figure out why we cannot just remove the first parameter
248248
// See for example: angular-cli#schematics/angular/component/index.ts#L160
249249
move(null as any, parsedPath.path),

0 commit comments

Comments
 (0)