UNPKG

@rongcloud/plugin-wechat-rtc

Version:

@rongcloud/plugin-wechat-rtc

63 lines (59 loc) 1.61 kB
const fs = require('fs') const path = require('path') const components = './components' const targetDirectory = '../../../rcComponents' /** * 需把 @rongcloud/plugin-wechat-rtc 下的 components 内容放到客户文件目录中 * 与 node_modules 同级创建 rcComponents 目录, * 把 @rongcloud/plugin-wechat-rtc 下的 components 内容放入 rcComponents 中 */ /** * 与 node_modules 同级创建 rcComponents 目录 */ fs.mkdirSync(targetDirectory) /** * 复制 components 至 targetDirectory */ const copyDir = (source, destination) => { const files = fs.readdirSync(source) for (let i = 0; i < files.length; i++) { if (files[i] === '.DS_Store') { continue } var srcPath = path.join(source, files[i]) var tarPath = path.join(destination, files[i]) const stat = fs.statSync(srcPath) if (stat.isDirectory()) { fs.mkdirSync(tarPath) copyDir(srcPath, tarPath) } else { fs.copyFileSync(srcPath, tarPath) } } } copyDir(components, targetDirectory) /** * 删除 @rongcloud/plugin-wechat-rtc 下的 components */ const removeDir = (dir) => { const files = fs.readdirSync(dir) for (let i = 0; i < files.length; i++) { const delPath = path.join(dir, files[i]) if (files[i] === '.DS_Store') { fs.unlinkSync(delPath) continue } const stat = fs.statSync(delPath) /** * 判断属于文件夹时,继续递归删除 */ if (stat.isDirectory()) { removeDir(delPath) } else { fs.unlinkSync(delPath) } } // 删除最外层文件夹 fs.rmdirSync(dir) } removeDir(components)