@@ -4,21 +4,44 @@ const { join, resolve } = require('node:path');
4
4
const { readdirSync, writeFileSync } = require ( 'node:fs' ) ;
5
5
const { spawnSync } = require ( "node:child_process" ) ;
6
6
7
+ const dedent = require ( 'codedent' ) ;
8
+
7
9
const PYTHON_DIR = resolve ( join ( __dirname , '..' , 'python' ) ) ;
8
10
const PYTHON_JS_DIR = resolve ( join ( __dirname , '..' , 'esm' , 'python' ) ) ;
9
11
10
12
const { stringify } = JSON ;
11
13
12
14
for ( const file of readdirSync ( PYTHON_DIR ) ) {
13
15
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
+ }
22
45
writeFileSync (
23
46
join ( PYTHON_JS_DIR , file . replace ( / \. p y $ / , '.js' ) ) ,
24
47
`// ⚠️ DO NOT MODIFY - SOURCE FILE: "../../python/${ file } "
0 commit comments