[next] Bring in stdlib as artifact (#1666)

This commit is contained in:
Andrea Giammarchi
2023-09-01 18:24:49 +02:00
committed by GitHub
parent da3b43abdd
commit ef44df5dda
14 changed files with 144 additions and 66 deletions

View File

@@ -0,0 +1,33 @@
/**
* Create through Python the pyscript module through
* the artifact generated at build time.
* This the returned value is a string that must be used
* either before a worker execute code or when the module
* is registered on the main thread.
*/
import pyscript from "./stdlib/pyscript.js";
const { entries } = Object;
const python = ["from pathlib import Path as _Path"];
const write = (base, literal) => {
for (const [key, value] of entries(literal)) {
const path = `_Path("${base}/${key}")`;
if (typeof value === "string") {
const code = JSON.stringify(value);
python.push(`${path}.write_text(${code})`);
} else {
python.push(`${path}.mkdir(parents=True, exist_ok=True)`);
write(`${base}/${key}`, value);
}
}
};
write(".", pyscript);
python.push("del _Path");
python.push("\n");
export default python.join("\n");