szyy-cli
Version:
93 lines (86 loc) • 3.81 kB
JavaScript
/**
* SZYY 下载最新工程
* @author Allen(wangzhk@yonyou.com)
* @date 2019-11-01 11:14:35
*/
const chalk = require('chalk');
const path = require('path');
const pathExists = require('path-exists');
const download = require('download-git-repo');
const fse = require('fs-extra');
const inquirer = require('inquirer');
const utils = require('./utils');
const unzipper = require('unzipper');
module.exports = async (folderName = '.') => {
if (folderName == '.') {
let inquirerProjectName = await inquirer.prompt([{
type: 'input',
name: 'name',
message: 'Project Name:',
default: function () {
return 'szyy-web';
}
}]);
folderName = inquirerProjectName.name;
}
console.log(chalk.green(`\t\t⏳ SZYY cloud transfer to local machine ⏳`));
console.log();
console.log(chalk.cyan.bold(`[Info] : 🚀 Start downloading UCF project to the current directory 🎁`));
console.log(chalk.cyan.bold(`Path:${path.resolve('.', folderName)} 🏠`));
console.log();
var ProgressBar = require('./processBar');
var pb = new ProgressBar('Download', 72);
var num = 0, total = 100;
function downloading() {
if (num <= total) {
pb.render({ completed: num, total: total, status: 'Downloading...' });
num++;
setTimeout(function () {
downloading();
}, 10);
} else {
pb.render({ completed: num, total: total, status: "Completed." });
}
}
if (!pathExists.sync(folderName) || folderName == 'szyy-web') {
downloading();
download('wangzhikui/koa2-bff', folderName, function (err) {
if (!err) {
pb.render({ completed: num, total: total, status: "Completed." });
console.log();
console.log();
console.log(chalk.cyan(`🚀 Next, install NPM package dependencies 🎁 `));
console.log(chalk.cyan(`[Tips] : 🏆 cd ${folderName} && npm install && npm start`));
}
});
// utils.download({
// url: "http://iuap-design-cdn.oss-cn-beijing.aliyuncs.com/static/ucf/templates/latest/ucf-webapp-master.zip"
// }, () => {
// pb.render({ completed: num, total: total, status: "Completed." });
// console.log();
// console.log();
// console.log(chalk.cyan(`🚀 Next, install NPM package dependencies 🎁 `));
// console.log(chalk.cyan(`[Tips] : 🏆 cd ${folderName} && npm install && npm start`));
// }, `${folderName}.zip`);
// let result = await utils.getRemoteZip({
// filename: folderName
// });
// let filepath = path.resolve('.');
// if (result.success) {
// fse.createReadStream(`${filepath}/ucf-webapp-master.tmp`).pipe(unzipper.Extract({ path: filepath })).on('close', () => {
// // 删除压缩包
// fse.remove(`${filepath}/ucf-webapp-master.tmp`);
// fse.renameSync(`${filepath}/ucf-webapp-master`,`${filepath}/${folderName}`);
// });
// pb.render({ completed: num, total: total, status: "Completed." });
// console.log();
// console.log();
// console.log(chalk.cyan(`🚀 Next, install NPM package dependencies 🎁 `));
// console.log(chalk.cyan(`[Tips] : 🏆 cd ${folderName} && npm install && npm start`));
// }
} else {
console.log(chalk.red.bold(`[Error] : ⚠️ directory ${folderName} already exists. 😫`));
console.log(chalk.yellow(`[Tips] : 🤔 Try renaming the project name 🤗 `));
process.exit(0);
}
}