@cfasim-ui/pyodide 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/src/vitePlugin.ts +35 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfasim-ui/pyodide",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Pyodide (Python-in-browser) integration for cfasim-ui",
6
6
  "license": "Apache-2.0",
@@ -13,11 +13,12 @@
13
13
  "src"
14
14
  ],
15
15
  "exports": {
16
- ".": "./src/index.ts"
16
+ ".": "./src/index.ts",
17
+ "./vite": "./src/vitePlugin.ts"
17
18
  },
18
19
  "dependencies": {
19
20
  "pyodide": "^0.29.3",
20
- "@cfasim-ui/shared": "0.1.2"
21
+ "@cfasim-ui/shared": "0.1.3"
21
22
  },
22
23
  "peerDependencies": {
23
24
  "vue": "^3.5.0"
@@ -0,0 +1,35 @@
1
+ import { execSync } from "node:child_process";
2
+ import { readdirSync, writeFileSync, mkdirSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import type { Plugin } from "vite";
5
+
6
+ interface CfasimPyodideOptions {
7
+ /** Path to the Python model directory (default: "model") */
8
+ model?: string;
9
+ }
10
+
11
+ /**
12
+ * Vite plugin that builds a Python wheel from a local model directory
13
+ * and generates wheels.json in the public directory.
14
+ */
15
+ export function cfasimPyodide(options?: CfasimPyodideOptions): Plugin {
16
+ const modelDir = options?.model ?? "model";
17
+
18
+ function build(root: string) {
19
+ const publicDir = resolve(root, "public");
20
+ mkdirSync(publicDir, { recursive: true });
21
+ execSync(`uv build ${modelDir} --wheel --out-dir public`, {
22
+ cwd: root,
23
+ stdio: "pipe",
24
+ });
25
+ const wheels = readdirSync(publicDir).filter((f) => f.endsWith(".whl"));
26
+ writeFileSync(resolve(publicDir, "wheels.json"), JSON.stringify(wheels));
27
+ }
28
+
29
+ return {
30
+ name: "cfasim-pyodide",
31
+ configResolved(config) {
32
+ build(config.root);
33
+ },
34
+ };
35
+ }