-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (41 loc) · 1.21 KB
/
index.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
#! /usr/bin/env node
const { spawn } = require('child_process')
const repoUrl = "https://github.com/pranavtalwar/express-api-skeleton"
const runCommand = (command, args, options=undefined) => {
const spawned = spawn(command, args, options)
return new Promise((resolve) => {
spawned.stdout.on("data", data => {
console.log(data.toString());
});
spawned.stderr.on("data", data => {
console.log(data.toString());
});
spawned.on('error', (err) => {
console.log('error:', err.message)
})
spawned.on("close", () => {
resolve()
});
})
}
const folderName = process.argv[2]
if(!folderName) {
return console.log('Please specify a directory name')
}
runCommand('git', ['clone', repoUrl, folderName])
.then(() => {
return runCommand('rm', ['-rf', `${folderName}/.git`])
})
.then(() => {
console.log('cloned')
console.log('Installing dependencies...')
return runCommand('npm',['install'], {
cwd: process.cwd() + '/' + folderName
})
})
.then(() => {
console.log('Done')
console.log('To run')
console.log(`cd ${folderName}`)
console.log('npm run dev')
})