-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
47 lines (41 loc) · 1.06 KB
/
init.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
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
const actions = [
{
name: 'Deleting old .git directory',
action: () => rimraf(path.join(__dirname, '.git'))
},
{
name: 'Initializing new git repo',
action: () => childProcess.execSync('git init', { stdio: [0, 1, 2] })
},
{
name: 'Installing packages',
action: () => childProcess.execSync('yarn', { stdio: [0, 1, 2] })
},
{
name: 'Deleting init.js file',
action: () => fs.unlinkSync(path.join(__dirname, 'init.js'))
}
];
console.log('Initializing starter kit\n');
actions.forEach(({ name, action }, i) => {
console.log(`Step ${i}: ${name}...`);
action();
console.log('Done.\n');
});
console.log('Initialization completed. Use "npm start" to run.\n');
function rimraf(dirPath) {
if (fs.existsSync(dirPath)) {
fs.readdirSync(dirPath).forEach(entry => {
const itemPath = path.join(dirPath, entry);
if (fs.lstatSync(itemPath).isDirectory()) {
rimraf(itemPath);
} else {
fs.unlinkSync(itemPath);
}
});
fs.rmdirSync(dirPath);
}
}