forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
64 lines (52 loc) · 1.65 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
const stringUtils = require('ember-cli-string-utils');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const Blueprint = require('../../ember-cli/lib/models/blueprint');
const getFiles = Blueprint.prototype.files;
export default Blueprint.extend({
description: '',
availableOptions: [
{ name: 'spec', type: Boolean }
],
normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]);
this.dynamicPath = parsedPath;
return parsedPath.name;
},
locals: function (options: any) {
const rawName = options.args[1] as string;
const nameParts = rawName.split('.')
.filter(part => part.length !== 0);
const classType = nameParts[1];
this.fileName = stringUtils.dasherize(options.entity.name);
if (classType) {
this.fileName += '.' + classType.toLowerCase();
}
options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.class');
return {
dynamicPath: this.dynamicPath.dir,
flat: options.flat,
fileName: this.fileName
};
},
files: function() {
let fileList = getFiles.call(this) as Array<string>;
if (this.options && !this.options.spec) {
fileList = fileList.filter(p => p.indexOf('__name__.spec.ts') < 0);
}
return fileList;
},
fileMapTokens: function () {
// Return custom template variables here.
return {
__path__: () => {
this.generatePath = this.dynamicPath.dir;
return this.generatePath;
},
__name__: () => {
return this.fileName;
}
};
}
});