加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
build.js 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
hehongyun 提交于 2024-02-20 10:38 . first update
import fs from 'node:fs';
import path from 'path';
import uglifyjs from 'uglify-js';
const copySpider = ['app', 'kunyu77_open', 'alist_open'];
const root = process.cwd();
const src = path.join(root);
const out = path.join(root, 'dist');
function minify(s, d) {
var jsContent = fs.readFileSync(s).toString();
jsContent = jsContent.replace('./lib/cat.js', 'assets://js/lib/cat.js');
jsContent = jsContent.replace('./cat.js', 'assets://js/lib/cat.js');
jsContent = uglifyjs.minify(jsContent, {
mangle: false,
});
fs.writeFileSync(d, jsContent.code);
}
function listAllFiles(dirPath, arrayOfFiles) {
var files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
arrayOfFiles = listAllFiles(dirPath + '/' + file, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, '/', file));
}
});
return arrayOfFiles;
}
function src2Out() {
if (fs.existsSync(out)) fs.rmSync(out, { recursive: true, force: true });
fs.mkdirSync(out, { recursive: true });
const libSrc = path.join(src, 'lib');
const libOut = path.join(out, 'lib');
fs.mkdirSync(libOut, { recursive: true });
const libs = listAllFiles(libSrc);
for (let index = 0; index < libs.length; index++) {
const element = libs[index];
const relative = path.relative(libSrc, element);
minify(element, path.join(libOut, relative));
}
for (const sp of copySpider) {
minify(path.join(src, sp + '.js'), path.join(out, sp + '.js'));
}
}
src2Out();
fs.copyFileSync(path.join(src, 'config_open.json'), path.join(out, 'config_open.json'));
console.log('done');
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化