-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbin.js
executable file
·63 lines (52 loc) · 1.51 KB
/
bin.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
#!/usr/bin/env node
const { resolve, join } = require('path');
const { promises: { copyFile, readdir } } = require('fs');
const { prompt } = require('inquirer');
const exist = require('@does/exist');
const exec = require('async-execute');
(async() => {
await fixtures();
await dependencies();
})();
async function dependencies() {
const dir = join(__dirname, 'devDependencies');
const devDependencies = await readdir(dir);
while(devDependencies.length) {
const dependency = devDependencies.pop();
const list = require(join(dir, dependency));
const { dependencies } = await prompt([ {
name: 'dependencies',
type: 'checkbox',
message: `Pick devDependencies to install for ${dependency.split('.').shift()}`,
choices: list.map(name => (
{ name, value: name, checked: true }
)),
} ]);
dependencies.length && await exec(
`npm i -D ${dependencies.map(d => [ d, 'latest' ].join('@')).join(' ')}`,
{ pipe: true },
);
}
}
async function fixtures() {
const dir = join(__dirname, 'fixtures');
const fixtures = await readdir(dir);
while (fixtures.length) {
const fixture = fixtures.pop();
const target = fixture.replace(/^__/, '.');
const source = join(dir, fixture);
const destination = resolve(target);
const exists = await exist(destination);
const { answer } = await prompt([ {
name: 'answer',
type: 'confirm',
message: [
exists ? 'Override' : 'Create',
target,
'?',
].join(' '),
default: !exists,
} ]);
answer && await copyFile(source, destination);
}
}