mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
5410a48a58
Co-authored-by: bofeng.song <bofeng.song@chukong-inc.com> Co-authored-by: dumganhar <dumganhar@gmail.com> Co-authored-by: mmyduckx <308303735@qq.com> Co-authored-by: Patrice Jiang <397136899@qq.com> Co-authored-by: 江战 <40414978+PatriceJiang@users.noreply.github.com>
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
const zlib = require('zlib');
|
|
const fs = require('fs');
|
|
const process = require('process');
|
|
const writeIfDifferent = require('./utils').writeIfDifferent;
|
|
|
|
if (process.argv.length !== 6) {
|
|
console.error('bad argument');
|
|
console.error(' - input file');
|
|
console.error(' - export var');
|
|
console.error(' - template file');
|
|
console.error(' - output file');
|
|
process.exit(-1);
|
|
}
|
|
|
|
const inputFile = process.argv[2];
|
|
const exportVar = process.argv[3];
|
|
const template = process.argv[4];
|
|
const outputFile = process.argv[5];
|
|
|
|
let data = require(inputFile)[exportVar];
|
|
|
|
let encoded = zlib.gzipSync(JSON.stringify(data, null, 2)).toString("base64");
|
|
let array = [];
|
|
let start = 0, last = encoded.length;
|
|
const charPerRow = 118;
|
|
while (start < last) {
|
|
array.push(`"${encoded.substr(start, charPerRow)}"`);
|
|
start += charPerRow;
|
|
}
|
|
encoded = array.join("\n");
|
|
let replaceData = fs.readFileSync(template).toString('utf-8').replace("${PLACE_HOLDER}", encoded);
|
|
writeIfDifferent(outputFile, replaceData, { encoding: 'utf-8' });
|
|
|
|
process.exit(0); |