Skip to content

Commit 2e53df3

Browse files
committed
feat: "after" task to optionally install deps
1 parent 7e94dce commit 2e53df3

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

after.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const which = require('npm-which')(process.cwd());
2+
3+
function isAvailable(bin) {
4+
try {
5+
return which.sync(bin);
6+
} catch (e) {
7+
return false;
8+
}
9+
}
10+
11+
module.exports = async function({
12+
unattended, prompts, run
13+
}) {
14+
if (unattended) return;
15+
16+
const choices = [
17+
{value: 'npm i', title: 'Yes, use npm'}
18+
];
19+
20+
if (isAvailable('yarn')) {
21+
choices.unshift({value: 'yarn', title: 'Yes, use yarn'});
22+
}
23+
24+
if (isAvailable('pnpm')) {
25+
choices.unshift({value: 'pnpm i', title: 'Yes, use pnpm'});
26+
}
27+
28+
choices.unshift({title: 'No'});
29+
30+
const result = await prompts.select({
31+
message: 'Do you want to install dependencies?',
32+
choices
33+
});
34+
35+
if (result) {
36+
await run(result);
37+
}
38+
};

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"del": "^4.1.0",
1515
"puppeteer": "^1.15.0",
1616
"standard-changelog": "^2.0.7"
17+
},
18+
"dependencies": {
19+
"npm-which": "^3.0.1"
1720
}
1821
}

0 commit comments

Comments
 (0)