everything-dev 1.12.4 → 1.13.1
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/cli.js +1 -1
- package/dist/app.cjs +17 -5
- package/dist/app.cjs.map +1 -1
- package/dist/app.mjs +17 -5
- package/dist/app.mjs.map +1 -1
- package/dist/cli/init.cjs +143 -66
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.d.cts +1 -1
- package/dist/cli/init.d.cts.map +1 -1
- package/dist/cli/init.d.mts +1 -1
- package/dist/cli/init.d.mts.map +1 -1
- package/dist/cli/init.mjs +144 -67
- package/dist/cli/init.mjs.map +1 -1
- package/dist/cli/prompts.cjs +3 -3
- package/dist/cli/prompts.cjs.map +1 -1
- package/dist/cli/prompts.mjs +3 -3
- package/dist/cli/prompts.mjs.map +1 -1
- package/dist/cli/sync.cjs +15 -56
- package/dist/cli/sync.cjs.map +1 -1
- package/dist/cli/sync.mjs +15 -56
- package/dist/cli/sync.mjs.map +1 -1
- package/dist/cli/upgrade.cjs +3 -1
- package/dist/cli/upgrade.cjs.map +1 -1
- package/dist/cli/upgrade.mjs +3 -1
- package/dist/cli/upgrade.mjs.map +1 -1
- package/dist/config.cjs +206 -69
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +13 -6
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +13 -6
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +201 -71
- package/dist/config.mjs.map +1 -1
- package/dist/contract.d.cts +104 -8
- package/dist/contract.d.cts.map +1 -1
- package/dist/contract.d.mts +104 -8
- package/dist/contract.d.mts.map +1 -1
- package/dist/host.cjs +34 -1
- package/dist/host.cjs.map +1 -1
- package/dist/host.d.cts.map +1 -1
- package/dist/host.d.mts.map +1 -1
- package/dist/host.mjs +34 -1
- package/dist/host.mjs.map +1 -1
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +5 -3
- package/dist/index.d.mts +5 -3
- package/dist/index.mjs +5 -3
- package/dist/merge.cjs +113 -0
- package/dist/merge.cjs.map +1 -0
- package/dist/merge.d.cts +7 -0
- package/dist/merge.d.cts.map +1 -0
- package/dist/merge.d.mts +7 -0
- package/dist/merge.d.mts.map +1 -0
- package/dist/merge.mjs +107 -0
- package/dist/merge.mjs.map +1 -0
- package/dist/plugin.cjs +117 -105
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +114 -8
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +114 -8
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +117 -105
- package/dist/plugin.mjs.map +1 -1
- package/dist/service-descriptor.cjs +21 -0
- package/dist/service-descriptor.cjs.map +1 -1
- package/dist/service-descriptor.d.cts +23 -1
- package/dist/service-descriptor.d.cts.map +1 -1
- package/dist/service-descriptor.d.mts +23 -1
- package/dist/service-descriptor.d.mts.map +1 -1
- package/dist/service-descriptor.mjs +21 -0
- package/dist/service-descriptor.mjs.map +1 -1
- package/dist/shared.cjs +24 -2
- package/dist/shared.cjs.map +1 -1
- package/dist/shared.d.cts +3 -0
- package/dist/shared.d.cts.map +1 -1
- package/dist/shared.d.mts +3 -0
- package/dist/shared.d.mts.map +1 -1
- package/dist/shared.mjs +25 -3
- package/dist/shared.mjs.map +1 -1
- package/dist/sidebar.cjs +124 -0
- package/dist/sidebar.cjs.map +1 -0
- package/dist/sidebar.d.cts +8 -0
- package/dist/sidebar.d.cts.map +1 -0
- package/dist/sidebar.d.mts +8 -0
- package/dist/sidebar.d.mts.map +1 -0
- package/dist/sidebar.mjs +122 -0
- package/dist/sidebar.mjs.map +1 -0
- package/dist/types.cjs +104 -10
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +256 -29
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +256 -29
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +100 -11
- package/dist/types.mjs.map +1 -1
- package/dist/utils/path-match.cjs +18 -0
- package/dist/utils/path-match.cjs.map +1 -0
- package/dist/utils/path-match.mjs +17 -0
- package/dist/utils/path-match.mjs.map +1 -0
- package/dist/utils/save-config.cjs +19 -0
- package/dist/utils/save-config.cjs.map +1 -0
- package/dist/utils/save-config.mjs +18 -0
- package/dist/utils/save-config.mjs.map +1 -0
- package/package.json +3 -2
- package/skills/dev-workflow/SKILL.md +8 -0
- package/skills/extends-config/SKILL.md +132 -0
- package/skills/init-upgrade/SKILL.md +128 -0
- package/skills/publish-sync/SKILL.md +30 -0
- package/src/app.ts +15 -5
- package/src/cli/init.ts +199 -100
- package/src/cli/prompts.ts +2 -2
- package/src/cli/sync.ts +27 -96
- package/src/cli/upgrade.ts +2 -0
- package/src/config.ts +306 -119
- package/src/host.ts +45 -0
- package/src/index.ts +1 -0
- package/src/merge.ts +198 -0
- package/src/plugin.ts +340 -318
- package/src/service-descriptor.ts +23 -0
- package/src/shared.ts +48 -5
- package/src/sidebar.ts +162 -0
- package/src/types.ts +134 -28
- package/src/utils/path-match.ts +16 -0
- package/src/utils/save-config.ts +20 -0
package/cli.js
CHANGED
package/dist/app.cjs
CHANGED
|
@@ -20,7 +20,10 @@ function detectLocalPackages(bosConfig, runtimeConfig) {
|
|
|
20
20
|
const hostLocalPath = runtimeConfig?.host?.localPath ?? require_config.resolveLocalDevelopmentPath(bosConfig?.app.host.development, configDir);
|
|
21
21
|
if (hostLocalPath && (0, node_fs.existsSync)((0, node_path.join)(hostLocalPath, "package.json"))) packages.push("host");
|
|
22
22
|
else if ((0, node_fs.existsSync)((0, node_path.join)(configDir, "host", "package.json"))) packages.push("host");
|
|
23
|
-
for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {}))
|
|
23
|
+
for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {})) {
|
|
24
|
+
if (pluginConfig.localPath && (0, node_fs.existsSync)((0, node_path.join)(pluginConfig.localPath, "package.json"))) packages.push(`plugin:${pluginId}`);
|
|
25
|
+
if (pluginConfig.ui?.localPath && (0, node_fs.existsSync)((0, node_path.join)(pluginConfig.ui.localPath, "package.json"))) packages.push(`plugin-ui:${pluginId}`);
|
|
26
|
+
}
|
|
24
27
|
const authLocalPath = runtimeConfig?.auth?.localPath ?? require_config.resolveLocalDevelopmentPath(bosConfig?.app.auth?.development, configDir);
|
|
25
28
|
if (authLocalPath && (0, node_fs.existsSync)((0, node_path.join)(authLocalPath, "package.json"))) packages.push("auth");
|
|
26
29
|
return packages;
|
|
@@ -106,10 +109,19 @@ async function prepareDevelopmentRuntimeConfig(runtimeConfig, options) {
|
|
|
106
109
|
const entries = Object.entries(next.plugins).sort(([a], [b]) => a.localeCompare(b));
|
|
107
110
|
let pluginBasePort = DEFAULT_PLUGIN_PORT_START;
|
|
108
111
|
for (const [pluginId, plugin] of entries) {
|
|
109
|
-
if (plugin.source
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
if (plugin.source === "local" && plugin.localPath) {
|
|
113
|
+
const pluginPort = await pickAvailablePort(plugin.port ?? pluginBasePort, usedPorts);
|
|
114
|
+
next.plugins[pluginId] = withLocalRuntimeUrl(plugin, pluginPort);
|
|
115
|
+
pluginBasePort = pluginPort + 1;
|
|
116
|
+
}
|
|
117
|
+
if (plugin.ui?.source === "local" && plugin.ui.localPath) {
|
|
118
|
+
const uiPort = await pickAvailablePort(plugin.ui.port ?? pluginBasePort, usedPorts);
|
|
119
|
+
next.plugins[pluginId] = {
|
|
120
|
+
...next.plugins[pluginId],
|
|
121
|
+
ui: withLocalRuntimeUrl(plugin.ui, uiPort)
|
|
122
|
+
};
|
|
123
|
+
pluginBasePort = uiPort + 1;
|
|
124
|
+
}
|
|
113
125
|
}
|
|
114
126
|
}
|
|
115
127
|
return next;
|
package/dist/app.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.cjs","names":["getProjectRoot","resolveLocalDevelopmentPath","configBuildRuntimeConfig"],"sources":["../src/app.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { createConnection } from \"node:net\";\nimport { join } from \"node:path\";\nimport {\n buildRuntimeConfig as configBuildRuntimeConfig,\n getProjectRoot,\n resolveLocalDevelopmentPath,\n} from \"./config\";\nimport type { AppOrchestrator } from \"./service-descriptor\";\nimport type { BosConfig, RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport type { AppOrchestrator };\n\nconst DEFAULT_HOST_PORT = 3000;\nconst DEFAULT_API_PORT = 3001;\nconst DEFAULT_AUTH_PORT = 3002;\nconst DEFAULT_UI_PORT = 3003;\nconst DEFAULT_PLUGIN_PORT_START = 3010;\n\nexport function detectLocalPackages(\n bosConfig?: BosConfig,\n runtimeConfig?: RuntimeConfig,\n): string[] {\n const packages: string[] = [];\n const configDir = getProjectRoot();\n\n const uiLocalPath =\n runtimeConfig?.ui.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.ui.development, configDir);\n if (uiLocalPath && existsSync(join(uiLocalPath, \"package.json\"))) {\n packages.push(\"ui\");\n }\n\n const apiLocalPath =\n runtimeConfig?.api.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.api.development, configDir);\n if (apiLocalPath && existsSync(join(apiLocalPath, \"package.json\"))) {\n packages.push(\"api\");\n }\n\n const hostLocalPath =\n runtimeConfig?.host?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.host.development, configDir);\n if (hostLocalPath && existsSync(join(hostLocalPath, \"package.json\"))) {\n packages.push(\"host\");\n } else if (existsSync(join(configDir, \"host\", \"package.json\"))) {\n packages.push(\"host\");\n }\n\n for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {})) {\n if (pluginConfig.localPath && existsSync(join(pluginConfig.localPath, \"package.json\"))) {\n packages.push(`plugin:${pluginId}`);\n }\n }\n\n const authLocalPath =\n runtimeConfig?.auth?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.auth?.development, configDir);\n if (authLocalPath && existsSync(join(authLocalPath, \"package.json\"))) {\n packages.push(\"auth\");\n }\n\n return packages;\n}\n\nexport function buildRuntimeConfig(\n bosConfig: BosConfig,\n options: {\n hostSource?: \"local\" | \"remote\";\n uiSource?: \"local\" | \"remote\";\n apiSource?: \"local\" | \"remote\";\n authSource?: \"local\" | \"remote\";\n proxy?: string;\n env?: \"development\" | \"production\";\n plugins?: Record<string, RuntimePluginConfig>;\n },\n): RuntimeConfig {\n return configBuildRuntimeConfig(bosConfig, getProjectRoot(), options.env ?? \"development\", {\n hostSource: options.hostSource,\n uiSource: options.uiSource,\n apiSource: options.apiSource,\n authSource: options.authSource,\n proxy: options.proxy,\n plugins: options.plugins,\n });\n}\n\nfunction probeTcpOpen(port: number, timeoutMs = 250): Promise<boolean> {\n return new Promise((resolve) => {\n const socket = createConnection({ host: \"127.0.0.1\", port });\n const timer = setTimeout(() => {\n socket.destroy();\n resolve(false);\n }, timeoutMs);\n\n socket.once(\"connect\", () => {\n clearTimeout(timer);\n socket.destroy();\n resolve(true);\n });\n\n socket.once(\"error\", () => {\n clearTimeout(timer);\n resolve(false);\n });\n });\n}\n\nasync function pickAvailablePort(preferred: number, usedPorts: Set<number>): Promise<number> {\n let port = preferred;\n while (usedPorts.has(port) || (await probeTcpOpen(port))) {\n port += 1;\n }\n usedPorts.add(port);\n return port;\n}\n\nfunction withLocalRuntimeUrl<\n T extends { url: string; entry: string; port?: number; localPath?: string },\n>(entry: T, port: number): T {\n const url = `http://localhost:${port}`;\n return {\n ...entry,\n url,\n entry: `${url}/mf-manifest.json`,\n port,\n };\n}\n\nexport async function prepareDevelopmentRuntimeConfig(\n runtimeConfig: RuntimeConfig,\n options?: { hostPort?: number; ssr?: boolean },\n): Promise<RuntimeConfig> {\n const usedPorts = new Set<number>();\n const hostPort = await pickAvailablePort(options?.hostPort ?? DEFAULT_HOST_PORT, usedPorts);\n\n const next: RuntimeConfig = {\n ...runtimeConfig,\n host: { ...runtimeConfig.host, url: `http://localhost:${hostPort}`, port: hostPort },\n ui: { ...runtimeConfig.ui },\n api: { ...runtimeConfig.api },\n auth: runtimeConfig.auth ? { ...runtimeConfig.auth } : undefined,\n plugins: runtimeConfig.plugins ? { ...runtimeConfig.plugins } : undefined,\n };\n\n if (next.api.source === \"local\" && next.api.localPath) {\n const apiPort = await pickAvailablePort(next.api.port ?? DEFAULT_API_PORT, usedPorts);\n next.api = withLocalRuntimeUrl(next.api, apiPort);\n }\n\n if (next.auth?.source === \"local\" && next.auth.localPath) {\n const authPort = await pickAvailablePort(next.auth.port ?? DEFAULT_AUTH_PORT, usedPorts);\n next.auth = withLocalRuntimeUrl(next.auth, authPort);\n }\n\n if (next.ui.source === \"local\" && next.ui.localPath) {\n const uiPort = await pickAvailablePort(next.ui.port ?? DEFAULT_UI_PORT, usedPorts);\n next.ui = withLocalRuntimeUrl(next.ui, uiPort);\n if (options?.ssr) {\n const ssrPort = await pickAvailablePort(uiPort + 1, usedPorts);\n next.ui.ssrUrl = `http://localhost:${ssrPort}`;\n } else {\n next.ui.ssrUrl = undefined;\n }\n }\n\n if (next.plugins) {\n const entries = Object.entries(next.plugins).sort(([a], [b]) => a.localeCompare(b));\n let pluginBasePort = DEFAULT_PLUGIN_PORT_START;\n\n for (const [pluginId, plugin] of entries) {\n if (plugin.source
|
|
1
|
+
{"version":3,"file":"app.cjs","names":["getProjectRoot","resolveLocalDevelopmentPath","configBuildRuntimeConfig"],"sources":["../src/app.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { createConnection } from \"node:net\";\nimport { join } from \"node:path\";\nimport {\n buildRuntimeConfig as configBuildRuntimeConfig,\n getProjectRoot,\n resolveLocalDevelopmentPath,\n} from \"./config\";\nimport type { AppOrchestrator } from \"./service-descriptor\";\nimport type { BosConfig, RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport type { AppOrchestrator };\n\nconst DEFAULT_HOST_PORT = 3000;\nconst DEFAULT_API_PORT = 3001;\nconst DEFAULT_AUTH_PORT = 3002;\nconst DEFAULT_UI_PORT = 3003;\nconst DEFAULT_PLUGIN_PORT_START = 3010;\n\nexport function detectLocalPackages(\n bosConfig?: BosConfig,\n runtimeConfig?: RuntimeConfig,\n): string[] {\n const packages: string[] = [];\n const configDir = getProjectRoot();\n\n const uiLocalPath =\n runtimeConfig?.ui.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.ui.development, configDir);\n if (uiLocalPath && existsSync(join(uiLocalPath, \"package.json\"))) {\n packages.push(\"ui\");\n }\n\n const apiLocalPath =\n runtimeConfig?.api.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.api.development, configDir);\n if (apiLocalPath && existsSync(join(apiLocalPath, \"package.json\"))) {\n packages.push(\"api\");\n }\n\n const hostLocalPath =\n runtimeConfig?.host?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.host.development, configDir);\n if (hostLocalPath && existsSync(join(hostLocalPath, \"package.json\"))) {\n packages.push(\"host\");\n } else if (existsSync(join(configDir, \"host\", \"package.json\"))) {\n packages.push(\"host\");\n }\n\n for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {})) {\n if (pluginConfig.localPath && existsSync(join(pluginConfig.localPath, \"package.json\"))) {\n packages.push(`plugin:${pluginId}`);\n }\n if (pluginConfig.ui?.localPath && existsSync(join(pluginConfig.ui.localPath, \"package.json\"))) {\n packages.push(`plugin-ui:${pluginId}`);\n }\n }\n\n const authLocalPath =\n runtimeConfig?.auth?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.auth?.development, configDir);\n if (authLocalPath && existsSync(join(authLocalPath, \"package.json\"))) {\n packages.push(\"auth\");\n }\n\n return packages;\n}\n\nexport function buildRuntimeConfig(\n bosConfig: BosConfig,\n options: {\n hostSource?: \"local\" | \"remote\";\n uiSource?: \"local\" | \"remote\";\n apiSource?: \"local\" | \"remote\";\n authSource?: \"local\" | \"remote\";\n proxy?: string;\n env?: \"development\" | \"production\";\n plugins?: Record<string, RuntimePluginConfig>;\n },\n): RuntimeConfig {\n return configBuildRuntimeConfig(bosConfig, getProjectRoot(), options.env ?? \"development\", {\n hostSource: options.hostSource,\n uiSource: options.uiSource,\n apiSource: options.apiSource,\n authSource: options.authSource,\n proxy: options.proxy,\n plugins: options.plugins,\n });\n}\n\nfunction probeTcpOpen(port: number, timeoutMs = 250): Promise<boolean> {\n return new Promise((resolve) => {\n const socket = createConnection({ host: \"127.0.0.1\", port });\n const timer = setTimeout(() => {\n socket.destroy();\n resolve(false);\n }, timeoutMs);\n\n socket.once(\"connect\", () => {\n clearTimeout(timer);\n socket.destroy();\n resolve(true);\n });\n\n socket.once(\"error\", () => {\n clearTimeout(timer);\n resolve(false);\n });\n });\n}\n\nasync function pickAvailablePort(preferred: number, usedPorts: Set<number>): Promise<number> {\n let port = preferred;\n while (usedPorts.has(port) || (await probeTcpOpen(port))) {\n port += 1;\n }\n usedPorts.add(port);\n return port;\n}\n\nfunction withLocalRuntimeUrl<\n T extends { url: string; entry: string; port?: number; localPath?: string },\n>(entry: T, port: number): T {\n const url = `http://localhost:${port}`;\n return {\n ...entry,\n url,\n entry: `${url}/mf-manifest.json`,\n port,\n };\n}\n\nexport async function prepareDevelopmentRuntimeConfig(\n runtimeConfig: RuntimeConfig,\n options?: { hostPort?: number; ssr?: boolean },\n): Promise<RuntimeConfig> {\n const usedPorts = new Set<number>();\n const hostPort = await pickAvailablePort(options?.hostPort ?? DEFAULT_HOST_PORT, usedPorts);\n\n const next: RuntimeConfig = {\n ...runtimeConfig,\n host: { ...runtimeConfig.host, url: `http://localhost:${hostPort}`, port: hostPort },\n ui: { ...runtimeConfig.ui },\n api: { ...runtimeConfig.api },\n auth: runtimeConfig.auth ? { ...runtimeConfig.auth } : undefined,\n plugins: runtimeConfig.plugins ? { ...runtimeConfig.plugins } : undefined,\n };\n\n if (next.api.source === \"local\" && next.api.localPath) {\n const apiPort = await pickAvailablePort(next.api.port ?? DEFAULT_API_PORT, usedPorts);\n next.api = withLocalRuntimeUrl(next.api, apiPort);\n }\n\n if (next.auth?.source === \"local\" && next.auth.localPath) {\n const authPort = await pickAvailablePort(next.auth.port ?? DEFAULT_AUTH_PORT, usedPorts);\n next.auth = withLocalRuntimeUrl(next.auth, authPort);\n }\n\n if (next.ui.source === \"local\" && next.ui.localPath) {\n const uiPort = await pickAvailablePort(next.ui.port ?? DEFAULT_UI_PORT, usedPorts);\n next.ui = withLocalRuntimeUrl(next.ui, uiPort);\n if (options?.ssr) {\n const ssrPort = await pickAvailablePort(uiPort + 1, usedPorts);\n next.ui.ssrUrl = `http://localhost:${ssrPort}`;\n } else {\n next.ui.ssrUrl = undefined;\n }\n }\n\n if (next.plugins) {\n const entries = Object.entries(next.plugins).sort(([a], [b]) => a.localeCompare(b));\n let pluginBasePort = DEFAULT_PLUGIN_PORT_START;\n\n for (const [pluginId, plugin] of entries) {\n if (plugin.source === \"local\" && plugin.localPath) {\n const pluginPort = await pickAvailablePort(plugin.port ?? pluginBasePort, usedPorts);\n next.plugins[pluginId] = withLocalRuntimeUrl(plugin, pluginPort);\n pluginBasePort = pluginPort + 1;\n }\n\n if (plugin.ui?.source === \"local\" && plugin.ui.localPath) {\n const uiPort = await pickAvailablePort(plugin.ui.port ?? pluginBasePort, usedPorts);\n next.plugins[pluginId] = {\n ...next.plugins[pluginId]!,\n ui: withLocalRuntimeUrl(plugin.ui, uiPort),\n };\n pluginBasePort = uiPort + 1;\n }\n }\n }\n\n return next;\n}\n"],"mappings":";;;;;;;AAaA,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB;AACxB,MAAM,4BAA4B;AAElC,SAAgB,oBACd,WACA,eACU;CACV,MAAM,WAAqB,EAAE;CAC7B,MAAM,YAAYA,+BAAgB;CAElC,MAAM,cACJ,eAAe,GAAG,aAClBC,2CAA4B,WAAW,IAAI,GAAG,aAAa,UAAU;AACvE,KAAI,2DAA+B,aAAa,eAAe,CAAC,CAC9D,UAAS,KAAK,KAAK;CAGrB,MAAM,eACJ,eAAe,IAAI,aACnBA,2CAA4B,WA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I,OAAO;AAC9C,MAAI,SAAS,KAAK;GAChB,MAAM,UAAU,MAAM,kBAAkB,SAAS,GAAG,UAAU;AAC9D,QAAK,GAAG,SAAS,oBAAoB;QAErC,MAAK,GAAG,SAAS;;AAIrB,KAAI,KAAK,SAAS;EAChB,MAAM,UAAU,OAAO,QAAQ,KAAK,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC;EACnF,IAAI,iBAAiB;AAErB,OAAK,MAAM,CAAC,UAAU,WAAW,SAAS;AACxC,OAAI,OAAO,WAAW,WAAW,OAAO,WAAW;IACjD,MAAM,aAAa,MAAM,kBAAkB,OAAO,QAAQ,gBAAgB,UAAU;AACpF,SAAK,QAAQ,YAAY,oBAAoB,QAAQ,WAAW;AAChE,qBAAiB,aAAa;;AAGhC,OAAI,OAAO,IAAI,WAAW,WAAW,OAAO,GAAG,WAAW;IACxD,MAAM,SAAS,MAAM,kBAAkB,OAAO,GAAG,QAAQ,gBAAgB,UAAU;AACnF,SAAK,QAAQ,YAAY;KACvB,GAAG,KAAK,QAAQ;KAChB,IAAI,oBAAoB,OAAO,IAAI,OAAO;KAC3C;AACD,qBAAiB,SAAS;;;;AAKhC,QAAO"}
|
package/dist/app.mjs
CHANGED
|
@@ -19,7 +19,10 @@ function detectLocalPackages(bosConfig, runtimeConfig) {
|
|
|
19
19
|
const hostLocalPath = runtimeConfig?.host?.localPath ?? resolveLocalDevelopmentPath(bosConfig?.app.host.development, configDir);
|
|
20
20
|
if (hostLocalPath && existsSync(join(hostLocalPath, "package.json"))) packages.push("host");
|
|
21
21
|
else if (existsSync(join(configDir, "host", "package.json"))) packages.push("host");
|
|
22
|
-
for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {}))
|
|
22
|
+
for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {})) {
|
|
23
|
+
if (pluginConfig.localPath && existsSync(join(pluginConfig.localPath, "package.json"))) packages.push(`plugin:${pluginId}`);
|
|
24
|
+
if (pluginConfig.ui?.localPath && existsSync(join(pluginConfig.ui.localPath, "package.json"))) packages.push(`plugin-ui:${pluginId}`);
|
|
25
|
+
}
|
|
23
26
|
const authLocalPath = runtimeConfig?.auth?.localPath ?? resolveLocalDevelopmentPath(bosConfig?.app.auth?.development, configDir);
|
|
24
27
|
if (authLocalPath && existsSync(join(authLocalPath, "package.json"))) packages.push("auth");
|
|
25
28
|
return packages;
|
|
@@ -105,10 +108,19 @@ async function prepareDevelopmentRuntimeConfig(runtimeConfig, options) {
|
|
|
105
108
|
const entries = Object.entries(next.plugins).sort(([a], [b]) => a.localeCompare(b));
|
|
106
109
|
let pluginBasePort = DEFAULT_PLUGIN_PORT_START;
|
|
107
110
|
for (const [pluginId, plugin] of entries) {
|
|
108
|
-
if (plugin.source
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
if (plugin.source === "local" && plugin.localPath) {
|
|
112
|
+
const pluginPort = await pickAvailablePort(plugin.port ?? pluginBasePort, usedPorts);
|
|
113
|
+
next.plugins[pluginId] = withLocalRuntimeUrl(plugin, pluginPort);
|
|
114
|
+
pluginBasePort = pluginPort + 1;
|
|
115
|
+
}
|
|
116
|
+
if (plugin.ui?.source === "local" && plugin.ui.localPath) {
|
|
117
|
+
const uiPort = await pickAvailablePort(plugin.ui.port ?? pluginBasePort, usedPorts);
|
|
118
|
+
next.plugins[pluginId] = {
|
|
119
|
+
...next.plugins[pluginId],
|
|
120
|
+
ui: withLocalRuntimeUrl(plugin.ui, uiPort)
|
|
121
|
+
};
|
|
122
|
+
pluginBasePort = uiPort + 1;
|
|
123
|
+
}
|
|
112
124
|
}
|
|
113
125
|
}
|
|
114
126
|
return next;
|
package/dist/app.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.mjs","names":["configBuildRuntimeConfig"],"sources":["../src/app.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { createConnection } from \"node:net\";\nimport { join } from \"node:path\";\nimport {\n buildRuntimeConfig as configBuildRuntimeConfig,\n getProjectRoot,\n resolveLocalDevelopmentPath,\n} from \"./config\";\nimport type { AppOrchestrator } from \"./service-descriptor\";\nimport type { BosConfig, RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport type { AppOrchestrator };\n\nconst DEFAULT_HOST_PORT = 3000;\nconst DEFAULT_API_PORT = 3001;\nconst DEFAULT_AUTH_PORT = 3002;\nconst DEFAULT_UI_PORT = 3003;\nconst DEFAULT_PLUGIN_PORT_START = 3010;\n\nexport function detectLocalPackages(\n bosConfig?: BosConfig,\n runtimeConfig?: RuntimeConfig,\n): string[] {\n const packages: string[] = [];\n const configDir = getProjectRoot();\n\n const uiLocalPath =\n runtimeConfig?.ui.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.ui.development, configDir);\n if (uiLocalPath && existsSync(join(uiLocalPath, \"package.json\"))) {\n packages.push(\"ui\");\n }\n\n const apiLocalPath =\n runtimeConfig?.api.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.api.development, configDir);\n if (apiLocalPath && existsSync(join(apiLocalPath, \"package.json\"))) {\n packages.push(\"api\");\n }\n\n const hostLocalPath =\n runtimeConfig?.host?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.host.development, configDir);\n if (hostLocalPath && existsSync(join(hostLocalPath, \"package.json\"))) {\n packages.push(\"host\");\n } else if (existsSync(join(configDir, \"host\", \"package.json\"))) {\n packages.push(\"host\");\n }\n\n for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {})) {\n if (pluginConfig.localPath && existsSync(join(pluginConfig.localPath, \"package.json\"))) {\n packages.push(`plugin:${pluginId}`);\n }\n }\n\n const authLocalPath =\n runtimeConfig?.auth?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.auth?.development, configDir);\n if (authLocalPath && existsSync(join(authLocalPath, \"package.json\"))) {\n packages.push(\"auth\");\n }\n\n return packages;\n}\n\nexport function buildRuntimeConfig(\n bosConfig: BosConfig,\n options: {\n hostSource?: \"local\" | \"remote\";\n uiSource?: \"local\" | \"remote\";\n apiSource?: \"local\" | \"remote\";\n authSource?: \"local\" | \"remote\";\n proxy?: string;\n env?: \"development\" | \"production\";\n plugins?: Record<string, RuntimePluginConfig>;\n },\n): RuntimeConfig {\n return configBuildRuntimeConfig(bosConfig, getProjectRoot(), options.env ?? \"development\", {\n hostSource: options.hostSource,\n uiSource: options.uiSource,\n apiSource: options.apiSource,\n authSource: options.authSource,\n proxy: options.proxy,\n plugins: options.plugins,\n });\n}\n\nfunction probeTcpOpen(port: number, timeoutMs = 250): Promise<boolean> {\n return new Promise((resolve) => {\n const socket = createConnection({ host: \"127.0.0.1\", port });\n const timer = setTimeout(() => {\n socket.destroy();\n resolve(false);\n }, timeoutMs);\n\n socket.once(\"connect\", () => {\n clearTimeout(timer);\n socket.destroy();\n resolve(true);\n });\n\n socket.once(\"error\", () => {\n clearTimeout(timer);\n resolve(false);\n });\n });\n}\n\nasync function pickAvailablePort(preferred: number, usedPorts: Set<number>): Promise<number> {\n let port = preferred;\n while (usedPorts.has(port) || (await probeTcpOpen(port))) {\n port += 1;\n }\n usedPorts.add(port);\n return port;\n}\n\nfunction withLocalRuntimeUrl<\n T extends { url: string; entry: string; port?: number; localPath?: string },\n>(entry: T, port: number): T {\n const url = `http://localhost:${port}`;\n return {\n ...entry,\n url,\n entry: `${url}/mf-manifest.json`,\n port,\n };\n}\n\nexport async function prepareDevelopmentRuntimeConfig(\n runtimeConfig: RuntimeConfig,\n options?: { hostPort?: number; ssr?: boolean },\n): Promise<RuntimeConfig> {\n const usedPorts = new Set<number>();\n const hostPort = await pickAvailablePort(options?.hostPort ?? DEFAULT_HOST_PORT, usedPorts);\n\n const next: RuntimeConfig = {\n ...runtimeConfig,\n host: { ...runtimeConfig.host, url: `http://localhost:${hostPort}`, port: hostPort },\n ui: { ...runtimeConfig.ui },\n api: { ...runtimeConfig.api },\n auth: runtimeConfig.auth ? { ...runtimeConfig.auth } : undefined,\n plugins: runtimeConfig.plugins ? { ...runtimeConfig.plugins } : undefined,\n };\n\n if (next.api.source === \"local\" && next.api.localPath) {\n const apiPort = await pickAvailablePort(next.api.port ?? DEFAULT_API_PORT, usedPorts);\n next.api = withLocalRuntimeUrl(next.api, apiPort);\n }\n\n if (next.auth?.source === \"local\" && next.auth.localPath) {\n const authPort = await pickAvailablePort(next.auth.port ?? DEFAULT_AUTH_PORT, usedPorts);\n next.auth = withLocalRuntimeUrl(next.auth, authPort);\n }\n\n if (next.ui.source === \"local\" && next.ui.localPath) {\n const uiPort = await pickAvailablePort(next.ui.port ?? DEFAULT_UI_PORT, usedPorts);\n next.ui = withLocalRuntimeUrl(next.ui, uiPort);\n if (options?.ssr) {\n const ssrPort = await pickAvailablePort(uiPort + 1, usedPorts);\n next.ui.ssrUrl = `http://localhost:${ssrPort}`;\n } else {\n next.ui.ssrUrl = undefined;\n }\n }\n\n if (next.plugins) {\n const entries = Object.entries(next.plugins).sort(([a], [b]) => a.localeCompare(b));\n let pluginBasePort = DEFAULT_PLUGIN_PORT_START;\n\n for (const [pluginId, plugin] of entries) {\n if (plugin.source
|
|
1
|
+
{"version":3,"file":"app.mjs","names":["configBuildRuntimeConfig"],"sources":["../src/app.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { createConnection } from \"node:net\";\nimport { join } from \"node:path\";\nimport {\n buildRuntimeConfig as configBuildRuntimeConfig,\n getProjectRoot,\n resolveLocalDevelopmentPath,\n} from \"./config\";\nimport type { AppOrchestrator } from \"./service-descriptor\";\nimport type { BosConfig, RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport type { AppOrchestrator };\n\nconst DEFAULT_HOST_PORT = 3000;\nconst DEFAULT_API_PORT = 3001;\nconst DEFAULT_AUTH_PORT = 3002;\nconst DEFAULT_UI_PORT = 3003;\nconst DEFAULT_PLUGIN_PORT_START = 3010;\n\nexport function detectLocalPackages(\n bosConfig?: BosConfig,\n runtimeConfig?: RuntimeConfig,\n): string[] {\n const packages: string[] = [];\n const configDir = getProjectRoot();\n\n const uiLocalPath =\n runtimeConfig?.ui.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.ui.development, configDir);\n if (uiLocalPath && existsSync(join(uiLocalPath, \"package.json\"))) {\n packages.push(\"ui\");\n }\n\n const apiLocalPath =\n runtimeConfig?.api.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.api.development, configDir);\n if (apiLocalPath && existsSync(join(apiLocalPath, \"package.json\"))) {\n packages.push(\"api\");\n }\n\n const hostLocalPath =\n runtimeConfig?.host?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.host.development, configDir);\n if (hostLocalPath && existsSync(join(hostLocalPath, \"package.json\"))) {\n packages.push(\"host\");\n } else if (existsSync(join(configDir, \"host\", \"package.json\"))) {\n packages.push(\"host\");\n }\n\n for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig?.plugins ?? {})) {\n if (pluginConfig.localPath && existsSync(join(pluginConfig.localPath, \"package.json\"))) {\n packages.push(`plugin:${pluginId}`);\n }\n if (pluginConfig.ui?.localPath && existsSync(join(pluginConfig.ui.localPath, \"package.json\"))) {\n packages.push(`plugin-ui:${pluginId}`);\n }\n }\n\n const authLocalPath =\n runtimeConfig?.auth?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.app.auth?.development, configDir);\n if (authLocalPath && existsSync(join(authLocalPath, \"package.json\"))) {\n packages.push(\"auth\");\n }\n\n return packages;\n}\n\nexport function buildRuntimeConfig(\n bosConfig: BosConfig,\n options: {\n hostSource?: \"local\" | \"remote\";\n uiSource?: \"local\" | \"remote\";\n apiSource?: \"local\" | \"remote\";\n authSource?: \"local\" | \"remote\";\n proxy?: string;\n env?: \"development\" | \"production\";\n plugins?: Record<string, RuntimePluginConfig>;\n },\n): RuntimeConfig {\n return configBuildRuntimeConfig(bosConfig, getProjectRoot(), options.env ?? \"development\", {\n hostSource: options.hostSource,\n uiSource: options.uiSource,\n apiSource: options.apiSource,\n authSource: options.authSource,\n proxy: options.proxy,\n plugins: options.plugins,\n });\n}\n\nfunction probeTcpOpen(port: number, timeoutMs = 250): Promise<boolean> {\n return new Promise((resolve) => {\n const socket = createConnection({ host: \"127.0.0.1\", port });\n const timer = setTimeout(() => {\n socket.destroy();\n resolve(false);\n }, timeoutMs);\n\n socket.once(\"connect\", () => {\n clearTimeout(timer);\n socket.destroy();\n resolve(true);\n });\n\n socket.once(\"error\", () => {\n clearTimeout(timer);\n resolve(false);\n });\n });\n}\n\nasync function pickAvailablePort(preferred: number, usedPorts: Set<number>): Promise<number> {\n let port = preferred;\n while (usedPorts.has(port) || (await probeTcpOpen(port))) {\n port += 1;\n }\n usedPorts.add(port);\n return port;\n}\n\nfunction withLocalRuntimeUrl<\n T extends { url: string; entry: string; port?: number; localPath?: string },\n>(entry: T, port: number): T {\n const url = `http://localhost:${port}`;\n return {\n ...entry,\n url,\n entry: `${url}/mf-manifest.json`,\n port,\n };\n}\n\nexport async function prepareDevelopmentRuntimeConfig(\n runtimeConfig: RuntimeConfig,\n options?: { hostPort?: number; ssr?: boolean },\n): Promise<RuntimeConfig> {\n const usedPorts = new Set<number>();\n const hostPort = await pickAvailablePort(options?.hostPort ?? DEFAULT_HOST_PORT, usedPorts);\n\n const next: RuntimeConfig = {\n ...runtimeConfig,\n host: { ...runtimeConfig.host, url: `http://localhost:${hostPort}`, port: hostPort },\n ui: { ...runtimeConfig.ui },\n api: { ...runtimeConfig.api },\n auth: runtimeConfig.auth ? { ...runtimeConfig.auth } : undefined,\n plugins: runtimeConfig.plugins ? { ...runtimeConfig.plugins } : undefined,\n };\n\n if (next.api.source === \"local\" && next.api.localPath) {\n const apiPort = await pickAvailablePort(next.api.port ?? DEFAULT_API_PORT, usedPorts);\n next.api = withLocalRuntimeUrl(next.api, apiPort);\n }\n\n if (next.auth?.source === \"local\" && next.auth.localPath) {\n const authPort = await pickAvailablePort(next.auth.port ?? DEFAULT_AUTH_PORT, usedPorts);\n next.auth = withLocalRuntimeUrl(next.auth, authPort);\n }\n\n if (next.ui.source === \"local\" && next.ui.localPath) {\n const uiPort = await pickAvailablePort(next.ui.port ?? DEFAULT_UI_PORT, usedPorts);\n next.ui = withLocalRuntimeUrl(next.ui, uiPort);\n if (options?.ssr) {\n const ssrPort = await pickAvailablePort(uiPort + 1, usedPorts);\n next.ui.ssrUrl = `http://localhost:${ssrPort}`;\n } else {\n next.ui.ssrUrl = undefined;\n }\n }\n\n if (next.plugins) {\n const entries = Object.entries(next.plugins).sort(([a], [b]) => a.localeCompare(b));\n let pluginBasePort = DEFAULT_PLUGIN_PORT_START;\n\n for (const [pluginId, plugin] of entries) {\n if (plugin.source === \"local\" && plugin.localPath) {\n const pluginPort = await pickAvailablePort(plugin.port ?? pluginBasePort, usedPorts);\n next.plugins[pluginId] = withLocalRuntimeUrl(plugin, pluginPort);\n pluginBasePort = pluginPort + 1;\n }\n\n if (plugin.ui?.source === \"local\" && plugin.ui.localPath) {\n const uiPort = await pickAvailablePort(plugin.ui.port ?? pluginBasePort, usedPorts);\n next.plugins[pluginId] = {\n ...next.plugins[pluginId]!,\n ui: withLocalRuntimeUrl(plugin.ui, uiPort),\n };\n pluginBasePort = uiPort + 1;\n }\n }\n }\n\n return next;\n}\n"],"mappings":";;;;;;AAaA,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB;AACxB,MAAM,4BAA4B;AAElC,SAAgB,oBACd,WACA,eACU;CACV,MAAM,WAAqB,EAAE;CAC7B,MAAM,YAAY,gBAAgB;CAElC,MAAM,cACJ,eAAe,GAAG,aAClB,4BAA4B,WAAW,IAAI,GAAG,aAAa,UAAU;AACvE,KAAI,eAAe,WAAW,KAAK,aAAa,eAAe,CAAC,CAC9D,UAAS,KAAK,KAAK;CAGrB,MAAM,eACJ,eAAe,IAAI,aACnB,4BAA4B,WAAW,IAAI,IAAI,aAAa,UAAU;AACxE,KAAI,gBAAgB,WAAW,KAA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B,KAAK,IAAI,OAAO;AAC9C,MAAI,SAAS,KAAK;GAChB,MAAM,UAAU,MAAM,kBAAkB,SAAS,GAAG,UAAU;AAC9D,QAAK,GAAG,SAAS,oBAAoB;QAErC,MAAK,GAAG,SAAS;;AAIrB,KAAI,KAAK,SAAS;EAChB,MAAM,UAAU,OAAO,QAAQ,KAAK,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC;EACnF,IAAI,iBAAiB;AAErB,OAAK,MAAM,CAAC,UAAU,WAAW,SAAS;AACxC,OAAI,OAAO,WAAW,WAAW,OAAO,WAAW;IACjD,MAAM,aAAa,MAAM,kBAAkB,OAAO,QAAQ,gBAAgB,UAAU;AACpF,SAAK,QAAQ,YAAY,oBAAoB,QAAQ,WAAW;AAChE,qBAAiB,aAAa;;AAGhC,OAAI,OAAO,IAAI,WAAW,WAAW,OAAO,GAAG,WAAW;IACxD,MAAM,SAAS,MAAM,kBAAkB,OAAO,GAAG,QAAQ,gBAAgB,UAAU;AACnF,SAAK,QAAQ,YAAY;KACvB,GAAG,KAAK,QAAQ;KAChB,IAAI,oBAAoB,OAAO,IAAI,OAAO;KAC3C;AACD,qBAAiB,SAAS;;;;AAKhC,QAAO"}
|
package/dist/cli/init.cjs
CHANGED
|
@@ -2,6 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_fastkv = require('../fastkv.cjs');
|
|
4
4
|
const require_manifest_normalizer = require('../internal/manifest-normalizer.cjs');
|
|
5
|
+
const require_path_match = require('../utils/path-match.cjs');
|
|
6
|
+
const require_save_config = require('../utils/save-config.cjs');
|
|
5
7
|
const require_snapshot = require('./snapshot.cjs');
|
|
6
8
|
let node_fs = require("node:fs");
|
|
7
9
|
let node_path = require("node:path");
|
|
@@ -14,23 +16,6 @@ let glob = require("glob");
|
|
|
14
16
|
|
|
15
17
|
//#region src/cli/init.ts
|
|
16
18
|
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
17
|
-
const BOS_CONFIG_ORDER = [
|
|
18
|
-
"extends",
|
|
19
|
-
"account",
|
|
20
|
-
"domain",
|
|
21
|
-
"testnet",
|
|
22
|
-
"staging",
|
|
23
|
-
"repository",
|
|
24
|
-
"app",
|
|
25
|
-
"plugins",
|
|
26
|
-
"shared"
|
|
27
|
-
];
|
|
28
|
-
function rebuildOrderedConfig(config) {
|
|
29
|
-
const ordered = {};
|
|
30
|
-
for (const key of BOS_CONFIG_ORDER) if (key in config) ordered[key] = config[key];
|
|
31
|
-
for (const key of Object.keys(config)) if (!BOS_CONFIG_ORDER.includes(key)) ordered[key] = config[key];
|
|
32
|
-
return ordered;
|
|
33
|
-
}
|
|
34
19
|
async function resolveSourceDir(opts) {
|
|
35
20
|
if (opts.source) {
|
|
36
21
|
const sourceDir = (0, node_path.resolve)(opts.source);
|
|
@@ -50,6 +35,11 @@ async function resolveSourceDir(opts) {
|
|
|
50
35
|
cleanup
|
|
51
36
|
};
|
|
52
37
|
}
|
|
38
|
+
async function readTemplatekeep(sourceDir) {
|
|
39
|
+
const keepFile = (0, node_path.join)(sourceDir, ".templatekeep");
|
|
40
|
+
if (!(0, node_fs.existsSync)(keepFile)) return [];
|
|
41
|
+
return (0, node_fs.readFileSync)(keepFile, "utf-8").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
42
|
+
}
|
|
53
43
|
async function fetchParentConfig(extendsAccount, extendsGateway) {
|
|
54
44
|
return require_fastkv.fetchBosConfigFromFastKv(`bos://${extendsAccount}/${extendsGateway}`);
|
|
55
45
|
}
|
|
@@ -126,11 +116,6 @@ function parseGitHubUrl(url) {
|
|
|
126
116
|
};
|
|
127
117
|
return null;
|
|
128
118
|
}
|
|
129
|
-
async function readTemplatekeep(sourceDir) {
|
|
130
|
-
const keepFile = (0, node_path.join)(sourceDir, ".templatekeep");
|
|
131
|
-
if (!(0, node_fs.existsSync)(keepFile)) return [];
|
|
132
|
-
return (0, node_fs.readFileSync)(keepFile, "utf-8").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
133
|
-
}
|
|
134
119
|
async function copyFilteredFiles(sourceDir, destination, patterns, options) {
|
|
135
120
|
if (patterns.length === 0) return 0;
|
|
136
121
|
const filteredPatterns = (options.withHost ? [...patterns, "host/**"] : patterns.filter((p) => !p.startsWith("host/") && p !== "host/**")).filter((p) => {
|
|
@@ -157,7 +142,7 @@ async function copyFilteredFiles(sourceDir, destination, patterns, options) {
|
|
|
157
142
|
const pluginName = pluginMatch[1];
|
|
158
143
|
if (!(options.plugins?.includes(pluginName) ?? true)) continue;
|
|
159
144
|
}
|
|
160
|
-
if (
|
|
145
|
+
if (require_path_match.isPathExcluded(match, excludedRoutePatterns)) continue;
|
|
161
146
|
allFiles.add(match);
|
|
162
147
|
}
|
|
163
148
|
}
|
|
@@ -171,7 +156,7 @@ async function copyFilteredFiles(sourceDir, destination, patterns, options) {
|
|
|
171
156
|
dot: true,
|
|
172
157
|
absolute: false
|
|
173
158
|
});
|
|
174
|
-
for (const match of matches) if (!
|
|
159
|
+
for (const match of matches) if (!require_path_match.isPathExcluded(match, excludedRoutePatterns)) routeFiles.add(match);
|
|
175
160
|
}
|
|
176
161
|
}
|
|
177
162
|
for (const f of routeFiles) allFiles.add(f);
|
|
@@ -187,14 +172,6 @@ async function copyFilteredFiles(sourceDir, destination, patterns, options) {
|
|
|
187
172
|
}
|
|
188
173
|
return count;
|
|
189
174
|
}
|
|
190
|
-
function isRouteExcluded(filePath, excludedPatterns) {
|
|
191
|
-
if (excludedPatterns.length === 0) return false;
|
|
192
|
-
for (const pattern of excludedPatterns) if (pattern.endsWith("/**")) {
|
|
193
|
-
const prefix = pattern.slice(0, -3);
|
|
194
|
-
if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;
|
|
195
|
-
} else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) return true;
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
175
|
async function personalizeConfig(destination, opts) {
|
|
199
176
|
const isInit = opts.mode !== "sync";
|
|
200
177
|
const configPath = (0, node_path.join)(destination, "bos.config.json");
|
|
@@ -221,17 +198,86 @@ async function personalizeConfig(destination, opts) {
|
|
|
221
198
|
if (opts.plugins && opts.plugins.length > 0) {
|
|
222
199
|
for (const pluginKey of Object.keys(plugins)) if (!opts.plugins.includes(pluginKey)) delete plugins[pluginKey];
|
|
223
200
|
}
|
|
224
|
-
if (isInit)
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
201
|
+
if (isInit) {
|
|
202
|
+
const parentDomain = opts.extendsGateway;
|
|
203
|
+
for (const pluginKey of Object.keys(plugins)) {
|
|
204
|
+
const plugin = plugins[pluginKey];
|
|
205
|
+
let pluginObj;
|
|
206
|
+
if (typeof plugin === "string") {
|
|
207
|
+
pluginObj = { extends: plugin };
|
|
208
|
+
plugins[pluginKey] = pluginObj;
|
|
209
|
+
} else if (plugin && typeof plugin === "object") pluginObj = { ...plugin };
|
|
210
|
+
else continue;
|
|
211
|
+
if (pluginObj.development && typeof pluginObj.development === "string" && pluginObj.development.startsWith("local:")) {
|
|
212
|
+
const pluginDir = (0, node_path.join)(destination, pluginObj.development.slice(6));
|
|
213
|
+
const pluginConfigPath = (0, node_path.join)(pluginDir, "bos.config.json");
|
|
214
|
+
if ((0, node_fs.existsSync)(pluginConfigPath)) try {
|
|
215
|
+
const pluginConfig = JSON.parse((0, node_fs.readFileSync)(pluginConfigPath, "utf-8"));
|
|
216
|
+
delete pluginConfig.extends;
|
|
217
|
+
if (pluginConfig.app && typeof pluginConfig.app === "object") {
|
|
218
|
+
const app = pluginConfig.app;
|
|
219
|
+
for (const entryKey of Object.keys(app)) {
|
|
220
|
+
const entry = app[entryKey];
|
|
221
|
+
if (entry && typeof entry === "object") {
|
|
222
|
+
const e = entry;
|
|
223
|
+
delete e.production;
|
|
224
|
+
delete e.integrity;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
(0, node_fs.writeFileSync)(pluginConfigPath, `${JSON.stringify(pluginConfig, null, 2)}\n`);
|
|
229
|
+
} catch {}
|
|
230
|
+
else if ((0, node_fs.existsSync)(pluginDir)) {
|
|
231
|
+
const pluginConfig = {};
|
|
232
|
+
pluginConfig.domain = `${pluginKey}.${opts.domain ?? parentDomain}`;
|
|
233
|
+
pluginConfig.app = { api: { development: "local:." } };
|
|
234
|
+
if (opts.pluginRoutes?.[pluginKey]) pluginConfig.routes = opts.pluginRoutes[pluginKey];
|
|
235
|
+
if (pluginObj.sidebar) pluginConfig.sidebar = pluginObj.sidebar;
|
|
236
|
+
(0, node_fs.mkdirSync)(pluginDir, { recursive: true });
|
|
237
|
+
(0, node_fs.writeFileSync)(pluginConfigPath, `${JSON.stringify(pluginConfig, null, 2)}\n`);
|
|
238
|
+
}
|
|
239
|
+
const cleanEntry = { development: pluginObj.development };
|
|
240
|
+
if (pluginObj.extends) cleanEntry.extends = pluginObj.extends;
|
|
241
|
+
if (pluginObj.secrets) cleanEntry.secrets = pluginObj.secrets;
|
|
242
|
+
if (pluginObj.variables) cleanEntry.variables = pluginObj.variables;
|
|
243
|
+
plugins[pluginKey] = cleanEntry;
|
|
244
|
+
} else {
|
|
245
|
+
delete pluginObj.production;
|
|
246
|
+
delete pluginObj.integrity;
|
|
247
|
+
delete pluginObj.sidebar;
|
|
248
|
+
delete pluginObj.routes;
|
|
249
|
+
}
|
|
230
250
|
}
|
|
251
|
+
} else for (const pluginKey of Object.keys(plugins)) {
|
|
252
|
+
const pluginConfigPath = (0, node_path.join)((0, node_path.resolve)(destination, plugins[pluginKey]?.development?.toString()?.slice(6) ?? ""), "bos.config.json");
|
|
253
|
+
if (!(0, node_fs.existsSync)(pluginConfigPath)) continue;
|
|
254
|
+
try {
|
|
255
|
+
const pluginConfig = JSON.parse((0, node_fs.readFileSync)(pluginConfigPath, "utf-8"));
|
|
256
|
+
let changed = false;
|
|
257
|
+
if ("extends" in pluginConfig) {
|
|
258
|
+
delete pluginConfig.extends;
|
|
259
|
+
changed = true;
|
|
260
|
+
}
|
|
261
|
+
if (pluginConfig.app && typeof pluginConfig.app === "object") {
|
|
262
|
+
const app = pluginConfig.app;
|
|
263
|
+
for (const entryKey of Object.keys(app)) {
|
|
264
|
+
const entry = app[entryKey];
|
|
265
|
+
if (entry && typeof entry === "object") {
|
|
266
|
+
const e = entry;
|
|
267
|
+
if ("production" in e || "integrity" in e) {
|
|
268
|
+
delete e.production;
|
|
269
|
+
delete e.integrity;
|
|
270
|
+
changed = true;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (changed) (0, node_fs.writeFileSync)(pluginConfigPath, `${JSON.stringify(pluginConfig, null, 2)}\n`);
|
|
276
|
+
} catch {}
|
|
231
277
|
}
|
|
232
278
|
if (Object.keys(plugins).length === 0) config.plugins = {};
|
|
233
279
|
}
|
|
234
|
-
|
|
280
|
+
await require_save_config.saveBosConfig(destination, config);
|
|
235
281
|
}
|
|
236
282
|
const pkgPath = (0, node_path.join)(destination, "package.json");
|
|
237
283
|
if ((0, node_fs.existsSync)(pkgPath)) {
|
|
@@ -312,22 +358,64 @@ async function personalizeConfig(destination, opts) {
|
|
|
312
358
|
(0, node_fs.mkdirSync)((0, node_path.dirname)(pluginsClientGenPath), { recursive: true });
|
|
313
359
|
(0, node_fs.writeFileSync)(pluginsClientGenPath, `import type { ContractRouterClient, AnyContractRouter } from "@orpc/contract";\ntype ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\nexport type PluginsClient = Record<string, never>;\n`);
|
|
314
360
|
}
|
|
315
|
-
const
|
|
316
|
-
|
|
361
|
+
const authTypesContent = generateAuthTypesTemplate();
|
|
362
|
+
const authTypesPaths = [(0, node_path.join)(destination, "ui", "src", "lib", "auth-types.gen.ts"), (0, node_path.join)(destination, "api", "src", "lib", "auth-types.gen.ts")];
|
|
363
|
+
if ((0, node_fs.existsSync)((0, node_path.join)(destination, "host", "src"))) authTypesPaths.push((0, node_path.join)(destination, "host", "src", "lib", "auth-types.gen.ts"));
|
|
364
|
+
for (const authTypesGenPath of authTypesPaths) if (!(0, node_fs.existsSync)(authTypesGenPath)) {
|
|
317
365
|
(0, node_fs.mkdirSync)((0, node_path.dirname)(authTypesGenPath), { recursive: true });
|
|
318
|
-
(0, node_fs.writeFileSync)(authTypesGenPath,
|
|
319
|
-
}
|
|
320
|
-
const apiAuthTypesGenPath = (0, node_path.join)(destination, "api", "src", "lib", "auth-types.gen.ts");
|
|
321
|
-
if (!(0, node_fs.existsSync)(apiAuthTypesGenPath)) {
|
|
322
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(apiAuthTypesGenPath), { recursive: true });
|
|
323
|
-
(0, node_fs.writeFileSync)(apiAuthTypesGenPath, `import type { Auth } from "better-auth";\nexport type { Auth } from "better-auth";\nexport type AuthSessionUser = NonNullable<Auth["$Infer"]["Session"]["user"]> & {\n role?: string | null;\n isAnonymous?: boolean | null;\n walletAddress?: string | null;\n banned?: boolean | null;\n};\nexport type AuthSessionData = NonNullable<Auth["$Infer"]["Session"]["session"]> & {\n activeOrganizationId?: string | null;\n};\nexport type AuthSession = {\n user: AuthSessionUser | null;\n session: AuthSessionData | null;\n};\nexport interface AuthOrganizationContext {\n activeOrganizationId: string | null;\n organization: { id: string; name: string; slug: string; logo?: string | null; metadata?: Record<string, unknown> } | null;\n member: { id: string; role: string } | null;\n isPersonal: boolean;\n hasOrganization: boolean;\n}\nexport interface AuthRequestContext {\n user: AuthSessionUser | null;\n userId: string | null;\n isAuthenticated: boolean;\n authMethod: "session" | "apiKey" | "anonymous" | "none";\n near: {\n primaryAccountId: string | null;\n linkedAccounts: Array<{ accountId: string; network: string; publicKey: string; isPrimary: boolean }>;\n hasNearAccount: boolean;\n };\n organization: AuthOrganizationContext;\n organizations?: Array<{ id: string; role: string; name?: string; slug?: string }>;\n}\nexport type AuthActiveMember = { id: string | null; role: string | null; organizationId: string | null };\nexport type AuthOrganization = NonNullable<AuthOrganizationContext["organization"]>;\nexport type AuthOrganizationMember = NonNullable<AuthOrganizationContext["member"]>;\nexport type AuthOrganizationSummary = NonNullable<AuthRequestContext["organizations"]>[number];\nexport type AuthBaseSession = Auth["$Infer"]["Session"];\nexport type createAuthInstance = never;\nexport interface AuthServices {\n auth: Auth;\n db: unknown;\n driver: { close(): Promise<void> };\n handler: (req: Request) => Promise<Response>;\n}\n`);
|
|
324
|
-
}
|
|
325
|
-
const hostAuthTypesGenPath = (0, node_path.join)(destination, "host", "src", "lib", "auth-types.gen.ts");
|
|
326
|
-
if ((0, node_fs.existsSync)((0, node_path.join)(destination, "host", "src")) && !(0, node_fs.existsSync)(hostAuthTypesGenPath)) {
|
|
327
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(hostAuthTypesGenPath), { recursive: true });
|
|
328
|
-
(0, node_fs.writeFileSync)(hostAuthTypesGenPath, `import type { Auth } from "better-auth";\nexport type { Auth } from "better-auth";\nexport type AuthSessionUser = NonNullable<Auth["$Infer"]["Session"]["user"]> & {\n role?: string | null;\n isAnonymous?: boolean | null;\n walletAddress?: string | null;\n banned?: boolean | null;\n};\nexport type AuthSessionData = NonNullable<Auth["$Infer"]["Session"]["session"]> & {\n activeOrganizationId?: string | null;\n};\nexport type AuthSession = {\n user: AuthSessionUser | null;\n session: AuthSessionData | null;\n};\nexport interface AuthOrganizationContext {\n activeOrganizationId: string | null;\n organization: { id: string; name: string; slug: string; logo?: string | null; metadata?: Record<string, unknown> } | null;\n member: { id: string; role: string } | null;\n isPersonal: boolean;\n hasOrganization: boolean;\n}\nexport interface AuthRequestContext {\n user: AuthSessionUser | null;\n userId: string | null;\n isAuthenticated: boolean;\n authMethod: "session" | "apiKey" | "anonymous" | "none";\n near: {\n primaryAccountId: string | null;\n linkedAccounts: Array<{ accountId: string; network: string; publicKey: string; isPrimary: boolean }>;\n hasNearAccount: boolean;\n };\n organization: AuthOrganizationContext;\n organizations?: Array<{ id: string; role: string; name?: string; slug?: string }>;\n}\nexport type AuthActiveMember = { id: string | null; role: string | null; organizationId: string | null };\nexport type AuthOrganization = NonNullable<AuthOrganizationContext["organization"]>;\nexport type AuthOrganizationMember = NonNullable<AuthOrganizationContext["member"]>;\nexport type AuthOrganizationSummary = NonNullable<AuthRequestContext["organizations"]>[number];\nexport type AuthBaseSession = Auth["$Infer"]["Session"];\nexport type createAuthInstance = never;\nexport interface AuthServices {\n auth: Auth;\n db: unknown;\n driver: { close(): Promise<void> };\n handler: (req: Request) => Promise<Response>;\n}\n`);
|
|
366
|
+
(0, node_fs.writeFileSync)(authTypesGenPath, authTypesContent);
|
|
329
367
|
}
|
|
330
368
|
}
|
|
369
|
+
function generateAuthTypesTemplate() {
|
|
370
|
+
return `import type { Auth } from "better-auth";
|
|
371
|
+
export type { Auth } from "better-auth";
|
|
372
|
+
export type AuthSessionUser = NonNullable<Auth["$Infer"]["Session"]["user"]> & {
|
|
373
|
+
role?: string | null;
|
|
374
|
+
isAnonymous?: boolean | null;
|
|
375
|
+
walletAddress?: string | null;
|
|
376
|
+
banned?: boolean | null;
|
|
377
|
+
};
|
|
378
|
+
export type AuthSessionData = NonNullable<Auth["$Infer"]["Session"]["session"]> & {
|
|
379
|
+
activeOrganizationId?: string | null;
|
|
380
|
+
};
|
|
381
|
+
export type AuthSession = {
|
|
382
|
+
user: AuthSessionUser | null;
|
|
383
|
+
session: AuthSessionData | null;
|
|
384
|
+
};
|
|
385
|
+
export interface AuthOrganizationContext {
|
|
386
|
+
activeOrganizationId: string | null;
|
|
387
|
+
organization: { id: string; name: string; slug: string; logo?: string | null; metadata?: Record<string, unknown> } | null;
|
|
388
|
+
member: { id: string; role: string } | null;
|
|
389
|
+
isPersonal: boolean;
|
|
390
|
+
hasOrganization: boolean;
|
|
391
|
+
}
|
|
392
|
+
export interface AuthRequestContext {
|
|
393
|
+
user: AuthSessionUser | null;
|
|
394
|
+
userId: string | null;
|
|
395
|
+
isAuthenticated: boolean;
|
|
396
|
+
authMethod: "session" | "apiKey" | "anonymous" | "none";
|
|
397
|
+
near: {
|
|
398
|
+
primaryAccountId: string | null;
|
|
399
|
+
linkedAccounts: Array<{ accountId: string; network: string; publicKey: string; isPrimary: boolean }>;
|
|
400
|
+
hasNearAccount: boolean;
|
|
401
|
+
};
|
|
402
|
+
organization: AuthOrganizationContext;
|
|
403
|
+
organizations?: Array<{ id: string; role: string; name?: string; slug?: string }>;
|
|
404
|
+
}
|
|
405
|
+
export type AuthActiveMember = { id: string | null; role: string | null; organizationId: string | null };
|
|
406
|
+
export type AuthOrganization = NonNullable<AuthOrganizationContext["organization"]>;
|
|
407
|
+
export type AuthOrganizationMember = NonNullable<AuthOrganizationContext["member"]>;
|
|
408
|
+
export type AuthOrganizationSummary = NonNullable<AuthRequestContext["organizations"]>[number];
|
|
409
|
+
export type AuthBaseSession = Auth["$Infer"]["Session"];
|
|
410
|
+
export type createAuthInstance = never;
|
|
411
|
+
export interface AuthServices {
|
|
412
|
+
auth: Auth;
|
|
413
|
+
db: unknown;
|
|
414
|
+
driver: { close(): Promise<void> };
|
|
415
|
+
handler: (req: Request) => Promise<Response>;
|
|
416
|
+
}
|
|
417
|
+
`;
|
|
418
|
+
}
|
|
331
419
|
async function runBunInstall(destination) {
|
|
332
420
|
await execCommand("bun", ["install", "--ignore-scripts"], destination);
|
|
333
421
|
}
|
|
@@ -384,7 +472,7 @@ async function writeInitSnapshot(destination, extendsAccount, extendsGateway, so
|
|
|
384
472
|
for (const match of matches) {
|
|
385
473
|
const pluginMatch = match.match(/^plugins\/([^/]+)/);
|
|
386
474
|
if (pluginMatch && !(options.plugins?.includes(pluginMatch[1]) ?? true)) continue;
|
|
387
|
-
if (
|
|
475
|
+
if (require_path_match.isPathExcluded(match, excludedRoutePatterns)) continue;
|
|
388
476
|
allFiles.add(match);
|
|
389
477
|
}
|
|
390
478
|
}
|
|
@@ -397,7 +485,7 @@ async function writeInitSnapshot(destination, extendsAccount, extendsGateway, so
|
|
|
397
485
|
dot: true,
|
|
398
486
|
absolute: false
|
|
399
487
|
});
|
|
400
|
-
for (const match of matches) if (!
|
|
488
|
+
for (const match of matches) if (!require_path_match.isPathExcluded(match, excludedRoutePatterns)) allFiles.add(match);
|
|
401
489
|
}
|
|
402
490
|
}
|
|
403
491
|
const fileHashes = {};
|
|
@@ -417,18 +505,7 @@ function computeHash(data) {
|
|
|
417
505
|
return (0, node_crypto.createHash)("sha256").update(data).digest("hex").substring(0, 16);
|
|
418
506
|
}
|
|
419
507
|
function mkTmpDir(prefix) {
|
|
420
|
-
|
|
421
|
-
let attempt = 0;
|
|
422
|
-
while (true) {
|
|
423
|
-
const dir = `${base}-${Date.now()}-${attempt}`;
|
|
424
|
-
try {
|
|
425
|
-
(0, node_fs.mkdirSync)(dir, { recursive: true });
|
|
426
|
-
return dir;
|
|
427
|
-
} catch {
|
|
428
|
-
attempt++;
|
|
429
|
-
if (attempt > 10) throw new Error("Failed to create temp directory");
|
|
430
|
-
}
|
|
431
|
-
}
|
|
508
|
+
return (0, node_fs.mkdtempSync)((0, node_path.join)((0, node_os.tmpdir)(), `${prefix}-`));
|
|
432
509
|
}
|
|
433
510
|
async function generateDatabaseMigrations(destination) {
|
|
434
511
|
const drizzleConfigs = await (0, glob.glob)("**/drizzle.config.ts", {
|