75 lines
2.2 KiB
JavaScript
Executable File
75 lines
2.2 KiB
JavaScript
Executable File
#!/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(' $ tsvue init myProject');
|
||
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}`;
|
||
const down = ora('Download template...');
|
||
const dependency = ora('Initializing dependency...');
|
||
|
||
console.log();
|
||
console.log(" 🎉 欢迎使用脚手架模板 Vue3Template\n 🎉 基于Vue-cli3+Vue3+TypeScript开发,一起感受Vue3+TypeScript的魅力吧\n\n 📦 项目地址:https://github.com/helpcode/Vue3Template\n 📦 注解包地址:https://www.npmjs.com/package/vue3decorators\n 📦 自动路由插件:https://www.npmjs.com/package/vue-cli-plugin-autorouter\n\n");
|
||
|
||
down.start();
|
||
run(cmdStr, (status) => {
|
||
if (status) {
|
||
down.stop();
|
||
console.log(chalk.green(' 🎉 Download Success...'));
|
||
console.log(chalk.green(' 📦 Initializing Dependency...\n'));
|
||
dependency.start();
|
||
|
||
let install = `cd ${projectName} && npm i`;
|
||
run(install, (res) => {
|
||
if(res) {
|
||
dependency.stop();
|
||
console.log("\n Dependency Installed Success...")
|
||
console.log(chalk.green(`\n cd ${projectName} #Enter the folder\n npm run dev #Running project`))
|
||
console.log();
|
||
process.exit();
|
||
}
|
||
});
|
||
|
||
} else {
|
||
console.log("项目初始化出错,请确保已经安装git,并保持网络通畅!")
|
||
process.exit()
|
||
}
|
||
});
|
||
//GetUserInfo()
|
||
|
||
|
||
function run(url, callback){
|
||
exec(url, (error, stdout, stderr) => {
|
||
if (error) {
|
||
console.log(error);
|
||
callback(false)
|
||
} else {
|
||
callback(true);
|
||
}
|
||
})
|
||
}
|
||
|
||
|