Skip to content

Commit

Permalink
Instrument CI to build minified python
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Sep 3, 2024
1 parent c791c74 commit b1958d0
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 106 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: python -m venv env
- run: source env/bin/activate
- run: pip install --upgrade pip
- run: pip install --ignore-requires-python python-minifier
- run: pip install setuptools
- run: npm ci
- run: npx playwright install
- run: npx playwright install chromium
- run: npm run build
- run: npm run test
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ This project requires some automatic artifact creation to:
Accordingly, to build latest project:

```sh
# activate once the Python env (to use pyminify)
. env.sh # or source env.sh

# create all artifacts needed to test core
npm run build

Expand Down
2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/zip-BIfA-Q-T.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions docs/zip-BIfA-Q-T.js → docs/zip-DrwYHuF9.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/zip-DrwYHuF9.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

# to use this env type either:
# . env.sh
# or
# source env.sh

python -m venv env
source env/bin/activate
pip install --upgrade pip
pip install --ignore-requires-python python-minifier
pip install setuptools
186 changes: 93 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"@playwright/test": "^1.46.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@zip.js/zip.js": "^2.7.51",
"@zip.js/zip.js": "^2.7.52",
"c8": "^10.1.2",
"chokidar": "^3.6.0",
"eslint": "^9.9.1",
"linkedom": "^0.18.4",
"rollup": "^4.21.1",
"rollup": "^4.21.2",
"static-handler": "^0.4.3",
"typescript": "^5.5.4"
},
Expand Down Expand Up @@ -86,6 +86,6 @@
"to-json-callback": "^0.1.1"
},
"worker": {
"blob": "sha256-QDmhtpGRALCZn/gNlUmUSRUiiNDmiCk9Pn61k6Addho="
"blob": "sha256-n5bp7XbiMOC5xSM8r1BjWIl0efV5DHH41AoMDzRWNdg="
}
}
15 changes: 11 additions & 4 deletions rollup/build_python.cjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// ⚠️ This file creates Python modules as JS TextEncoder().encode results

const { join, resolve } = require('node:path');
const { readdirSync, readFileSync, writeFileSync } = require('node:fs');
const { readdirSync, writeFileSync } = require('node:fs');
const { spawnSync } = require("node:child_process");

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 python = stringify(
readFileSync(join(PYTHON_DIR, file)).toString()
);
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());
writeFileSync(
join(PYTHON_JS_DIR, file.replace(/\.py$/, '.js')),
`// ⚠️ DO NOT MODIFY - SOURCE FILE: "../../python/${file}"
Expand Down

0 comments on commit b1958d0

Please sign in to comment.