first commit
This commit is contained in:
50
whtml-cli/bin/whtml-init
Executable file
50
whtml-cli/bin/whtml-init
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env node
|
||||
const program = require('commander')
|
||||
const exec = require('child_process').exec
|
||||
const chalk = require('chalk')
|
||||
const ora = require('ora')
|
||||
const { GetUserInfo } = require('./../lib')
|
||||
const config = require('../package')
|
||||
|
||||
program.on('--help', () => {
|
||||
console.log()
|
||||
console.log(' Examples:')
|
||||
console.log()
|
||||
console.log(chalk.gray(' # create a new project with an official template'))
|
||||
console.log(' $ whtml init my-project')
|
||||
console.log()
|
||||
})
|
||||
|
||||
|
||||
function help () {
|
||||
program.parse(process.argv)
|
||||
if (program.args.length < 1) return program.help()
|
||||
}
|
||||
help()
|
||||
|
||||
|
||||
|
||||
let projectName = program.args[0], gitUrl, branch, cmdStr
|
||||
gitUrl = config.git.url, branch = config.git.branch
|
||||
cmdStr = `git clone ${gitUrl} ${projectName} && cd ${projectName} && git checkout ${branch}`
|
||||
|
||||
run(cmdStr)
|
||||
GetUserInfo()
|
||||
const spinner = ora('downloading template...')
|
||||
spinner.start()
|
||||
|
||||
function run(url){
|
||||
exec(url, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.log(error)
|
||||
process.exit()
|
||||
}
|
||||
spinner.stop()
|
||||
console.log(chalk.green('\n √ Download Success...'))
|
||||
console.log(chalk.green(`\n cd ${projectName} #Enter the folder\n npm install #Resolve dependence\n npm run all #Running project`))
|
||||
console.log()
|
||||
process.exit()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user