forge-cw 0.1.21 → 0.1.22
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/index.js +108 -53
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9027,8 +9027,8 @@ async function createDatabase(opts) {
|
|
|
9027
9027
|
await db.migrate();
|
|
9028
9028
|
return db;
|
|
9029
9029
|
}
|
|
9030
|
-
const { join:
|
|
9031
|
-
return new ForgeDB(
|
|
9030
|
+
const { join: join22 } = await import("node:path");
|
|
9031
|
+
return new ForgeDB(join22(opts.dataDir, "forge.db"));
|
|
9032
9032
|
}
|
|
9033
9033
|
var init_db_factory = __esm({
|
|
9034
9034
|
"../core/dist/db-factory.js"() {
|
|
@@ -9115,6 +9115,82 @@ var init_port_in_use = __esm({
|
|
|
9115
9115
|
}
|
|
9116
9116
|
});
|
|
9117
9117
|
|
|
9118
|
+
// ../core/dist/start.js
|
|
9119
|
+
import { existsSync as existsSync17, readFileSync as readFileSync13 } from "node:fs";
|
|
9120
|
+
import { join as join20 } from "node:path";
|
|
9121
|
+
async function startForge(options) {
|
|
9122
|
+
const { port, version, consoleDist: consoleDist2, bundledModulesDir: bundledModulesDir2, databaseUrl, authToken, fallbackToFreePort = false } = options;
|
|
9123
|
+
const { forgeDir } = ensureForgeDir();
|
|
9124
|
+
const isTeam = !!databaseUrl;
|
|
9125
|
+
const { host, localOnly } = resolveListenOptions(isTeam);
|
|
9126
|
+
const authProblem = remoteAuthProblem(localOnly, authToken);
|
|
9127
|
+
if (authProblem)
|
|
9128
|
+
return { status: "refused", reason: authProblem };
|
|
9129
|
+
const remoteToken = localOnly ? void 0 : authToken;
|
|
9130
|
+
const db = await createDatabase({ mode: isTeam ? "team" : "local", dataDir: forgeDir, databaseUrl });
|
|
9131
|
+
const server = createForgeServer({
|
|
9132
|
+
dataDir: forgeDir,
|
|
9133
|
+
port,
|
|
9134
|
+
db,
|
|
9135
|
+
authToken: remoteToken,
|
|
9136
|
+
localOnly,
|
|
9137
|
+
bundledModulesDir: bundledModulesDir2,
|
|
9138
|
+
version
|
|
9139
|
+
});
|
|
9140
|
+
if (consoleDist2 && existsSync17(join20(consoleDist2, "index.html"))) {
|
|
9141
|
+
const { serveStatic } = await import("@hono/node-server/serve-static");
|
|
9142
|
+
server.app.use("/*", serveStatic({ root: consoleDist2 }));
|
|
9143
|
+
const indexHtml = readFileSync13(join20(consoleDist2, "index.html"), "utf-8");
|
|
9144
|
+
server.app.get("*", (c) => c.html(indexHtml));
|
|
9145
|
+
}
|
|
9146
|
+
const { serve } = await import("@hono/node-server");
|
|
9147
|
+
const listen = async (p) => {
|
|
9148
|
+
const s = serve({ fetch: server.app.fetch, port: p, hostname: host });
|
|
9149
|
+
await waitForListening(s);
|
|
9150
|
+
return s;
|
|
9151
|
+
};
|
|
9152
|
+
let httpServer;
|
|
9153
|
+
try {
|
|
9154
|
+
httpServer = await listen(port);
|
|
9155
|
+
} catch (err) {
|
|
9156
|
+
if (err.code !== "EADDRINUSE") {
|
|
9157
|
+
server.close();
|
|
9158
|
+
throw err;
|
|
9159
|
+
}
|
|
9160
|
+
const holder = await probePort(port);
|
|
9161
|
+
if (holder === "forge" || !fallbackToFreePort) {
|
|
9162
|
+
server.close();
|
|
9163
|
+
return { status: "in-use", port, holder };
|
|
9164
|
+
}
|
|
9165
|
+
httpServer = await listen(0);
|
|
9166
|
+
}
|
|
9167
|
+
server.attachTerminalWs(httpServer);
|
|
9168
|
+
const address = httpServer.address();
|
|
9169
|
+
const actualPort = typeof address === "object" && address ? address.port : port;
|
|
9170
|
+
return {
|
|
9171
|
+
status: "listening",
|
|
9172
|
+
url: `http://localhost:${actualPort}`,
|
|
9173
|
+
port: actualPort,
|
|
9174
|
+
isTeam,
|
|
9175
|
+
authRequired: !!remoteToken,
|
|
9176
|
+
close: () => {
|
|
9177
|
+
server.close();
|
|
9178
|
+
httpServer.close();
|
|
9179
|
+
}
|
|
9180
|
+
};
|
|
9181
|
+
}
|
|
9182
|
+
var init_start = __esm({
|
|
9183
|
+
"../core/dist/start.js"() {
|
|
9184
|
+
"use strict";
|
|
9185
|
+
init_server();
|
|
9186
|
+
init_db_factory();
|
|
9187
|
+
init_init();
|
|
9188
|
+
init_origin_guard();
|
|
9189
|
+
init_auth();
|
|
9190
|
+
init_port_in_use();
|
|
9191
|
+
}
|
|
9192
|
+
});
|
|
9193
|
+
|
|
9118
9194
|
// ../core/dist/index.js
|
|
9119
9195
|
var dist_exports = {};
|
|
9120
9196
|
__export(dist_exports, {
|
|
@@ -9158,6 +9234,7 @@ __export(dist_exports, {
|
|
|
9158
9234
|
resolveKiokuBin: () => resolveKiokuBin,
|
|
9159
9235
|
resolveListenOptions: () => resolveListenOptions,
|
|
9160
9236
|
skillRoutes: () => skillRoutes,
|
|
9237
|
+
startForge: () => startForge,
|
|
9161
9238
|
supports: () => supports,
|
|
9162
9239
|
validateParams: () => validateParams,
|
|
9163
9240
|
waitForListening: () => waitForListening
|
|
@@ -9187,15 +9264,16 @@ var init_dist2 = __esm({
|
|
|
9187
9264
|
init_kioku_routes();
|
|
9188
9265
|
init_kioku();
|
|
9189
9266
|
init_port_in_use();
|
|
9267
|
+
init_start();
|
|
9190
9268
|
init_module_install();
|
|
9191
9269
|
init_task_review();
|
|
9192
9270
|
}
|
|
9193
9271
|
});
|
|
9194
9272
|
|
|
9195
9273
|
// src/index.ts
|
|
9196
|
-
import { existsSync as
|
|
9274
|
+
import { existsSync as existsSync18, readFileSync as readFileSync14 } from "node:fs";
|
|
9197
9275
|
import { homedir as homedir9 } from "node:os";
|
|
9198
|
-
import { join as
|
|
9276
|
+
import { join as join21 } from "node:path";
|
|
9199
9277
|
function parseArgs(argv) {
|
|
9200
9278
|
const out = { open: true };
|
|
9201
9279
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -9206,82 +9284,59 @@ function parseArgs(argv) {
|
|
|
9206
9284
|
}
|
|
9207
9285
|
return out;
|
|
9208
9286
|
}
|
|
9209
|
-
var packageRoot =
|
|
9210
|
-
var isCheckout =
|
|
9211
|
-
var consoleDist = isCheckout ?
|
|
9212
|
-
var forgeVersion = JSON.parse(
|
|
9213
|
-
var bundledModulesDir = isCheckout ?
|
|
9287
|
+
var packageRoot = join21(import.meta.dirname, "..");
|
|
9288
|
+
var isCheckout = existsSync18(join21(packageRoot, "src"));
|
|
9289
|
+
var consoleDist = isCheckout ? join21(packageRoot, "../console/dist") : join21(packageRoot, "console");
|
|
9290
|
+
var forgeVersion = JSON.parse(readFileSync14(join21(packageRoot, "package.json"), "utf-8")).version;
|
|
9291
|
+
var bundledModulesDir = isCheckout ? join21(packageRoot, "../../modules") : join21(packageRoot, "modules");
|
|
9214
9292
|
async function main() {
|
|
9215
|
-
const { ensureForgeDir: ensureForgeDir2,
|
|
9293
|
+
const { ensureForgeDir: ensureForgeDir2, startForge: startForge2, ensureCw: ensureCw2, pathWithCw: pathWithCw2, quietSqliteWarning: quietSqliteWarning2, portInUseMessage: portInUseMessage2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
9216
9294
|
quietSqliteWarning2();
|
|
9217
9295
|
const args = parseArgs(process.argv.slice(2));
|
|
9218
|
-
const {
|
|
9296
|
+
const { created } = ensureForgeDir2();
|
|
9219
9297
|
if (created) {
|
|
9220
9298
|
console.log("First run \u2014 initialized Forge.");
|
|
9221
9299
|
}
|
|
9222
|
-
const cwHome =
|
|
9223
|
-
const cw = isCheckout ? { action: "skipped", message: "a checkout does not install CW" } : await ensureCw2({ cwHome, bundleDir:
|
|
9300
|
+
const cwHome = join21(process.env.HOME ?? homedir9(), ".cw");
|
|
9301
|
+
const cw = isCheckout ? { action: "skipped", message: "a checkout does not install CW" } : await ensureCw2({ cwHome, bundleDir: join21(packageRoot, "cw") });
|
|
9224
9302
|
if (cw.action === "installed") console.log(` Installed CW ${cw.version} in ${cwHome}`);
|
|
9225
9303
|
else if (cw.action === "updated") console.log(` Updated ${cw.message}`);
|
|
9226
9304
|
else if (cw.action === "failed") console.log(` Could not install CW: ${cw.message}`);
|
|
9227
9305
|
process.env.PATH = pathWithCw2(cwHome, process.env.PATH);
|
|
9228
9306
|
const port = parseInt(args.port ?? process.env.FORGE_PORT ?? "3000", 10);
|
|
9229
|
-
const dbUrl = process.env.FORGE_DB_URL;
|
|
9230
9307
|
const authToken = process.env.FORGE_AUTH_TOKEN;
|
|
9231
|
-
const
|
|
9232
|
-
const { host, localOnly } = resolveListenOptions2(isTeam);
|
|
9233
|
-
const authProblem = remoteAuthProblem2(localOnly, authToken);
|
|
9234
|
-
if (authProblem) {
|
|
9235
|
-
console.log(`
|
|
9236
|
-
${authProblem}
|
|
9237
|
-
`);
|
|
9238
|
-
process.exit(1);
|
|
9239
|
-
}
|
|
9240
|
-
const remoteToken = localOnly ? void 0 : authToken;
|
|
9241
|
-
const db = await createDatabase2({
|
|
9242
|
-
mode: isTeam ? "team" : "local",
|
|
9243
|
-
dataDir: forgeDir,
|
|
9244
|
-
databaseUrl: dbUrl
|
|
9245
|
-
});
|
|
9246
|
-
const server = createForgeServer2({
|
|
9247
|
-
dataDir: forgeDir,
|
|
9308
|
+
const started = await startForge2({
|
|
9248
9309
|
port,
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
localOnly,
|
|
9310
|
+
version: forgeVersion,
|
|
9311
|
+
consoleDist,
|
|
9252
9312
|
bundledModulesDir,
|
|
9253
|
-
|
|
9313
|
+
databaseUrl: process.env.FORGE_DB_URL,
|
|
9314
|
+
authToken
|
|
9254
9315
|
});
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9316
|
+
if (started.status === "refused") {
|
|
9317
|
+
console.log(`
|
|
9318
|
+
${started.reason}
|
|
9319
|
+
`);
|
|
9320
|
+
process.exit(1);
|
|
9260
9321
|
}
|
|
9261
|
-
|
|
9262
|
-
const httpServer = serve({ fetch: server.app.fetch, port, hostname: host });
|
|
9263
|
-
try {
|
|
9264
|
-
await waitForListening2(httpServer);
|
|
9265
|
-
} catch (err) {
|
|
9266
|
-
if (err.code !== "EADDRINUSE") throw err;
|
|
9267
|
-
const holder = await probePort2(port);
|
|
9322
|
+
if (started.status === "in-use") {
|
|
9268
9323
|
console.log(`
|
|
9269
|
-
${portInUseMessage2(port, holder)}
|
|
9324
|
+
${portInUseMessage2(port, started.holder)}
|
|
9270
9325
|
`);
|
|
9271
|
-
if (holder === "forge" && args.open && process.env.FORGE_NO_OPEN !== "1") {
|
|
9326
|
+
if (started.holder === "forge" && args.open && process.env.FORGE_NO_OPEN !== "1") {
|
|
9272
9327
|
try {
|
|
9273
9328
|
const open = (await import("open")).default;
|
|
9274
9329
|
await open(`http://localhost:${port}`);
|
|
9275
9330
|
} catch {
|
|
9276
9331
|
}
|
|
9277
9332
|
}
|
|
9278
|
-
process.exit(holder === "forge" ? 0 : 1);
|
|
9333
|
+
process.exit(started.holder === "forge" ? 0 : 1);
|
|
9279
9334
|
}
|
|
9280
|
-
|
|
9335
|
+
const { isTeam, authRequired } = started;
|
|
9281
9336
|
console.log(`
|
|
9282
9337
|
Forge Console running at http://localhost:${port}
|
|
9283
9338
|
Mode: ${isTeam ? "team (PostgreSQL)" : "local (SQLite)"}
|
|
9284
|
-
${
|
|
9339
|
+
${authRequired ? ` Auth: token required. Browsers sign in once at http://<this host>:${port}/auth?token=<FORGE_AUTH_TOKEN>;
|
|
9285
9340
|
the CLI and scripts send Authorization: Bearer <FORGE_AUTH_TOKEN>
|
|
9286
9341
|
` : ""}
|
|
9287
9342
|
Dashboard: http://localhost:${port}
|
|
@@ -9292,7 +9347,7 @@ ${remoteToken ? ` Auth: token required. Browsers sign in once at http://<this h
|
|
|
9292
9347
|
if (args.open && process.env.FORGE_NO_OPEN !== "1") {
|
|
9293
9348
|
try {
|
|
9294
9349
|
const open = (await import("open")).default;
|
|
9295
|
-
await open(
|
|
9350
|
+
await open(authRequired && authToken ? `http://localhost:${port}/auth?token=${encodeURIComponent(authToken)}` : `http://localhost:${port}`);
|
|
9296
9351
|
} catch {
|
|
9297
9352
|
}
|
|
9298
9353
|
}
|