UNPKG

bmui

Version:

Bluemoon Moon Components

49 lines (40 loc) 1.39 kB
const fs = require('fs-extra') const fsNode = require('fs') const compileSfc = require('./compile-sfc') const compileJs = require('./compile-js') const path = require('path') // 清空文件夹 exports.clearDir = async function (path) { await fs.emptyDir(path) } // 复制文件夹 exports.copyDir = async function (sourcePath, targetPath) { await fs.copy(sourcePath, targetPath) } // 判断文件后缀是否一致 function isExt (ext, filename) { let lastExt = filename.split('.').pop() return lastExt && lastExt === ext } // 是否是vue文件 function isSfcFile (filename) { return isExt('vue', filename) } // 是否是js文件 function isJsFile (filename) { return isExt('js', filename) } exports.isSfcFile = isSfcFile exports.isJsFile = isJsFile function compileFile (filePath) { if (isJsFile(filePath)) return compileJs(filePath) if (isSfcFile(filePath)) return compileSfc(filePath) } async function compileDir (filePath) { if (fsNode.statSync(filePath).isFile()) { // 如果是文件,则直接编译 compileFile(filePath) } else if (fsNode.statSync(filePath).isDirectory()) { // 如果是文件夹,则递归遍历 let fileArr = fsNode.readdirSync(filePath) fileArr.forEach(function (filename) { compileDir(path.join(filePath, filename)) }) } } // 遍历编译文件夹内的所有js/vue文件 exports.compileDir = compileDir