(path, json)
| 12 | const dedent = require("codedent"); |
| 13 | |
| 14 | const crawl = (path, json) => { |
| 15 | for (const file of readdirSync(path)) { |
| 16 | const full = join(path, file); |
| 17 | if (/\.py$/.test(file)) { |
| 18 | if (process.env.NO_MIN) json[file] = readFileSync(full).toString(); |
| 19 | else { |
| 20 | try { |
| 21 | const { |
| 22 | output: [error, result], |
| 23 | } = spawnSync("pyminify", [ |
| 24 | "--remove-literal-statements", |
| 25 | full, |
| 26 | ]); |
| 27 | if (error) { |
| 28 | console.error(error); |
| 29 | process.exit(1); |
| 30 | } |
| 31 | json[file] = result.toString(); |
| 32 | } catch (error) { |
| 33 | console.error(error); |
| 34 | console.log( |
| 35 | dedent(` |
| 36 | \x1b[1m⚠️ is your env activated?\x1b[0m |
| 37 | \x1b[2mYou need a Python env to run \x1b[0mpyminify\x1b[2m.\x1b[0m |
| 38 | \x1b[2mTo do so, you can try the following:\x1b[0m |
| 39 | python -m venv env |
| 40 | source env/bin/activate |
| 41 | pip install --upgrade pip |
| 42 | pip install --ignore-requires-python python-minifier |
| 43 | pip install setuptools |
| 44 | \x1b[2mand you can then try \x1b[0mnpm run build\x1b[2m again.\x1b[0m |
| 45 | `), |
| 46 | ); |
| 47 | process.exit(1); |
| 48 | } |
| 49 | } |
| 50 | } else if (statSync(full).isDirectory() && !file.endsWith("_")) |
| 51 | crawl(full, (json[file] = {})); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | const json = {}; |
| 56 |
no test coverage detected