everything-dev 0.3.2 → 1.3.2
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 +64 -0
- package/cli.js +10 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/api-contract.cjs +172 -0
- package/dist/api-contract.cjs.map +1 -0
- package/dist/api-contract.mjs +171 -0
- package/dist/api-contract.mjs.map +1 -0
- package/dist/api.cjs +124 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +36 -0
- package/dist/api.d.cts.map +1 -0
- package/dist/api.d.mts +36 -0
- package/dist/api.d.mts.map +1 -0
- package/dist/api.mjs +119 -0
- package/dist/api.mjs.map +1 -0
- package/dist/app.cjs +156 -0
- package/dist/app.cjs.map +1 -0
- package/dist/app.mjs +153 -0
- package/dist/app.mjs.map +1 -0
- package/dist/cli/catalog.cjs +30 -0
- package/dist/cli/catalog.cjs.map +1 -0
- package/dist/cli/catalog.mjs +29 -0
- package/dist/cli/catalog.mjs.map +1 -0
- package/dist/cli/help.cjs +16 -0
- package/dist/cli/help.cjs.map +1 -0
- package/dist/cli/help.mjs +16 -0
- package/dist/cli/help.mjs.map +1 -0
- package/dist/cli/init.cjs +317 -0
- package/dist/cli/init.cjs.map +1 -0
- package/dist/cli/init.d.cts +36 -0
- package/dist/cli/init.d.cts.map +1 -0
- package/dist/cli/init.d.mts +36 -0
- package/dist/cli/init.d.mts.map +1 -0
- package/dist/cli/init.mjs +309 -0
- package/dist/cli/init.mjs.map +1 -0
- package/dist/cli/parse.cjs +96 -0
- package/dist/cli/parse.cjs.map +1 -0
- package/dist/cli/parse.mjs +95 -0
- package/dist/cli/parse.mjs.map +1 -0
- package/dist/cli/prompts.cjs +42 -0
- package/dist/cli/prompts.cjs.map +1 -0
- package/dist/cli/prompts.mjs +41 -0
- package/dist/cli/prompts.mjs.map +1 -0
- package/dist/cli.cjs +167 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +166 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/components/dev-view.cjs +307 -0
- package/dist/components/dev-view.cjs.map +1 -0
- package/dist/components/dev-view.mjs +306 -0
- package/dist/components/dev-view.mjs.map +1 -0
- package/dist/components/streaming-view.cjs +146 -0
- package/dist/components/streaming-view.cjs.map +1 -0
- package/dist/components/streaming-view.mjs +144 -0
- package/dist/components/streaming-view.mjs.map +1 -0
- package/dist/config.cjs +280 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +35 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +35 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +266 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract.cjs +209 -0
- package/dist/contract.cjs.map +1 -0
- package/dist/contract.d.cts +490 -0
- package/dist/contract.d.cts.map +1 -0
- package/dist/contract.d.mts +490 -0
- package/dist/contract.d.mts.map +1 -0
- package/dist/contract.meta.cjs +104 -0
- package/dist/contract.meta.cjs.map +1 -0
- package/dist/contract.meta.d.cts +141 -0
- package/dist/contract.meta.d.cts.map +1 -0
- package/dist/contract.meta.d.mts +141 -0
- package/dist/contract.meta.d.mts.map +1 -0
- package/dist/contract.meta.mjs +102 -0
- package/dist/contract.meta.mjs.map +1 -0
- package/dist/contract.mjs +186 -0
- package/dist/contract.mjs.map +1 -0
- package/dist/dev-logs.cjs +53 -0
- package/dist/dev-logs.cjs.map +1 -0
- package/dist/dev-logs.mjs +51 -0
- package/dist/dev-logs.mjs.map +1 -0
- package/dist/dev-session.cjs +195 -0
- package/dist/dev-session.cjs.map +1 -0
- package/dist/dev-session.mjs +194 -0
- package/dist/dev-session.mjs.map +1 -0
- package/dist/fastkv.cjs +89 -0
- package/dist/fastkv.cjs.map +1 -0
- package/dist/fastkv.d.cts +11 -0
- package/dist/fastkv.d.cts.map +1 -0
- package/dist/fastkv.d.mts +11 -0
- package/dist/fastkv.d.mts.map +1 -0
- package/dist/fastkv.mjs +82 -0
- package/dist/fastkv.mjs.map +1 -0
- package/dist/federation.server.cjs +27 -0
- package/dist/federation.server.cjs.map +1 -0
- package/dist/federation.server.mjs +27 -0
- package/dist/federation.server.mjs.map +1 -0
- package/dist/host.cjs +367 -0
- package/dist/host.cjs.map +1 -0
- package/dist/host.d.cts +22 -0
- package/dist/host.d.cts.map +1 -0
- package/dist/host.d.mts +22 -0
- package/dist/host.d.mts.map +1 -0
- package/dist/host.mjs +364 -0
- package/dist/host.mjs.map +1 -0
- package/dist/index.cjs +122 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +9 -0
- package/dist/integrity.cjs +39 -0
- package/dist/integrity.cjs.map +1 -0
- package/dist/integrity.d.cts +7 -0
- package/dist/integrity.d.cts.map +1 -0
- package/dist/integrity.d.mts +7 -0
- package/dist/integrity.d.mts.map +1 -0
- package/dist/integrity.mjs +35 -0
- package/dist/integrity.mjs.map +1 -0
- package/dist/mf.cjs +77 -0
- package/dist/mf.cjs.map +1 -0
- package/dist/mf.d.cts +19 -0
- package/dist/mf.d.cts.map +1 -0
- package/dist/mf.d.mts +19 -0
- package/dist/mf.d.mts.map +1 -0
- package/dist/mf.mjs +71 -0
- package/dist/mf.mjs.map +1 -0
- package/dist/near-cli.cjs +196 -0
- package/dist/near-cli.cjs.map +1 -0
- package/dist/near-cli.mjs +193 -0
- package/dist/near-cli.mjs.map +1 -0
- package/dist/network.cjs +9 -0
- package/dist/network.cjs.map +1 -0
- package/dist/network.mjs +8 -0
- package/dist/network.mjs.map +1 -0
- package/dist/orchestrator.cjs +441 -0
- package/dist/orchestrator.cjs.map +1 -0
- package/dist/orchestrator.d.cts +40 -0
- package/dist/orchestrator.d.cts.map +1 -0
- package/dist/orchestrator.d.mts +40 -0
- package/dist/orchestrator.d.mts.map +1 -0
- package/dist/orchestrator.mjs +436 -0
- package/dist/orchestrator.mjs.map +1 -0
- package/dist/plugin.cjs +825 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts +347 -0
- package/dist/plugin.d.cts.map +1 -0
- package/dist/plugin.d.mts +348 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/plugin.mjs +822 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/process-registry.cjs +120 -0
- package/dist/process-registry.cjs.map +1 -0
- package/dist/process-registry.d.cts +25 -0
- package/dist/process-registry.d.cts.map +1 -0
- package/dist/process-registry.d.mts +25 -0
- package/dist/process-registry.d.mts.map +1 -0
- package/dist/process-registry.mjs +119 -0
- package/dist/process-registry.mjs.map +1 -0
- package/dist/sdk.cjs +61 -0
- package/dist/sdk.d.cts +5 -0
- package/dist/sdk.d.mts +5 -0
- package/dist/sdk.mjs +6 -0
- package/dist/shared.cjs +143 -0
- package/dist/shared.cjs.map +1 -0
- package/dist/shared.d.cts +33 -0
- package/dist/shared.d.cts.map +1 -0
- package/dist/shared.d.mts +33 -0
- package/dist/shared.d.mts.map +1 -0
- package/dist/shared.mjs +140 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/types.cjs +160 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +269 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +269 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +144 -0
- package/dist/types.mjs.map +1 -0
- package/dist/ui/head.cjs +67 -0
- package/dist/ui/head.cjs.map +1 -0
- package/dist/ui/head.d.cts +19 -0
- package/dist/ui/head.d.cts.map +1 -0
- package/dist/ui/head.d.mts +19 -0
- package/dist/ui/head.d.mts.map +1 -0
- package/dist/ui/head.mjs +61 -0
- package/dist/ui/head.mjs.map +1 -0
- package/dist/ui/index.cjs +32 -0
- package/dist/ui/index.d.cts +7 -0
- package/dist/ui/index.d.mts +7 -0
- package/dist/ui/index.mjs +6 -0
- package/dist/ui/metadata.cjs +106 -0
- package/dist/ui/metadata.cjs.map +1 -0
- package/dist/ui/metadata.d.cts +35 -0
- package/dist/ui/metadata.d.cts.map +1 -0
- package/dist/ui/metadata.d.mts +35 -0
- package/dist/ui/metadata.d.mts.map +1 -0
- package/dist/ui/metadata.mjs +100 -0
- package/dist/ui/metadata.mjs.map +1 -0
- package/dist/ui/router.cjs +56 -0
- package/dist/ui/router.cjs.map +1 -0
- package/dist/ui/router.d.cts +11 -0
- package/dist/ui/router.d.cts.map +1 -0
- package/dist/ui/router.d.mts +11 -0
- package/dist/ui/router.d.mts.map +1 -0
- package/dist/ui/router.mjs +51 -0
- package/dist/ui/router.mjs.map +1 -0
- package/dist/ui/runtime.cjs +65 -0
- package/dist/ui/runtime.cjs.map +1 -0
- package/dist/ui/runtime.d.cts +29 -0
- package/dist/ui/runtime.d.cts.map +1 -0
- package/dist/ui/runtime.d.mts +29 -0
- package/dist/ui/runtime.d.mts.map +1 -0
- package/dist/ui/runtime.mjs +53 -0
- package/dist/ui/runtime.mjs.map +1 -0
- package/dist/ui/types.cjs +0 -0
- package/dist/ui/types.d.cts +52 -0
- package/dist/ui/types.d.cts.map +1 -0
- package/dist/ui/types.d.mts +52 -0
- package/dist/ui/types.d.mts.map +1 -0
- package/dist/ui/types.mjs +1 -0
- package/dist/utils/banner.cjs +24 -0
- package/dist/utils/banner.cjs.map +1 -0
- package/dist/utils/banner.mjs +23 -0
- package/dist/utils/banner.mjs.map +1 -0
- package/dist/utils/linkify.cjs +15 -0
- package/dist/utils/linkify.cjs.map +1 -0
- package/dist/utils/linkify.mjs +14 -0
- package/dist/utils/linkify.mjs.map +1 -0
- package/dist/utils/run.cjs +40 -0
- package/dist/utils/run.cjs.map +1 -0
- package/dist/utils/run.mjs +39 -0
- package/dist/utils/run.mjs.map +1 -0
- package/dist/utils/theme.cjs +44 -0
- package/dist/utils/theme.cjs.map +1 -0
- package/dist/utils/theme.mjs +37 -0
- package/dist/utils/theme.mjs.map +1 -0
- package/package.json +269 -80
- package/src/api-contract.ts +309 -0
- package/src/api.ts +181 -0
- package/src/app.ts +346 -0
- package/src/cli/catalog.ts +49 -0
- package/src/cli/help.ts +13 -0
- package/src/cli/init.ts +415 -0
- package/src/cli/parse.ts +130 -0
- package/src/cli/prompts.ts +64 -0
- package/src/cli.ts +203 -1507
- package/src/components/dev-view.tsx +104 -41
- package/src/components/streaming-view.ts +89 -22
- package/src/config.ts +462 -532
- package/src/contract.meta.ts +96 -0
- package/src/contract.ts +164 -561
- package/src/dev-logs.ts +85 -0
- package/src/dev-session.ts +318 -0
- package/src/fastkv.ts +153 -0
- package/src/federation.server.ts +43 -0
- package/src/host.ts +526 -0
- package/src/index.ts +6 -3
- package/src/integrity.ts +54 -0
- package/src/mf.ts +105 -0
- package/src/near-cli.ts +284 -0
- package/src/network.ts +3 -0
- package/src/orchestrator.ts +648 -0
- package/src/plugin.ts +1116 -2303
- package/src/process-registry.ts +154 -0
- package/src/scripts/sync-api-contract.ts +24 -0
- package/src/sdk.ts +14 -0
- package/src/shared.ts +206 -0
- package/src/types.ts +152 -206
- package/src/ui/head.ts +34 -27
- package/src/ui/index.ts +3 -3
- package/src/ui/metadata.ts +95 -0
- package/src/ui/router.ts +22 -6
- package/src/ui/runtime.ts +55 -6
- package/src/ui/types.ts +24 -11
- package/src/utils/banner.ts +10 -6
- package/src/utils/run.ts +26 -27
- package/src/utils/theme.ts +3 -66
- package/src/components/monitor-view.tsx +0 -475
- package/src/components/status-view.tsx +0 -173
- package/src/lib/env.ts +0 -109
- package/src/lib/near-cli.ts +0 -289
- package/src/lib/nova.ts +0 -266
- package/src/lib/orchestrator.ts +0 -276
- package/src/lib/process-registry.ts +0 -166
- package/src/lib/process.ts +0 -549
- package/src/lib/resource-monitor/assertions.ts +0 -234
- package/src/lib/resource-monitor/command.ts +0 -283
- package/src/lib/resource-monitor/diff.ts +0 -157
- package/src/lib/resource-monitor/errors.ts +0 -127
- package/src/lib/resource-monitor/index.ts +0 -305
- package/src/lib/resource-monitor/platform/darwin.ts +0 -306
- package/src/lib/resource-monitor/platform/index.ts +0 -35
- package/src/lib/resource-monitor/platform/linux.ts +0 -332
- package/src/lib/resource-monitor/platform/windows.ts +0 -298
- package/src/lib/resource-monitor/snapshot.ts +0 -217
- package/src/lib/resource-monitor/types.ts +0 -74
- package/src/lib/session-recorder/errors.ts +0 -102
- package/src/lib/session-recorder/flows/login.ts +0 -210
- package/src/lib/session-recorder/index.ts +0 -361
- package/src/lib/session-recorder/playwright.ts +0 -257
- package/src/lib/session-recorder/report.ts +0 -353
- package/src/lib/session-recorder/server.ts +0 -267
- package/src/lib/session-recorder/types.ts +0 -115
- package/src/lib/sync.ts +0 -1
- package/src/ui/files.ts +0 -134
package/dist/plugin.mjs
ADDED
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
import { buildRegistryConfigUrlForNetwork, fetchBosConfigFromFastKv, getRegistryNamespaceForAccount, getRegistryNamespaceForNetwork } from "./fastkv.mjs";
|
|
2
|
+
import { getNetworkIdForAccount } from "./network.mjs";
|
|
3
|
+
import { createPlugin, z } from "./sdk.mjs";
|
|
4
|
+
import { buildRuntimePluginsForConfig, getHostDevelopmentPort, getProjectRoot, loadConfig, parsePort, resolveDevelopmentHostUrl, resolveLocalDevelopmentPath } from "./config.mjs";
|
|
5
|
+
import { bosContract } from "./contract.mjs";
|
|
6
|
+
import { syncApiContractBridge } from "./api-contract.mjs";
|
|
7
|
+
import { buildRuntimeConfig, detectLocalPackages, prepareDevelopmentRuntimeConfig } from "./app.mjs";
|
|
8
|
+
import { copyFilteredFiles, personalizeConfig, readTemplatekeep, resolveSourceDir, runBunInstall } from "./cli/init.mjs";
|
|
9
|
+
import { promptInitOptions } from "./cli/prompts.mjs";
|
|
10
|
+
import { startApp } from "./dev-session.mjs";
|
|
11
|
+
import { addFunctionCallAccessKey, ensureNearCli, executeTransaction } from "./near-cli.mjs";
|
|
12
|
+
import { syncAndGenerateSharedUi } from "./shared.mjs";
|
|
13
|
+
import { run } from "./utils/run.mjs";
|
|
14
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { basename, join, resolve } from "node:path";
|
|
16
|
+
import { Effect } from "effect";
|
|
17
|
+
|
|
18
|
+
//#region src/plugin.ts
|
|
19
|
+
const DEFAULT_DEV_CONFIG = {
|
|
20
|
+
host: "local",
|
|
21
|
+
ui: "local",
|
|
22
|
+
api: "local",
|
|
23
|
+
ssr: false
|
|
24
|
+
};
|
|
25
|
+
const buildCommands = {
|
|
26
|
+
host: {
|
|
27
|
+
cmd: "bun",
|
|
28
|
+
args: ["run", "build"]
|
|
29
|
+
},
|
|
30
|
+
ui: {
|
|
31
|
+
cmd: "bun",
|
|
32
|
+
args: ["run", "build"]
|
|
33
|
+
},
|
|
34
|
+
api: {
|
|
35
|
+
cmd: "bun",
|
|
36
|
+
args: ["run", "build"]
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const PUBLISH_FUNCTION_NAMES = ["__fastdata_kv"];
|
|
40
|
+
function parseSourceMode(value, defaultValue) {
|
|
41
|
+
if (value === "local" || value === "remote") return value;
|
|
42
|
+
return defaultValue;
|
|
43
|
+
}
|
|
44
|
+
function buildAppConfig(options) {
|
|
45
|
+
return {
|
|
46
|
+
host: parseSourceMode(options.host, DEFAULT_DEV_CONFIG.host),
|
|
47
|
+
ui: parseSourceMode(options.ui, DEFAULT_DEV_CONFIG.ui),
|
|
48
|
+
api: parseSourceMode(options.api, DEFAULT_DEV_CONFIG.api),
|
|
49
|
+
proxy: options.proxy,
|
|
50
|
+
ssr: options.ssr ?? DEFAULT_DEV_CONFIG.ssr
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function buildDescription(config) {
|
|
54
|
+
if (config.host === "local" && config.ui === "local" && config.api === "local" && !config.proxy) return "Full Local Development";
|
|
55
|
+
const parts = [];
|
|
56
|
+
parts.push(config.host === "remote" ? "Remote Host" : "Local Host");
|
|
57
|
+
if (config.ui === "remote") parts.push("Remote UI");
|
|
58
|
+
if (config.proxy) parts.push("Proxy API → Production");
|
|
59
|
+
else if (config.api === "remote") parts.push("Remote API");
|
|
60
|
+
return parts.join(" + ");
|
|
61
|
+
}
|
|
62
|
+
function buildConfigResult(bosConfig) {
|
|
63
|
+
const packages = bosConfig ? Object.keys(bosConfig.app) : [];
|
|
64
|
+
return {
|
|
65
|
+
config: bosConfig,
|
|
66
|
+
packages,
|
|
67
|
+
remotes: packages.filter((name) => name !== "host")
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function resolveWorkspaceTarget(key, bosConfig, runtimeConfig, configDir) {
|
|
71
|
+
if (bosConfig?.app && key in bosConfig.app) return {
|
|
72
|
+
key,
|
|
73
|
+
kind: "app",
|
|
74
|
+
path: `${configDir}/${key}`
|
|
75
|
+
};
|
|
76
|
+
const pluginPath = (runtimeConfig?.plugins?.[key])?.localPath ?? resolveLocalDevelopmentPath(bosConfig?.plugins?.[key]?.development, configDir);
|
|
77
|
+
if (pluginPath) return {
|
|
78
|
+
key,
|
|
79
|
+
kind: "plugin",
|
|
80
|
+
path: pluginPath
|
|
81
|
+
};
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
function determineProcesses(config, localPackages, runtimeConfig) {
|
|
85
|
+
const processes = [];
|
|
86
|
+
if (config.ssr && config.ui === "local") processes.push("ui-ssr");
|
|
87
|
+
if (config.ui === "local") processes.push("ui");
|
|
88
|
+
if (config.api === "local" && !config.proxy) processes.push("api");
|
|
89
|
+
for (const pkg of localPackages) if (pkg.startsWith("plugin:")) {
|
|
90
|
+
const pluginId = pkg.slice(7);
|
|
91
|
+
if (runtimeConfig?.plugins?.[pluginId]?.source === "local") processes.push(pkg);
|
|
92
|
+
}
|
|
93
|
+
processes.push("host");
|
|
94
|
+
return processes;
|
|
95
|
+
}
|
|
96
|
+
function isValidProxyUrl(url) {
|
|
97
|
+
try {
|
|
98
|
+
const parsed = new URL(url);
|
|
99
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function resolveProxyUrl(bosConfig) {
|
|
105
|
+
if (!bosConfig) return null;
|
|
106
|
+
const apiConfig = bosConfig.app.api;
|
|
107
|
+
if (!apiConfig) return null;
|
|
108
|
+
if (apiConfig.proxy && isValidProxyUrl(apiConfig.proxy)) return apiConfig.proxy;
|
|
109
|
+
if (apiConfig.production && isValidProxyUrl(apiConfig.production)) return apiConfig.production;
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
function sanitizePluginKey(value) {
|
|
113
|
+
return value.replace(/[^A-Za-z0-9/_-]/g, "-").replace(/\/+/g, "/").split("/").filter(Boolean).map((segment) => segment.replace(/[^A-Za-z0-9_-]/g, "-")).join("/").replace(/^\/+|\/+$/g, "");
|
|
114
|
+
}
|
|
115
|
+
function defaultPluginKey(source) {
|
|
116
|
+
const normalized = source.replace(/^local:/, "").replace(/\/$/, "");
|
|
117
|
+
if (source.startsWith("local:")) return sanitizePluginKey(basename(normalized)) || "plugin";
|
|
118
|
+
try {
|
|
119
|
+
const url = new URL(source);
|
|
120
|
+
return sanitizePluginKey(basename(url.pathname) || url.hostname) || "plugin";
|
|
121
|
+
} catch {
|
|
122
|
+
return sanitizePluginKey(source) || "plugin";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function pluginLocalPath(configDir, attachment) {
|
|
126
|
+
const source = attachment.development ?? attachment.production;
|
|
127
|
+
if (!source?.startsWith("local:")) return null;
|
|
128
|
+
return join(configDir, source.slice(6));
|
|
129
|
+
}
|
|
130
|
+
async function saveBosConfig(configDir, config) {
|
|
131
|
+
const filePath = join(configDir, "bos.config.json");
|
|
132
|
+
const next = `${JSON.stringify(config, null, 2)}\n`;
|
|
133
|
+
try {
|
|
134
|
+
if (readFileSync(filePath, "utf8") === next) return;
|
|
135
|
+
} catch {}
|
|
136
|
+
writeFileSync(filePath, next);
|
|
137
|
+
}
|
|
138
|
+
function listPluginAttachments(config) {
|
|
139
|
+
return Object.entries(config?.plugins ?? {}).map(([key, attachment]) => ({
|
|
140
|
+
key,
|
|
141
|
+
development: attachment.development,
|
|
142
|
+
production: attachment.production,
|
|
143
|
+
localPath: attachment.development?.startsWith("local:") ? attachment.development.slice(6) : void 0,
|
|
144
|
+
source: attachment.development?.startsWith("local:") ? "local" : "remote"
|
|
145
|
+
})).sort((a, b) => a.key.localeCompare(b.key));
|
|
146
|
+
}
|
|
147
|
+
async function refreshApiContractBridge(configDir) {
|
|
148
|
+
const refreshed = await loadConfig({
|
|
149
|
+
cwd: configDir,
|
|
150
|
+
env: "development"
|
|
151
|
+
});
|
|
152
|
+
if (!refreshed) return;
|
|
153
|
+
await syncApiContractBridge({
|
|
154
|
+
configDir,
|
|
155
|
+
runtimeConfig: refreshed.runtime,
|
|
156
|
+
apiBaseUrl: refreshed.runtime.api.url
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function extractPublishedUrl(output) {
|
|
160
|
+
const match = output.match(/https?:\/\/[^\s"'<>]+/g);
|
|
161
|
+
if (!match || match.length === 0) return null;
|
|
162
|
+
return match[match.length - 1] ?? null;
|
|
163
|
+
}
|
|
164
|
+
async function buildEnvVars(config, bosConfig) {
|
|
165
|
+
const env = {
|
|
166
|
+
HOST_SOURCE: config.host,
|
|
167
|
+
UI_SOURCE: config.ui,
|
|
168
|
+
API_SOURCE: config.api
|
|
169
|
+
};
|
|
170
|
+
if (config.host === "remote") {
|
|
171
|
+
const remoteUrl = bosConfig?.app.host.production;
|
|
172
|
+
if (remoteUrl) env.HOST_REMOTE_URL = remoteUrl;
|
|
173
|
+
}
|
|
174
|
+
if (config.ui === "remote") {
|
|
175
|
+
const remoteUrl = bosConfig?.app.ui.production;
|
|
176
|
+
if (remoteUrl) env.UI_REMOTE_URL = remoteUrl;
|
|
177
|
+
}
|
|
178
|
+
if (config.api === "remote") {
|
|
179
|
+
const remoteUrl = bosConfig?.app.api.production;
|
|
180
|
+
if (remoteUrl) env.API_REMOTE_URL = remoteUrl;
|
|
181
|
+
}
|
|
182
|
+
if (config.proxy && bosConfig) {
|
|
183
|
+
const proxyUrl = resolveProxyUrl(bosConfig);
|
|
184
|
+
if (proxyUrl) env.API_PROXY = proxyUrl;
|
|
185
|
+
}
|
|
186
|
+
return env;
|
|
187
|
+
}
|
|
188
|
+
async function buildEveryPluginQuietly(cwd) {
|
|
189
|
+
const distPath = `${cwd}/packages/every-plugin/dist/build/rspack/plugin.mjs`;
|
|
190
|
+
if (await Bun.file(distPath).exists()) return;
|
|
191
|
+
const result = await run("bun", [
|
|
192
|
+
"run",
|
|
193
|
+
"--cwd",
|
|
194
|
+
"packages/every-plugin",
|
|
195
|
+
"build"
|
|
196
|
+
], {
|
|
197
|
+
cwd,
|
|
198
|
+
capture: true
|
|
199
|
+
});
|
|
200
|
+
if (result.exitCode === 0) {
|
|
201
|
+
console.log("[build:ssr] build succeeded");
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (result.stdout.trim()) process.stdout.write(result.stdout);
|
|
205
|
+
if (result.stderr.trim()) process.stderr.write(result.stderr);
|
|
206
|
+
throw new Error(`bun run --cwd packages/every-plugin build failed with exit code ${result.exitCode}`);
|
|
207
|
+
}
|
|
208
|
+
async function buildEverythingDevQuietly(cwd) {
|
|
209
|
+
const distPath = `${cwd}/packages/everything-dev/dist/index.mjs`;
|
|
210
|
+
if (await Bun.file(distPath).exists()) return;
|
|
211
|
+
const result = await run("bun", [
|
|
212
|
+
"run",
|
|
213
|
+
"--cwd",
|
|
214
|
+
"packages/everything-dev",
|
|
215
|
+
"build"
|
|
216
|
+
], {
|
|
217
|
+
cwd,
|
|
218
|
+
capture: true
|
|
219
|
+
});
|
|
220
|
+
if (result.exitCode === 0) {
|
|
221
|
+
console.log("[everything-dev] build succeeded");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (result.stdout.trim()) process.stdout.write(result.stdout);
|
|
225
|
+
if (result.stderr.trim()) process.stderr.write(result.stderr);
|
|
226
|
+
throw new Error(`bun run --cwd packages/everything-dev build failed with exit code ${result.exitCode}`);
|
|
227
|
+
}
|
|
228
|
+
async function fetchPublishedConfig(accountId, gatewayId) {
|
|
229
|
+
try {
|
|
230
|
+
return await fetchBosConfigFromFastKv(`bos://${accountId}/${gatewayId}`);
|
|
231
|
+
} catch {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function selectWorkspaceTargets(packages, bosConfig) {
|
|
236
|
+
const allPackages = [...Object.keys(bosConfig?.app ?? {}), ...Object.keys(bosConfig?.plugins ?? {})];
|
|
237
|
+
if (packages === "all") return allPackages;
|
|
238
|
+
return packages.split(",").map((pkg) => pkg.trim()).filter((pkg) => allPackages.includes(pkg));
|
|
239
|
+
}
|
|
240
|
+
async function buildWorkspaceTargets(opts) {
|
|
241
|
+
const existing = [];
|
|
242
|
+
const skipped = [];
|
|
243
|
+
for (const target of opts.targets) {
|
|
244
|
+
const resolved = resolveWorkspaceTarget(target, opts.bosConfig, opts.runtimeConfig, opts.configDir);
|
|
245
|
+
if (!resolved) {
|
|
246
|
+
skipped.push(target);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (await Bun.file(`${resolved.path}/package.json`).exists()) existing.push(resolved);
|
|
250
|
+
else skipped.push(target);
|
|
251
|
+
}
|
|
252
|
+
if (existing.length === 0) return {
|
|
253
|
+
built: [],
|
|
254
|
+
skipped
|
|
255
|
+
};
|
|
256
|
+
if ((await syncAndGenerateSharedUi({
|
|
257
|
+
configDir: opts.configDir,
|
|
258
|
+
hostMode: "local",
|
|
259
|
+
bosConfig: opts.bosConfig ?? void 0
|
|
260
|
+
})).catalogChanged) await run("bun", ["install"], { cwd: opts.configDir });
|
|
261
|
+
if (existing.some((entry) => entry.key === "api")) await buildEveryPluginQuietly(opts.configDir);
|
|
262
|
+
await buildEverythingDevQuietly(opts.configDir);
|
|
263
|
+
const env = {
|
|
264
|
+
...process.env,
|
|
265
|
+
NODE_ENV: opts.deploy ? "production" : "development"
|
|
266
|
+
};
|
|
267
|
+
if (opts.deploy) env.DEPLOY = "true";
|
|
268
|
+
else delete env.DEPLOY;
|
|
269
|
+
const orderedExisting = opts.deploy ? [
|
|
270
|
+
...existing.filter((entry) => entry.kind === "app" && entry.key !== "host"),
|
|
271
|
+
...existing.filter((entry) => entry.kind === "plugin"),
|
|
272
|
+
...existing.filter((entry) => entry.kind === "app" && entry.key === "host")
|
|
273
|
+
] : existing;
|
|
274
|
+
const built = [];
|
|
275
|
+
for (const resolved of orderedExisting) {
|
|
276
|
+
const pkgJson = JSON.parse(await Bun.file(`${resolved.path}/package.json`).text());
|
|
277
|
+
const buildConfig = opts.deploy && pkgJson.scripts?.deploy ? {
|
|
278
|
+
cmd: "bun",
|
|
279
|
+
args: ["run", "deploy"]
|
|
280
|
+
} : buildCommands[resolved.key] ?? {
|
|
281
|
+
cmd: "bun",
|
|
282
|
+
args: ["run", "build"]
|
|
283
|
+
};
|
|
284
|
+
await run(buildConfig.cmd, buildConfig.args, {
|
|
285
|
+
cwd: resolved.path,
|
|
286
|
+
env
|
|
287
|
+
});
|
|
288
|
+
built.push(resolved.key);
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
built,
|
|
292
|
+
skipped
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
var plugin_default = createPlugin({
|
|
296
|
+
variables: z.object({ configPath: z.string().optional() }),
|
|
297
|
+
secrets: z.object({}),
|
|
298
|
+
contract: bosContract,
|
|
299
|
+
initialize: (config) => Effect.promise(async () => {
|
|
300
|
+
const configResult = await loadConfig({ path: config.variables.configPath });
|
|
301
|
+
return {
|
|
302
|
+
bosConfig: configResult?.config ?? null,
|
|
303
|
+
runtimeConfig: configResult?.runtime ?? null,
|
|
304
|
+
configDir: getProjectRoot()
|
|
305
|
+
};
|
|
306
|
+
}),
|
|
307
|
+
shutdown: () => Effect.void,
|
|
308
|
+
createRouter: (deps, builder) => ({
|
|
309
|
+
config: builder.config.handler(async () => buildConfigResult(deps.bosConfig)),
|
|
310
|
+
pluginAdd: builder.pluginAdd.handler(async ({ input }) => {
|
|
311
|
+
if (!deps.bosConfig) return {
|
|
312
|
+
status: "error",
|
|
313
|
+
key: "",
|
|
314
|
+
error: "No bos.config.json found"
|
|
315
|
+
};
|
|
316
|
+
const key = sanitizePluginKey(input.as ?? defaultPluginKey(input.source));
|
|
317
|
+
const existing = deps.bosConfig.plugins?.[key];
|
|
318
|
+
const nextPlugins = { ...deps.bosConfig.plugins ?? {} };
|
|
319
|
+
nextPlugins[key] = input.source.startsWith("local:") ? {
|
|
320
|
+
...existing ?? {},
|
|
321
|
+
development: input.source,
|
|
322
|
+
production: input.production ?? existing?.production
|
|
323
|
+
} : {
|
|
324
|
+
...existing ?? {},
|
|
325
|
+
production: input.production ?? input.source
|
|
326
|
+
};
|
|
327
|
+
deps.bosConfig = {
|
|
328
|
+
...deps.bosConfig,
|
|
329
|
+
plugins: nextPlugins
|
|
330
|
+
};
|
|
331
|
+
await saveBosConfig(deps.configDir, deps.bosConfig);
|
|
332
|
+
await refreshApiContractBridge(deps.configDir);
|
|
333
|
+
return {
|
|
334
|
+
status: "added",
|
|
335
|
+
key,
|
|
336
|
+
development: deps.bosConfig.plugins?.[key]?.development,
|
|
337
|
+
production: deps.bosConfig.plugins?.[key]?.production
|
|
338
|
+
};
|
|
339
|
+
}),
|
|
340
|
+
pluginRemove: builder.pluginRemove.handler(async ({ input }) => {
|
|
341
|
+
if (!deps.bosConfig) return {
|
|
342
|
+
status: "error",
|
|
343
|
+
key: input.key,
|
|
344
|
+
error: "No bos.config.json found"
|
|
345
|
+
};
|
|
346
|
+
if (!deps.bosConfig.plugins?.[input.key]) return {
|
|
347
|
+
status: "error",
|
|
348
|
+
key: input.key,
|
|
349
|
+
error: `Plugin '${input.key}' is not configured`
|
|
350
|
+
};
|
|
351
|
+
const nextPlugins = { ...deps.bosConfig.plugins ?? {} };
|
|
352
|
+
delete nextPlugins[input.key];
|
|
353
|
+
deps.bosConfig = {
|
|
354
|
+
...deps.bosConfig,
|
|
355
|
+
plugins: Object.keys(nextPlugins).length > 0 ? nextPlugins : void 0
|
|
356
|
+
};
|
|
357
|
+
await saveBosConfig(deps.configDir, deps.bosConfig);
|
|
358
|
+
await refreshApiContractBridge(deps.configDir);
|
|
359
|
+
return {
|
|
360
|
+
status: "removed",
|
|
361
|
+
key: input.key
|
|
362
|
+
};
|
|
363
|
+
}),
|
|
364
|
+
pluginList: builder.pluginList.handler(async () => {
|
|
365
|
+
return {
|
|
366
|
+
status: "listed",
|
|
367
|
+
plugins: listPluginAttachments(deps.bosConfig)
|
|
368
|
+
};
|
|
369
|
+
}),
|
|
370
|
+
pluginPublish: builder.pluginPublish.handler(async ({ input }) => {
|
|
371
|
+
if (!deps.bosConfig) return {
|
|
372
|
+
status: "error",
|
|
373
|
+
key: input.key,
|
|
374
|
+
error: "No bos.config.json found"
|
|
375
|
+
};
|
|
376
|
+
const attachment = deps.bosConfig.plugins?.[input.key];
|
|
377
|
+
if (!attachment) return {
|
|
378
|
+
status: "error",
|
|
379
|
+
key: input.key,
|
|
380
|
+
error: `Plugin '${input.key}' is not configured`
|
|
381
|
+
};
|
|
382
|
+
const localPath = pluginLocalPath(deps.configDir, attachment);
|
|
383
|
+
if (!localPath) return {
|
|
384
|
+
status: "error",
|
|
385
|
+
key: input.key,
|
|
386
|
+
error: `Plugin '${input.key}' does not have a local development path`
|
|
387
|
+
};
|
|
388
|
+
const pkgPath = join(localPath, "package.json");
|
|
389
|
+
if (!await Bun.file(pkgPath).exists()) return {
|
|
390
|
+
status: "error",
|
|
391
|
+
key: input.key,
|
|
392
|
+
error: `Missing package.json at ${localPath}`
|
|
393
|
+
};
|
|
394
|
+
const script = (await Bun.file(pkgPath).json()).scripts?.deploy ? "deploy" : "build";
|
|
395
|
+
const { stdout, stderr, exitCode } = await run("bun", ["run", script], {
|
|
396
|
+
cwd: localPath,
|
|
397
|
+
capture: true
|
|
398
|
+
});
|
|
399
|
+
if (exitCode !== 0) {
|
|
400
|
+
if (stdout.trim()) process.stdout.write(stdout);
|
|
401
|
+
if (stderr.trim()) process.stderr.write(stderr);
|
|
402
|
+
return {
|
|
403
|
+
status: "error",
|
|
404
|
+
key: input.key,
|
|
405
|
+
error: `Publish failed with exit code ${exitCode}`
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
if (stdout.trim()) process.stdout.write(stdout);
|
|
409
|
+
if (stderr.trim()) process.stderr.write(stderr);
|
|
410
|
+
const publishedUrl = extractPublishedUrl(`${stdout}\n${stderr}`);
|
|
411
|
+
if (publishedUrl) {
|
|
412
|
+
deps.bosConfig = {
|
|
413
|
+
...deps.bosConfig,
|
|
414
|
+
plugins: {
|
|
415
|
+
...deps.bosConfig.plugins ?? {},
|
|
416
|
+
[input.key]: {
|
|
417
|
+
...deps.bosConfig.plugins?.[input.key] ?? {},
|
|
418
|
+
production: publishedUrl
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
await saveBosConfig(deps.configDir, deps.bosConfig);
|
|
423
|
+
await refreshApiContractBridge(deps.configDir);
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
status: "published",
|
|
427
|
+
key: input.key,
|
|
428
|
+
path: localPath,
|
|
429
|
+
script,
|
|
430
|
+
production: publishedUrl ?? attachment.production
|
|
431
|
+
};
|
|
432
|
+
}),
|
|
433
|
+
dev: builder.dev.handler(async ({ input }) => {
|
|
434
|
+
const localPackages = detectLocalPackages(deps.bosConfig ?? void 0, deps.runtimeConfig ?? void 0);
|
|
435
|
+
const appConfig = buildAppConfig({
|
|
436
|
+
host: localPackages.includes("host") ? input.host : "remote",
|
|
437
|
+
ui: localPackages.includes("ui") ? input.ui : "remote",
|
|
438
|
+
api: localPackages.includes("api") ? input.api : "remote",
|
|
439
|
+
proxy: input.proxy,
|
|
440
|
+
ssr: input.ssr
|
|
441
|
+
});
|
|
442
|
+
if ((await syncAndGenerateSharedUi({
|
|
443
|
+
configDir: deps.configDir,
|
|
444
|
+
hostMode: appConfig.host,
|
|
445
|
+
bosConfig: deps.bosConfig ?? void 0
|
|
446
|
+
})).catalogChanged) await run("bun", ["install"], { cwd: deps.configDir });
|
|
447
|
+
if (appConfig.api === "local" && !appConfig.proxy || localPackages.some((pkg) => pkg.startsWith("plugin:"))) await buildEveryPluginQuietly(deps.configDir);
|
|
448
|
+
await buildEverythingDevQuietly(deps.configDir);
|
|
449
|
+
const refreshed = await loadConfig({ cwd: deps.configDir });
|
|
450
|
+
deps.bosConfig = refreshed?.config ?? deps.bosConfig;
|
|
451
|
+
deps.runtimeConfig = refreshed?.runtime ?? deps.runtimeConfig;
|
|
452
|
+
if (!deps.bosConfig) return {
|
|
453
|
+
status: "error",
|
|
454
|
+
description: "No bos.config.json found",
|
|
455
|
+
processes: []
|
|
456
|
+
};
|
|
457
|
+
if (appConfig.proxy && !resolveProxyUrl(deps.bosConfig)) return {
|
|
458
|
+
status: "error",
|
|
459
|
+
description: "No valid proxy URL configured in bos.config.json",
|
|
460
|
+
processes: []
|
|
461
|
+
};
|
|
462
|
+
const processes = determineProcesses(appConfig, detectLocalPackages(deps.bosConfig ?? void 0, deps.runtimeConfig ?? void 0), deps.runtimeConfig);
|
|
463
|
+
const env = await buildEnvVars(appConfig, deps.bosConfig);
|
|
464
|
+
const hostPort = input.port ?? getHostDevelopmentPort(deps.bosConfig.app.host.development);
|
|
465
|
+
const runtimeConfig = await prepareDevelopmentRuntimeConfig(buildRuntimeConfig(deps.bosConfig, {
|
|
466
|
+
uiSource: appConfig.ui,
|
|
467
|
+
apiSource: appConfig.api,
|
|
468
|
+
hostUrl: `http://localhost:${hostPort}`,
|
|
469
|
+
proxy: env.API_PROXY,
|
|
470
|
+
env: "development",
|
|
471
|
+
plugins: deps.runtimeConfig?.plugins
|
|
472
|
+
}), {
|
|
473
|
+
hostPort,
|
|
474
|
+
ssr: appConfig.ssr
|
|
475
|
+
});
|
|
476
|
+
await syncApiContractBridge({
|
|
477
|
+
configDir: deps.configDir,
|
|
478
|
+
runtimeConfig,
|
|
479
|
+
apiBaseUrl: runtimeConfig.api.url
|
|
480
|
+
});
|
|
481
|
+
const orchestrator = {
|
|
482
|
+
packages: processes,
|
|
483
|
+
env,
|
|
484
|
+
description: buildDescription(appConfig),
|
|
485
|
+
appConfig,
|
|
486
|
+
bosConfig: deps.bosConfig,
|
|
487
|
+
runtimeConfig,
|
|
488
|
+
port: parsePort(runtimeConfig.hostUrl),
|
|
489
|
+
interactive: input.interactive
|
|
490
|
+
};
|
|
491
|
+
startApp(orchestrator);
|
|
492
|
+
return {
|
|
493
|
+
status: "started",
|
|
494
|
+
description: orchestrator.description,
|
|
495
|
+
processes
|
|
496
|
+
};
|
|
497
|
+
}),
|
|
498
|
+
start: builder.start.handler(async ({ input }) => {
|
|
499
|
+
let remoteConfig = null;
|
|
500
|
+
if (input.account && input.domain) {
|
|
501
|
+
remoteConfig = await fetchPublishedConfig(input.account, input.domain);
|
|
502
|
+
if (!remoteConfig) return {
|
|
503
|
+
status: "error",
|
|
504
|
+
url: ""
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
const config = remoteConfig || deps.bosConfig;
|
|
508
|
+
if (!config) return {
|
|
509
|
+
status: "error",
|
|
510
|
+
url: ""
|
|
511
|
+
};
|
|
512
|
+
const port = input.port ?? getHostDevelopmentPort(config.app.host.development);
|
|
513
|
+
const appConfig = {
|
|
514
|
+
host: "remote",
|
|
515
|
+
ui: "remote",
|
|
516
|
+
api: "remote"
|
|
517
|
+
};
|
|
518
|
+
const env = await buildEnvVars(appConfig, config);
|
|
519
|
+
const isStaging = input.env === "staging";
|
|
520
|
+
const runtimePlugins = remoteConfig ? await buildRuntimePluginsForConfig(config, deps.configDir, "production") : deps.runtimeConfig?.plugins;
|
|
521
|
+
const runtimeConfig = buildRuntimeConfig(config, {
|
|
522
|
+
uiSource: "remote",
|
|
523
|
+
apiSource: "remote",
|
|
524
|
+
hostUrl: `http://localhost:${port}`,
|
|
525
|
+
env: "production",
|
|
526
|
+
plugins: runtimePlugins
|
|
527
|
+
});
|
|
528
|
+
await syncApiContractBridge({
|
|
529
|
+
configDir: deps.configDir,
|
|
530
|
+
runtimeConfig,
|
|
531
|
+
apiBaseUrl: runtimeConfig.api.url
|
|
532
|
+
});
|
|
533
|
+
const stagingEnvVars = isStaging ? { GATEWAY_DOMAIN: config.staging?.domain ?? config.domain ?? "" } : {};
|
|
534
|
+
startApp({
|
|
535
|
+
packages: ["host"],
|
|
536
|
+
env: {
|
|
537
|
+
NODE_ENV: "production",
|
|
538
|
+
...env,
|
|
539
|
+
...stagingEnvVars
|
|
540
|
+
},
|
|
541
|
+
description: `${isStaging ? "Staging" : "Production"} Mode (${config.account})`,
|
|
542
|
+
appConfig,
|
|
543
|
+
bosConfig: config,
|
|
544
|
+
runtimeConfig,
|
|
545
|
+
port,
|
|
546
|
+
interactive: input.interactive,
|
|
547
|
+
noLogs: true
|
|
548
|
+
});
|
|
549
|
+
return {
|
|
550
|
+
status: "running",
|
|
551
|
+
url: `http://localhost:${port}`
|
|
552
|
+
};
|
|
553
|
+
}),
|
|
554
|
+
build: builder.build.handler(async ({ input }) => {
|
|
555
|
+
if (!deps.bosConfig) return {
|
|
556
|
+
status: "error",
|
|
557
|
+
built: [],
|
|
558
|
+
skipped: []
|
|
559
|
+
};
|
|
560
|
+
const targets = selectWorkspaceTargets(input.packages, deps.bosConfig);
|
|
561
|
+
if (targets.length === 0) return {
|
|
562
|
+
status: "error",
|
|
563
|
+
built: [],
|
|
564
|
+
skipped: []
|
|
565
|
+
};
|
|
566
|
+
const runtimeConfig = buildRuntimeConfig(deps.bosConfig, {
|
|
567
|
+
uiSource: deps.bosConfig.app.ui?.development ? "local" : "remote",
|
|
568
|
+
apiSource: deps.bosConfig.app.api?.development ? "local" : "remote",
|
|
569
|
+
hostUrl: resolveDevelopmentHostUrl(deps.bosConfig.app.host.development),
|
|
570
|
+
env: "development",
|
|
571
|
+
plugins: deps.runtimeConfig?.plugins
|
|
572
|
+
});
|
|
573
|
+
await syncApiContractBridge({
|
|
574
|
+
configDir: deps.configDir,
|
|
575
|
+
runtimeConfig,
|
|
576
|
+
apiBaseUrl: runtimeConfig.api.url
|
|
577
|
+
});
|
|
578
|
+
const { built, skipped } = await buildWorkspaceTargets({
|
|
579
|
+
configDir: deps.configDir,
|
|
580
|
+
bosConfig: deps.bosConfig,
|
|
581
|
+
runtimeConfig,
|
|
582
|
+
targets,
|
|
583
|
+
deploy: input.deploy
|
|
584
|
+
});
|
|
585
|
+
if (built.length === 0) return {
|
|
586
|
+
status: "error",
|
|
587
|
+
built: [],
|
|
588
|
+
skipped
|
|
589
|
+
};
|
|
590
|
+
return {
|
|
591
|
+
status: "success",
|
|
592
|
+
built,
|
|
593
|
+
skipped,
|
|
594
|
+
deployed: input.deploy
|
|
595
|
+
};
|
|
596
|
+
}),
|
|
597
|
+
publish: builder.publish.handler(async ({ input }) => {
|
|
598
|
+
if (!deps.bosConfig) return {
|
|
599
|
+
status: "error",
|
|
600
|
+
registryUrl: "",
|
|
601
|
+
error: "No bos.config.json found"
|
|
602
|
+
};
|
|
603
|
+
const account = deps.bosConfig.account;
|
|
604
|
+
const gateway = deps.bosConfig.domain;
|
|
605
|
+
if (!gateway) return {
|
|
606
|
+
status: "error",
|
|
607
|
+
registryUrl: "",
|
|
608
|
+
error: "bos.config.json must define domain to publish"
|
|
609
|
+
};
|
|
610
|
+
const network = input.network ?? getNetworkIdForAccount(account);
|
|
611
|
+
const bosUrl = `bos://${account}/${gateway}`;
|
|
612
|
+
const registryUrl = buildRegistryConfigUrlForNetwork(network, account, gateway);
|
|
613
|
+
const targets = selectWorkspaceTargets(input.packages, deps.bosConfig);
|
|
614
|
+
let publishConfig = deps.bosConfig;
|
|
615
|
+
let built;
|
|
616
|
+
let skipped;
|
|
617
|
+
if (input.dryRun) return {
|
|
618
|
+
status: "dry-run",
|
|
619
|
+
registryUrl,
|
|
620
|
+
built,
|
|
621
|
+
skipped
|
|
622
|
+
};
|
|
623
|
+
if (input.deploy) {
|
|
624
|
+
const result = await buildWorkspaceTargets({
|
|
625
|
+
configDir: deps.configDir,
|
|
626
|
+
bosConfig: deps.bosConfig,
|
|
627
|
+
runtimeConfig: deps.runtimeConfig,
|
|
628
|
+
targets,
|
|
629
|
+
deploy: true
|
|
630
|
+
});
|
|
631
|
+
built = result.built;
|
|
632
|
+
skipped = result.skipped;
|
|
633
|
+
const refreshed = await loadConfig({ cwd: deps.configDir });
|
|
634
|
+
if (refreshed?.config) {
|
|
635
|
+
deps.bosConfig = refreshed.config;
|
|
636
|
+
deps.runtimeConfig = refreshed.runtime;
|
|
637
|
+
publishConfig = refreshed.config;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
const payload = JSON.stringify({ [`apps/${account}/${gateway}/bos.config.json`]: JSON.stringify(publishConfig) });
|
|
641
|
+
const argsBase64 = Buffer.from(payload).toString("base64");
|
|
642
|
+
const privateKey = input.privateKey || process.env.NEAR_PRIVATE_KEY || process.env.BOS_NEAR_PRIVATE_KEY;
|
|
643
|
+
try {
|
|
644
|
+
await Effect.runPromise(ensureNearCli);
|
|
645
|
+
let txHash;
|
|
646
|
+
try {
|
|
647
|
+
txHash = (await Effect.runPromise(executeTransaction({
|
|
648
|
+
account,
|
|
649
|
+
contract: getRegistryNamespaceForNetwork(network),
|
|
650
|
+
method: "__fastdata_kv",
|
|
651
|
+
argsBase64,
|
|
652
|
+
network,
|
|
653
|
+
privateKey,
|
|
654
|
+
gas: "300Tgas",
|
|
655
|
+
deposit: "0NEAR"
|
|
656
|
+
}))).txHash;
|
|
657
|
+
} catch (error) {
|
|
658
|
+
txHash = extractTransactionHash(error);
|
|
659
|
+
if (!txHash) throw error;
|
|
660
|
+
const verifiedConfig = await fetchBosConfigFromFastKv(bosUrl);
|
|
661
|
+
if (JSON.stringify(verifiedConfig) !== JSON.stringify(publishConfig)) throw error;
|
|
662
|
+
}
|
|
663
|
+
return {
|
|
664
|
+
status: "published",
|
|
665
|
+
registryUrl,
|
|
666
|
+
txHash,
|
|
667
|
+
built,
|
|
668
|
+
skipped
|
|
669
|
+
};
|
|
670
|
+
} catch (error) {
|
|
671
|
+
return {
|
|
672
|
+
status: "error",
|
|
673
|
+
registryUrl,
|
|
674
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
675
|
+
built,
|
|
676
|
+
skipped
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
}),
|
|
680
|
+
keyPublish: builder.keyPublish.handler(async ({ input }) => {
|
|
681
|
+
if (!deps.bosConfig) return {
|
|
682
|
+
status: "error",
|
|
683
|
+
account: "",
|
|
684
|
+
network: "mainnet",
|
|
685
|
+
contract: "",
|
|
686
|
+
allowance: input.allowance,
|
|
687
|
+
functionNames: PUBLISH_FUNCTION_NAMES,
|
|
688
|
+
error: "No bos.config.json found"
|
|
689
|
+
};
|
|
690
|
+
const account = deps.bosConfig.account;
|
|
691
|
+
const network = getNetworkIdForAccount(account);
|
|
692
|
+
const contract = getRegistryNamespaceForAccount(account);
|
|
693
|
+
try {
|
|
694
|
+
await Effect.runPromise(ensureNearCli);
|
|
695
|
+
const keyPair = await addFunctionCallAccessKey({
|
|
696
|
+
account,
|
|
697
|
+
contract,
|
|
698
|
+
allowance: input.allowance,
|
|
699
|
+
functionNames: PUBLISH_FUNCTION_NAMES,
|
|
700
|
+
network
|
|
701
|
+
});
|
|
702
|
+
return {
|
|
703
|
+
status: "published",
|
|
704
|
+
account,
|
|
705
|
+
network,
|
|
706
|
+
contract,
|
|
707
|
+
allowance: input.allowance,
|
|
708
|
+
functionNames: PUBLISH_FUNCTION_NAMES,
|
|
709
|
+
publicKey: keyPair.publicKey,
|
|
710
|
+
privateKey: keyPair.privateKey
|
|
711
|
+
};
|
|
712
|
+
} catch (error) {
|
|
713
|
+
return {
|
|
714
|
+
status: "error",
|
|
715
|
+
account,
|
|
716
|
+
network,
|
|
717
|
+
contract,
|
|
718
|
+
allowance: input.allowance,
|
|
719
|
+
functionNames: PUBLISH_FUNCTION_NAMES,
|
|
720
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
}),
|
|
724
|
+
init: builder.init.handler(async ({ input }) => {
|
|
725
|
+
try {
|
|
726
|
+
let account = input.account;
|
|
727
|
+
let gateway = input.gateway;
|
|
728
|
+
let destination = input.destination;
|
|
729
|
+
let name = input.name;
|
|
730
|
+
let domain = input.domain;
|
|
731
|
+
let withHost = input.withHost;
|
|
732
|
+
if (!account || !gateway) {
|
|
733
|
+
if (input.noInteractive) return {
|
|
734
|
+
status: "error",
|
|
735
|
+
destination: "",
|
|
736
|
+
parentAccount: account ?? "",
|
|
737
|
+
parentGateway: gateway ?? "",
|
|
738
|
+
name: input.name,
|
|
739
|
+
domain: input.domain,
|
|
740
|
+
extends: account && gateway ? `bos://${account}/${gateway}` : "",
|
|
741
|
+
filesCopied: 0,
|
|
742
|
+
error: "account and gateway are required (use --no-interactive to skip prompts and provide them as positional args)"
|
|
743
|
+
};
|
|
744
|
+
const prompted = await promptInitOptions({
|
|
745
|
+
account,
|
|
746
|
+
gateway,
|
|
747
|
+
destination,
|
|
748
|
+
name,
|
|
749
|
+
domain,
|
|
750
|
+
withHost
|
|
751
|
+
});
|
|
752
|
+
account = prompted.account;
|
|
753
|
+
gateway = prompted.gateway;
|
|
754
|
+
destination = prompted.destination;
|
|
755
|
+
name = prompted.name;
|
|
756
|
+
domain = prompted.domain;
|
|
757
|
+
withHost = prompted.withHost;
|
|
758
|
+
}
|
|
759
|
+
destination = destination || gateway;
|
|
760
|
+
const { sourceDir, cleanup } = await resolveSourceDir({
|
|
761
|
+
account,
|
|
762
|
+
gateway,
|
|
763
|
+
source: input.source
|
|
764
|
+
});
|
|
765
|
+
try {
|
|
766
|
+
const patterns = await readTemplatekeep(sourceDir);
|
|
767
|
+
if (patterns.length === 0) return {
|
|
768
|
+
status: "error",
|
|
769
|
+
destination,
|
|
770
|
+
parentAccount: account,
|
|
771
|
+
parentGateway: gateway,
|
|
772
|
+
name,
|
|
773
|
+
domain,
|
|
774
|
+
extends: `bos://${account}/${gateway}`,
|
|
775
|
+
filesCopied: 0,
|
|
776
|
+
error: "No .templatekeep found in template source"
|
|
777
|
+
};
|
|
778
|
+
const filesCopied = await copyFilteredFiles(sourceDir, destination, patterns, { withHost });
|
|
779
|
+
await personalizeConfig(destination, {
|
|
780
|
+
parentAccount: account,
|
|
781
|
+
parentGateway: gateway,
|
|
782
|
+
name: name || account,
|
|
783
|
+
domain: domain || gateway
|
|
784
|
+
});
|
|
785
|
+
if (!input.noInstall) await runBunInstall(destination);
|
|
786
|
+
return {
|
|
787
|
+
status: "initialized",
|
|
788
|
+
destination: resolve(destination),
|
|
789
|
+
parentAccount: account,
|
|
790
|
+
parentGateway: gateway,
|
|
791
|
+
name,
|
|
792
|
+
domain,
|
|
793
|
+
extends: `bos://${account}/${gateway}`,
|
|
794
|
+
filesCopied
|
|
795
|
+
};
|
|
796
|
+
} finally {
|
|
797
|
+
await cleanup();
|
|
798
|
+
}
|
|
799
|
+
} catch (error) {
|
|
800
|
+
return {
|
|
801
|
+
status: "error",
|
|
802
|
+
destination: input.destination ?? input.gateway ?? "",
|
|
803
|
+
parentAccount: input.account ?? "",
|
|
804
|
+
parentGateway: input.gateway ?? "",
|
|
805
|
+
name: input.name,
|
|
806
|
+
domain: input.domain,
|
|
807
|
+
extends: input.account && input.gateway ? `bos://${input.account}/${input.gateway}` : "",
|
|
808
|
+
filesCopied: 0,
|
|
809
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
})
|
|
813
|
+
})
|
|
814
|
+
});
|
|
815
|
+
function extractTransactionHash(error) {
|
|
816
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
817
|
+
return (message.match(/Transaction ID:\s*([A-Za-z0-9]+)/i) || message.match(/([A-HJ-NP-Za-km-z1-9]{43,44})/))?.[1];
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
//#endregion
|
|
821
|
+
export { plugin_default as default };
|
|
822
|
+
//# sourceMappingURL=plugin.mjs.map
|