Skip to content

Commit 92c15b1

Browse files
committed
1 parent 7d0db15 commit 92c15b1

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

rollup/build_python.cjs

+31-8
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,44 @@ const { join, resolve } = require('node:path');
44
const { readdirSync, writeFileSync } = require('node:fs');
55
const { spawnSync } = require("node:child_process");
66

7+
const dedent = require('codedent');
8+
79
const PYTHON_DIR = resolve(join(__dirname, '..', 'python'));
810
const PYTHON_JS_DIR = resolve(join(__dirname, '..', 'esm', 'python'));
911

1012
const { stringify } = JSON;
1113

1214
for (const file of readdirSync(PYTHON_DIR)) {
1315
const full = join(PYTHON_DIR, file);
14-
const {
15-
output: [error, result],
16-
} = spawnSync("pyminify", [
17-
"--remove-literal-statements",
18-
full,
19-
]);
20-
if (error) process.exit(1);
21-
const python = stringify(result.toString());
16+
let python = '';
17+
try {
18+
const {
19+
output: [error, result],
20+
} = spawnSync("pyminify", [
21+
"--remove-literal-statements",
22+
full,
23+
]);
24+
if (error) {
25+
console.error(error);
26+
process.exit(1);
27+
}
28+
python = stringify(result.toString());
29+
}
30+
catch (error) {
31+
console.error(error);
32+
console.log(dedent(`
33+
\x1b[1m⚠️ is your env activated?\x1b[0m
34+
\x1b[2mYou need a Python env to run \x1b[0mpyminify\x1b[2m.\x1b[0m
35+
\x1b[2mTo do so, you can try the following:\x1b[0m
36+
python -m venv env
37+
source env/bin/activate
38+
pip install --upgrade pip
39+
pip install --ignore-requires-python python-minifier
40+
pip install setuptools
41+
\x1b[2mand you can then try \x1b[0mnpm run build\x1b[2m again.\x1b[0m
42+
`));
43+
process.exit(1);
44+
}
2245
writeFileSync(
2346
join(PYTHON_JS_DIR, file.replace(/\.py$/, '.js')),
2447
`// ⚠️ DO NOT MODIFY - SOURCE FILE: "../../python/${file}"

0 commit comments

Comments
 (0)