mirror of
https://github.com/horsicq/Detect-It-Easy.git
synced 2026-06-24 01:54:08 +00:00
+dbs_min
This commit is contained in:
parent
6d37d64843
commit
0d87c69c8b
3 changed files with 83 additions and 0 deletions
6
autotools/dbcompiler/package.json
Normal file
6
autotools/dbcompiler/package.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "dbcompiler",
|
||||
"version": "1.0.0",
|
||||
"main": "task.js",
|
||||
"author": "DosX"
|
||||
}
|
||||
76
autotools/dbcompiler/task.js
Normal file
76
autotools/dbcompiler/task.js
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
const
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
terser = require('terser');
|
||||
|
||||
const
|
||||
inputDirs = ['db', 'db_custom', 'db_extra'],
|
||||
outputDir = 'dbs_min';
|
||||
|
||||
function shouldMinify(filePath) {
|
||||
const ext = path.extname(filePath).toLowerCase();
|
||||
return ext === '.sg' || ext === '';
|
||||
}
|
||||
|
||||
async function processFile(srcFile, dstFile) {
|
||||
let text;
|
||||
try {
|
||||
text = fs.readFileSync(srcFile, 'utf8');
|
||||
} catch (e) {
|
||||
fs.mkdirSync(path.dirname(dstFile), { recursive: true });
|
||||
fs.copyFileSync(srcFile, dstFile);
|
||||
console.log('[COPIED] ' + srcFile);
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldMinify(srcFile)) {
|
||||
try {
|
||||
const minified = await terser.minify(text, {
|
||||
compress: true,
|
||||
mangle: { toplevel: false },
|
||||
format: { semicolons: false, beautify: false }
|
||||
});
|
||||
if (minified.error) throw minified.error;
|
||||
fs.mkdirSync(path.dirname(dstFile), { recursive: true });
|
||||
fs.writeFileSync(dstFile, minified.code, 'utf8');
|
||||
console.log('[MINIFIED] ' + srcFile);
|
||||
} catch (e) {
|
||||
// Если что-то пошло не так, просто копируем исходный файл
|
||||
fs.mkdirSync(path.dirname(dstFile), { recursive: true });
|
||||
fs.writeFileSync(dstFile, text, 'utf8');
|
||||
console.warn('[SKIP/BROKEN] ' + srcFile + ' (minify failed: ' + e.message + ')');
|
||||
}
|
||||
} else {
|
||||
fs.mkdirSync(path.dirname(dstFile), { recursive: true });
|
||||
fs.writeFileSync(dstFile, text, 'utf8');
|
||||
console.log('[COPIED] ' + srcFile);
|
||||
}
|
||||
}
|
||||
|
||||
async function walk(srcDir, relBase, dstBase) {
|
||||
for (const item of fs.readdirSync(srcDir)) {
|
||||
const
|
||||
srcPath = path.join(srcDir, item),
|
||||
relPath = path.relative(relBase, srcPath),
|
||||
dstPath = path.join(dstBase, relPath);
|
||||
|
||||
const stat = fs.statSync(srcPath);
|
||||
if (stat.isDirectory()) {
|
||||
await walk(srcPath, relBase, dstBase);
|
||||
} else {
|
||||
await processFile(srcPath, dstPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
for (const dir of inputDirs) {
|
||||
if (fs.existsSync(dir)) {
|
||||
const dstSubdir = path.join(outputDir, path.basename(dir));
|
||||
await walk(dir, dir, dstSubdir);
|
||||
} else {
|
||||
console.warn('[SKIP] Dir not found: ' + dir);
|
||||
}
|
||||
}
|
||||
console.log('✅ Done!');
|
||||
})();
|
||||
1
dbs_min_generate.cmd
Normal file
1
dbs_min_generate.cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
@node autotools\dbcompiler\task.js
|
||||
Loading…
Add table
Add a link
Reference in a new issue