forked from ember-cli/ember-app-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
170 lines (144 loc) · 4.57 KB
/
index.js
File metadata and controls
170 lines (144 loc) · 4.57 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
'use strict';
const stringUtil = require('ember-cli-string-utils');
const chalk = require('chalk');
const directoryForPackageName = require('./lib/directory-for-package-name');
module.exports = {
description: 'The default blueprint for ember-cli projects.',
shouldTransformTypeScript: true,
filesToRemove: [
'app/styles/.gitkeep',
'app/templates/.gitkeep',
'app/views/.gitkeep',
'public/.gitkeep',
'Brocfile.js',
'testem.json',
],
locals(options) {
let entity = options.entity;
let rawName = entity.name;
let name = stringUtil.dasherize(rawName);
let namespace = stringUtil.classify(rawName);
let hasOptions =
!options.welcome || options.packageManager || options.ciProvider;
let blueprintOptions = '';
if (hasOptions) {
let indent = `\n `;
let outdent = `\n `;
blueprintOptions =
indent +
[
!options.welcome && '"--no-welcome"',
options.packageManager === 'yarn' && '"--yarn"',
options.packageManager === 'pnpm' && '"--pnpm"',
options.ciProvider && `"--ci-provider=${options.ciProvider}"`,
options.typescript && `"--typescript"`,
!options.emberData && `"--no-ember-data"`,
!options.warpDrive && `"--no-warp-drive"`,
]
.filter(Boolean)
.join(',\n ') +
outdent;
}
let invokeScriptPrefix = 'npm run';
let execBinPrefix = 'npm exec';
if (options.packageManager === 'yarn') {
invokeScriptPrefix = 'yarn';
execBinPrefix = 'yarn';
}
if (options.packageManager === 'pnpm') {
invokeScriptPrefix = 'pnpm';
execBinPrefix = 'pnpm';
}
return {
appDirectory: directoryForPackageName(name),
name,
modulePrefix: name,
namespace,
blueprintVersion: require('./package').version,
yarn: options.packageManager === 'yarn',
pnpm: options.packageManager === 'pnpm',
npm:
options.packageManager !== 'yarn' && options.packageManager !== 'pnpm',
invokeScriptPrefix,
execBinPrefix,
welcome: options.welcome,
blueprint: 'app',
blueprintOptions,
lang: options.lang,
warpDrive: options.warpDrive ?? options.emberData,
ciProvider: options.ciProvider,
typescript: options.typescript,
packageManager: options.packageManager ?? 'npm',
};
},
files(options) {
if (this._files) {
return this._files;
}
let files = this._super();
if (options.ciProvider !== 'github') {
files = files.filter((file) => file.indexOf('.github') < 0);
}
if (!options.typescript) {
files = files.filter(
(file) =>
!['tsconfig.json', 'app/config/', 'types/'].includes(file) &&
!file.endsWith('.d.ts'),
);
}
const warpDrive = options.warpDrive || options.emberData;
if (!warpDrive) {
files = files.filter((file) => !file.includes('services/store.ts'));
} else {
files = files.filter((file) => !file.includes('services/.gitkeep'));
}
this._files = files;
return this._files;
},
beforeInstall() {
const prependEmoji = require('./lib/prepend-emoji');
this.ui.writeLine(
prependEmoji(
'✨',
`Creating a new Ember app in ${chalk.yellow(process.cwd())}:`,
),
);
},
/**
* @override
*
* This modification of buildFileInfo allows our differing
* input files to output to a single file, depending on the options.
* For example:
*
* for javascript,
* _ts_eslint.config.mjs is deleted
* _js_eslint.config.mjs is renamed to eslint.config.mjs
*
* for typescript,
* _js_eslint.config.mjs is deleted
* _ts_eslint.config.mjs is renamed to eslint.config.mjs
*/
buildFileInfo(intoDir, templateVariables, file, options) {
let fileInfo = this._super.buildFileInfo.apply(this, arguments);
if (file.includes('_js_')) {
if (options.typescript) {
return null;
}
fileInfo.outputBasePath = fileInfo.outputPath.replace('_js_', '');
fileInfo.outputPath = fileInfo.outputPath.replace('_js_', '');
fileInfo.displayPath = fileInfo.outputPath.replace('_js_', '');
return fileInfo;
}
if (file.includes('_ts_')) {
if (!options.typescript) {
return null;
}
fileInfo.outputBasePath = fileInfo.outputPath.replace('_ts_', '');
fileInfo.outputPath = fileInfo.outputPath.replace('_ts_', '');
fileInfo.displayPath = fileInfo.outputPath.replace('_ts_', '');
return fileInfo;
}
return fileInfo;
},
};