angular-cli
Version:
CLI tool for Angular
74 lines • 3.32 kB
JavaScript
"use strict";
var path = require('path');
var Blueprint = require('../../ember-cli/lib/models/blueprint');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var getFiles = Blueprint.prototype.files;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Blueprint.extend({
description: '',
availableOptions: [
{ name: 'spec', type: Boolean },
{ name: 'routing', type: Boolean, default: false }
],
normalizeEntityName: function (entityName) {
this.entityName = entityName;
var parsedPath = dynamicPathParser(this.project, entityName);
this.dynamicPath = parsedPath;
return parsedPath.name;
},
locals: function (options) {
options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.module');
return {
dynamicPath: this.dynamicPath.dir,
spec: options.spec,
routing: options.routing
};
},
files: function () {
var fileList = getFiles.call(this);
if (!this.options || !this.options.spec) {
fileList = fileList.filter(function (p) { return p.indexOf('__name__.module.spec.ts') < 0; });
}
if (this.options && !this.options.routing) {
fileList = fileList.filter(function (p) { return p.indexOf('__name__-routing.module.ts') < 0; });
}
return fileList;
},
fileMapTokens: function (options) {
var _this = this;
// Return custom template variables here.
this.dasherizedModuleName = options.dasherizedModuleName;
return {
__path__: function () {
_this.generatePath = _this.dynamicPath.dir
+ path.sep
+ options.dasherizedModuleName;
return _this.generatePath;
}
};
},
afterInstall: function (options) {
if (this.options && this.options.routing) {
// Component folder needs to be `/{moduleName}/{ComponentName}`
// Note that we are using `flat`, so no extra dir will be created
// We need the leading `/` so the component path resolution work for both cases below:
// 1. If module name has no path (no `/`), that's going to be `/mod-name/mod-name`
// as `this.dynamicPath.dir` will be the same as `this.dynamicPath.appRoot`
// 2. If it does have `/` (like `parent/mod-name`), it'll be `/parent/mod-name/mod-name`
// as `this.dynamicPath.dir` minus `this.dynamicPath.appRoot` will be `/parent`
var moduleDir = this.dynamicPath.dir.replace(this.dynamicPath.appRoot, '')
+ path.sep + this.dasherizedModuleName;
options.entity.name = moduleDir + path.sep + this.dasherizedModuleName;
options.flat = true;
options.route = false;
options.inlineTemplate = false;
options.inlineStyle = false;
options.prefix = null;
options.spec = true;
return Blueprint.load(path.join(__dirname, '../component')).install(options);
}
}
});
//# sourceMappingURL=/Users/hans/Sources/angular-cli/packages/angular-cli/blueprints/module/index.js.map