@magneticjs/cli 0.1.2 → 0.1.4
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.
- package/dist/cli.js +28 -2
- package/package.json +3 -3
- package/scripts/install-server.js +12 -12
- package/src/bundler.ts +46 -2
- package/wasm/transport.wasm +0 -0
package/dist/cli.js
CHANGED
|
@@ -148,8 +148,33 @@ function generateBridge(scan) {
|
|
|
148
148
|
|
|
149
149
|
// src/bundler.ts
|
|
150
150
|
import { build } from "esbuild";
|
|
151
|
-
import { join as join2 } from "node:path";
|
|
152
|
-
import { mkdirSync, existsSync as existsSync2, statSync as statSync2, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
151
|
+
import { join as join2, dirname as dirname2 } from "node:path";
|
|
152
|
+
import { mkdirSync, existsSync as existsSync2, statSync as statSync2, readdirSync as readdirSync2, readFileSync as readFileSync2, copyFileSync } from "node:fs";
|
|
153
|
+
import { createRequire } from "node:module";
|
|
154
|
+
function copyTransportWasm(appDir, monorepoRoot) {
|
|
155
|
+
const publicDir = join2(appDir, "public");
|
|
156
|
+
const dest = join2(publicDir, "transport.wasm");
|
|
157
|
+
if (existsSync2(dest)) return true;
|
|
158
|
+
const candidates = [];
|
|
159
|
+
if (monorepoRoot) {
|
|
160
|
+
candidates.push(join2(monorepoRoot, "js/packages/magnetic-server/wasm/transport.wasm"));
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const require2 = createRequire(join2(appDir, "package.json"));
|
|
164
|
+
const serverPkg = require2.resolve("@magneticjs/server");
|
|
165
|
+
candidates.push(join2(dirname2(serverPkg), "..", "wasm", "transport.wasm"));
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
candidates.push(join2(import.meta.dirname || __dirname, "..", "wasm", "transport.wasm"));
|
|
169
|
+
for (const src of candidates) {
|
|
170
|
+
if (existsSync2(src)) {
|
|
171
|
+
mkdirSync(publicDir, { recursive: true });
|
|
172
|
+
copyFileSync(src, dest);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
153
178
|
async function bundleApp(opts) {
|
|
154
179
|
const outDir = opts.outDir || join2(opts.appDir, "dist");
|
|
155
180
|
const outFile = opts.outFile || "app.js";
|
|
@@ -157,6 +182,7 @@ async function bundleApp(opts) {
|
|
|
157
182
|
if (!existsSync2(outDir)) {
|
|
158
183
|
mkdirSync(outDir, { recursive: true });
|
|
159
184
|
}
|
|
185
|
+
copyTransportWasm(opts.appDir, opts.monorepoRoot);
|
|
160
186
|
const alias = {};
|
|
161
187
|
if (opts.monorepoRoot) {
|
|
162
188
|
const serverPkg = join2(opts.monorepoRoot, "js/packages/magnetic-server/src");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magneticjs/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Magnetic CLI — build, dev, and deploy server-driven UI apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"dev": "tsx src/cli.ts",
|
|
12
12
|
"postinstall": "node scripts/install-server.js || true"
|
|
13
13
|
},
|
|
14
|
-
"files": ["dist", "src", "scripts"],
|
|
14
|
+
"files": ["dist", "src", "scripts", "wasm"],
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@magneticjs/server": "^0.1.
|
|
19
|
+
"@magneticjs/server": "^0.1.1",
|
|
20
20
|
"esbuild": "^0.27.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* for the current platform during `npm install @magneticjs/cli`.
|
|
5
5
|
*
|
|
6
6
|
* Update strategy:
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
7
|
+
* - SERVER_VERSION is hardcoded (decoupled from npm package version)
|
|
8
|
+
* - Only bump SERVER_VERSION when a new binary is uploaded to GitHub Releases
|
|
9
9
|
* - Binary version is tracked in bin/.version
|
|
10
10
|
* - If version mismatch → re-download; if match → skip
|
|
11
11
|
*
|
|
@@ -26,18 +26,18 @@ const binDir = join(pkgDir, 'bin');
|
|
|
26
26
|
const binPath = join(binDir, 'magnetic-v8-server');
|
|
27
27
|
const versionFile = join(binDir, '.version');
|
|
28
28
|
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
const
|
|
29
|
+
// Server binary version — decoupled from npm package version.
|
|
30
|
+
// Only bump this when a new binary is uploaded to GitHub Releases.
|
|
31
|
+
const SERVER_VERSION = '0.1.0';
|
|
32
32
|
|
|
33
|
-
// Check if installed binary matches current
|
|
33
|
+
// Check if installed binary matches current server version
|
|
34
34
|
if (existsSync(binPath) && existsSync(versionFile)) {
|
|
35
35
|
const installed = readFileSync(versionFile, 'utf-8').trim();
|
|
36
|
-
if (installed ===
|
|
37
|
-
console.log(`[magnetic] Server binary v${
|
|
36
|
+
if (installed === SERVER_VERSION) {
|
|
37
|
+
console.log(`[magnetic] Server binary v${SERVER_VERSION} already installed, skipping`);
|
|
38
38
|
process.exit(0);
|
|
39
39
|
}
|
|
40
|
-
console.log(`[magnetic] Server binary outdated (${installed} → ${
|
|
40
|
+
console.log(`[magnetic] Server binary outdated (${installed} → ${SERVER_VERSION}), updating...`);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Determine platform target
|
|
@@ -60,7 +60,7 @@ if (!target) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const baseUrl = process.env.MAGNETIC_BINARY_URL ||
|
|
63
|
-
`https://github.com/inventhq/magnetic/releases/download/v${
|
|
63
|
+
`https://github.com/inventhq/magnetic/releases/download/v${SERVER_VERSION}`;
|
|
64
64
|
const filename = `magnetic-v8-server-${target}.tar.gz`;
|
|
65
65
|
const url = `${baseUrl}/${filename}`;
|
|
66
66
|
|
|
@@ -91,8 +91,8 @@ try {
|
|
|
91
91
|
|
|
92
92
|
if (downloaded && existsSync(binPath)) {
|
|
93
93
|
chmodSync(binPath, 0o755);
|
|
94
|
-
writeFileSync(versionFile,
|
|
95
|
-
console.log(`[magnetic] ✓ Server binary v${
|
|
94
|
+
writeFileSync(versionFile, SERVER_VERSION);
|
|
95
|
+
console.log(`[magnetic] ✓ Server binary v${SERVER_VERSION} installed: ${binPath}`);
|
|
96
96
|
} else {
|
|
97
97
|
throw new Error(`Download failed or binary not found after extraction`);
|
|
98
98
|
}
|
package/src/bundler.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Takes generated bridge code and bundles it into an IIFE for V8
|
|
3
3
|
|
|
4
4
|
import { build } from 'esbuild';
|
|
5
|
-
import { join, resolve } from 'node:path';
|
|
6
|
-
import { mkdirSync, existsSync, writeFileSync, statSync, readdirSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { join, resolve, dirname } from 'node:path';
|
|
6
|
+
import { mkdirSync, existsSync, writeFileSync, statSync, readdirSync, readFileSync, copyFileSync } from 'node:fs';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
7
8
|
|
|
8
9
|
export interface BundleOptions {
|
|
9
10
|
/** Absolute path to the app directory */
|
|
@@ -25,6 +26,46 @@ export interface BundleResult {
|
|
|
25
26
|
sizeBytes: number;
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Copy transport.wasm into the app's public/ directory.
|
|
31
|
+
* Looks in @magneticjs/server/wasm/ (npm) or monorepo path.
|
|
32
|
+
*/
|
|
33
|
+
export function copyTransportWasm(appDir: string, monorepoRoot?: string): boolean {
|
|
34
|
+
const publicDir = join(appDir, 'public');
|
|
35
|
+
const dest = join(publicDir, 'transport.wasm');
|
|
36
|
+
|
|
37
|
+
// Already there — skip
|
|
38
|
+
if (existsSync(dest)) return true;
|
|
39
|
+
|
|
40
|
+
// Candidate locations for the WASM file
|
|
41
|
+
const candidates: string[] = [];
|
|
42
|
+
|
|
43
|
+
// Monorepo path
|
|
44
|
+
if (monorepoRoot) {
|
|
45
|
+
candidates.push(join(monorepoRoot, 'js/packages/magnetic-server/wasm/transport.wasm'));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// npm-installed @magneticjs/server
|
|
49
|
+
try {
|
|
50
|
+
const require = createRequire(join(appDir, 'package.json'));
|
|
51
|
+
const serverPkg = require.resolve('@magneticjs/server');
|
|
52
|
+
candidates.push(join(dirname(serverPkg), '..', 'wasm', 'transport.wasm'));
|
|
53
|
+
} catch {}
|
|
54
|
+
|
|
55
|
+
// CLI's own bundled copy (sibling to dist/)
|
|
56
|
+
candidates.push(join(import.meta.dirname || __dirname, '..', 'wasm', 'transport.wasm'));
|
|
57
|
+
|
|
58
|
+
for (const src of candidates) {
|
|
59
|
+
if (existsSync(src)) {
|
|
60
|
+
mkdirSync(publicDir, { recursive: true });
|
|
61
|
+
copyFileSync(src, dest);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
28
69
|
/**
|
|
29
70
|
* Bundle the generated bridge code into an IIFE for V8 consumption.
|
|
30
71
|
* Uses esbuild with stdin so no temp file is needed.
|
|
@@ -38,6 +79,9 @@ export async function bundleApp(opts: BundleOptions): Promise<BundleResult> {
|
|
|
38
79
|
mkdirSync(outDir, { recursive: true });
|
|
39
80
|
}
|
|
40
81
|
|
|
82
|
+
// Ensure transport.wasm is in public/
|
|
83
|
+
copyTransportWasm(opts.appDir, opts.monorepoRoot);
|
|
84
|
+
|
|
41
85
|
// Resolve @magneticjs/server — in monorepo use actual path, otherwise npm package
|
|
42
86
|
const alias: Record<string, string> = {};
|
|
43
87
|
if (opts.monorepoRoot) {
|
|
Binary file
|