mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Added npm run dev (#1572)
This commit is contained in:
committed by
GitHub
parent
3a3cb7b11d
commit
7813c3f03f
@@ -8,5 +8,6 @@
|
||||
"ecmaVersion": 12,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"ignorePatterns": ["__template.js"],
|
||||
"rules": {}
|
||||
}
|
||||
|
||||
1
pyscript.core/.gitignore
vendored
1
pyscript.core/.gitignore
vendored
@@ -5,4 +5,5 @@ cjs/
|
||||
!cjs/package.json
|
||||
core.js
|
||||
esm/worker/xworker.js
|
||||
esm/worker/__template.js
|
||||
types/
|
||||
|
||||
@@ -16,4 +16,6 @@ node.importmap
|
||||
sw.js
|
||||
tsconfig.json
|
||||
cjs/worker/_template.js
|
||||
cjs/worker/__template.js
|
||||
esm/worker/_template.js
|
||||
esm/worker/__template.js
|
||||
|
||||
@@ -43,3 +43,7 @@ NO_MIN=1 npm run build
|
||||
|
||||
npm run server
|
||||
```
|
||||
|
||||
### Dev Build
|
||||
|
||||
Beside spinning the _localhost_ server via `npm run server`, the `npm run dev` will watch changes in the `./esm` folder and it will build automatically non optimized artifacts out of the box.
|
||||
|
||||
33
pyscript.core/dev.cjs
Normal file
33
pyscript.core/dev.cjs
Normal file
@@ -0,0 +1,33 @@
|
||||
let queue = Promise.resolve();
|
||||
|
||||
const { exec } = require("node:child_process");
|
||||
|
||||
const build = (fileName) => {
|
||||
if (fileName) console.log(fileName, "changed");
|
||||
else console.log("building without optimizations");
|
||||
queue = queue.then(
|
||||
() =>
|
||||
new Promise((resolve, reject) => {
|
||||
exec(
|
||||
"npm run rollup:xworker && npm run rollup:core && npm run rollup:pyscript",
|
||||
{ cwd: __dirname, env: { ...process.env, NO_MIN: true } },
|
||||
(error) => {
|
||||
if (error) reject(error);
|
||||
else
|
||||
resolve(
|
||||
console.log(fileName || "", "build completed"),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const options = {
|
||||
ignored: /\/(?:__template|interpreters|xworker)\.[mc]?js$/,
|
||||
persistent: true,
|
||||
};
|
||||
|
||||
require("chokidar").watch("./esm", options).on("change", build);
|
||||
|
||||
build();
|
||||
@@ -8,6 +8,7 @@
|
||||
"server": "npx static-handler --cors --coep --coop --corp .",
|
||||
"build": "npm run rollup:xworker && npm run rollup:core && npm run rollup:pyscript && eslint esm/ && npm run ts && npm run cjs && npm run test",
|
||||
"cjs": "ascjs --no-default esm cjs",
|
||||
"dev": "node dev.cjs",
|
||||
"rollup:core": "rollup --config rollup/core.config.js",
|
||||
"rollup:pyscript": "rollup --config rollup/pyscript.config.js",
|
||||
"rollup:xworker": "rollup --config rollup/xworker.config.js",
|
||||
@@ -32,6 +33,7 @@
|
||||
"@rollup/plugin-terser": "^0.4.3",
|
||||
"ascjs": "^5.0.1",
|
||||
"c8": "^8.0.0",
|
||||
"chokidar": "^3.5.3",
|
||||
"eslint": "^8.43.0",
|
||||
"linkedom": "^0.14.26",
|
||||
"rollup": "^3.25.3",
|
||||
@@ -64,6 +66,6 @@
|
||||
"coincident": "^0.8.3"
|
||||
},
|
||||
"worker": {
|
||||
"blob": "sha256-CaHDEAEttvghrbLR/GVAofT+zQZyy0Ri9tkpVTNBbiE="
|
||||
"blob": "sha256-eWNZbyS06lxxlUW/bkU7/fl/Levxxxfiv/+frsgl/fA="
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ const PACKAGE_JSON = resolve(join(__dirname, "..", "package.json"));
|
||||
|
||||
for (const file of readdirSync(WORKERS_DIR)) {
|
||||
if (file.startsWith("__")) {
|
||||
if (process.env.NO_MIN) {
|
||||
writeFileSync(
|
||||
join(WORKERS_DIR, "xworker.js"),
|
||||
`/* c8 ignore next */\nexport default () => new Worker('/esm/worker/__template.js',{type:'module'});`,
|
||||
);
|
||||
} else {
|
||||
const js = JSON.stringify(
|
||||
readFileSync(join(WORKERS_DIR, file)).toString(),
|
||||
);
|
||||
@@ -20,11 +26,15 @@ for (const file of readdirSync(WORKERS_DIR)) {
|
||||
hash.update(js);
|
||||
const json = require(PACKAGE_JSON);
|
||||
json.worker = { blob: "sha256-" + hash.digest("base64") };
|
||||
writeFileSync(PACKAGE_JSON, JSON.stringify(json, null, " ") + "\n");
|
||||
writeFileSync(
|
||||
PACKAGE_JSON,
|
||||
JSON.stringify(json, null, " ") + "\n",
|
||||
);
|
||||
writeFileSync(
|
||||
join(WORKERS_DIR, "xworker.js"),
|
||||
`/* c8 ignore next */\nexport default () => new Worker(URL.createObjectURL(new Blob([${js}],{type:'application/javascript'})),{type:'module'});`,
|
||||
);
|
||||
rmSync(join(WORKERS_DIR, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user