diff --git a/packages/angular-cli/blueprints/module/files/__path__/__name__.module.ts b/packages/angular-cli/blueprints/module/files/__path__/__name__.module.ts index 2505c216531f..ce04effc1689 100644 --- a/packages/angular-cli/blueprints/module/files/__path__/__name__.module.ts +++ b/packages/angular-cli/blueprints/module/files/__path__/__name__.module.ts @@ -2,6 +2,9 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common';<% if (routing) { %> import { <%= classifiedModuleName %>RoutingModule } from './<%= dasherizedModuleName %>-routing.module';<% } %> +<% if (prefix) { %> +export const ModulePrefix = '<%= prefix %>'; +<% } %> @NgModule({ imports: [ CommonModule<% if (routing) { %>, diff --git a/packages/angular-cli/blueprints/module/index.js b/packages/angular-cli/blueprints/module/index.js index 035a1355d7f2..95609eebfc10 100644 --- a/packages/angular-cli/blueprints/module/index.js +++ b/packages/angular-cli/blueprints/module/index.js @@ -8,7 +8,8 @@ module.exports = { availableOptions: [ { name: 'spec', type: Boolean }, - { name: 'routing', type: Boolean, default: false } + { name: 'routing', type: Boolean, default: false }, + { name: 'prefix', type: String, default: null} ], normalizeEntityName: function (entityName) { @@ -27,7 +28,8 @@ module.exports = { return { dynamicPath: this.dynamicPath.dir, spec: options.spec, - routing: options.routing + routing: options.routing, + prefix: options.prefix }; }, diff --git a/tests/acceptance/generate-module.spec.js b/tests/acceptance/generate-module.spec.js index a4e38274da4c..28eab5e399d2 100644 --- a/tests/acceptance/generate-module.spec.js +++ b/tests/acceptance/generate-module.spec.js @@ -2,6 +2,8 @@ const ng = require('../helpers/ng'); const tmp = require('../helpers/tmp'); +var fs = require('fs-extra'); + const existsSync = require('exists-sync'); const expect = require('chai').expect; @@ -36,6 +38,7 @@ describe('Acceptance: ng generate module', function () { expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true); expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false); expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false); + }); }); @@ -55,6 +58,15 @@ describe('Acceptance: ng generate module', function () { }); }); + it('ng generate module my-module --prefix=my', function () { + return ng(['generate', 'module', 'my-module', '--prefix=my']).then(() => { + expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true); + var contents = fs.readFileSync(path.join(testPath, 'my-module', 'my-module.module.ts'), 'utf8'); + expect(contents.indexOf('export const ModulePrefix = \'my\';') === -1).to.equal(false); + expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false); + expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false); }); + }); + it('ng generate module TwoWord', function () { return ng(['generate', 'module', 'TwoWord']).then(() => { expect(existsSync(path.join(testPath, 'two-word', 'two-word.module.ts'))).to.equal(true);