epmp-cli
Version:
A simple init for epm scaffolding projects.
74 lines (70 loc) • 2 kB
JavaScript
/*
* @Description:
* @Version: 2.0
* @Autor: makaik
* @Date: 2022-05-11 09:34:37
* @LastEditors: makaik
* @LastEditTime: 2022-05-31 19:06:58
*/
const path = require('path');
const glob = require('glob');
const fse = require('fs-extra');
const rp = require('request-promise');
const argv = require('minimist')(process.argv.slice(2));
const commands = argv;
exports.download = async function (options, filename, cb) {
let opts = {
method: 'get',
headers: {
Accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
Connection: 'keep-alive',
'Upgrade-Insecure-Requests': 1,
},
};
opts = { ...opts, ...options };
// 获得文件夹路径
let fileFolder = path.dirname(filename);
// 创建文件夹
fse.ensureDirSync(fileFolder);
// 开始下载无需返回
rp(opts).pipe(fse.createWriteStream(filename)).on('close', cb);
};
/**
* 下载zip压缩包包含路径文件名
*/
exports.getRemoteZip = ({ filename, filepath }, cb) => {
let url = `http://iuap-design-cdn.oss-cn-beijing.aliyuncs.com/static/ucf/templates/1.4.x/epmp-webapp-master.zip`;
return new Promise((resolve, reject) => {
download({ url }, `epmp-webapp-master.tmp`, () => {
resolve({ success: true });
});
});
};
/**
* @function 获取某个目录下的子目录
*/
exports.getModules = (_findPath,splitPath) => {
let modules = [];
glob.sync(_findPath).forEach((_path) => {
//例: moduleName = 'bcs'
let moduleName=""
if(splitPath){
moduleName = _path.split(`/${splitPath}/`)[1];
}else{
moduleName = _path.split(`/epmp-apps/`)[1];
}
modules.push(moduleName);
});
return modules;
};
/**
* @function 创建文件夹
*/
exports.mkdirSync=(dirname)=>{
if (!fse.existsSync(dirname)) {
fse.mkdirSync(dirname);
}
}