-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
before.js
72 lines (65 loc) · 2.55 KB
/
before.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
// Use "before" task to ask user to select a preset (to skip questionnaire).
const PRESETS = {
'default-esnext': ['app', 'vite', 'babel', 'vitest'],
'default-typescript': ['app', 'vite', 'typescript', 'vitest'],
// TODO: move plugin to vite+vitest
// FIXME: vite compiles plugin with separate css dist file, and removed
// import('./style.css') from js code, need to:
// 1. hook up a css loader in runtime for normal css and css-module.
// 2. hook up a text loader in runtime for shadow-dom css.
'default-esnext-plugin': ['plugin', 'webpack', 'babel', 'shadow-dom', 'jest'],
'default-typescript-plugin': ['plugin', 'webpack', 'typescript', 'shadow-dom', 'jest'],
};
const REQUIRE_NODEJS_VESION = [18, 0, 0];
function isNodejsOutdated() {
const version = process.version.slice(1).split('.');
for (let i = 0; i < 3; i++) {
const actual = version[i];
const required = REQUIRE_NODEJS_VESION[i];
if (actual > required) return false;
if (actual < required) return true;
}
return false;
}
if (isNodejsOutdated()) {
console.error('\x1b[31m' + `Aurelia 2 requires at least Nodejs v${REQUIRE_NODEJS_VESION.join('.')}. Your Nodejs version is ${process.version}. Please install latest version from https://nodejs.org` + '\x1b[0m');
process.exit(1);
}
module.exports = async function({unattended, prompts, ansiColors}) {
// don't ask when running in silent mode.
if (unattended) return;
const preset = await prompts.select({
message: 'Would you like to use the default setup or customize your choices?',
choices: [
{
value: 'default-esnext',
title: 'Default ESNext Aurelia 2 App',
hint: 'A basic Aurelia 2 app with Babel and Vite'
}, {
value: 'default-typescript',
title: 'Default TypeScript Aurelia 2 App',
hint: 'A basic Aurelia 2 app with TypeScript and Vite'
}, {
value: 'default-esnext-plugin',
title: 'Default ESNext Aurelia 2 Plugin',
hint: 'A basic Aurelia 2 plugin project with Babel, Webpack and ShadowDOM'
}, {
value: 'default-typescript-plugin',
title: 'Default TypeScript Aurelia 2 Plugin',
hint: 'A basic Aurelia 2 plugin project with TypeScript, Webpack and ShadowDOM'
}, {
title: 'Custom Aurelia 2 Project',
hint: 'Select bundler, transpiler, and more.'
}
]
});
if (preset) {
const preselectedFeatures = PRESETS[preset];
if (preselectedFeatures) {
return {
silentQuestions: true, // skip following questionnaire
preselectedFeatures
};
}
}
};