coverage-shaker
Version:
Minify JavaScript code from chrome/puppeteer coverage report. tree shaking.
43 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
if (require.main !== module) {
throw new Error('Executable-only module should not be required');
}
const yargs = require("yargs");
const helpers_1 = require("yargs/helpers");
const path_1 = require("path");
const fs_1 = require("fs");
const shake_1 = require("./shake");
const argv = yargs(helpers_1.hideBin(process.argv))
.scriptName('coverage-shaker')
.usage('Usage: $0 [file]')
.option('file', {
type: 'array',
alias: 'f',
describe: 'files you want to minify, sg: lottie_canvas.js'
})
.option('output', {
type: 'string',
alias: 'o',
describe: 'output dir, eg: ./output'
})
.demandCommand(1, 'You need specify a coverage file first')
.help()
.argv;
// console.log(argv)
// console.log(process.cwd())
const [source] = argv._;
const { file = [], output = '' } = argv;
const cwd = process.cwd();
const sourcePath = path_1.resolve(cwd, source);
const outputPath = path_1.resolve(cwd, output);
const sourceStr = fs_1.readFileSync(sourcePath, { encoding: 'utf-8' });
const sourceData = JSON.parse(sourceStr);
const results = shake_1.default(sourceData, file);
results.forEach(r => {
const filename = r.url.replace(/[^\\\/]*[\\\/]+/g, '');
const filepath = path_1.resolve(outputPath, filename);
fs_1.writeFileSync(filepath, r.code);
});
//# sourceMappingURL=cli.js.map