@@ -5,17 +5,24 @@ import {
5
5
chain ,
6
6
schematic ,
7
7
SchematicsException ,
8
+ template ,
9
+ mergeWith ,
10
+ apply ,
11
+ url ,
12
+ move ,
8
13
} from '@angular-devkit/schematics' ;
9
14
import { addProviderToModule } from '@schematics/angular/utility/ast-utils' ;
10
15
import { InsertChange } from '@schematics/angular/utility/change' ;
16
+ import { dasherize , classify } from '@angular-devkit/core/src/utils/strings' ;
17
+ import { dirname , Path } from '@angular-devkit/core' ;
11
18
12
19
import { addExtension } from '../utils' ;
13
20
import { getSourceFile } from '../ts-utils' ;
14
21
import { getNsConfigExtension } from '../generate/utils' ;
15
22
import { parseModuleInfo , ModuleInfo } from './module-info-utils' ;
16
23
17
- import { Schema as ModuleSchema } from '../generate/module/schema' ;
18
24
import { Schema as MigrateComponentSchema } from '../migrate-component/schema' ;
25
+ import { Schema as CommonModuleSchema } from '../generate/common-module/schema' ;
19
26
import { Schema as ConvertRelativeImportsSchema } from '../convert-relative-imports/schema' ;
20
27
import { Schema as MigrateModuleSchema } from './schema' ;
21
28
@@ -36,30 +43,52 @@ export default function(options: MigrateModuleSchema): Rule {
36
43
moduleInfo = parseModuleInfo ( options ) ( tree , context ) ;
37
44
} ,
38
45
39
- addModuleFile ( options . name , options . project ) ,
46
+ ( tree ) => {
47
+ const moduleDir = dirname ( moduleInfo . modulePath as Path ) ;
48
+
49
+ return addModuleFile ( options . name , nsext , moduleDir ) ( tree ) ;
50
+ } ,
40
51
41
52
( tree , context ) => migrateComponents ( moduleInfo , options ) ( tree , context ) ,
42
53
migrateProviders ( ) ,
43
54
55
+ ( ) => addCommonModuleFile ( options , moduleInfo ) ,
56
+
44
57
schematic < ConvertRelativeImportsSchema > ( 'convert-relative-imports' , options ) ,
45
58
] ) ;
46
59
}
47
60
61
+ const addCommonModuleFile = ( options , modInfo ) => {
62
+ const { name } = options ;
63
+ const { modulePath } = modInfo ;
64
+ const moduleDirectory = dirname ( modulePath ) ;
65
+ const commonModuleOptions = {
66
+ name,
67
+ path : moduleDirectory ,
68
+ } ;
69
+
70
+ return schematic < CommonModuleSchema > ( 'common-module' , commonModuleOptions ) ;
71
+ } ;
72
+
48
73
const addModuleFile =
49
- ( name : string , project : string ) =>
50
- ( tree : Tree , context : SchematicContext ) =>
51
- schematic ( 'module' , {
52
- name,
53
- project,
54
- nsExtension : nsext ,
55
- flat : false ,
56
- web : false ,
57
- spec : false ,
58
- common : true ,
59
- } ) ( tree , context ) ;
74
+ ( name : string , nsExtension : string , path : string ) =>
75
+ ( _tree : Tree ) => {
76
+ const templateSource = apply ( url ( './_ns-files' ) , [
77
+ template ( {
78
+ name,
79
+ nsext : nsExtension ,
80
+ dasherize,
81
+ classify,
82
+ } ) ,
83
+ move ( path ) ,
84
+ ] ) ;
85
+
86
+ return mergeWith ( templateSource ) ;
87
+ } ;
60
88
61
89
const migrateComponents = ( modInfo : ModuleInfo , options : MigrateModuleSchema ) => {
62
- const components = modInfo . declarations . filter ( ( d ) => d . name . endsWith ( 'Component' ) ) ;
90
+ const isComponent = ( className : string ) => className . endsWith ( 'Component' ) ;
91
+ const components = modInfo . declarations . filter ( ( { name } ) => isComponent ( name ) ) ;
63
92
64
93
return chain (
65
94
components . map ( ( component ) => {
0 commit comments