mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 10:47:35 -05:00
* Implemented pyminify for our stdlib * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const {
|
|
readdirSync,
|
|
readFileSync,
|
|
statSync,
|
|
writeFileSync,
|
|
} = require("node:fs");
|
|
|
|
const { spawnSync } = require("node:child_process");
|
|
|
|
const { join } = require("node:path");
|
|
|
|
const crawl = (path, json) => {
|
|
for (const file of readdirSync(path)) {
|
|
const full = join(path, file);
|
|
if (/\.py$/.test(file)) {
|
|
if (process.env.NO_MIN) json[file] = readFileSync(full).toString();
|
|
else {
|
|
const {
|
|
output: [error, result],
|
|
} = spawnSync("pyminify", [
|
|
"--remove-literal-statements",
|
|
full,
|
|
]);
|
|
if (error) process.exit(1);
|
|
json[file] = result.toString();
|
|
}
|
|
} else if (statSync(full).isDirectory() && !file.endsWith("_"))
|
|
crawl(full, (json[file] = {}));
|
|
}
|
|
};
|
|
|
|
const json = {};
|
|
|
|
crawl(join(__dirname, "..", "src", "stdlib"), json);
|
|
|
|
writeFileSync(
|
|
join(__dirname, "..", "src", "stdlib", "pyscript.js"),
|
|
`// ⚠️ This file is an artifact: DO NOT MODIFY\nexport default ${JSON.stringify(
|
|
json,
|
|
null,
|
|
" ",
|
|
)};\n`,
|
|
);
|