Mike Brocchi 9db71d870f fix(@angular/cli): remove component generation from module generation (#4706)
Fixes #4209

BREAKING CHANGE: Generating a module with routing will no longer generate an associated component.
2017-02-15 22:26:49 -05:00

66 lines
1.8 KiB
TypeScript

const path = require('path');
const Blueprint = require('../../ember-cli/lib/models/blueprint');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const getFiles = Blueprint.prototype.files;
export default Blueprint.extend({
description: '',
availableOptions: [
{ name: 'spec', type: Boolean },
{ name: 'flat', type: Boolean },
{ name: 'routing', type: Boolean, default: false }
],
normalizeEntityName: function (entityName: string) {
this.entityName = entityName;
const parsedPath = dynamicPathParser(this.project, entityName);
this.dynamicPath = parsedPath;
return parsedPath.name;
},
locals: function (options: any) {
options.flat = options.flat !== undefined ?
options.flat :
this.project.ngConfigObj.get('defaults.module.flat');
options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.module.spec');
return {
dynamicPath: this.dynamicPath.dir,
spec: options.spec,
routing: options.routing
};
},
files: function() {
let fileList = getFiles.call(this) as Array<string>;
if (!this.options || !this.options.spec) {
fileList = fileList.filter(p => p.indexOf('__name__.module.spec.ts') < 0);
}
if (this.options && !this.options.routing) {
fileList = fileList.filter(p => p.indexOf('__name__-routing.module.ts') < 0);
}
return fileList;
},
fileMapTokens: function (options: any) {
// Return custom template variables here.
this.dasherizedModuleName = options.dasherizedModuleName;
return {
__path__: () => {
this.generatePath = this.dynamicPath.dir;
if (!options.locals.flat) {
this.generatePath += path.sep + options.dasherizedModuleName;
}
return this.generatePath;
}
};
}
});