UNPKG

1.69 kBPlain TextView Raw
1const stringUtils = require('ember-cli-string-utils');
2const dynamicPathParser = require('../../utilities/dynamic-path-parser');
3const Blueprint = require('../../ember-cli/lib/models/blueprint');
4const getFiles = Blueprint.prototype.files;
5
6export default Blueprint.extend({
7 description: '',
8
9 availableOptions: [
10 { name: 'spec', type: Boolean }
11 ],
12
13 normalizeEntityName: function (entityName: string) {
14 const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]);
15
16 this.dynamicPath = parsedPath;
17 return parsedPath.name;
18 },
19
20 locals: function (options: any) {
21 const rawName = options.args[1] as string;
22 const nameParts = rawName.split('.')
23 .filter(part => part.length !== 0);
24
25 const classType = nameParts[1];
26 this.fileName = stringUtils.dasherize(options.entity.name);
27 if (classType) {
28 this.fileName += '.' + classType.toLowerCase();
29 }
30
31 options.spec = options.spec !== undefined ?
32 options.spec :
33 this.project.ngConfigObj.get('defaults.spec.class');
34
35 return {
36 dynamicPath: this.dynamicPath.dir,
37 flat: options.flat,
38 fileName: this.fileName
39 };
40 },
41
42 files: function() {
43 let fileList = getFiles.call(this) as Array<string>;
44
45 if (this.options && !this.options.spec) {
46 fileList = fileList.filter(p => p.indexOf('__name__.spec.ts') < 0);
47 }
48
49 return fileList;
50 },
51
52 fileMapTokens: function () {
53 // Return custom template variables here.
54 return {
55 __path__: () => {
56 this.generatePath = this.dynamicPath.dir;
57 return this.generatePath;
58 },
59 __name__: () => {
60 return this.fileName;
61 }
62 };
63 }
64});