diff --git a/packages/schematics/src/collection/lib/index.ts b/packages/schematics/src/collection/lib/index.ts index 9bef3051793d2..0d02f66371022 100644 --- a/packages/schematics/src/collection/lib/index.ts +++ b/packages/schematics/src/collection/lib/index.ts @@ -235,7 +235,7 @@ function addChildren(schema: NormalizedSchema): Rule { export default function(schema: Schema): Rule { return wrapIntoFormat(() => { const options = normalizeOptions(schema); - const moduleFileName = `${toFileName(options.name)}.module`; + const moduleFileName = `${options.moduleName}.module`; const modulePath = `${options.fullPath}/${moduleFileName}.ts`; const indexFile = `libs/${toFileName(options.fullName)}/index.ts`; @@ -251,7 +251,7 @@ export default function(schema: Schema): Rule { url(options.nomodule ? './files' : './ngfiles'), [ template({ - ...names(options.name), + ...names(options.moduleName), dot: '.', tmpl: '', ...(options as object) @@ -284,6 +284,9 @@ function normalizeOptions(options: Schema): NormalizedSchema { const fullName = options.directory ? `${toFileName(options.directory)}/${name}` : name; + const moduleName = options.moduleName + ? toFileName(options.moduleName) + : toFileName(options.name); const fullPath = `libs/${fullName}/src`; - return { ...options, sourceDir: 'src', name, fullName, fullPath }; + return { ...options, sourceDir: 'src', name, fullName, fullPath, moduleName }; } diff --git a/packages/schematics/src/collection/lib/lib.spec.ts b/packages/schematics/src/collection/lib/lib.spec.ts index efc5a81bf6059..6935f20624fb5 100644 --- a/packages/schematics/src/collection/lib/lib.spec.ts +++ b/packages/schematics/src/collection/lib/lib.spec.ts @@ -41,7 +41,7 @@ describe('lib', () => { ]); }); - it('should generate files', () => { + it('should generate files when nomodule = true', () => { const tree = schematicRunner.runSchematic( 'lib', { name: 'myLib', nomodule: true }, @@ -68,6 +68,20 @@ describe('lib', () => { getFileContent(tree, 'libs/my-lib/src/my-lib.module.ts') ).toContain('class MyLibModule'); }); + + it('should generate files when moduleName is set', () => { + const tree = schematicRunner.runSchematic( + 'lib', + { name: 'myLib', moduleName: 'other' }, + appTree + ); + expect(tree.exists('libs/my-lib/src/other.module.ts')).toBeTruthy(); + expect(tree.exists('libs/my-lib/src/other.module.spec.ts')).toBeTruthy(); + expect(tree.exists('libs/my-lib/index.ts')).toBeTruthy(); + expect(getFileContent(tree, 'libs/my-lib/src/other.module.ts')).toContain( + 'class OtherModule' + ); + }); }); describe('nested', () => { diff --git a/packages/schematics/src/collection/lib/schema.d.ts b/packages/schematics/src/collection/lib/schema.d.ts index 34f47890684f3..37c0ab1a70bab 100644 --- a/packages/schematics/src/collection/lib/schema.d.ts +++ b/packages/schematics/src/collection/lib/schema.d.ts @@ -1,5 +1,6 @@ export interface Schema { name: string; + moduleName: string; directory?: string; sourceDir?: string; nomodule: boolean; diff --git a/packages/schematics/src/collection/lib/schema.json b/packages/schematics/src/collection/lib/schema.json index 50f7e95cccb18..c680806666d0c 100644 --- a/packages/schematics/src/collection/lib/schema.json +++ b/packages/schematics/src/collection/lib/schema.json @@ -12,6 +12,10 @@ "type": "string", "description": "A directory where the app is placed" }, + "moduleName": { + "type": "string", + "description": "A module name" + }, "nomodule": { "type": "boolean", "default": false,