9 Star 130 Fork 26

ByLiangCheng / TTime

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
modules-update.ts 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
liangcheng 提交于 2023-05-25 20:25 . TTime.v0.0.7 版本开源
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
// 将 修改过源码的 node_modules_update 内的文件覆盖在 node_modules 中
// node_modules
const NODE_MODULES = path.resolve('./node_modules')
// 修改过源码的 node_modules
const UPDATE_NODE_MODULES = path.resolve('./node_modules_update')
copy(UPDATE_NODE_MODULES, NODE_MODULES)
/**
* @param {string} origin 需要复制的目录、文件
* @param {string} target 复制到指定的目录、文件
* @param {string} filterFn 每次复制前,都会经过一次filterFn,若返回true,则复制。
*/
function copy(origin, target, filterFn = (origin, target) => true) {
if (fs.statSync(origin).isDirectory()) {
if (!fs.existsSync(target)) {
fs.mkdirSync(target)
}
fs.readdirSync(origin).forEach(originName => {
const originFilePath = path.resolve(origin, originName)
const targetFilePath = path.resolve(target, originName)
copy(originFilePath, targetFilePath, filterFn)
})
} else if (filterFn(origin, target)) {
console.info(chalk.blue('已手动修改过源码:', target))
//执行替换
fs.copyFileSync(origin, target)
}
}
console.info(chalk.bold.yellow('以上的文件已被 node_modules_update 中的文件替换,升级版本后请注意检查'))
1
https://gitee.com/ByLiangCheng/TTime.git
git@gitee.com:ByLiangCheng/TTime.git
ByLiangCheng
TTime
TTime
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891