Skip to content

Commit f40e6f1

Browse files
Broccofilipesilva
authored andcommitted
feat(module): add generation of modules
Close #1650
1 parent 6b7dea8 commit f40e6f1

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import <%= classifiedModuleName %>Module from './<%= dasherizedModuleName %>.module';
4+
5+
describe('<%= classifiedModuleName %>Module', () => {
6+
let <%= camelizedModuleName %>Module;
7+
8+
beforeEach(() => {
9+
<%= camelizedModuleName %>Module = new <%= classifiedModuleName %>Module();
10+
});
11+
12+
it('should create an instance', () => {
13+
expect(<%= camelizedModuleName %>Module).toBeTruthy();
14+
})
15+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
@NgModule({
5+
imports: [ CommonModule ],
6+
declarations: []
7+
})
8+
export default class <%= classifiedModuleName %>Module { }

addon/ng2/blueprints/module/index.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
2+
var Blueprint = require('ember-cli/lib/models/blueprint');
3+
var getFiles = Blueprint.prototype.files;
4+
5+
module.exports = {
6+
description: '',
7+
8+
availableOptions: [
9+
{ name: 'spec', type: Boolean, default: false }
10+
],
11+
12+
normalizeEntityName: function (entityName) {
13+
var parsedPath = dynamicPathParser(this.project, entityName);
14+
15+
this.dynamicPath = parsedPath;
16+
return parsedPath.name;
17+
},
18+
19+
locals: function (options) {
20+
return {
21+
dynamicPath: this.dynamicPath.dir,
22+
spec: options.spec
23+
};
24+
},
25+
26+
files: function() {
27+
var fileList = getFiles.call(this);
28+
29+
if (!this.options || !this.options.spec) {
30+
fileList = fileList.filter(p => p.indexOf('__name__.module.spec.ts') < 0);
31+
}
32+
33+
return fileList;
34+
},
35+
36+
fileMapTokens: function () {
37+
// Return custom template variables here.
38+
return {
39+
__path__: () => {
40+
this.generatePath = this.dynamicPath.dir;
41+
return this.generatePath;
42+
}
43+
};
44+
}
45+
};

addon/ng2/commands/generate.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const aliasMap = {
5353
'c': 'component',
5454
'd': 'directive',
5555
'e': 'enum',
56+
'm': 'module',
5657
'p': 'pipe',
5758
'r': 'route',
5859
's': 'service'
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
3+
const ng = require('../helpers/ng');
4+
const tmp = require('../helpers/tmp');
5+
6+
const conf = require('ember-cli/tests/helpers/conf');
7+
const existsSync = require('exists-sync');
8+
const expect = require('chai').expect;
9+
const path = require('path');
10+
const root = process.cwd();
11+
12+
const testPath = path.join(root, 'tmp', 'foo', 'src', 'app');
13+
14+
describe('Acceptance: ng generate module', function () {
15+
before(conf.setup);
16+
17+
after(conf.restore);
18+
19+
beforeEach(function () {
20+
return tmp.setup('./tmp').then(function () {
21+
process.chdir('./tmp');
22+
}).then(function () {
23+
return ng(['new', 'foo', '--skip-npm', '--skip-bower']);
24+
});
25+
});
26+
27+
afterEach(function () {
28+
this.timeout(10000);
29+
30+
return tmp.teardown('./tmp');
31+
});
32+
33+
it('ng generate module my-module', function () {
34+
return ng(['generate', 'module', 'my-module']).then(() => {
35+
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
36+
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(false);
37+
});
38+
});
39+
40+
it('ng generate module my-module --spec', function () {
41+
return ng(['generate', 'module', 'my-module', '--spec']).then(() => {
42+
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
43+
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(true);
44+
});
45+
});
46+
47+
it(`ng generate module shared${path.sep}my-module`, function () {
48+
return ng(['generate', 'module', 'shared/my-module']).then(() => {
49+
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.ts'))).to.equal(true);
50+
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.spec.ts'))).to.equal(false);
51+
});
52+
});
53+
54+
it(`ng generate module shared${path.sep}my-module --spec`, function () {
55+
return ng(['generate', 'module', 'shared/my-module', '--spec']).then(() => {
56+
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.ts'))).to.equal(true);
57+
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.spec.ts'))).to.equal(true);
58+
});
59+
});
60+
});

0 commit comments

Comments
 (0)