UNPKG

epmp-cli

Version:

A simple init for epm scaffolding projects.

102 lines (94 loc) 3.48 kB
/** * EPMP 下载最新仓库内的EPMP完整工程 * @author zhaoyuu(zhaoyuu@yonyou.com) */ 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 'epmp-web'; }, }, ]); folderName = inquirerProjectName.name; } console.log(chalk.green(`\t\t⏳ EPMP cloud transfer to local machine ⏳`)); console.log(); // console.log(chalk.green(`⏳🔊📢⚠️🇺🇿🌍☁️`)); console.log(chalk.cyan.bold(`[Info] : 🚀 Start downloading EPMP 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." }); //process.exit(0); } } if (!pathExists.sync(folderName) || folderName == 'epmp-web') { downloading(); // download('iuap-design/epmp-webapp', 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`)); // } else { // } // }); // utils.download({ // url: "http://iuap-design-cdn.oss-cn-beijing.aliyuncs.com/static/ucf/templates/latest/epmp-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}/epmp-webapp-master.tmp`) .pipe(unzipper.Extract({ path: filepath })) .on('close', () => { // 删除压缩包 fse.remove(`${filepath}/epmp-webapp-master.tmp`); fse.renameSync(`${filepath}/epmp-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); } };