Skip to content

Commit eeb2138

Browse files
committed
feat(cli): add a --prefix option to generate module
when set, --prefix=foo will add a ``export const ModulePrefix = 'foo';`` to the .module.ts file see angular#3452
1 parent 3bd33dc commit eeb2138

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

packages/angular-cli/blueprints/module/files/__path__/__name__.module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';<% if (routing) { %>
33
import { <%= classifiedModuleName %>RoutingModule } from './<%= dasherizedModuleName %>-routing.module';<% } %>
44

5+
<% if (prefix) { %>
6+
export const ModulePrefix = '<%= prefix %>';
7+
<% } %>
58
@NgModule({
69
imports: [
710
CommonModule<% if (routing) { %>,

packages/angular-cli/blueprints/module/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = {
88

99
availableOptions: [
1010
{ name: 'spec', type: Boolean },
11-
{ name: 'routing', type: Boolean, default: false }
11+
{ name: 'routing', type: Boolean, default: false },
12+
{ name: 'prefix', type: String, default: null}
1213
],
1314

1415
normalizeEntityName: function (entityName) {
@@ -27,7 +28,8 @@ module.exports = {
2728
return {
2829
dynamicPath: this.dynamicPath.dir,
2930
spec: options.spec,
30-
routing: options.routing
31+
routing: options.routing,
32+
prefix: options.prefix
3133
};
3234
},
3335

tests/acceptance/generate-module.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const ng = require('../helpers/ng');
44
const tmp = require('../helpers/tmp');
5+
var fs = require('fs-extra');
6+
57

68
const existsSync = require('exists-sync');
79
const expect = require('chai').expect;
@@ -36,6 +38,7 @@ describe('Acceptance: ng generate module', function () {
3638
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
3739
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
3840
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false);
41+
3942
});
4043
});
4144

@@ -55,6 +58,15 @@ describe('Acceptance: ng generate module', function () {
5558
});
5659
});
5760

61+
it('ng generate module my-module --prefix=my', function () {
62+
return ng(['generate', 'module', 'my-module', '--prefix=my']).then(() => {
63+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
64+
var contents = fs.readFileSync(path.join(testPath, 'my-module', 'my-module.module.ts'), 'utf8');
65+
expect(contents.indexOf('export const ModulePrefix = \'my\';') === -1).to.equal(false);
66+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
67+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false); });
68+
});
69+
5870
it('ng generate module TwoWord', function () {
5971
return ng(['generate', 'module', 'TwoWord']).then(() => {
6072
expect(existsSync(path.join(testPath, 'two-word', 'two-word.module.ts'))).to.equal(true);

0 commit comments

Comments
 (0)