uino-kiss-cli
Version:
uino-kiss-cli 用来初始化项目的方便工具
35 lines (29 loc) • 872 B
JavaScript
/*
* @Date: 2021-04-13 17:53:45
* @Description: In User Settings Edit
*/
const fs = require('fs');
const { spawn } = require('child_process');
const isWin32 = process.platform === 'win32';
const log = console.log;
// 判断文件夹是否存在
global.directoryExists = (filePath) => {
try {
return fs.statSync(filePath).isDirectory();
} catch (err) {
return false;
}
}
// 安装npm包
global.installPack = (packs, fn) => {
const dirPath = process.cwd() + (global.dirPath ? `/${global.dirPath}` : '');
const npm = isWin32 ? 'npm.cmd' : 'npm';
const ps = ['install', '--registry', 'https://npm.uino.cn']
if (packs && packs.length > 0) ps.splice(1, 0, ...packs)
log(`在【${dirPath}】开始安装依赖...`);
const npmInit = spawn(npm, ps, {
cwd: dirPath,
stdio: 'inherit',
});
npmInit.on('close', fn ? fn : (code) => { });
}