UNPKG

@fuse-oo/cli

Version:

fuse内部脚手架工具

63 lines (54 loc) 1.51 kB
// 写入文件,安装依赖 const fs = require('fs-extra') const chalk = require('chalk') const path = require('path') const appendLibs = require('./appendLibs') const writeHtmlIndex = require('./writeHtmlIndex') const tree = require('tree-node-cli') const { log, error, done, logWithSpinner, stopSpinner, clearLog } = require('./common') // CLI 模板文件夹路径 const src = path.resolve(__dirname, '../../temp/html') async function generateHtml(context, cliOptions) { logWithSpinner(`${chalk.cyan('[1/3]')} 🔍 拷贝${chalk.yellow('项目模版文件')}...`) // 目标路径 const dest = path.resolve(context) // 拷贝模板文件 await fs.copy(src, dest).then(async () => { // 判断文件夹是否存在 await existsSrc(`${context}/js`) // 添加第三方库文件 await appendLibs(context, cliOptions) // 修改index.html的引入 await writeHtmlIndex(context, cliOptions) }) await clearLog() const fileTree = tree(context, { allFiles: true, exclude: [/node_modules/], maxDepth: 4 }) done(`${chalk.green(context)} 创建成功`, '🎉') log(`${chalk.white(fileTree)}`) stopSpinner() } // 检测文件路径是否存在,不存在则新建 async function existsSrc(context) { if(!fs.existsSync(context)){ await fs.mkdir(context) } } module.exports = (context, cliOptions) => { Promise.all([ generateHtml(context, cliOptions) ]).catch(err => { stopSpinner(false) error(err) }) }