@jxrstudios/jxr 1.1.11 → 1.2.11

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/bin/jxr.js +174 -4
  2. package/package.json +1 -1
package/bin/jxr.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { JXRServerManager, JXRDeployer } from "../src/index.ts";
3
3
 
4
- import { mkdir, writeFile, cp } from "fs/promises";
4
+ import { mkdir, writeFile, cp, readdir } from "fs/promises";
5
5
  import { existsSync } from "fs";
6
6
  import path from "path";
7
7
  import { fileURLToPath } from "url";
@@ -73,6 +73,175 @@ if (command === "init") {
73
73
  process.exit(1);
74
74
  }
75
75
 
76
+ } else if (command === "build") {
77
+ // Build command - production-optimized build
78
+ const platform = args.find((a) => a.startsWith("--platform="))?.split("=")[1] || "web";
79
+ const analyze = args.includes("--analyze");
80
+ const noMinify = args.includes("--no-minify");
81
+ const outDir = args.find((a) => a.startsWith("--out-dir="))?.split("=")[1] || "dist";
82
+
83
+ console.log(`šŸ”Ø Building for ${platform}...`);
84
+
85
+ try {
86
+ const esbuild = await import("esbuild");
87
+ const fs = await import("fs");
88
+ const path = await import("path");
89
+ const crypto = await import("crypto");
90
+
91
+ // Ensure output directory exists
92
+ await mkdir(outDir, { recursive: true });
93
+ await mkdir(path.join(outDir, "assets"), { recursive: true });
94
+
95
+ // Find entry point
96
+ const entryFile = fs.existsSync("src/main.tsx") ? "src/main.tsx" :
97
+ fs.existsSync("src/main.ts") ? "src/main.ts" :
98
+ fs.existsSync("src/App.tsx") ? "src/App.tsx" : "src/index.tsx";
99
+
100
+ // Build configuration
101
+ const buildConfig = {
102
+ entryPoints: [entryFile],
103
+ bundle: true,
104
+ platform: platform === "node" ? "node" : "browser",
105
+ target: platform === "cloudflare-worker" ? "es2022" : "es2020",
106
+ format: "esm",
107
+ minify: !noMinify,
108
+ sourcemap: !noMinify,
109
+ splitting: platform !== "node",
110
+ outdir: path.join(outDir, "assets"),
111
+ entryNames: "[name]-[hash]",
112
+ chunkNames: "[name]-[hash]",
113
+ assetNames: "[name]-[hash]",
114
+ metafile: true,
115
+ define: {
116
+ "process.env.NODE_ENV": '"production"',
117
+ ...(platform === "cloudflare-worker" && {
118
+ "process": "{}",
119
+ "process.env": "{}",
120
+ }),
121
+ },
122
+ external: [
123
+ "react", "react/jsx-runtime", "react/jsx-dev-runtime", "react-dom/client",
124
+ "wouter", "lucide-react", "sonner", "next-themes", "framer-motion", "motion-dom",
125
+ "@radix-ui/react-dialog", "@radix-ui/react-tooltip", "@radix-ui/react-slot",
126
+ "clsx", "tailwind-merge", "class-variance-authority",
127
+ "tailwindcss", "tw-animate-css",
128
+ ...(platform === "cloudflare-worker" ? ["__STATIC_CONTENT_MANIFEST"] : []),
129
+ ],
130
+ alias: {
131
+ "@": "./src",
132
+ },
133
+ loader: {
134
+ ".tsx": "tsx",
135
+ ".ts": "ts",
136
+ ".css": "css",
137
+ ".png": "file",
138
+ ".jpg": "file",
139
+ ".svg": "file",
140
+ },
141
+ };
142
+
143
+ // Run build
144
+ const result = await esbuild.build(buildConfig);
145
+
146
+ console.log(`āœ… Build complete: ${outDir}/`);
147
+
148
+ // Analyze bundle if requested
149
+ if (analyze && result.metafile) {
150
+ console.log("\nšŸ“Š Bundle Analysis:");
151
+ const outputs = Object.entries(result.metafile.outputs);
152
+ outputs.sort((a, b) => b[1].bytes - a[1].bytes);
153
+ outputs.slice(0, 10).forEach(([file, info]) => {
154
+ const sizeKB = (info.bytes / 1024).toFixed(2);
155
+ console.log(` ${file}: ${sizeKB} KB`);
156
+ });
157
+ }
158
+
159
+ // Find main entry output (exclude source maps)
160
+ const mainOutput = Object.keys(result.metafile?.outputs || {}).find(k =>
161
+ (k.includes("main-") || k.includes("index-")) && k.endsWith(".js")
162
+ );
163
+ const vendorOutput = Object.keys(result.metafile?.outputs || {}).find(k =>
164
+ k.includes("chunk-") && k.endsWith(".js")
165
+ );
166
+
167
+ // Copy compiled CSS if available
168
+ if (fs.existsSync("src/index.compiled.css")) {
169
+ fs.copyFileSync("src/index.compiled.css", path.join(outDir, "assets", "index-[hash].css"));
170
+ console.log(` šŸ“„ Copied compiled CSS`);
171
+ }
172
+
173
+ // Find CSS output
174
+ const cssOutput = Object.keys(result.metafile?.outputs || {}).find(k => k.endsWith(".css"));
175
+
176
+ // Generate index.html with proper CSS and JS references
177
+ const indexHtml = `<!DOCTYPE html>
178
+ <html lang="en">
179
+ <head>
180
+ <meta charset="UTF-8">
181
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
182
+ <title>JXR.js — Edge OS Runtime Framework</title>
183
+ <meta name="description" content="JXR.js is the next-generation edge runtime framework for React Native and React. MoQ transport, Web Crypto, Worker pools.">
184
+
185
+ <!-- Google Fonts -->
186
+ <link rel="preconnect" href="https://fonts.googleapis.com">
187
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
188
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
189
+
190
+ ${cssOutput ? `<link rel="stylesheet" href="${cssOutput.replace(outDir, "").replace(/^\//, "")}">` : ""}
191
+ </head>
192
+ <body>
193
+ <div id="root"></div>
194
+ ${vendorOutput ? `<script type="module" src="${vendorOutput.replace(outDir, "").replace(/^\//, "")}"></script>` : ""}
195
+ <script type="module" src="${mainOutput ? mainOutput.replace(outDir, "").replace(/^\//, "") : "assets/index.js"}"></script>
196
+ </body>
197
+ </html>`;
198
+
199
+ await writeFile(path.join(outDir, "index.html"), indexHtml);
200
+
201
+ // Generate crypto-signed manifest
202
+ const manifest = {
203
+ version: "1.0.0",
204
+ platform,
205
+ buildTime: new Date().toISOString(),
206
+ entries: {
207
+ main: mainOutput ? path.basename(mainOutput) : "index.js",
208
+ ...(vendorOutput && { vendor: path.basename(vendorOutput) }),
209
+ },
210
+ files: Object.keys(result.metafile?.outputs || {}).map(k => path.basename(k)),
211
+ };
212
+
213
+ // Sign manifest with ECDSA P-256
214
+ const manifestJson = JSON.stringify(manifest, null, 2);
215
+ const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", {
216
+ namedCurve: "prime256v1",
217
+ });
218
+ const signature = crypto.sign("sha256", Buffer.from(manifestJson), privateKey);
219
+
220
+ const signedManifest = {
221
+ ...manifest,
222
+ signature: signature.toString("base64"),
223
+ algorithm: "ECDSA-P256",
224
+ publicKey: publicKey.export({ type: "spki", format: "pem" }),
225
+ };
226
+
227
+ await writeFile(
228
+ path.join(outDir, "jxr-manifest.json"),
229
+ JSON.stringify(signedManifest, null, 2)
230
+ );
231
+
232
+ console.log(`āœ… Manifest: ${outDir}/jxr-manifest.json`);
233
+ console.log(` Signed with ECDSA-P256`);
234
+
235
+ // Show output files
236
+ console.log("\nšŸ“ Build outputs:");
237
+ const files = await readdir(outDir, { recursive: true });
238
+ files.forEach(f => console.log(` ${f}`));
239
+
240
+ } catch (err) {
241
+ console.error("āŒ Build failed:", err.message);
242
+ process.exit(1);
243
+ }
244
+
76
245
  } else if (command === "deploy") {
77
246
  // Deploy command
78
247
  const projectPath = args[1] || "./dist";
@@ -123,8 +292,9 @@ if (command === "init") {
123
292
 
124
293
  } else {
125
294
  console.log("Usage:");
126
- console.log(" jxr init <project-name> Create new project");
127
- console.log(" jxr dev [--port=3000] Start dev server");
128
- console.log(" jxr deploy <path> Deploy to production");
295
+ console.log(" jxr init <project-name> Create new project");
296
+ console.log(" jxr dev [--port=3000] Start dev server");
297
+ console.log(" jxr build [--platform=web] Production build");
298
+ console.log(" jxr deploy <path> [--env=prod] Deploy to production");
129
299
  process.exit(1);
130
300
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jxrstudios/jxr",
3
- "version": "1.1.11",
3
+ "version": "1.2.11",
4
4
  "description": "JXR.js — Edge OS Runtime Framework for elite developers",
5
5
  "type": "module",
6
6
  "license": "MIT",