Files
Vue3Template/Vue3TCli/bin/tsvue-init
2024-09-27 00:58:46 +08:00

75 lines
2.2 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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);
}
})
}