Skip to content

Commit

Permalink
feat(cli): add a --prefix option to generate module
Browse files Browse the repository at this point in the history
when set, --prefix=foo will add a ``export const ModulePrefix = 'foo';`` to the
.module.ts file

see angular#3452
  • Loading branch information
nlm-pro committed Dec 14, 2016
1 parent 3bd33dc commit eeb2138
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) { %>,
Expand Down
6 changes: 4 additions & 2 deletions packages/angular-cli/blueprints/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -27,7 +28,8 @@ module.exports = {
return {
dynamicPath: this.dynamicPath.dir,
spec: options.spec,
routing: options.routing
routing: options.routing,
prefix: options.prefix
};
},

Expand Down
12 changes: 12 additions & 0 deletions tests/acceptance/generate-module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

});
});

Expand All @@ -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);
Expand Down

0 comments on commit eeb2138

Please sign in to comment.