-
Notifications
You must be signed in to change notification settings - Fork 12k
/
index.js
84 lines (73 loc) · 2.75 KB
/
index.js
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
84
const Blueprint = require('ember-cli/lib/models/blueprint');
const path = require('path');
const stringUtils = require('ember-cli-string-utils');
const getFiles = Blueprint.prototype.files;
module.exports = {
description: '',
availableOptions: [
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'style', type: String, default: 'css' },
{ name: 'mobile', type: Boolean, default: false },
{ name: 'routing', type: Boolean, default: false },
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
],
afterInstall: function (options) {
if (options.mobile) {
return Blueprint.load(path.join(__dirname, '../mobile')).install(options);
}
},
locals: function(options) {
this.styleExt = options.style;
this.version = require(path.resolve(__dirname, '../../package.json')).version;
// Split/join with / not path.sep as reference to typings require forward slashes.
const relativeRootPath = options.sourceDir.split('/').map(() => '..').join('/');
const fullAppName = stringUtils.dasherize(options.entity.name)
.replace(/-(.)/g, (_, l) => ' ' + l.toUpperCase())
.replace(/^./, (l) => l.toUpperCase());
// For mobile projects, force inline styles and templates.
if (options.mobile) {
options.inlineStyle = true;
options.inlineTemplate = true;
}
return {
htmlComponentName: stringUtils.dasherize(options.entity.name),
jsComponentName: stringUtils.classify(options.entity.name),
fullAppName: fullAppName,
version: this.version,
sourceDir: options.sourceDir,
prefix: options.prefix,
styleExt: this.styleExt,
relativeRootPath: relativeRootPath,
isMobile: options.mobile,
routing: options.routing,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate
};
},
files: function() {
var fileList = getFiles.call(this);
if (this.options && !this.options.routing) {
fileList = fileList.filter(p => p.indexOf('app-routing.module.ts') < 0);
}
if (this.options && this.options.inlineTemplate) {
fileList = fileList.filter(p => p.indexOf('app.component.html') < 0);
}
if (this.options && this.options.inlineStyle) {
fileList = fileList.filter(p => p.indexOf('app.component.__styleext__') < 0);
}
return fileList;
},
fileMapTokens: function (options) {
// Return custom template variables here.
return {
__path__: () => {
return options.locals.sourceDir;
},
__styleext__: () => {
return this.styleExt;
}
};
}
};