Adjust size stats output on build (#393)
This commit is contained in:
+11
-15
@@ -6,34 +6,30 @@ const fs = require('fs');
|
||||
const mkdirp = require('mkdirp');
|
||||
const { formatNumber } = require('@polkadot/util');
|
||||
|
||||
const DIR_DENO = `./${process.env.PKG_NAME}-wasm/build-deno/deno`;
|
||||
const DIR_CJS = `./${process.env.PKG_NAME}-wasm/build/cjs`;
|
||||
const HDR = `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// Generated as part of the build, do not edit\n`;
|
||||
|
||||
const data = fs.readFileSync(`./${process.env.PKG_NAME}/build-wasm/wasm_opt.wasm`);
|
||||
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
|
||||
const denoDir = `./${process.env.PKG_NAME}-wasm/build-deno/deno`;
|
||||
const base64 = compressed.toString('base64');
|
||||
|
||||
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
|
||||
console.log(`*** Compressed WASM: in=${formatNumber(data.length)}, out=${formatNumber(compressed.length)}, opt=${(100 * compressed.length / data.length).toFixed(2)}%, base64=${formatNumber(base64.length)}`);
|
||||
|
||||
mkdirp.sync(denoDir);
|
||||
|
||||
fs.writeFileSync(`./${process.env.PKG_NAME}-wasm/build/cjs/bytes.js`, `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Generated as part of the build, do not edit
|
||||
mkdirp.sync(DIR_DENO);
|
||||
|
||||
fs.writeFileSync(`${DIR_CJS}/bytes.js`, `${HDR}
|
||||
const lenIn = ${compressed.length};
|
||||
const lenOut = ${data.length};
|
||||
const bytes = '${compressed.toString('base64')}';
|
||||
const bytes = '${base64}';
|
||||
|
||||
module.exports = { bytes, lenIn, lenOut };
|
||||
`);
|
||||
|
||||
fs.writeFileSync(`${denoDir}/bytes.js`, `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Generated as part of the build, do not edit
|
||||
|
||||
fs.writeFileSync(`${DIR_DENO}/bytes.js`, `${HDR}
|
||||
export const lenIn = ${compressed.length};
|
||||
|
||||
export const lenOut = ${data.length};
|
||||
|
||||
export const bytes = '${compressed.toString('base64')}';
|
||||
export const bytes = '${base64}';
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user