ethers.js/misc/admin/src.ts/cmds/bundle-testcases.ts

62 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2020-11-14 17:42:36 -05:00
"use strict";
/** bundle-testcases
*
* This sript converts all the testase data (including needed
* text files) into a single JSON file.
*
* All gzip files (mostly .json.gz) are decompressed and recompressed
* using deflate, so a much more simple deflate library can be used.
*/
import fs from "fs";
import { join } from "path";
import zlib from "zlib";
import { colorify } from "../log";
import { resolve } from "../path";
2020-11-16 21:20:35 -05:00
import { mkdir } from "../utils";
2020-11-14 17:42:36 -05:00
const config = {
dirs: [
"./input/easyseed-bip39",
"./testcases",
"./input/wordlists"
]
};
(async function() {
console.log(colorify.bold(`Bundling Testcase Data...`));
const data: Record<string, string> = { "_": JSON.stringify({ name: "browser-fs", config: config }) };
config.dirs.forEach((dirname) => {
let fulldirname = resolve("packages/testcases", dirname);
fs.readdirSync(fulldirname).forEach((filename) => {
const key = join(dirname, filename);
const content = fs.readFileSync(join(fulldirname, filename));
if (filename.split(".").pop() === "gz") {
const contentData = zlib.gunzipSync(content);
data[key] = String(contentData.length) + "," + zlib.deflateRawSync(contentData).toString("base64");
} else {
data[key] = content.toString("base64");
}
2020-11-25 15:34:05 -05:00
//console.log(` - Added ${ key } (${ data[key].length } bytes)`);
2020-11-14 17:42:36 -05:00
});
});
2020-11-16 21:20:35 -05:00
mkdir(resolve("packages/testcases/lib"));
mkdir(resolve("packages/testcases/lib._esm"));
mkdir(resolve("packages/testcases/lib.esm"));
2020-11-14 17:42:36 -05:00
// We write it out to all needed places
fs.writeFileSync(resolve("packages/testcases/lib/browser-data.json"), JSON.stringify(data));
fs.writeFileSync(resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data));
fs.writeFileSync(resolve("packages/testcases/lib.esm/browser-data.json"), JSON.stringify(data));
// Write it to the TypeScript source last, in case it is running it will
// be regenerated overwriting the above files, but with identical content
fs.writeFileSync(resolve("packages/testcases/src.ts/browser-data.json"), JSON.stringify(data));
})();