forked from aurelia/new
-
Notifications
You must be signed in to change notification settings - Fork 0
/
after.js
69 lines (57 loc) · 1.86 KB
/
after.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
// Use "after" task to ask user to install deps.
const {execSync} = require('child_process');
function isAvailable(bin) {
try {
execSync(bin + ' -v', {stdio: 'ignore'});
return true;
} catch (e) {
return false;
}
}
module.exports = async function({
unattended, here, prompts, run, properties, features, notDefaultFeatures, ansiColors
}, {
// for testing
_isAvailable = isAvailable,
_log = console.log
} = {}) {
const c = ansiColors;
let depsInstalled = false;
let packageManager = undefined;
if (!unattended) {
const choices = [
{title: 'No'},
{value: 'npm', title: 'Yes, use npm'}
];
if (_isAvailable('yarn')) {
choices.push({value: 'yarn', title: 'Yes, use yarn (node-modules)'});
}
if (_isAvailable('pnpm')) {
choices.push({value: 'pnpm', title: 'Yes, use pnpm'});
}
packageManager = await prompts.select({
message: 'Do you want to install npm dependencies now?',
choices
});
if (packageManager) {
await run(packageManager, ['install']);
if (features.includes('playwright')) {
if (packageManager === 'npm') {
await run('npx', ['playwright', 'install', '--with-deps']);
} else {
await run(packageManager, ['dlx', 'playwright', 'install', '--with-deps']);
}
}
depsInstalled = true;
}
_log(`\nNext time, you can try to create similar project in silent mode:`);
_log(c.inverse(` npx makes aurelia new-project-name${here ? ' --here' : ''} -s ${notDefaultFeatures.length ? (notDefaultFeatures.join(',') + ' ') : ''}`));
}
_log(`\n${c.underline.bold('Get Started')}`);
if (!here) _log('cd ' + properties.name);
if (!depsInstalled) {
_log('npm install');
if (features.includes('playwright')) _log('npx playwright install --with-deps');
}
_log((packageManager ?? 'npm') + ' start\n');
};