Skip to content

Commit

Permalink
Follow up on pyscript/pyscript#2168
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Sep 13, 2024
1 parent 7d0db15 commit 92c15b1
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions rollup/build_python.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,44 @@ const { join, resolve } = require('node:path');
const { readdirSync, writeFileSync } = require('node:fs');
const { spawnSync } = require("node:child_process");

const dedent = require('codedent');

const PYTHON_DIR = resolve(join(__dirname, '..', 'python'));
const PYTHON_JS_DIR = resolve(join(__dirname, '..', 'esm', 'python'));

const { stringify } = JSON;

for (const file of readdirSync(PYTHON_DIR)) {
const full = join(PYTHON_DIR, file);
const {
output: [error, result],
} = spawnSync("pyminify", [
"--remove-literal-statements",
full,
]);
if (error) process.exit(1);
const python = stringify(result.toString());
let python = '';
try {
const {
output: [error, result],
} = spawnSync("pyminify", [
"--remove-literal-statements",
full,
]);
if (error) {
console.error(error);
process.exit(1);
}
python = stringify(result.toString());
}
catch (error) {
console.error(error);
console.log(dedent(`
\x1b[1m⚠️ is your env activated?\x1b[0m
\x1b[2mYou need a Python env to run \x1b[0mpyminify\x1b[2m.\x1b[0m
\x1b[2mTo do so, you can try the following:\x1b[0m
python -m venv env
source env/bin/activate
pip install --upgrade pip
pip install --ignore-requires-python python-minifier
pip install setuptools
\x1b[2mand you can then try \x1b[0mnpm run build\x1b[2m again.\x1b[0m
`));
process.exit(1);
}
writeFileSync(
join(PYTHON_JS_DIR, file.replace(/\.py$/, '.js')),
`// ⚠️ DO NOT MODIFY - SOURCE FILE: "../../python/${file}"
Expand Down

0 comments on commit 92c15b1

Please sign in to comment.