|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import {WorkspaceProject} from '@schematics/angular/utility/config';
|
10 |
| -import {Schema as ComponentOptions} from '@schematics/angular/component/schema'; |
11 | 10 |
|
12 | 11 | /**
|
13 |
| - * Looks for options that are not explicitly specified but can fall back to a default value that |
14 |
| - * has been specified at project initialization (ng new or ng init). |
| 12 | + * Returns the default options for the `@schematics/angular:component` schematic which would |
| 13 | + * have been specified at project initialization (ng new or ng init). |
15 | 14 | *
|
16 | 15 | * This is necessary because the Angular CLI only exposes the default values for the "--style",
|
17 | 16 | * "--inlineStyle", "--skipTests" and "--inlineTemplate" options to the "component" schematic.
|
18 | 17 | */
|
19 |
| -export function setDefaultSchematicOptions(project: WorkspaceProject, |
20 |
| - options: ComponentOptions) { |
21 |
| - |
| 18 | +export function getDefaultComponentOptions(project: WorkspaceProject) { |
22 | 19 | // Note: Not all options which are available when running "ng new" will be stored in the
|
23 |
| - // workspace config. List of options which will be stored in the configuration: |
| 20 | + // workspace config. List of options which will be available in the configuration: |
24 | 21 | // angular/angular-cli/blob/master/packages/schematics/angular/application/index.ts#L109-L131
|
25 |
| - |
26 |
| - if (!options.styleext) { |
27 |
| - options.styleext = getDefaultSchematicOption(project, 'styleext', 'css'); |
28 |
| - } |
29 |
| - |
30 |
| - if (options.inlineStyle === undefined) { |
31 |
| - options.inlineStyle = getDefaultSchematicOption(project, 'inlineStyle', false); |
32 |
| - } |
33 |
| - |
34 |
| - if (options.inlineTemplate === undefined) { |
35 |
| - options.inlineTemplate = getDefaultSchematicOption(project, 'inlineTemplate', false); |
36 |
| - } |
37 |
| - |
38 |
| - if (options.spec === undefined) { |
39 |
| - options.spec = getDefaultSchematicOption(project, 'spec', true); |
40 |
| - } |
| 22 | + return { |
| 23 | + styleext: getDefaultComponentOption(project, 'styleext', 'css'), |
| 24 | + inlineStyle: getDefaultComponentOption(project, 'inlineStyle', false), |
| 25 | + inlineTemplate: getDefaultComponentOption(project, 'inlineTemplate', false), |
| 26 | + spec: getDefaultComponentOption(project, 'spec', true), |
| 27 | + }; |
41 | 28 | }
|
42 | 29 |
|
43 | 30 | /**
|
44 | 31 | * Gets the default value for the specified option. The default options will be determined
|
45 | 32 | * by looking at the stored schematic options for `@schematics/angular:component` in the
|
46 | 33 | * CLI workspace configuration.
|
47 | 34 | */
|
48 |
| -function getDefaultSchematicOption<T>(project: WorkspaceProject, optionName: string, |
| 35 | +function getDefaultComponentOption<T>(project: WorkspaceProject, optionName: string, |
49 | 36 | fallbackValue: T): T | null {
|
50 | 37 | if (project.schematics &&
|
51 | 38 | project.schematics['@schematics/angular:component'] &&
|
52 |
| - project.schematics['@schematics/angular:component'][optionName] !== undefined) { |
| 39 | + project.schematics['@schematics/angular:component'][optionName] != null) { |
53 | 40 |
|
54 | 41 | return project.schematics['@schematics/angular:component'][optionName];
|
55 | 42 | }
|
|
0 commit comments