Hans c57ce2a3a0 fix(@angular/cli): apps fixes (#4942)
We dont have ngConfig on projects anymore.
2017-02-23 10:03:42 +00:00

92 lines
2.5 KiB
TypeScript

import {CliConfig} from '../../models/config';
import {getAppFromConfig} from '../../utilities/app-utils';
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,
description: 'Specifies if a spec file is generated.'
},
{
name: 'flat',
type: Boolean,
description: 'Flag to indicate if a dir is created.'
},
{
name: 'routing',
type: Boolean,
default: false,
description: 'Specifies if a routing module file should be generated.'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],
normalizeEntityName: function (entityName: string) {
this.entityName = entityName;
const cliConfig = CliConfig.fromProject();
const ngConfig = cliConfig && cliConfig.config;
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
this.dynamicPath = parsedPath;
return parsedPath.name;
},
locals: function (options: any) {
const cliConfig = CliConfig.fromProject();
options.flat = options.flat !== undefined ?
options.flat :
cliConfig && cliConfig.get('defaults.module.flat');
options.spec = options.spec !== undefined ?
options.spec :
cliConfig && cliConfig.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;
}
};
}
});