reroute-js 0.6.0 → 0.7.0
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/README.md +1 -0
- package/_/basic/package.json +4 -4
- package/_/basic/src/client/index.html +1 -1
- package/_/basic/src/index.ts +1 -3
- package/_/blog/package.json +4 -4
- package/_/blog/src/client/App.tsx +1 -0
- package/_/blog/src/client/index.html +1 -1
- package/_/blog/src/client/routes/blog/content/1-hello-world.tsx +1 -1
- package/_/blog/src/client/routes/blog/content/3-markdown-with-syntax-highlighting.mdx +213 -0
- package/_/blog/src/client/routes/blog/content/4-content-in-markdown.md +143 -0
- package/_/blog/src/client/routes/blog/content/5-mdx-with-components.mdx +267 -0
- package/_/blog/src/client/routes/blog/index.tsx +59 -0
- package/_/blog/src/client/routes/client.tsx +564 -0
- package/_/blog/src/client/routes/docs.tsx +670 -0
- package/_/blog/src/client/routes/index.tsx +37 -0
- package/_/blog/src/client/routes/markdown-demo.md +169 -0
- package/_/blog/src/client/routes/markdown.tsx +160 -0
- package/_/blog/src/index.ts +5 -2
- package/_/store/package.json +4 -4
- package/_/store/src/client/index.html +1 -1
- package/_/store/src/index.ts +1 -1
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +806 -14
- package/cli/bin.js.map +11 -7
- package/cli/index.d.ts +1 -1
- package/cli/index.js +52 -3
- package/cli/index.js.map +4 -3
- package/cli/src/cli.d.ts +1 -1
- package/cli/src/commands/boot.d.ts +1 -1
- package/cli/src/commands/build.d.ts +19 -0
- package/cli/src/commands/build.d.ts.map +1 -0
- package/cli/src/commands/dev.d.ts +18 -0
- package/cli/src/commands/dev.d.ts.map +1 -0
- package/cli/src/commands/gen.d.ts +1 -1
- package/cli/src/commands/init.d.ts +1 -1
- package/cli/src/commands/start.d.ts +19 -0
- package/cli/src/commands/start.d.ts.map +1 -0
- package/cli/src/libs/index.d.ts +2 -1
- package/cli/src/libs/index.d.ts.map +1 -1
- package/cli/src/libs/log.d.ts +46 -0
- package/cli/src/libs/log.d.ts.map +1 -0
- package/cli/src/libs/markdown-processor.d.ts +1 -1
- package/cli/src/libs/markdown.d.ts +1 -1
- package/cli/src/libs/tailwind.d.ts +1 -1
- package/cli/src/libs/version.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +5 -5
- package/core/index.js.map +3 -3
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/bundler/transpile.d.ts +1 -1
- package/core/src/content/discovery.d.ts +1 -1
- package/core/src/content/index.d.ts +1 -1
- package/core/src/content/metadata.d.ts +1 -1
- package/core/src/content/registry.d.ts +1 -1
- package/core/src/index.d.ts +1 -1
- package/core/src/ssr/data.d.ts +1 -1
- package/core/src/ssr/index.d.ts +1 -1
- package/core/src/ssr/modules.d.ts +1 -1
- package/core/src/ssr/render.d.ts +1 -1
- package/core/src/ssr/seed.d.ts +1 -1
- package/core/src/template/html.d.ts +1 -1
- package/core/src/template/index.d.ts +1 -1
- package/core/src/types.d.ts +1 -1
- package/core/src/utils/cache.d.ts +1 -1
- package/core/src/utils/compression.d.ts +1 -1
- package/core/src/utils/index.d.ts +1 -1
- package/core/src/utils/mime.d.ts +1 -1
- package/core/src/utils/path.d.ts +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +5 -5
- package/elysia/index.js.map +3 -3
- package/elysia/src/index.d.ts +1 -1
- package/elysia/src/libs/http.d.ts +1 -1
- package/elysia/src/libs/image.d.ts +1 -1
- package/elysia/src/plugin.d.ts +1 -1
- package/elysia/src/routes/artifacts.d.ts +1 -1
- package/elysia/src/routes/content.d.ts +1 -1
- package/elysia/src/routes/dev.d.ts +1 -1
- package/elysia/src/routes/image.d.ts +1 -1
- package/elysia/src/routes/ssr.d.ts +1 -1
- package/elysia/src/routes/static.d.ts +1 -1
- package/elysia/src/types.d.ts +1 -1
- package/package.json +6 -1
- package/react/index.d.ts +1 -1
- package/react/index.js +50 -24
- package/react/index.js.map +3 -3
- package/react/src/components/ClientOnly.d.ts +1 -1
- package/react/src/components/ContentRoute.d.ts +1 -1
- package/react/src/components/Image.d.ts +1 -1
- package/react/src/components/Link.d.ts +1 -1
- package/react/src/components/Markdown.d.ts +1 -1
- package/react/src/components/Outlet.d.ts +1 -1
- package/react/src/components/index.d.ts +1 -1
- package/react/src/hooks/index.d.ts +1 -1
- package/react/src/hooks/useContent.d.ts +1 -1
- package/react/src/hooks/useData.d.ts +1 -1
- package/react/src/hooks/useNavigate.d.ts +1 -1
- package/react/src/hooks/useParams.d.ts +1 -1
- package/react/src/hooks/useRouter.d.ts +1 -1
- package/react/src/hooks/useSearchParams.d.ts +1 -1
- package/react/src/index.d.ts +1 -1
- package/react/src/providers/ContentProvider.d.ts +1 -1
- package/react/src/providers/RerouteProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts.map +1 -1
- package/react/src/providers/index.d.ts +1 -1
- package/react/src/types/any.d.ts +1 -1
- package/react/src/types/index.d.ts +1 -1
- package/react/src/types/router.d.ts +1 -1
- package/react/src/utils/content.d.ts +1 -1
- package/react/src/utils/head.d.ts +1 -1
- package/react/src/utils/index.d.ts +1 -1
- package/_/blog/src/client/components/Counter.tsx +0 -14
package/cli/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
3
|
/**
|
|
4
|
-
* reroute-js v0.
|
|
4
|
+
* reroute-js v0.7.0
|
|
5
5
|
*
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @copyright 2025 stewones <hi@stewan.io>
|
|
@@ -10,7 +10,22 @@
|
|
|
10
10
|
* Built with Bun <3
|
|
11
11
|
*/
|
|
12
12
|
import { createRequire } from "node:module";
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __defProp = Object.defineProperty;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
19
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
20
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
21
|
+
for (let key of __getOwnPropNames(mod))
|
|
22
|
+
if (!__hasOwnProp.call(to, key))
|
|
23
|
+
__defProp(to, key, {
|
|
24
|
+
get: () => mod[key],
|
|
25
|
+
enumerable: true
|
|
26
|
+
});
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
14
29
|
var __export = (target, all) => {
|
|
15
30
|
for (var name in all)
|
|
16
31
|
__defProp(target, name, {
|
|
@@ -32,7 +47,7 @@ async function getVersionString() {
|
|
|
32
47
|
}
|
|
33
48
|
async function getVersion() {
|
|
34
49
|
if (true) {
|
|
35
|
-
return "0.
|
|
50
|
+
return "0.7.0";
|
|
36
51
|
}
|
|
37
52
|
const possiblePaths = [
|
|
38
53
|
path.join(import.meta.dir, "../../../../package.json"),
|
|
@@ -50,7 +65,7 @@ async function getVersion() {
|
|
|
50
65
|
}
|
|
51
66
|
async function getCommit() {
|
|
52
67
|
if (true) {
|
|
53
|
-
return "
|
|
68
|
+
return "4b119c0";
|
|
54
69
|
}
|
|
55
70
|
return "dev";
|
|
56
71
|
}
|
|
@@ -115,15 +130,53 @@ async function scaffoldProject(options) {
|
|
|
115
130
|
console.log(`
|
|
116
131
|
\uD83D\uDCE6 Template: ${template}
|
|
117
132
|
`);
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
const possibleTemplatePaths = [
|
|
134
|
+
join(import.meta.dir, "..", "_", template),
|
|
135
|
+
join(import.meta.dir, "..", "..", "..", "_", template)
|
|
136
|
+
];
|
|
137
|
+
let templatePath;
|
|
138
|
+
for (const path2 of possibleTemplatePaths) {
|
|
139
|
+
if (existsSync(path2)) {
|
|
140
|
+
templatePath = path2;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!templatePath) {
|
|
145
|
+
console.error(`Error: Template directory not found for template "${template}"`);
|
|
146
|
+
console.error(`Tried paths: ${possibleTemplatePaths.join(", ")}`);
|
|
121
147
|
process.exit(1);
|
|
122
148
|
}
|
|
149
|
+
const possibleExamplesPaths = [
|
|
150
|
+
join(import.meta.dir, "..", "..", "..", "..", "examples", template, "src"),
|
|
151
|
+
join(import.meta.dir, "..", "..", "..", "..", "..", "examples", template, "src")
|
|
152
|
+
];
|
|
153
|
+
let examplesPath;
|
|
154
|
+
for (const path2 of possibleExamplesPaths) {
|
|
155
|
+
if (existsSync(path2)) {
|
|
156
|
+
examplesPath = path2;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
123
160
|
await mkdir(projectPath, { recursive: true });
|
|
124
161
|
await copyTemplateFiles(templatePath, projectPath, {
|
|
125
162
|
PROJECT_NAME: projectName
|
|
126
163
|
});
|
|
164
|
+
const sourceVariables = {
|
|
165
|
+
PROJECT_NAME: projectName
|
|
166
|
+
};
|
|
167
|
+
if (examplesPath) {
|
|
168
|
+
await copySourceFiles(examplesPath, join(projectPath, "src"), sourceVariables);
|
|
169
|
+
} else {
|
|
170
|
+
const templateSrcPath = join(templatePath, "src");
|
|
171
|
+
if (existsSync(templateSrcPath)) {
|
|
172
|
+
await copySourceFiles(templateSrcPath, join(projectPath, "src"), sourceVariables);
|
|
173
|
+
} else {
|
|
174
|
+
console.error(`Error: No src directory found for template "${template}"`);
|
|
175
|
+
console.error(`Tried examples paths: ${possibleExamplesPaths.join(", ")}`);
|
|
176
|
+
console.error(`Tried template path: ${templateSrcPath}`);
|
|
177
|
+
process.exit(1);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
127
180
|
console.log(`\uD83D\uDCE5 Installing dependencies...
|
|
128
181
|
`);
|
|
129
182
|
const proc = Bun.spawn(["bun", "install"], {
|
|
@@ -137,6 +190,9 @@ async function scaffoldProject(options) {
|
|
|
137
190
|
async function copyTemplateFiles(templatePath, targetPath, variables) {
|
|
138
191
|
const entries = await readdir(templatePath, { withFileTypes: true });
|
|
139
192
|
for (const entry of entries) {
|
|
193
|
+
if (entry.isDirectory() && entry.name === "src") {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
140
196
|
const sourcePath = join(templatePath, entry.name);
|
|
141
197
|
const destPath = join(targetPath, entry.name);
|
|
142
198
|
if (entry.isDirectory()) {
|
|
@@ -153,6 +209,34 @@ async function copyTemplateFiles(templatePath, targetPath, variables) {
|
|
|
153
209
|
}
|
|
154
210
|
}
|
|
155
211
|
}
|
|
212
|
+
function applyVariableReplacements(content, fileName, variables) {
|
|
213
|
+
const shouldReplaceVariables = VARIABLE_REPLACEMENT_PATTERNS.some((pattern) => pattern.test(fileName));
|
|
214
|
+
if (!shouldReplaceVariables) {
|
|
215
|
+
return content;
|
|
216
|
+
}
|
|
217
|
+
let processedContent = content;
|
|
218
|
+
if (/\.html$/i.test(fileName)) {
|
|
219
|
+
if (variables.PROJECT_NAME) {
|
|
220
|
+
processedContent = processedContent.replace(/<title>.*?<\/title>/i, `<title>${variables.PROJECT_NAME}</title>`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return processedContent;
|
|
224
|
+
}
|
|
225
|
+
async function copySourceFiles(sourcePath, targetPath, variables) {
|
|
226
|
+
const entries = await readdir(sourcePath, { withFileTypes: true });
|
|
227
|
+
await mkdir(targetPath, { recursive: true });
|
|
228
|
+
for (const entry of entries) {
|
|
229
|
+
const sourceEntryPath = join(sourcePath, entry.name);
|
|
230
|
+
const targetEntryPath = join(targetPath, entry.name);
|
|
231
|
+
if (entry.isDirectory()) {
|
|
232
|
+
await copySourceFiles(sourceEntryPath, targetEntryPath, variables);
|
|
233
|
+
} else if (entry.isFile()) {
|
|
234
|
+
const content = await readFile(sourceEntryPath, "utf-8");
|
|
235
|
+
const processedContent = variables ? applyVariableReplacements(content, entry.name, variables) : content;
|
|
236
|
+
await writeFile(targetEntryPath, processedContent);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
156
240
|
function printSuccess(projectName, template) {
|
|
157
241
|
console.log(`
|
|
158
242
|
\uD83C\uDFCE️ Project created successfully!
|
|
@@ -205,8 +289,12 @@ async function printHelp() {
|
|
|
205
289
|
console.log(" reroute init my-blog --template blog");
|
|
206
290
|
console.log(" reroute init my-store --template store");
|
|
207
291
|
}
|
|
292
|
+
var VARIABLE_REPLACEMENT_PATTERNS;
|
|
208
293
|
var init_init = __esm(() => {
|
|
209
294
|
init_version();
|
|
295
|
+
VARIABLE_REPLACEMENT_PATTERNS = [
|
|
296
|
+
/\.html$/i
|
|
297
|
+
];
|
|
210
298
|
});
|
|
211
299
|
|
|
212
300
|
// packages/cli/src/libs/markdown.ts
|
|
@@ -1155,7 +1243,7 @@ async function generate(cwd) {
|
|
|
1155
1243
|
await writeFile2(join5(cwd, OUTPUT_INDEX), indexLines.join(`
|
|
1156
1244
|
`), "utf-8");
|
|
1157
1245
|
console.log(`[reroute/gen] Generated index: ${join5(cwd, OUTPUT_INDEX)}`);
|
|
1158
|
-
console.log("[reroute/gen]
|
|
1246
|
+
console.log("[reroute/gen] Generation complete");
|
|
1159
1247
|
}
|
|
1160
1248
|
async function gen(args) {
|
|
1161
1249
|
const cwd = process.cwd();
|
|
@@ -1269,7 +1357,7 @@ async function boot(_) {
|
|
|
1269
1357
|
console.log(`[reroute/boot] Created stub: ${OUTPUT_CONTENT_TS2}`);
|
|
1270
1358
|
await writeFile3(join6(cwd, OUTPUT_INDEX2), STUB_INDEX, "utf-8");
|
|
1271
1359
|
console.log(`[reroute/boot] Created stub: ${OUTPUT_INDEX2}`);
|
|
1272
|
-
console.log("[reroute/boot]
|
|
1360
|
+
console.log("[reroute/boot] Initialization complete");
|
|
1273
1361
|
console.log('[reroute/boot] Run "reroute gen" to generate actual routes and content.');
|
|
1274
1362
|
} catch (error) {
|
|
1275
1363
|
console.error("[reroute/boot] Failed to initialize:", error);
|
|
@@ -1313,12 +1401,692 @@ export type RerouteArtifacts = typeof artifacts;
|
|
|
1313
1401
|
`;
|
|
1314
1402
|
var init_boot = () => {};
|
|
1315
1403
|
|
|
1404
|
+
// packages/cli/src/libs/log.ts
|
|
1405
|
+
function colorizeLogPrefix(text) {
|
|
1406
|
+
let colored = text;
|
|
1407
|
+
const sortedPrefixes = Object.entries(PREFIX_COLORS).sort(([a], [b]) => b.length - a.length);
|
|
1408
|
+
for (const [prefix, colorTag] of sortedPrefixes) {
|
|
1409
|
+
colored = colored.replace(new RegExp(`(${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`, "g"), `${colorTag}$1{/}`);
|
|
1410
|
+
}
|
|
1411
|
+
return colored;
|
|
1412
|
+
}
|
|
1413
|
+
function blessedToAnsi(text) {
|
|
1414
|
+
return text.replace(/\{cyan-fg\}/g, "\x1B[36m").replace(/\{blue-fg\}/g, "\x1B[34m").replace(/\{magenta-fg\}/g, "\x1B[35m").replace(/\{yellow-fg\}/g, "\x1B[33m").replace(/\{green-fg\}/g, "\x1B[32m").replace(/\{red-fg\}/g, "\x1B[31m").replace(/\{bright-cyan-fg\}/g, "\x1B[96m").replace(/\{bright-blue-fg\}/g, "\x1B[94m").replace(/\{bright-magenta-fg\}/g, "\x1B[95m").replace(/\{bright-yellow-fg\}/g, "\x1B[93m").replace(/\{bright-green-fg\}/g, "\x1B[92m").replace(/\{bright-red-fg\}/g, "\x1B[91m").replace(/\{\/\}/g, "\x1B[0m");
|
|
1415
|
+
}
|
|
1416
|
+
function colorizeLogPrefixAnsi(text) {
|
|
1417
|
+
return blessedToAnsi(colorizeLogPrefix(text));
|
|
1418
|
+
}
|
|
1419
|
+
function createServerOutputHandler(buffer) {
|
|
1420
|
+
return (data) => {
|
|
1421
|
+
const text = buffer.current + data.toString();
|
|
1422
|
+
const lines = text.split(`
|
|
1423
|
+
`);
|
|
1424
|
+
buffer.current = lines.pop() || "";
|
|
1425
|
+
for (const line of lines) {
|
|
1426
|
+
const trimmedLine = line.trim();
|
|
1427
|
+
if (!trimmedLine) {
|
|
1428
|
+
continue;
|
|
1429
|
+
}
|
|
1430
|
+
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1431
|
+
console.log(ansiColored);
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
var PREFIX_COLORS;
|
|
1436
|
+
var init_log = __esm(() => {
|
|
1437
|
+
PREFIX_COLORS = {
|
|
1438
|
+
"[reroute]": "{cyan-fg}",
|
|
1439
|
+
"[reroute/gen]": "{bright-blue-fg}",
|
|
1440
|
+
"[reroute/content]": "{magenta-fg}",
|
|
1441
|
+
"[reroute/markdown]": "{yellow-fg}",
|
|
1442
|
+
"[reroute/tailwind]": "{red-fg}",
|
|
1443
|
+
"[reroute/mdx]": "{bright-red-fg}",
|
|
1444
|
+
"[reroute/boot]": "{bright-yellow-fg}",
|
|
1445
|
+
"[reroute/dev]": "{green-fg}",
|
|
1446
|
+
"[reroute/start]": "{bright-cyan-fg}",
|
|
1447
|
+
"[reroute/build]": "{bright-magenta-fg}",
|
|
1448
|
+
"[api]": "{blue-fg}",
|
|
1449
|
+
"[app]": "{bright-green-fg}"
|
|
1450
|
+
};
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
// packages/cli/src/commands/dev.ts
|
|
1454
|
+
var exports_dev = {};
|
|
1455
|
+
__export(exports_dev, {
|
|
1456
|
+
default: () => dev
|
|
1457
|
+
});
|
|
1458
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
1459
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
1460
|
+
import { join as join7 } from "node:path";
|
|
1461
|
+
function getRerouteCommand() {
|
|
1462
|
+
const binPath = join7(import.meta.dir, "..", "..", "bin.ts");
|
|
1463
|
+
const isBunDev = existsSync5(binPath);
|
|
1464
|
+
if (isBunDev) {
|
|
1465
|
+
return `bun ${binPath}`;
|
|
1466
|
+
}
|
|
1467
|
+
const cwd = process.cwd();
|
|
1468
|
+
const nodeModulesPaths = [
|
|
1469
|
+
join7(cwd, "node_modules", ".bin", "reroute"),
|
|
1470
|
+
join7(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
1471
|
+
join7(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
1472
|
+
join7(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
1473
|
+
];
|
|
1474
|
+
for (const binPath2 of nodeModulesPaths) {
|
|
1475
|
+
if (existsSync5(binPath2)) {
|
|
1476
|
+
return binPath2;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return "reroute";
|
|
1480
|
+
}
|
|
1481
|
+
async function dev(args) {
|
|
1482
|
+
const singleColumn = args.includes("--single") || args.includes("-s");
|
|
1483
|
+
try {
|
|
1484
|
+
console.log("[reroute/dev] Running boot...");
|
|
1485
|
+
await boot([]);
|
|
1486
|
+
console.log(`[reroute/dev] Boot complete
|
|
1487
|
+
`);
|
|
1488
|
+
console.log("[reroute/dev] Starting development servers...");
|
|
1489
|
+
console.log(`[reroute/dev] Press Ctrl+C to stop
|
|
1490
|
+
`);
|
|
1491
|
+
const rerouteCmd = getRerouteCommand();
|
|
1492
|
+
const useShell = rerouteCmd.includes(" ");
|
|
1493
|
+
const genCommand = useShell ? `${rerouteCmd} gen --watch` : rerouteCmd;
|
|
1494
|
+
const genArgs = useShell ? [] : ["gen", "--watch"];
|
|
1495
|
+
const genProcess = spawn2(genCommand, genArgs, {
|
|
1496
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1497
|
+
shell: useShell
|
|
1498
|
+
});
|
|
1499
|
+
const serverProcess = spawn2("bun", ["--watch", "src/index.ts"], {
|
|
1500
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1501
|
+
});
|
|
1502
|
+
if (singleColumn) {
|
|
1503
|
+
const genBuffer = { current: "" };
|
|
1504
|
+
const serverBuffer = { current: "" };
|
|
1505
|
+
const handleGenOutput = (data) => {
|
|
1506
|
+
const text = genBuffer.current + data.toString();
|
|
1507
|
+
const lines = text.split(`
|
|
1508
|
+
`);
|
|
1509
|
+
genBuffer.current = lines.pop() || "";
|
|
1510
|
+
for (const line of lines) {
|
|
1511
|
+
if (!line.trim()) {
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1515
|
+
console.log(ansiColored);
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
const handleServerOutput = createServerOutputHandler(serverBuffer);
|
|
1519
|
+
genProcess.stdout?.on("data", handleGenOutput);
|
|
1520
|
+
genProcess.stderr?.on("data", handleGenOutput);
|
|
1521
|
+
serverProcess.stdout?.on("data", handleServerOutput);
|
|
1522
|
+
serverProcess.stderr?.on("data", handleServerOutput);
|
|
1523
|
+
genProcess.on("exit", (code) => {
|
|
1524
|
+
console.log(`
|
|
1525
|
+
[reroute/gen] Process exited with code ${code}`);
|
|
1526
|
+
});
|
|
1527
|
+
serverProcess.on("exit", (code) => {
|
|
1528
|
+
console.log(`
|
|
1529
|
+
[server] Process exited with code ${code}`);
|
|
1530
|
+
});
|
|
1531
|
+
process.on("SIGINT", () => {
|
|
1532
|
+
console.log(`
|
|
1533
|
+
[reroute/dev] Shutting down...`);
|
|
1534
|
+
genProcess.kill("SIGINT");
|
|
1535
|
+
serverProcess.kill("SIGINT");
|
|
1536
|
+
process.exit(0);
|
|
1537
|
+
});
|
|
1538
|
+
} else {
|
|
1539
|
+
const blessed = await import("blessed");
|
|
1540
|
+
const contrib = await import("blessed-contrib");
|
|
1541
|
+
const screen = blessed.default.screen({
|
|
1542
|
+
smartCSR: true,
|
|
1543
|
+
title: "reroute dev",
|
|
1544
|
+
mouse: true
|
|
1545
|
+
});
|
|
1546
|
+
const grid = new contrib.default.grid({
|
|
1547
|
+
rows: 1,
|
|
1548
|
+
cols: 2,
|
|
1549
|
+
screen
|
|
1550
|
+
});
|
|
1551
|
+
const genBox = grid.set(0, 0, 1, 1, blessed.default.log, {
|
|
1552
|
+
label: " reroute gen --watch ",
|
|
1553
|
+
border: { type: "line" },
|
|
1554
|
+
style: {
|
|
1555
|
+
border: { fg: "cyan" }
|
|
1556
|
+
},
|
|
1557
|
+
scrollable: true,
|
|
1558
|
+
alwaysScroll: true,
|
|
1559
|
+
scrollbar: {
|
|
1560
|
+
ch: " ",
|
|
1561
|
+
inverse: true
|
|
1562
|
+
},
|
|
1563
|
+
tags: true,
|
|
1564
|
+
keys: true,
|
|
1565
|
+
vi: true,
|
|
1566
|
+
mouse: true,
|
|
1567
|
+
input: true,
|
|
1568
|
+
clickable: true
|
|
1569
|
+
});
|
|
1570
|
+
const serverBox = grid.set(0, 1, 1, 1, blessed.default.log, {
|
|
1571
|
+
label: " bun --watch src/index.ts ",
|
|
1572
|
+
border: { type: "line" },
|
|
1573
|
+
style: {
|
|
1574
|
+
border: { fg: "green" }
|
|
1575
|
+
},
|
|
1576
|
+
scrollable: true,
|
|
1577
|
+
alwaysScroll: true,
|
|
1578
|
+
scrollbar: {
|
|
1579
|
+
ch: " ",
|
|
1580
|
+
inverse: true
|
|
1581
|
+
},
|
|
1582
|
+
tags: true,
|
|
1583
|
+
keys: true,
|
|
1584
|
+
vi: true,
|
|
1585
|
+
mouse: true,
|
|
1586
|
+
input: true,
|
|
1587
|
+
clickable: true
|
|
1588
|
+
});
|
|
1589
|
+
genBox.key(["up", "k"], () => {
|
|
1590
|
+
genBox.scroll(-1);
|
|
1591
|
+
screen.render();
|
|
1592
|
+
});
|
|
1593
|
+
genBox.key(["down", "j"], () => {
|
|
1594
|
+
genBox.scroll(1);
|
|
1595
|
+
screen.render();
|
|
1596
|
+
});
|
|
1597
|
+
genBox.key(["pageup"], () => {
|
|
1598
|
+
genBox.scroll(-genBox.height);
|
|
1599
|
+
screen.render();
|
|
1600
|
+
});
|
|
1601
|
+
genBox.key(["pagedown"], () => {
|
|
1602
|
+
genBox.scroll(genBox.height);
|
|
1603
|
+
screen.render();
|
|
1604
|
+
});
|
|
1605
|
+
genBox.key(["home", "g"], () => {
|
|
1606
|
+
genBox.setScrollPerc(0);
|
|
1607
|
+
screen.render();
|
|
1608
|
+
});
|
|
1609
|
+
genBox.key(["end", "G"], () => {
|
|
1610
|
+
genBox.setScrollPerc(100);
|
|
1611
|
+
screen.render();
|
|
1612
|
+
});
|
|
1613
|
+
serverBox.key(["up", "k"], () => {
|
|
1614
|
+
serverBox.scroll(-1);
|
|
1615
|
+
screen.render();
|
|
1616
|
+
});
|
|
1617
|
+
serverBox.key(["down", "j"], () => {
|
|
1618
|
+
serverBox.scroll(1);
|
|
1619
|
+
screen.render();
|
|
1620
|
+
});
|
|
1621
|
+
serverBox.key(["pageup"], () => {
|
|
1622
|
+
serverBox.scroll(-serverBox.height);
|
|
1623
|
+
screen.render();
|
|
1624
|
+
});
|
|
1625
|
+
serverBox.key(["pagedown"], () => {
|
|
1626
|
+
serverBox.scroll(serverBox.height);
|
|
1627
|
+
screen.render();
|
|
1628
|
+
});
|
|
1629
|
+
serverBox.key(["home", "g"], () => {
|
|
1630
|
+
serverBox.setScrollPerc(0);
|
|
1631
|
+
screen.render();
|
|
1632
|
+
});
|
|
1633
|
+
serverBox.key(["end", "G"], () => {
|
|
1634
|
+
serverBox.setScrollPerc(100);
|
|
1635
|
+
screen.render();
|
|
1636
|
+
});
|
|
1637
|
+
genBox.on("wheeldown", () => {
|
|
1638
|
+
genBox.scroll(3);
|
|
1639
|
+
screen.render();
|
|
1640
|
+
});
|
|
1641
|
+
genBox.on("wheelup", () => {
|
|
1642
|
+
genBox.scroll(-3);
|
|
1643
|
+
screen.render();
|
|
1644
|
+
});
|
|
1645
|
+
serverBox.on("wheeldown", () => {
|
|
1646
|
+
serverBox.scroll(3);
|
|
1647
|
+
screen.render();
|
|
1648
|
+
});
|
|
1649
|
+
serverBox.on("wheelup", () => {
|
|
1650
|
+
serverBox.scroll(-3);
|
|
1651
|
+
screen.render();
|
|
1652
|
+
});
|
|
1653
|
+
genBox.on("click", () => {
|
|
1654
|
+
genBox.focus();
|
|
1655
|
+
screen.render();
|
|
1656
|
+
});
|
|
1657
|
+
serverBox.on("click", () => {
|
|
1658
|
+
serverBox.focus();
|
|
1659
|
+
screen.render();
|
|
1660
|
+
});
|
|
1661
|
+
screen.key(["tab"], () => {
|
|
1662
|
+
if (screen.focused === genBox) {
|
|
1663
|
+
serverBox.focus();
|
|
1664
|
+
} else {
|
|
1665
|
+
genBox.focus();
|
|
1666
|
+
}
|
|
1667
|
+
screen.render();
|
|
1668
|
+
});
|
|
1669
|
+
genBox.focus();
|
|
1670
|
+
screen.render();
|
|
1671
|
+
genProcess.stdout?.on("data", (data) => {
|
|
1672
|
+
const text = data.toString();
|
|
1673
|
+
const lines = text.split(`
|
|
1674
|
+
`).filter((line) => line.trim());
|
|
1675
|
+
if (lines.length > 0) {
|
|
1676
|
+
const colored = colorizeLogPrefix(lines.join(`
|
|
1677
|
+
`));
|
|
1678
|
+
genBox.log(colored);
|
|
1679
|
+
screen.render();
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
genProcess.stderr?.on("data", (data) => {
|
|
1683
|
+
const text = data.toString();
|
|
1684
|
+
const lines = text.split(`
|
|
1685
|
+
`).filter((line) => line.trim());
|
|
1686
|
+
if (lines.length > 0) {
|
|
1687
|
+
const colored = colorizeLogPrefix(lines.join(`
|
|
1688
|
+
`));
|
|
1689
|
+
genBox.log(colored);
|
|
1690
|
+
screen.render();
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
serverProcess.stdout?.on("data", (data) => {
|
|
1694
|
+
const text = data.toString();
|
|
1695
|
+
const filteredText = text.split(`
|
|
1696
|
+
`).filter((line) => line.trim()).join(`
|
|
1697
|
+
`);
|
|
1698
|
+
if (filteredText) {
|
|
1699
|
+
const colored = colorizeLogPrefix(filteredText);
|
|
1700
|
+
serverBox.log(colored);
|
|
1701
|
+
screen.render();
|
|
1702
|
+
}
|
|
1703
|
+
});
|
|
1704
|
+
serverProcess.stderr?.on("data", (data) => {
|
|
1705
|
+
const text = data.toString();
|
|
1706
|
+
const filteredText = text.split(`
|
|
1707
|
+
`).filter((line) => line.trim()).join(`
|
|
1708
|
+
`);
|
|
1709
|
+
if (filteredText) {
|
|
1710
|
+
const colored = colorizeLogPrefix(filteredText);
|
|
1711
|
+
serverBox.log(colored);
|
|
1712
|
+
screen.render();
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
genProcess.on("exit", (code) => {
|
|
1716
|
+
genBox.log(`
|
|
1717
|
+
[Process exited with code ${code}]`);
|
|
1718
|
+
screen.render();
|
|
1719
|
+
});
|
|
1720
|
+
serverProcess.on("exit", (code) => {
|
|
1721
|
+
serverBox.log(`
|
|
1722
|
+
[Process exited with code ${code}]`);
|
|
1723
|
+
screen.render();
|
|
1724
|
+
});
|
|
1725
|
+
screen.key(["escape", "q", "C-c"], () => {
|
|
1726
|
+
genProcess.kill("SIGINT");
|
|
1727
|
+
serverProcess.kill("SIGINT");
|
|
1728
|
+
screen.destroy();
|
|
1729
|
+
process.exit(0);
|
|
1730
|
+
});
|
|
1731
|
+
screen.on("resize", () => {
|
|
1732
|
+
screen.render();
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
} catch (error) {
|
|
1736
|
+
if (error.code === "SIGINT") {
|
|
1737
|
+
console.log(`
|
|
1738
|
+
[reroute/dev] Shutting down...`);
|
|
1739
|
+
process.exit(0);
|
|
1740
|
+
}
|
|
1741
|
+
console.error("[reroute/dev] Error:", error);
|
|
1742
|
+
throw error;
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
var init_dev = __esm(() => {
|
|
1746
|
+
init_log();
|
|
1747
|
+
init_boot();
|
|
1748
|
+
});
|
|
1749
|
+
|
|
1750
|
+
// packages/cli/src/commands/start.ts
|
|
1751
|
+
var exports_start = {};
|
|
1752
|
+
__export(exports_start, {
|
|
1753
|
+
default: () => start
|
|
1754
|
+
});
|
|
1755
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
1756
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
1757
|
+
import { join as join8 } from "node:path";
|
|
1758
|
+
function getRerouteCommand2() {
|
|
1759
|
+
const binPath = join8(import.meta.dir, "..", "..", "bin.ts");
|
|
1760
|
+
const isBunDev = existsSync6(binPath);
|
|
1761
|
+
if (isBunDev) {
|
|
1762
|
+
return `bun ${binPath}`;
|
|
1763
|
+
}
|
|
1764
|
+
const cwd = process.cwd();
|
|
1765
|
+
const nodeModulesPaths = [
|
|
1766
|
+
join8(cwd, "node_modules", ".bin", "reroute"),
|
|
1767
|
+
join8(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
1768
|
+
join8(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
1769
|
+
join8(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
1770
|
+
];
|
|
1771
|
+
for (const binPath2 of nodeModulesPaths) {
|
|
1772
|
+
if (existsSync6(binPath2)) {
|
|
1773
|
+
return binPath2;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
return "reroute";
|
|
1777
|
+
}
|
|
1778
|
+
async function start(_args) {
|
|
1779
|
+
try {
|
|
1780
|
+
const rerouteCmd = getRerouteCommand2();
|
|
1781
|
+
const useShell = rerouteCmd.includes(" ");
|
|
1782
|
+
const bootBuffer = { current: "" };
|
|
1783
|
+
const genBuffer = { current: "" };
|
|
1784
|
+
const handleBootOutput = (data) => {
|
|
1785
|
+
const text = bootBuffer.current + data.toString();
|
|
1786
|
+
const lines = text.split(`
|
|
1787
|
+
`);
|
|
1788
|
+
bootBuffer.current = lines.pop() || "";
|
|
1789
|
+
for (const line of lines) {
|
|
1790
|
+
if (!line.trim()) {
|
|
1791
|
+
continue;
|
|
1792
|
+
}
|
|
1793
|
+
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1794
|
+
console.log(ansiColored);
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
const handleGenOutput = (data) => {
|
|
1798
|
+
const text = genBuffer.current + data.toString();
|
|
1799
|
+
const lines = text.split(`
|
|
1800
|
+
`);
|
|
1801
|
+
genBuffer.current = lines.pop() || "";
|
|
1802
|
+
for (const line of lines) {
|
|
1803
|
+
if (!line.trim()) {
|
|
1804
|
+
continue;
|
|
1805
|
+
}
|
|
1806
|
+
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1807
|
+
console.log(ansiColored);
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/start] Running boot...")}
|
|
1811
|
+
`);
|
|
1812
|
+
const bootCommand = useShell ? `${rerouteCmd} boot` : rerouteCmd;
|
|
1813
|
+
const bootArgs = useShell ? [] : ["boot"];
|
|
1814
|
+
await new Promise((resolve, reject) => {
|
|
1815
|
+
const bootProcess = spawn3(bootCommand, bootArgs, {
|
|
1816
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1817
|
+
shell: useShell
|
|
1818
|
+
});
|
|
1819
|
+
bootProcess.stdout?.on("data", handleBootOutput);
|
|
1820
|
+
bootProcess.stderr?.on("data", handleBootOutput);
|
|
1821
|
+
bootProcess.on("exit", (code) => {
|
|
1822
|
+
if (code !== null && code !== 0) {
|
|
1823
|
+
reject(new Error(`Boot exited with code ${code}`));
|
|
1824
|
+
} else {
|
|
1825
|
+
resolve();
|
|
1826
|
+
}
|
|
1827
|
+
});
|
|
1828
|
+
bootProcess.on("error", (error) => {
|
|
1829
|
+
reject(error);
|
|
1830
|
+
});
|
|
1831
|
+
});
|
|
1832
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Boot complete
|
|
1833
|
+
`));
|
|
1834
|
+
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/start] Running gen...")}
|
|
1835
|
+
`);
|
|
1836
|
+
const genCommand = useShell ? `${rerouteCmd} gen` : rerouteCmd;
|
|
1837
|
+
const genArgs = useShell ? [] : ["gen"];
|
|
1838
|
+
await new Promise((resolve, reject) => {
|
|
1839
|
+
const genProcess = spawn3(genCommand, genArgs, {
|
|
1840
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1841
|
+
shell: useShell
|
|
1842
|
+
});
|
|
1843
|
+
genProcess.stdout?.on("data", handleGenOutput);
|
|
1844
|
+
genProcess.stderr?.on("data", handleGenOutput);
|
|
1845
|
+
genProcess.on("exit", (code) => {
|
|
1846
|
+
if (code !== null && code !== 0) {
|
|
1847
|
+
reject(new Error(`Gen exited with code ${code}`));
|
|
1848
|
+
} else {
|
|
1849
|
+
resolve();
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
genProcess.on("error", (error) => {
|
|
1853
|
+
reject(error);
|
|
1854
|
+
});
|
|
1855
|
+
});
|
|
1856
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Generation complete
|
|
1857
|
+
`));
|
|
1858
|
+
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/start] Starting server...")}
|
|
1859
|
+
`);
|
|
1860
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Press Ctrl+C to stop
|
|
1861
|
+
`));
|
|
1862
|
+
const serverProcess = spawn3("bun", ["src/index.ts"], {
|
|
1863
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1864
|
+
});
|
|
1865
|
+
const serverBuffer = { current: "" };
|
|
1866
|
+
const handleServerOutput = createServerOutputHandler(serverBuffer);
|
|
1867
|
+
serverProcess.stdout?.on("data", handleServerOutput);
|
|
1868
|
+
serverProcess.stderr?.on("data", handleServerOutput);
|
|
1869
|
+
process.on("SIGINT", () => {
|
|
1870
|
+
process.stdout.write(`${colorizeLogPrefixAnsi(`
|
|
1871
|
+
[reroute/start] Shutting down...`)}
|
|
1872
|
+
`);
|
|
1873
|
+
serverProcess.kill("SIGINT");
|
|
1874
|
+
process.exit(0);
|
|
1875
|
+
});
|
|
1876
|
+
await new Promise((resolve, reject) => {
|
|
1877
|
+
serverProcess.on("exit", (code) => {
|
|
1878
|
+
if (code !== null && code !== 0) {
|
|
1879
|
+
console.error(colorizeLogPrefixAnsi(`[reroute/start] Server exited with code ${code}`));
|
|
1880
|
+
reject(new Error(`Server exited with code ${code}`));
|
|
1881
|
+
} else {
|
|
1882
|
+
resolve();
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
serverProcess.on("error", (error) => {
|
|
1886
|
+
reject(error);
|
|
1887
|
+
});
|
|
1888
|
+
});
|
|
1889
|
+
} catch (error) {
|
|
1890
|
+
if (error.code === "SIGINT") {
|
|
1891
|
+
process.stdout.write(`${colorizeLogPrefixAnsi(`
|
|
1892
|
+
[reroute/start] Shutting down...`)}
|
|
1893
|
+
`);
|
|
1894
|
+
process.exit(0);
|
|
1895
|
+
}
|
|
1896
|
+
process.stderr.write(`${colorizeLogPrefixAnsi("[reroute/start] Error: ") + String(error)}
|
|
1897
|
+
`);
|
|
1898
|
+
throw error;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
var init_start = __esm(() => {
|
|
1902
|
+
init_log();
|
|
1903
|
+
});
|
|
1904
|
+
|
|
1905
|
+
// packages/cli/src/commands/build.ts
|
|
1906
|
+
var exports_build = {};
|
|
1907
|
+
__export(exports_build, {
|
|
1908
|
+
default: () => build
|
|
1909
|
+
});
|
|
1910
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
1911
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
|
|
1912
|
+
import { join as join9 } from "node:path";
|
|
1913
|
+
function getRerouteCommand3() {
|
|
1914
|
+
const binPath = join9(import.meta.dir, "..", "..", "bin.ts");
|
|
1915
|
+
const isBunDev = existsSync7(binPath);
|
|
1916
|
+
if (isBunDev) {
|
|
1917
|
+
return `bun ${binPath}`;
|
|
1918
|
+
}
|
|
1919
|
+
const cwd = process.cwd();
|
|
1920
|
+
const nodeModulesPaths = [
|
|
1921
|
+
join9(cwd, "node_modules", ".bin", "reroute"),
|
|
1922
|
+
join9(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
1923
|
+
join9(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
1924
|
+
join9(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
1925
|
+
];
|
|
1926
|
+
for (const binPath2 of nodeModulesPaths) {
|
|
1927
|
+
if (existsSync7(binPath2)) {
|
|
1928
|
+
return binPath2;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
return "reroute";
|
|
1932
|
+
}
|
|
1933
|
+
function getOutputName() {
|
|
1934
|
+
const cwd = process.cwd();
|
|
1935
|
+
const packageJsonPath = join9(cwd, "package.json");
|
|
1936
|
+
if (existsSync7(packageJsonPath)) {
|
|
1937
|
+
try {
|
|
1938
|
+
const packageJson = JSON.parse(readFileSync4(packageJsonPath, "utf-8"));
|
|
1939
|
+
const name = packageJson.name;
|
|
1940
|
+
if (name) {
|
|
1941
|
+
const parts = name.split("-");
|
|
1942
|
+
if (parts.length > 1 && parts[parts.length - 1] === "example") {
|
|
1943
|
+
return parts[parts.length - 2] || "app";
|
|
1944
|
+
}
|
|
1945
|
+
return parts[parts.length - 1] || name;
|
|
1946
|
+
}
|
|
1947
|
+
} catch {}
|
|
1948
|
+
}
|
|
1949
|
+
return "app";
|
|
1950
|
+
}
|
|
1951
|
+
async function build(args) {
|
|
1952
|
+
try {
|
|
1953
|
+
const rerouteCmd = getRerouteCommand3();
|
|
1954
|
+
const useShell = rerouteCmd.includes(" ");
|
|
1955
|
+
let outputPath = `./dist/${getOutputName()}`;
|
|
1956
|
+
const outfileIndex = args.indexOf("--outfile");
|
|
1957
|
+
const shortOutfileIndex = args.indexOf("-o");
|
|
1958
|
+
const outfileArgIndex = outfileIndex !== -1 ? outfileIndex : shortOutfileIndex;
|
|
1959
|
+
if (outfileArgIndex !== -1 && args[outfileArgIndex + 1]) {
|
|
1960
|
+
outputPath = args[outfileArgIndex + 1];
|
|
1961
|
+
}
|
|
1962
|
+
const bootBuffer = { current: "" };
|
|
1963
|
+
const genBuffer = { current: "" };
|
|
1964
|
+
const handleBootOutput = (data) => {
|
|
1965
|
+
const text = bootBuffer.current + data.toString();
|
|
1966
|
+
const lines = text.split(`
|
|
1967
|
+
`);
|
|
1968
|
+
bootBuffer.current = lines.pop() || "";
|
|
1969
|
+
for (const line of lines) {
|
|
1970
|
+
if (!line.trim()) {
|
|
1971
|
+
continue;
|
|
1972
|
+
}
|
|
1973
|
+
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1974
|
+
console.log(ansiColored);
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
const handleGenOutput = (data) => {
|
|
1978
|
+
const text = genBuffer.current + data.toString();
|
|
1979
|
+
const lines = text.split(`
|
|
1980
|
+
`);
|
|
1981
|
+
genBuffer.current = lines.pop() || "";
|
|
1982
|
+
for (const line of lines) {
|
|
1983
|
+
if (!line.trim()) {
|
|
1984
|
+
continue;
|
|
1985
|
+
}
|
|
1986
|
+
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1987
|
+
console.log(ansiColored);
|
|
1988
|
+
}
|
|
1989
|
+
};
|
|
1990
|
+
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/build] Running boot...")}
|
|
1991
|
+
`);
|
|
1992
|
+
const bootCommand = useShell ? `${rerouteCmd} boot` : rerouteCmd;
|
|
1993
|
+
const bootArgs = useShell ? [] : ["boot"];
|
|
1994
|
+
await new Promise((resolve, reject) => {
|
|
1995
|
+
const bootProcess = spawn4(bootCommand, bootArgs, {
|
|
1996
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1997
|
+
shell: useShell
|
|
1998
|
+
});
|
|
1999
|
+
bootProcess.stdout?.on("data", handleBootOutput);
|
|
2000
|
+
bootProcess.stderr?.on("data", handleBootOutput);
|
|
2001
|
+
bootProcess.on("exit", (code) => {
|
|
2002
|
+
if (code !== null && code !== 0) {
|
|
2003
|
+
reject(new Error(`Boot exited with code ${code}`));
|
|
2004
|
+
} else {
|
|
2005
|
+
resolve();
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
bootProcess.on("error", (error) => {
|
|
2009
|
+
reject(error);
|
|
2010
|
+
});
|
|
2011
|
+
});
|
|
2012
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Boot complete
|
|
2013
|
+
`));
|
|
2014
|
+
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/build] Running gen...")}
|
|
2015
|
+
`);
|
|
2016
|
+
const genCommand = useShell ? `${rerouteCmd} gen` : rerouteCmd;
|
|
2017
|
+
const genArgs = useShell ? [] : ["gen"];
|
|
2018
|
+
await new Promise((resolve, reject) => {
|
|
2019
|
+
const genProcess = spawn4(genCommand, genArgs, {
|
|
2020
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
2021
|
+
shell: useShell
|
|
2022
|
+
});
|
|
2023
|
+
genProcess.stdout?.on("data", handleGenOutput);
|
|
2024
|
+
genProcess.stderr?.on("data", handleGenOutput);
|
|
2025
|
+
genProcess.on("exit", (code) => {
|
|
2026
|
+
if (code !== null && code !== 0) {
|
|
2027
|
+
reject(new Error(`Gen exited with code ${code}`));
|
|
2028
|
+
} else {
|
|
2029
|
+
resolve();
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
genProcess.on("error", (error) => {
|
|
2033
|
+
reject(error);
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Generation complete
|
|
2037
|
+
`));
|
|
2038
|
+
process.stdout.write(`${colorizeLogPrefixAnsi(`[reroute/build] Building binary to ${outputPath}...`)}
|
|
2039
|
+
`);
|
|
2040
|
+
const isProduction = true;
|
|
2041
|
+
const buildArgs = ["build", "src/index.ts", "--target", "bun", "--compile"];
|
|
2042
|
+
if (isProduction) {
|
|
2043
|
+
buildArgs.push("--minify");
|
|
2044
|
+
}
|
|
2045
|
+
const filteredArgs = args.filter((arg, idx) => {
|
|
2046
|
+
if (outfileArgIndex !== -1) {
|
|
2047
|
+
if (idx === outfileArgIndex || idx === outfileArgIndex + 1) {
|
|
2048
|
+
return false;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
return arg !== "--outfile" && arg !== "-o" && arg !== "--minify" && arg !== "--no-minify";
|
|
2052
|
+
});
|
|
2053
|
+
buildArgs.push(...filteredArgs, "--outfile", outputPath);
|
|
2054
|
+
await new Promise((resolve, reject) => {
|
|
2055
|
+
const buildProcess = spawn4("bun", buildArgs, {
|
|
2056
|
+
stdio: "inherit"
|
|
2057
|
+
});
|
|
2058
|
+
buildProcess.on("exit", (code) => {
|
|
2059
|
+
if (code !== null && code !== 0) {
|
|
2060
|
+
reject(new Error(`Build exited with code ${code}`));
|
|
2061
|
+
} else {
|
|
2062
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Build complete: ${outputPath}
|
|
2063
|
+
`));
|
|
2064
|
+
resolve();
|
|
2065
|
+
}
|
|
2066
|
+
});
|
|
2067
|
+
buildProcess.on("error", (error) => {
|
|
2068
|
+
reject(error);
|
|
2069
|
+
});
|
|
2070
|
+
});
|
|
2071
|
+
} catch (error) {
|
|
2072
|
+
process.stderr.write(`${colorizeLogPrefixAnsi("[reroute/build] Error: ") + String(error)}
|
|
2073
|
+
`);
|
|
2074
|
+
throw error;
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
var init_build = __esm(() => {
|
|
2078
|
+
init_log();
|
|
2079
|
+
});
|
|
2080
|
+
|
|
1316
2081
|
// packages/cli/src/cli.ts
|
|
1317
2082
|
import path2 from "node:path";
|
|
1318
2083
|
var commands = {
|
|
1319
2084
|
init: () => Promise.resolve().then(() => (init_init(), exports_init)),
|
|
1320
2085
|
gen: () => Promise.resolve().then(() => (init_gen(), exports_gen)),
|
|
1321
|
-
boot: () => Promise.resolve().then(() => (init_boot(), exports_boot))
|
|
2086
|
+
boot: () => Promise.resolve().then(() => (init_boot(), exports_boot)),
|
|
2087
|
+
dev: () => Promise.resolve().then(() => (init_dev(), exports_dev)),
|
|
2088
|
+
start: () => Promise.resolve().then(() => (init_start(), exports_start)),
|
|
2089
|
+
build: () => Promise.resolve().then(() => (init_build(), exports_build))
|
|
1322
2090
|
};
|
|
1323
2091
|
async function main() {
|
|
1324
2092
|
const args = process.argv.slice(2);
|
|
@@ -1347,25 +2115,49 @@ async function main() {
|
|
|
1347
2115
|
}
|
|
1348
2116
|
}
|
|
1349
2117
|
async function printHelp2() {
|
|
2118
|
+
console.log("");
|
|
1350
2119
|
console.log(await getVersionString2());
|
|
1351
2120
|
console.log("");
|
|
2121
|
+
console.log("");
|
|
1352
2122
|
console.log("Usage:");
|
|
2123
|
+
console.log("");
|
|
1353
2124
|
console.log(" reroute <command> [options]");
|
|
1354
2125
|
console.log("");
|
|
2126
|
+
console.log("");
|
|
1355
2127
|
console.log("Commands:");
|
|
2128
|
+
console.log("");
|
|
2129
|
+
console.log(" init Scaffold a new Reroute project");
|
|
1356
2130
|
console.log(" boot Initialize .reroute directory with stub files");
|
|
1357
2131
|
console.log(" gen Generate content registry and static assets");
|
|
1358
|
-
console.log("
|
|
2132
|
+
console.log(" dev Start development environment");
|
|
2133
|
+
console.log(" start Run production-like server locally");
|
|
2134
|
+
console.log(" build Build production binary");
|
|
2135
|
+
console.log("");
|
|
1359
2136
|
console.log("");
|
|
1360
2137
|
console.log("Options:");
|
|
2138
|
+
console.log("");
|
|
1361
2139
|
console.log(" -h, --help Show help");
|
|
1362
2140
|
console.log(" -v, --version Show version");
|
|
1363
2141
|
console.log("");
|
|
2142
|
+
console.log("");
|
|
1364
2143
|
console.log("Examples:");
|
|
2144
|
+
console.log("");
|
|
2145
|
+
console.log(" reroute init my-app");
|
|
1365
2146
|
console.log(" reroute boot");
|
|
2147
|
+
console.log("");
|
|
1366
2148
|
console.log(" reroute gen");
|
|
2149
|
+
console.log(" reroute gen -w");
|
|
1367
2150
|
console.log(" reroute gen --watch");
|
|
1368
|
-
console.log("
|
|
2151
|
+
console.log("");
|
|
2152
|
+
console.log(" reroute dev");
|
|
2153
|
+
console.log(" reroute dev -s");
|
|
2154
|
+
console.log(" reroute dev --single");
|
|
2155
|
+
console.log("");
|
|
2156
|
+
console.log(" reroute start");
|
|
2157
|
+
console.log("");
|
|
2158
|
+
console.log(" reroute build");
|
|
2159
|
+
console.log(" reroute build -o ./dist/myapp");
|
|
2160
|
+
console.log(" reroute build --outfile ./dist/myapp");
|
|
1369
2161
|
}
|
|
1370
2162
|
async function getVersionString2() {
|
|
1371
2163
|
const version = await getVersion2();
|
|
@@ -1374,7 +2166,7 @@ async function getVersionString2() {
|
|
|
1374
2166
|
}
|
|
1375
2167
|
async function getVersion2() {
|
|
1376
2168
|
if (true) {
|
|
1377
|
-
return "0.
|
|
2169
|
+
return "0.7.0";
|
|
1378
2170
|
}
|
|
1379
2171
|
const possiblePaths = [
|
|
1380
2172
|
path2.join(import.meta.dir, "../../../package.json"),
|
|
@@ -1391,10 +2183,10 @@ async function getVersion2() {
|
|
|
1391
2183
|
}
|
|
1392
2184
|
async function getCommit2() {
|
|
1393
2185
|
if (true) {
|
|
1394
|
-
return "
|
|
2186
|
+
return "4b119c0";
|
|
1395
2187
|
}
|
|
1396
2188
|
return "dev";
|
|
1397
2189
|
}
|
|
1398
2190
|
main();
|
|
1399
2191
|
|
|
1400
|
-
//# debugId=
|
|
2192
|
+
//# debugId=B8066BB70A3F2A9464756E2164756E21
|