Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions addon/ng2/blueprints/module/files/__path__/__name__.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* tslint:disable:no-unused-variable */

import <%= classifiedModuleName %>Module from './<%= dasherizedModuleName %>.module';

describe('<%= classifiedModuleName %>Module', () => {
let <%= camelizedModuleName %>Module;

beforeEach(() => {
<%= camelizedModuleName %>Module = new <%= classifiedModuleName %>Module();
});

it('should create an instance', () => {
expect(<%= camelizedModuleName %>Module).toBeTruthy();
})
});
8 changes: 8 additions & 0 deletions addon/ng2/blueprints/module/files/__path__/__name__.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
imports: [ CommonModule ],
declarations: []
})
export default class <%= classifiedModuleName %>Module { }
45 changes: 45 additions & 0 deletions addon/ng2/blueprints/module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var Blueprint = require('ember-cli/lib/models/blueprint');
var getFiles = Blueprint.prototype.files;

module.exports = {
description: '',

availableOptions: [
{ name: 'spec', type: Boolean, default: false }
],

normalizeEntityName: function (entityName) {
var parsedPath = dynamicPathParser(this.project, entityName);

this.dynamicPath = parsedPath;
return parsedPath.name;
},

locals: function (options) {
return {
dynamicPath: this.dynamicPath.dir,
spec: options.spec
};
},

files: function() {
var fileList = getFiles.call(this);

if (!this.options || !this.options.spec) {
fileList = fileList.filter(p => p.indexOf('__name__.module.spec.ts') < 0);
}

return fileList;
},

fileMapTokens: function () {
// Return custom template variables here.
return {
__path__: () => {
this.generatePath = this.dynamicPath.dir;
return this.generatePath;
}
};
}
};
1 change: 1 addition & 0 deletions addon/ng2/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const aliasMap = {
'c': 'component',
'd': 'directive',
'e': 'enum',
'm': 'module',
'p': 'pipe',
'r': 'route',
's': 'service'
Expand Down
60 changes: 60 additions & 0 deletions tests/acceptance/generate-module.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

const ng = require('../helpers/ng');
const tmp = require('../helpers/tmp');

const conf = require('ember-cli/tests/helpers/conf');
const existsSync = require('exists-sync');
const expect = require('chai').expect;
const path = require('path');
const root = process.cwd();

const testPath = path.join(root, 'tmp', 'foo', 'src', 'app');

describe('Acceptance: ng generate module', function () {
before(conf.setup);

after(conf.restore);

beforeEach(function () {
return tmp.setup('./tmp').then(function () {
process.chdir('./tmp');
}).then(function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower']);
});
});

afterEach(function () {
this.timeout(10000);

return tmp.teardown('./tmp');
});

it('ng generate module my-module', function () {
return ng(['generate', 'module', 'my-module']).then(() => {
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(false);
});
});

it('ng generate module my-module --spec', function () {
return ng(['generate', 'module', 'my-module', '--spec']).then(() => {
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(true);
});
});

it(`ng generate module shared${path.sep}my-module`, function () {
return ng(['generate', 'module', 'shared/my-module']).then(() => {
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.spec.ts'))).to.equal(false);
});
});

it(`ng generate module shared${path.sep}my-module --spec`, function () {
return ng(['generate', 'module', 'shared/my-module', '--spec']).then(() => {
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.spec.ts'))).to.equal(true);
});
});
});