-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
48 lines (44 loc) · 1.24 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
#!/usr/bin/env node
const StackUpgrade = require('organic-stack-upgrade')
const path = require('path')
const prompts = require('prompts')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const generateProjectName = function () {
return 'project-' + Math.ceil(Math.random() * 1000)
}
const execute = async function ({destDir = process.cwd(), answers}) {
answers = answers || {}
const questions = [
{
name: 'project-name',
message: 'project name',
initial: answers['project-name'] || generateProjectName(),
type: 'text'
}
]
Object.assign(answers, await prompts(questions))
await exec(`mkdir -p ${answers['project-name']}`)
destDir = path.join(destDir, answers['project-name'])
let stack = new StackUpgrade({
destDir: destDir,
packagejson: path.join(__dirname, 'package.json')
})
await stack.merge({
sourceDir: path.join(__dirname, 'seed'),
answers
})
await stack.updateJSON()
console.info('run npm install...')
await stack.exec('npm install')
console.info('run git init...')
await stack.exec('git init .')
}
if (module.parent) {
module.exports = execute
} else {
execute({}).catch((err) => {
console.error(err)
process.exit(1)
})
}