2022-02-06 21:18:32 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const { join } = require('path');
|
|
|
|
|
|
|
|
const stripCode = (code) => code
|
|
|
|
.replace(/(^| )\/\/.*$/gm, '')
|
|
|
|
.replaceAll('const ', 'const#')
|
|
|
|
.replaceAll('let ', 'let#')
|
|
|
|
.replaceAll('var ', 'var#')
|
|
|
|
.replaceAll('class ', 'class#')
|
|
|
|
.replaceAll('get ', 'get#')
|
|
|
|
.replaceAll('delete ', 'delete#')
|
|
|
|
.replaceAll(' extends ', '#extends#')
|
|
|
|
.replaceAll('typeof ', 'typeof#')
|
|
|
|
.replaceAll(' of ', '#of#')
|
|
|
|
.replaceAll(' in ', '#in#')
|
2022-02-06 21:33:04 +00:00
|
|
|
.replaceAll('case ', 'case#')
|
2022-02-06 21:18:32 +00:00
|
|
|
.replaceAll('await ', 'await#')
|
|
|
|
.replaceAll('new ', 'new#')
|
|
|
|
.replaceAll('return ', 'return#')
|
|
|
|
.replaceAll('function ', 'function#')
|
|
|
|
.replaceAll('void ', 'void#')
|
|
|
|
.replaceAll('throw ', 'throw#')
|
|
|
|
.replaceAll('async ', 'async#')
|
|
|
|
.replaceAll('else ', 'else#')
|
2022-02-08 14:10:25 +00:00
|
|
|
.replaceAll('false', '!!0')
|
|
|
|
.replaceAll('true', '!0')
|
2022-02-06 21:18:32 +00:00
|
|
|
.replace(/((['"`])[\s\S]*?\2)|[ \n]/g, (_, g1) => g1 || '')
|
|
|
|
.replaceAll('#', ' ')
|
|
|
|
.replaceAll('? ?', '??');
|
|
|
|
|
2022-02-08 14:19:38 +00:00
|
|
|
const stripJs = (jsPath) => fs.writeFileSync(jsPath, stripCode(fs.readFileSync(jsPath, 'utf8')));
|
|
|
|
|
|
|
|
const minJson = (data) => {
|
|
|
|
if (data.description) delete data.description;
|
|
|
|
|
|
|
|
return data;
|
2022-02-06 21:18:32 +00:00
|
|
|
};
|
|
|
|
|
2022-02-08 14:19:38 +00:00
|
|
|
const stripJson = (path) => fs.writeFileSync(path, JSON.stringify(minJson(JSON.parse(fs.readFileSync(path, 'utf8')))));
|
|
|
|
|
2022-02-06 21:18:32 +00:00
|
|
|
const tree = (dirPath) => fs.readdirSync(dirPath).forEach((x) => {
|
2022-02-08 14:19:38 +00:00
|
|
|
const path = join(dirPath, x);
|
|
|
|
console.log(path);
|
|
|
|
|
|
|
|
if (x.endsWith('.js')) return stripJs(path);
|
|
|
|
if (x.endsWith('.json')) return stripJson(path);
|
|
|
|
if (!x.includes('.')) return tree(path);
|
2022-02-06 21:18:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tree(join(__dirname, '..', 'src'));
|