@@ -5,17 +5,24 @@ import {
55 chain ,
66 schematic ,
77 SchematicsException ,
8+ template ,
9+ mergeWith ,
10+ apply ,
11+ url ,
12+ move ,
813} from '@angular-devkit/schematics' ;
914import { addProviderToModule } from '@schematics/angular/utility/ast-utils' ;
1015import { 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' ;
1118
1219import { addExtension } from '../utils' ;
1320import { getSourceFile } from '../ts-utils' ;
1421import { getNsConfigExtension } from '../generate/utils' ;
1522import { parseModuleInfo , ModuleInfo } from './module-info-utils' ;
1623
17- import { Schema as ModuleSchema } from '../generate/module/schema' ;
1824import { Schema as MigrateComponentSchema } from '../migrate-component/schema' ;
25+ import { Schema as CommonModuleSchema } from '../generate/common-module/schema' ;
1926import { Schema as ConvertRelativeImportsSchema } from '../convert-relative-imports/schema' ;
2027import { Schema as MigrateModuleSchema } from './schema' ;
2128
@@ -36,30 +43,52 @@ export default function(options: MigrateModuleSchema): Rule {
3643 moduleInfo = parseModuleInfo ( options ) ( tree , context ) ;
3744 } ,
3845
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+ } ,
4051
4152 ( tree , context ) => migrateComponents ( moduleInfo , options ) ( tree , context ) ,
4253 migrateProviders ( ) ,
4354
55+ ( ) => addCommonModuleFile ( options , moduleInfo ) ,
56+
4457 schematic < ConvertRelativeImportsSchema > ( 'convert-relative-imports' , options ) ,
4558 ] ) ;
4659}
4760
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+
4873const 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+ } ;
6088
6189const 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 ) ) ;
6392
6493 return chain (
6594 components . map ( ( component ) => {
0 commit comments