|
9 | 9 | branchAndMerge,
|
10 | 10 | mergeWith,
|
11 | 11 | SchematicsException,
|
| 12 | + noop, |
12 | 13 | } from '@angular-devkit/schematics';
|
13 | 14 | import { InsertChange } from '@schematics/angular/utility/change';
|
14 | 15 | import { addDeclarationToModule } from '@schematics/angular/utility/ast-utils';
|
@@ -40,6 +41,9 @@ export default function(options: MigrateComponentSchema): Rule {
|
40 | 41 | (tree: Tree, context: SchematicContext) =>
|
41 | 42 | addNsFiles(componentInfo, options)(tree, context),
|
42 | 43 |
|
| 44 | + (tree: Tree, context: SchematicContext) => |
| 45 | + addNsStyle(componentInfo, options)(tree, context), |
| 46 | + |
43 | 47 | (tree: Tree) =>
|
44 | 48 | addComponentToNsModuleProviders(componentInfo, options)(tree)
|
45 | 49 | ]);
|
@@ -104,3 +108,23 @@ or if you just want to update the component without updating its module, then re
|
104 | 108 | );
|
105 | 109 | tree.commitUpdate(recorder);
|
106 | 110 | }
|
| 111 | + |
| 112 | +const addNsStyle = (componentInfo: ComponentInfo, options: MigrateComponentSchema) => (tree: Tree, context: SchematicContext) => { |
| 113 | + if (!componentInfo.componentStylePath || !options.style) { |
| 114 | + return noop; |
| 115 | + } |
| 116 | + |
| 117 | + context.logger.info('Adding {N} StyleSheet'); |
| 118 | + |
| 119 | + const templateOptions = { |
| 120 | + path: dirname(componentInfo.componentHtmlPath), |
| 121 | + styleFileName: basename(componentInfo.componentStylePath), |
| 122 | + |
| 123 | + addNsExtension: (path: string) => addExtension(path, extensions.ns), |
| 124 | + }; |
| 125 | + |
| 126 | + const templateSource = apply(url('./_ns-style'), [ |
| 127 | + template(templateOptions) |
| 128 | + ]); |
| 129 | + return branchAndMerge(mergeWith(templateSource))(tree, context); |
| 130 | +} |
0 commit comments