forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
83 lines (70 loc) · 2.77 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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: '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.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() {
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
+ path.sep
+ options.dasherizedModuleName;
return this.generatePath;
}
};
},
afterInstall: function (options: any) {
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`
const 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);
}
}
});