everything-dev 1.8.1 → 1.8.3

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.
@@ -0,0 +1,7 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region \0rolldown/runtime.js
4
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
+
6
+ //#endregion
7
+ export { __require };
@@ -67,25 +67,25 @@ async function remoteContractSource(opts) {
67
67
  };
68
68
  }
69
69
  async function resolveContractSource(opts) {
70
- if (opts.key === "api" && (!opts.source || !("localPath" in opts.source) || opts.source.localPath)) {
70
+ if (opts.key === "api") {
71
71
  const localPath = opts.source && "localPath" in opts.source ? opts.source.localPath : void 0;
72
- if (localPath) return {
72
+ if (localPath != null && localPath !== "") return {
73
73
  key: opts.key,
74
74
  importName: "BaseApiContract",
75
75
  sourceFilePath: (0, node_path.join)(localPath, "src", "contract.ts")
76
76
  };
77
77
  if (!opts.baseUrl) return localApiContractSource(opts.configDir);
78
78
  }
79
- if (opts.key === "auth" && opts.localSourceFactory && (!opts.source || !("localPath" in opts.source) || opts.source.localPath)) {
79
+ if (opts.key === "auth" && opts.localSourceFactory) {
80
80
  const localPath = opts.source && "localPath" in opts.source ? opts.source.localPath : void 0;
81
- if (localPath) return {
81
+ if (localPath != null && localPath !== "") return {
82
82
  key: opts.key,
83
83
  importName: "authContract",
84
84
  sourceFilePath: (0, node_path.join)(localPath, "src", "contract.ts")
85
85
  };
86
86
  if (!opts.baseUrl) return opts.localSourceFactory(opts.configDir);
87
87
  }
88
- if (opts.source && "localPath" in opts.source && opts.source.localPath) return {
88
+ if (opts.source && "localPath" in opts.source && opts.source.localPath != null && opts.source.localPath !== "") return {
89
89
  key: opts.key,
90
90
  importName: `${sanitizeIdentifier(opts.key)}Contract`,
91
91
  sourceFilePath: (0, node_path.join)(opts.source.localPath, "src", "contract.ts")
@@ -1 +1 @@
1
- {"version":3,"file":"api-contract.cjs","names":[],"sources":["../src/api-contract.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport type { RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport interface ApiPluginManifest {\n schemaVersion: 1;\n kind: \"every-plugin/manifest\";\n plugin: {\n name: string;\n version: string;\n };\n runtime: {\n remoteEntry: string;\n };\n contract?: {\n kind: \"orpc\";\n types: {\n path: string;\n exportName: string;\n typeName: string;\n sha256?: string;\n };\n };\n}\n\ninterface ContractSource {\n key: string;\n importName: string;\n sourceFilePath: string;\n generatedPath?: string;\n}\n\nfunction sha256(input: string): string {\n return createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction trimTrailingSlash(input: string): string {\n return input.replace(/\\/$/, \"\");\n}\n\nfunction sanitizeIdentifier(input: string): string {\n return input.replace(/[^A-Za-z0-9_]/g, \"_\").replace(/^[^A-Za-z_]+/, \"_\");\n}\n\nfunction toImportPath(fromFile: string, targetFile: string): string {\n const rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nfunction writeFileIfChanged(filePath: string, content: string) {\n try {\n if (readFileSync(filePath, \"utf8\") === content) return false;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, content);\n return true;\n}\n\nfunction getApiPluginManifestUrl(apiBaseUrl: string): string {\n return `${trimTrailingSlash(apiBaseUrl)}/plugin.manifest.json`;\n}\n\nasync function fetchApiPluginManifest(apiBaseUrl: string): Promise<ApiPluginManifest> {\n const response = await fetch(getApiPluginManifestUrl(apiBaseUrl));\n if (!response.ok) {\n throw new Error(\n `Failed to fetch API plugin manifest: ${response.status} ${response.statusText}`,\n );\n }\n\n const manifest = (await response.json()) as ApiPluginManifest;\n if (manifest.schemaVersion !== 1 || manifest.kind !== \"every-plugin/manifest\") {\n throw new Error(\"Unsupported API plugin manifest format\");\n }\n\n return manifest;\n}\n\nfunction localApiContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"api\", \"src\", \"contract.ts\");\n return {\n key: \"api\",\n importName: \"BaseApiContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nfunction localAuthContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"plugins\", \"auth\", \"src\", \"contract.ts\");\n return {\n key: \"auth\",\n importName: \"authContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nasync function remoteContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n name: string;\n baseUrl: string;\n generatedSubdir: string;\n}): Promise<ContractSource> {\n const manifest = await fetchApiPluginManifest(opts.baseUrl);\n if (!manifest.contract) {\n throw new Error(\n `Plugin manifest for ${manifest.plugin.name} does not advertise contract types`,\n );\n }\n\n const contractUrl = `${trimTrailingSlash(opts.baseUrl)}/${manifest.contract.types.path.replace(/^\\.\\//, \"\")}`;\n const contractResponse = await fetch(contractUrl);\n if (!contractResponse.ok) {\n throw new Error(\n `Failed to fetch contract types: ${contractResponse.status} ${contractResponse.statusText}`,\n );\n }\n\n const contractTypes = await contractResponse.text();\n if (manifest.contract.types.sha256 && manifest.contract.types.sha256 !== sha256(contractTypes)) {\n throw new Error(\"Fetched contract types failed checksum verification\");\n }\n\n const generatedPath = join(opts.runtimeDir, opts.generatedSubdir, \"contract.d.ts\");\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, contractTypes);\n\n return {\n key: opts.name,\n importName: `${sanitizeIdentifier(opts.name)}Contract`,\n sourceFilePath: generatedPath,\n generatedPath,\n };\n}\n\nasync function resolveContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n key: string;\n source: RuntimePluginConfig | { url: string; localPath?: string; name: string } | null;\n baseUrl: string;\n generatedSubdir: string;\n localSourceFactory?: (configDir: string) => ContractSource;\n}): Promise<ContractSource> {\n if (\n opts.key === \"api\" &&\n (!opts.source || !(\"localPath\" in opts.source) || opts.source.localPath)\n ) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath) {\n return {\n key: opts.key,\n importName: \"BaseApiContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return localApiContractSource(opts.configDir);\n }\n }\n\n if (\n opts.key === \"auth\" &&\n opts.localSourceFactory &&\n (!opts.source || !(\"localPath\" in opts.source) || opts.source.localPath)\n ) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath) {\n return {\n key: opts.key,\n importName: \"authContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return opts.localSourceFactory(opts.configDir);\n }\n }\n\n if (opts.source && \"localPath\" in opts.source && opts.source.localPath) {\n return {\n key: opts.key,\n importName: `${sanitizeIdentifier(opts.key)}Contract`,\n sourceFilePath: join(opts.source.localPath, \"src\", \"contract.ts\"),\n };\n }\n\n return remoteContractSource({\n configDir: opts.configDir,\n runtimeDir: opts.runtimeDir,\n name: opts.key,\n baseUrl: opts.baseUrl,\n generatedSubdir: opts.generatedSubdir,\n });\n}\n\nfunction writeGeneratedFiles(opts: {\n configDir: string;\n sources: ContractSource[];\n pluginKeys: string[];\n authSource: ContractSource | null;\n}) {\n const baseSource = opts.sources.find((source) => source.key === \"api\");\n const pluginSources = opts.pluginKeys\n .map((key) => opts.sources.find((entry) => entry.key === key))\n .filter((source): source is ContractSource => Boolean(source));\n\n if (!baseSource) {\n throw new Error(\"API contract source is required to generate the aggregate contract\");\n }\n\n // --- Generate ui/src/api-contract.gen.ts ---\n const uiContractPath = join(opts.configDir, \"ui\", \"src\", \"api-contract.gen.ts\");\n const uiLines: string[] = [];\n\n for (const source of opts.sources) {\n const importPath = toImportPath(uiContractPath, source.sourceFilePath);\n uiLines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n uiLines.push(\"\");\n\n const compositeParts: string[] = [];\n if (opts.authSource) {\n compositeParts.push(`auth: ${opts.authSource.importName}`);\n }\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);\n compositeParts.push(`${key}: ${source.importName}`);\n }\n\n if (compositeParts.length === 0) {\n uiLines.push(`export type ApiContract = ${baseSource.importName};`);\n } else {\n uiLines.push(`export type ApiContract = ${baseSource.importName} & {`);\n for (const part of compositeParts) {\n uiLines.push(` ${part};`);\n }\n uiLines.push(\"};\");\n }\n mkdirSync(dirname(uiContractPath), { recursive: true });\n writeFileIfChanged(uiContractPath, `${uiLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/plugins-client.gen.ts ---\n const pluginsClientPath = join(opts.configDir, \"api\", \"src\", \"plugins-client.gen.ts\");\n const pluginsClientLines: string[] = [];\n\n for (const source of pluginSources) {\n const importPath = toImportPath(pluginsClientPath, source.sourceFilePath);\n pluginsClientLines.push(\n `import type { ContractType as ${source.importName} } from \"${importPath}\";`,\n );\n }\n\n pluginsClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n pluginsClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n pluginsClientLines.push(\"\");\n\n if (pluginSources.length === 0) {\n pluginsClientLines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n pluginsClientLines.push(\"export type PluginsClient = {\");\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n pluginsClientLines.push(` ${key}: ClientFactory<${source.importName}>;`);\n }\n pluginsClientLines.push(\"};\");\n }\n\n mkdirSync(dirname(pluginsClientPath), { recursive: true });\n writeFileIfChanged(pluginsClientPath, `${pluginsClientLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/auth-client.gen.ts ---\n if (opts.authSource) {\n const authClientPath = join(opts.configDir, \"api\", \"src\", \"auth-client.gen.ts\");\n const authClientLines: string[] = [];\n\n const importPath = toImportPath(authClientPath, opts.authSource.sourceFilePath);\n authClientLines.push(\n `import type { ContractType as ${opts.authSource.importName} } from \"${importPath}\";`,\n );\n authClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n authClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n authClientLines.push(\"\");\n authClientLines.push(`export type AuthClient = ClientFactory<${opts.authSource.importName}>;`);\n\n mkdirSync(dirname(authClientPath), { recursive: true });\n writeFileIfChanged(authClientPath, `${authClientLines.join(\"\\n\")}\\n`);\n }\n\n return uiContractPath;\n}\n\nexport async function syncApiContractBridge(opts: {\n configDir: string;\n runtimeConfig: RuntimeConfig;\n apiBaseUrl: string;\n}): Promise<{\n bridgePath: string;\n generatedPath: string | null;\n manifest: ApiPluginManifest | null;\n source: \"local\" | \"remote\";\n}> {\n const runtimeDir = join(opts.configDir, \".bos\", \"generated\");\n const pluginEntries = Object.entries(opts.runtimeConfig.plugins ?? {}).sort(([a], [b]) =>\n a.localeCompare(b),\n );\n const sources: ContractSource[] = [];\n let manifest: ApiPluginManifest | null = null;\n let generatedPath: string | null = null;\n let authSource: ContractSource | null = null;\n\n const baseSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"api\",\n source: opts.runtimeConfig.api,\n baseUrl: opts.apiBaseUrl,\n generatedSubdir: \"api\",\n });\n sources.push(baseSource);\n\n if (opts.runtimeConfig.auth) {\n authSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"auth\",\n source: opts.runtimeConfig.auth,\n baseUrl: opts.runtimeConfig.auth.url,\n generatedSubdir: \"auth\",\n localSourceFactory: localAuthContractSource,\n });\n sources.push(authSource);\n if (authSource.generatedPath) {\n generatedPath = authSource.generatedPath;\n }\n }\n\n for (const [key, plugin] of pluginEntries) {\n const source = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key,\n source: plugin,\n baseUrl: plugin.url,\n generatedSubdir: `plugins/${key}`,\n });\n sources.push(source);\n if (source.generatedPath) {\n generatedPath = source.generatedPath;\n }\n }\n\n const allPluginKeys = pluginEntries.map(([key]) => key);\n\n writeGeneratedFiles({\n configDir: opts.configDir,\n sources,\n pluginKeys: allPluginKeys,\n authSource,\n });\n\n if (opts.runtimeConfig.api.source !== \"local\") {\n manifest = await fetchApiPluginManifest(opts.apiBaseUrl);\n }\n\n return {\n bridgePath: join(opts.configDir, \"ui\", \"src\", \"api-contract.gen.ts\"),\n generatedPath,\n manifest,\n source: opts.runtimeConfig.api.source,\n };\n}\n"],"mappings":";;;;;;AAiCA,SAAS,OAAO,OAAuB;AACrC,oCAAkB,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGzD,SAAS,kBAAkB,OAAuB;AAChD,QAAO,MAAM,QAAQ,OAAO,GAAG;;AAGjC,SAAS,mBAAmB,OAAuB;AACjD,QAAO,MAAM,QAAQ,kBAAkB,IAAI,CAAC,QAAQ,gBAAgB,IAAI;;AAG1E,SAAS,aAAa,UAAkB,YAA4B;CAClE,MAAM,qDAAuB,SAAS,EAAE,WAAW,CAAC,QAAQ,OAAO,IAAI;AACvE,QAAO,IAAI,WAAW,IAAI,GAAG,MAAM,KAAK;;AAG1C,SAAS,mBAAmB,UAAkB,SAAiB;AAC7D,KAAI;AACF,gCAAiB,UAAU,OAAO,KAAK,QAAS,QAAO;SACjD;AAIR,4BAAc,UAAU,QAAQ;AAChC,QAAO;;AAGT,SAAS,wBAAwB,YAA4B;AAC3D,QAAO,GAAG,kBAAkB,WAAW,CAAC;;AAG1C,eAAe,uBAAuB,YAAgD;CACpF,MAAM,WAAW,MAAM,MAAM,wBAAwB,WAAW,CAAC;AACjE,KAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MACR,wCAAwC,SAAS,OAAO,GAAG,SAAS,aACrE;CAGH,MAAM,WAAY,MAAM,SAAS,MAAM;AACvC,KAAI,SA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GACjB,oBAAoB;GACrB,CAAC;AACF,UAAQ,KAAK,WAAW;AACxB,MAAI,WAAW,cACb,iBAAgB,WAAW;;AAI/B,MAAK,MAAM,CAAC,KAAK,WAAW,eAAe;EACzC,MAAM,SAAS,MAAM,sBAAsB;GACzC,WAAW,KAAK;GAChB;GACA;GACA,QAAQ;GACR,SAAS,OAAO;GAChB,iBAAiB,WAAW;GAC7B,CAAC;AACF,UAAQ,KAAK,OAAO;AACpB,MAAI,OAAO,cACT,iBAAgB,OAAO;;CAI3B,MAAM,gBAAgB,cAAc,KAAK,CAAC,SAAS,IAAI;AAEvD,qBAAoB;EAClB,WAAW,KAAK;EAChB;EACA,YAAY;EACZ;EACD,CAAC;AAEF,KAAI,KAAK,cAAc,IAAI,WAAW,QACpC,YAAW,MAAM,uBAAuB,KAAK,WAAW;AAG1D,QAAO;EACL,gCAAiB,KAAK,WAAW,MAAM,OAAO,sBAAsB;EACpE;EACA;EACA,QAAQ,KAAK,cAAc,IAAI;EAChC"}
1
+ {"version":3,"file":"api-contract.cjs","names":[],"sources":["../src/api-contract.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport type { RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport interface ApiPluginManifest {\n schemaVersion: 1;\n kind: \"every-plugin/manifest\";\n plugin: {\n name: string;\n version: string;\n };\n runtime: {\n remoteEntry: string;\n };\n contract?: {\n kind: \"orpc\";\n types: {\n path: string;\n exportName: string;\n typeName: string;\n sha256?: string;\n };\n };\n}\n\ninterface ContractSource {\n key: string;\n importName: string;\n sourceFilePath: string;\n generatedPath?: string;\n}\n\nfunction sha256(input: string): string {\n return createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction trimTrailingSlash(input: string): string {\n return input.replace(/\\/$/, \"\");\n}\n\nfunction sanitizeIdentifier(input: string): string {\n return input.replace(/[^A-Za-z0-9_]/g, \"_\").replace(/^[^A-Za-z_]+/, \"_\");\n}\n\nfunction toImportPath(fromFile: string, targetFile: string): string {\n const rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nfunction writeFileIfChanged(filePath: string, content: string) {\n try {\n if (readFileSync(filePath, \"utf8\") === content) return false;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, content);\n return true;\n}\n\nfunction getApiPluginManifestUrl(apiBaseUrl: string): string {\n return `${trimTrailingSlash(apiBaseUrl)}/plugin.manifest.json`;\n}\n\nasync function fetchApiPluginManifest(apiBaseUrl: string): Promise<ApiPluginManifest> {\n const response = await fetch(getApiPluginManifestUrl(apiBaseUrl));\n if (!response.ok) {\n throw new Error(\n `Failed to fetch API plugin manifest: ${response.status} ${response.statusText}`,\n );\n }\n\n const manifest = (await response.json()) as ApiPluginManifest;\n if (manifest.schemaVersion !== 1 || manifest.kind !== \"every-plugin/manifest\") {\n throw new Error(\"Unsupported API plugin manifest format\");\n }\n\n return manifest;\n}\n\nfunction localApiContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"api\", \"src\", \"contract.ts\");\n return {\n key: \"api\",\n importName: \"BaseApiContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nfunction localAuthContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"plugins\", \"auth\", \"src\", \"contract.ts\");\n return {\n key: \"auth\",\n importName: \"authContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nasync function remoteContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n name: string;\n baseUrl: string;\n generatedSubdir: string;\n}): Promise<ContractSource> {\n const manifest = await fetchApiPluginManifest(opts.baseUrl);\n if (!manifest.contract) {\n throw new Error(\n `Plugin manifest for ${manifest.plugin.name} does not advertise contract types`,\n );\n }\n\n const contractUrl = `${trimTrailingSlash(opts.baseUrl)}/${manifest.contract.types.path.replace(/^\\.\\//, \"\")}`;\n const contractResponse = await fetch(contractUrl);\n if (!contractResponse.ok) {\n throw new Error(\n `Failed to fetch contract types: ${contractResponse.status} ${contractResponse.statusText}`,\n );\n }\n\n const contractTypes = await contractResponse.text();\n if (manifest.contract.types.sha256 && manifest.contract.types.sha256 !== sha256(contractTypes)) {\n throw new Error(\"Fetched contract types failed checksum verification\");\n }\n\n const generatedPath = join(opts.runtimeDir, opts.generatedSubdir, \"contract.d.ts\");\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, contractTypes);\n\n return {\n key: opts.name,\n importName: `${sanitizeIdentifier(opts.name)}Contract`,\n sourceFilePath: generatedPath,\n generatedPath,\n };\n}\n\nasync function resolveContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n key: string;\n source: RuntimePluginConfig | { url: string; localPath?: string; name: string } | null;\n baseUrl: string;\n generatedSubdir: string;\n localSourceFactory?: (configDir: string) => ContractSource;\n}): Promise<ContractSource> {\n if (opts.key === \"api\") {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"BaseApiContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return localApiContractSource(opts.configDir);\n }\n }\n\n if (opts.key === \"auth\" && opts.localSourceFactory) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"authContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return opts.localSourceFactory(opts.configDir);\n }\n }\n\n if (\n opts.source &&\n \"localPath\" in opts.source &&\n opts.source.localPath != null &&\n opts.source.localPath !== \"\"\n ) {\n return {\n key: opts.key,\n importName: `${sanitizeIdentifier(opts.key)}Contract`,\n sourceFilePath: join(opts.source.localPath, \"src\", \"contract.ts\"),\n };\n }\n\n return remoteContractSource({\n configDir: opts.configDir,\n runtimeDir: opts.runtimeDir,\n name: opts.key,\n baseUrl: opts.baseUrl,\n generatedSubdir: opts.generatedSubdir,\n });\n}\n\nfunction writeGeneratedFiles(opts: {\n configDir: string;\n sources: ContractSource[];\n pluginKeys: string[];\n authSource: ContractSource | null;\n}) {\n const baseSource = opts.sources.find((source) => source.key === \"api\");\n const pluginSources = opts.pluginKeys\n .map((key) => opts.sources.find((entry) => entry.key === key))\n .filter((source): source is ContractSource => Boolean(source));\n\n if (!baseSource) {\n throw new Error(\"API contract source is required to generate the aggregate contract\");\n }\n\n // --- Generate ui/src/api-contract.gen.ts ---\n const uiContractPath = join(opts.configDir, \"ui\", \"src\", \"api-contract.gen.ts\");\n const uiLines: string[] = [];\n\n for (const source of opts.sources) {\n const importPath = toImportPath(uiContractPath, source.sourceFilePath);\n uiLines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n uiLines.push(\"\");\n\n const compositeParts: string[] = [];\n if (opts.authSource) {\n compositeParts.push(`auth: ${opts.authSource.importName}`);\n }\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);\n compositeParts.push(`${key}: ${source.importName}`);\n }\n\n if (compositeParts.length === 0) {\n uiLines.push(`export type ApiContract = ${baseSource.importName};`);\n } else {\n uiLines.push(`export type ApiContract = ${baseSource.importName} & {`);\n for (const part of compositeParts) {\n uiLines.push(` ${part};`);\n }\n uiLines.push(\"};\");\n }\n mkdirSync(dirname(uiContractPath), { recursive: true });\n writeFileIfChanged(uiContractPath, `${uiLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/plugins-client.gen.ts ---\n const pluginsClientPath = join(opts.configDir, \"api\", \"src\", \"plugins-client.gen.ts\");\n const pluginsClientLines: string[] = [];\n\n for (const source of pluginSources) {\n const importPath = toImportPath(pluginsClientPath, source.sourceFilePath);\n pluginsClientLines.push(\n `import type { ContractType as ${source.importName} } from \"${importPath}\";`,\n );\n }\n\n pluginsClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n pluginsClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n pluginsClientLines.push(\"\");\n\n if (pluginSources.length === 0) {\n pluginsClientLines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n pluginsClientLines.push(\"export type PluginsClient = {\");\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n pluginsClientLines.push(` ${key}: ClientFactory<${source.importName}>;`);\n }\n pluginsClientLines.push(\"};\");\n }\n\n mkdirSync(dirname(pluginsClientPath), { recursive: true });\n writeFileIfChanged(pluginsClientPath, `${pluginsClientLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/auth-client.gen.ts ---\n if (opts.authSource) {\n const authClientPath = join(opts.configDir, \"api\", \"src\", \"auth-client.gen.ts\");\n const authClientLines: string[] = [];\n\n const importPath = toImportPath(authClientPath, opts.authSource.sourceFilePath);\n authClientLines.push(\n `import type { ContractType as ${opts.authSource.importName} } from \"${importPath}\";`,\n );\n authClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n authClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n authClientLines.push(\"\");\n authClientLines.push(`export type AuthClient = ClientFactory<${opts.authSource.importName}>;`);\n\n mkdirSync(dirname(authClientPath), { recursive: true });\n writeFileIfChanged(authClientPath, `${authClientLines.join(\"\\n\")}\\n`);\n }\n\n return uiContractPath;\n}\n\nexport async function syncApiContractBridge(opts: {\n configDir: string;\n runtimeConfig: RuntimeConfig;\n apiBaseUrl: string;\n}): Promise<{\n bridgePath: string;\n generatedPath: string | null;\n manifest: ApiPluginManifest | null;\n source: \"local\" | \"remote\";\n}> {\n const runtimeDir = join(opts.configDir, \".bos\", \"generated\");\n const pluginEntries = Object.entries(opts.runtimeConfig.plugins ?? {}).sort(([a], [b]) =>\n a.localeCompare(b),\n );\n const sources: ContractSource[] = [];\n let manifest: ApiPluginManifest | null = null;\n let generatedPath: string | null = null;\n let authSource: ContractSource | null = null;\n\n const baseSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"api\",\n source: opts.runtimeConfig.api,\n baseUrl: opts.apiBaseUrl,\n generatedSubdir: \"api\",\n });\n sources.push(baseSource);\n\n if (opts.runtimeConfig.auth) {\n authSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"auth\",\n source: opts.runtimeConfig.auth,\n baseUrl: opts.runtimeConfig.auth.url,\n generatedSubdir: \"auth\",\n localSourceFactory: localAuthContractSource,\n });\n sources.push(authSource);\n if (authSource.generatedPath) {\n generatedPath = authSource.generatedPath;\n }\n }\n\n for (const [key, plugin] of pluginEntries) {\n const source = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key,\n source: plugin,\n baseUrl: plugin.url,\n generatedSubdir: `plugins/${key}`,\n });\n sources.push(source);\n if (source.generatedPath) {\n generatedPath = source.generatedPath;\n }\n }\n\n const allPluginKeys = pluginEntries.map(([key]) => key);\n\n writeGeneratedFiles({\n configDir: opts.configDir,\n sources,\n pluginKeys: allPluginKeys,\n authSource,\n });\n\n if (opts.runtimeConfig.api.source !== \"local\") {\n manifest = await fetchApiPluginManifest(opts.apiBaseUrl);\n }\n\n return {\n bridgePath: join(opts.configDir, \"ui\", \"src\", \"api-contract.gen.ts\"),\n generatedPath,\n manifest,\n source: opts.runtimeConfig.api.source,\n };\n}\n"],"mappings":";;;;;;AAiCA,SAAS,OAAO,OAAuB;AACrC,oCAAkB,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGzD,SAAS,kBAAkB,OAAuB;AAChD,QAAO,MAAM,QAAQ,OAAO,GAAG;;AAGjC,SAAS,mBAAmB,OAAuB;AACjD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ContractSource(opts) {
66
66
  };
67
67
  }
68
68
  async function resolveContractSource(opts) {
69
- if (opts.key === "api" && (!opts.source || !("localPath" in opts.source) || opts.source.localPath)) {
69
+ if (opts.key === "api") {
70
70
  const localPath = opts.source && "localPath" in opts.source ? opts.source.localPath : void 0;
71
- if (localPath) return {
71
+ if (localPath != null && localPath !== "") return {
72
72
  key: opts.key,
73
73
  importName: "BaseApiContract",
74
74
  sourceFilePath: join(localPath, "src", "contract.ts")
75
75
  };
76
76
  if (!opts.baseUrl) return localApiContractSource(opts.configDir);
77
77
  }
78
- if (opts.key === "auth" && opts.localSourceFactory && (!opts.source || !("localPath" in opts.source) || opts.source.localPath)) {
78
+ if (opts.key === "auth" && opts.localSourceFactory) {
79
79
  const localPath = opts.source && "localPath" in opts.source ? opts.source.localPath : void 0;
80
- if (localPath) return {
80
+ if (localPath != null && localPath !== "") return {
81
81
  key: opts.key,
82
82
  importName: "authContract",
83
83
  sourceFilePath: join(localPath, "src", "contract.ts")
84
84
  };
85
85
  if (!opts.baseUrl) return opts.localSourceFactory(opts.configDir);
86
86
  }
87
- if (opts.source && "localPath" in opts.source && opts.source.localPath) return {
87
+ if (opts.source && "localPath" in opts.source && opts.source.localPath != null && opts.source.localPath !== "") return {
88
88
  key: opts.key,
89
89
  importName: `${sanitizeIdentifier(opts.key)}Contract`,
90
90
  sourceFilePath: join(opts.source.localPath, "src", "contract.ts")
@@ -1 +1 @@
1
- {"version":3,"file":"api-contract.mjs","names":[],"sources":["../src/api-contract.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport type { RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport interface ApiPluginManifest {\n schemaVersion: 1;\n kind: \"every-plugin/manifest\";\n plugin: {\n name: string;\n version: string;\n };\n runtime: {\n remoteEntry: string;\n };\n contract?: {\n kind: \"orpc\";\n types: {\n path: string;\n exportName: string;\n typeName: string;\n sha256?: string;\n };\n };\n}\n\ninterface ContractSource {\n key: string;\n importName: string;\n sourceFilePath: string;\n generatedPath?: string;\n}\n\nfunction sha256(input: string): string {\n return createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction trimTrailingSlash(input: string): string {\n return input.replace(/\\/$/, \"\");\n}\n\nfunction sanitizeIdentifier(input: string): string {\n return input.replace(/[^A-Za-z0-9_]/g, \"_\").replace(/^[^A-Za-z_]+/, \"_\");\n}\n\nfunction toImportPath(fromFile: string, targetFile: string): string {\n const rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nfunction writeFileIfChanged(filePath: string, content: string) {\n try {\n if (readFileSync(filePath, \"utf8\") === content) return false;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, content);\n return true;\n}\n\nfunction getApiPluginManifestUrl(apiBaseUrl: string): string {\n return `${trimTrailingSlash(apiBaseUrl)}/plugin.manifest.json`;\n}\n\nasync function fetchApiPluginManifest(apiBaseUrl: string): Promise<ApiPluginManifest> {\n const response = await fetch(getApiPluginManifestUrl(apiBaseUrl));\n if (!response.ok) {\n throw new Error(\n `Failed to fetch API plugin manifest: ${response.status} ${response.statusText}`,\n );\n }\n\n const manifest = (await response.json()) as ApiPluginManifest;\n if (manifest.schemaVersion !== 1 || manifest.kind !== \"every-plugin/manifest\") {\n throw new Error(\"Unsupported API plugin manifest format\");\n }\n\n return manifest;\n}\n\nfunction localApiContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"api\", \"src\", \"contract.ts\");\n return {\n key: \"api\",\n importName: \"BaseApiContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nfunction localAuthContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"plugins\", \"auth\", \"src\", \"contract.ts\");\n return {\n key: \"auth\",\n importName: \"authContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nasync function remoteContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n name: string;\n baseUrl: string;\n generatedSubdir: string;\n}): Promise<ContractSource> {\n const manifest = await fetchApiPluginManifest(opts.baseUrl);\n if (!manifest.contract) {\n throw new Error(\n `Plugin manifest for ${manifest.plugin.name} does not advertise contract types`,\n );\n }\n\n const contractUrl = `${trimTrailingSlash(opts.baseUrl)}/${manifest.contract.types.path.replace(/^\\.\\//, \"\")}`;\n const contractResponse = await fetch(contractUrl);\n if (!contractResponse.ok) {\n throw new Error(\n `Failed to fetch contract types: ${contractResponse.status} ${contractResponse.statusText}`,\n );\n }\n\n const contractTypes = await contractResponse.text();\n if (manifest.contract.types.sha256 && manifest.contract.types.sha256 !== sha256(contractTypes)) {\n throw new Error(\"Fetched contract types failed checksum verification\");\n }\n\n const generatedPath = join(opts.runtimeDir, opts.generatedSubdir, \"contract.d.ts\");\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, contractTypes);\n\n return {\n key: opts.name,\n importName: `${sanitizeIdentifier(opts.name)}Contract`,\n sourceFilePath: generatedPath,\n generatedPath,\n };\n}\n\nasync function resolveContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n key: string;\n source: RuntimePluginConfig | { url: string; localPath?: string; name: string } | null;\n baseUrl: string;\n generatedSubdir: string;\n localSourceFactory?: (configDir: string) => ContractSource;\n}): Promise<ContractSource> {\n if (\n opts.key === \"api\" &&\n (!opts.source || !(\"localPath\" in opts.source) || opts.source.localPath)\n ) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath) {\n return {\n key: opts.key,\n importName: \"BaseApiContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return localApiContractSource(opts.configDir);\n }\n }\n\n if (\n opts.key === \"auth\" &&\n opts.localSourceFactory &&\n (!opts.source || !(\"localPath\" in opts.source) || opts.source.localPath)\n ) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath) {\n return {\n key: opts.key,\n importName: \"authContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return opts.localSourceFactory(opts.configDir);\n }\n }\n\n if (opts.source && \"localPath\" in opts.source && opts.source.localPath) {\n return {\n key: opts.key,\n importName: `${sanitizeIdentifier(opts.key)}Contract`,\n sourceFilePath: join(opts.source.localPath, \"src\", \"contract.ts\"),\n };\n }\n\n return remoteContractSource({\n configDir: opts.configDir,\n runtimeDir: opts.runtimeDir,\n name: opts.key,\n baseUrl: opts.baseUrl,\n generatedSubdir: opts.generatedSubdir,\n });\n}\n\nfunction writeGeneratedFiles(opts: {\n configDir: string;\n sources: ContractSource[];\n pluginKeys: string[];\n authSource: ContractSource | null;\n}) {\n const baseSource = opts.sources.find((source) => source.key === \"api\");\n const pluginSources = opts.pluginKeys\n .map((key) => opts.sources.find((entry) => entry.key === key))\n .filter((source): source is ContractSource => Boolean(source));\n\n if (!baseSource) {\n throw new Error(\"API contract source is required to generate the aggregate contract\");\n }\n\n // --- Generate ui/src/api-contract.gen.ts ---\n const uiContractPath = join(opts.configDir, \"ui\", \"src\", \"api-contract.gen.ts\");\n const uiLines: string[] = [];\n\n for (const source of opts.sources) {\n const importPath = toImportPath(uiContractPath, source.sourceFilePath);\n uiLines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n uiLines.push(\"\");\n\n const compositeParts: string[] = [];\n if (opts.authSource) {\n compositeParts.push(`auth: ${opts.authSource.importName}`);\n }\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);\n compositeParts.push(`${key}: ${source.importName}`);\n }\n\n if (compositeParts.length === 0) {\n uiLines.push(`export type ApiContract = ${baseSource.importName};`);\n } else {\n uiLines.push(`export type ApiContract = ${baseSource.importName} & {`);\n for (const part of compositeParts) {\n uiLines.push(` ${part};`);\n }\n uiLines.push(\"};\");\n }\n mkdirSync(dirname(uiContractPath), { recursive: true });\n writeFileIfChanged(uiContractPath, `${uiLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/plugins-client.gen.ts ---\n const pluginsClientPath = join(opts.configDir, \"api\", \"src\", \"plugins-client.gen.ts\");\n const pluginsClientLines: string[] = [];\n\n for (const source of pluginSources) {\n const importPath = toImportPath(pluginsClientPath, source.sourceFilePath);\n pluginsClientLines.push(\n `import type { ContractType as ${source.importName} } from \"${importPath}\";`,\n );\n }\n\n pluginsClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n pluginsClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n pluginsClientLines.push(\"\");\n\n if (pluginSources.length === 0) {\n pluginsClientLines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n pluginsClientLines.push(\"export type PluginsClient = {\");\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n pluginsClientLines.push(` ${key}: ClientFactory<${source.importName}>;`);\n }\n pluginsClientLines.push(\"};\");\n }\n\n mkdirSync(dirname(pluginsClientPath), { recursive: true });\n writeFileIfChanged(pluginsClientPath, `${pluginsClientLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/auth-client.gen.ts ---\n if (opts.authSource) {\n const authClientPath = join(opts.configDir, \"api\", \"src\", \"auth-client.gen.ts\");\n const authClientLines: string[] = [];\n\n const importPath = toImportPath(authClientPath, opts.authSource.sourceFilePath);\n authClientLines.push(\n `import type { ContractType as ${opts.authSource.importName} } from \"${importPath}\";`,\n );\n authClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n authClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n authClientLines.push(\"\");\n authClientLines.push(`export type AuthClient = ClientFactory<${opts.authSource.importName}>;`);\n\n mkdirSync(dirname(authClientPath), { recursive: true });\n writeFileIfChanged(authClientPath, `${authClientLines.join(\"\\n\")}\\n`);\n }\n\n return uiContractPath;\n}\n\nexport async function syncApiContractBridge(opts: {\n configDir: string;\n runtimeConfig: RuntimeConfig;\n apiBaseUrl: string;\n}): Promise<{\n bridgePath: string;\n generatedPath: string | null;\n manifest: ApiPluginManifest | null;\n source: \"local\" | \"remote\";\n}> {\n const runtimeDir = join(opts.configDir, \".bos\", \"generated\");\n const pluginEntries = Object.entries(opts.runtimeConfig.plugins ?? {}).sort(([a], [b]) =>\n a.localeCompare(b),\n );\n const sources: ContractSource[] = [];\n let manifest: ApiPluginManifest | null = null;\n let generatedPath: string | null = null;\n let authSource: ContractSource | null = null;\n\n const baseSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"api\",\n source: opts.runtimeConfig.api,\n baseUrl: opts.apiBaseUrl,\n generatedSubdir: \"api\",\n });\n sources.push(baseSource);\n\n if (opts.runtimeConfig.auth) {\n authSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"auth\",\n source: opts.runtimeConfig.auth,\n baseUrl: opts.runtimeConfig.auth.url,\n generatedSubdir: \"auth\",\n localSourceFactory: localAuthContractSource,\n });\n sources.push(authSource);\n if (authSource.generatedPath) {\n generatedPath = authSource.generatedPath;\n }\n }\n\n for (const [key, plugin] of pluginEntries) {\n const source = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key,\n source: plugin,\n baseUrl: plugin.url,\n generatedSubdir: `plugins/${key}`,\n });\n sources.push(source);\n if (source.generatedPath) {\n generatedPath = source.generatedPath;\n }\n }\n\n const allPluginKeys = pluginEntries.map(([key]) => key);\n\n writeGeneratedFiles({\n configDir: opts.configDir,\n sources,\n pluginKeys: allPluginKeys,\n authSource,\n });\n\n if (opts.runtimeConfig.api.source !== \"local\") {\n manifest = await fetchApiPluginManifest(opts.apiBaseUrl);\n }\n\n return {\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GACR,SAAS,OAAO;GAChB,iBAAiB,WAAW;GAC7B,CAAC;AACF,UAAQ,KAAK,OAAO;AACpB,MAAI,OAAO,cACT,iBAAgB,OAAO;;CAI3B,MAAM,gBAAgB,cAAc,KAAK,CAAC,SAAS,IAAI;AAEvD,qBAAoB;EAClB,WAAW,KAAK;EAChB;EACA,YAAY;EACZ;EACD,CAAC;AAEF,KAAI,KAAK,cAAc,IAAI,WAAW,QACpC,YAAW,MAAM,uBAAuB,KAAK,WAAW;AAG1D,QAAO;EACL,YAAY,KAAK,KAAK,WAAW,MAAM,OAAO,sBAAsB;EACpE;EACA;EACA,QAAQ,KAAK,cAAc,IAAI;EAChC"}
1
+ {"version":3,"file":"api-contract.mjs","names":[],"sources":["../src/api-contract.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport type { RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport interface ApiPluginManifest {\n schemaVersion: 1;\n kind: \"every-plugin/manifest\";\n plugin: {\n name: string;\n version: string;\n };\n runtime: {\n remoteEntry: string;\n };\n contract?: {\n kind: \"orpc\";\n types: {\n path: string;\n exportName: string;\n typeName: string;\n sha256?: string;\n };\n };\n}\n\ninterface ContractSource {\n key: string;\n importName: string;\n sourceFilePath: string;\n generatedPath?: string;\n}\n\nfunction sha256(input: string): string {\n return createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction trimTrailingSlash(input: string): string {\n return input.replace(/\\/$/, \"\");\n}\n\nfunction sanitizeIdentifier(input: string): string {\n return input.replace(/[^A-Za-z0-9_]/g, \"_\").replace(/^[^A-Za-z_]+/, \"_\");\n}\n\nfunction toImportPath(fromFile: string, targetFile: string): string {\n const rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nfunction writeFileIfChanged(filePath: string, content: string) {\n try {\n if (readFileSync(filePath, \"utf8\") === content) return false;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, content);\n return true;\n}\n\nfunction getApiPluginManifestUrl(apiBaseUrl: string): string {\n return `${trimTrailingSlash(apiBaseUrl)}/plugin.manifest.json`;\n}\n\nasync function fetchApiPluginManifest(apiBaseUrl: string): Promise<ApiPluginManifest> {\n const response = await fetch(getApiPluginManifestUrl(apiBaseUrl));\n if (!response.ok) {\n throw new Error(\n `Failed to fetch API plugin manifest: ${response.status} ${response.statusText}`,\n );\n }\n\n const manifest = (await response.json()) as ApiPluginManifest;\n if (manifest.schemaVersion !== 1 || manifest.kind !== \"every-plugin/manifest\") {\n throw new Error(\"Unsupported API plugin manifest format\");\n }\n\n return manifest;\n}\n\nfunction localApiContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"api\", \"src\", \"contract.ts\");\n return {\n key: \"api\",\n importName: \"BaseApiContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nfunction localAuthContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"plugins\", \"auth\", \"src\", \"contract.ts\");\n return {\n key: \"auth\",\n importName: \"authContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nasync function remoteContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n name: string;\n baseUrl: string;\n generatedSubdir: string;\n}): Promise<ContractSource> {\n const manifest = await fetchApiPluginManifest(opts.baseUrl);\n if (!manifest.contract) {\n throw new Error(\n `Plugin manifest for ${manifest.plugin.name} does not advertise contract types`,\n );\n }\n\n const contractUrl = `${trimTrailingSlash(opts.baseUrl)}/${manifest.contract.types.path.replace(/^\\.\\//, \"\")}`;\n const contractResponse = await fetch(contractUrl);\n if (!contractResponse.ok) {\n throw new Error(\n `Failed to fetch contract types: ${contractResponse.status} ${contractResponse.statusText}`,\n );\n }\n\n const contractTypes = await contractResponse.text();\n if (manifest.contract.types.sha256 && manifest.contract.types.sha256 !== sha256(contractTypes)) {\n throw new Error(\"Fetched contract types failed checksum verification\");\n }\n\n const generatedPath = join(opts.runtimeDir, opts.generatedSubdir, \"contract.d.ts\");\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, contractTypes);\n\n return {\n key: opts.name,\n importName: `${sanitizeIdentifier(opts.name)}Contract`,\n sourceFilePath: generatedPath,\n generatedPath,\n };\n}\n\nasync function resolveContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n key: string;\n source: RuntimePluginConfig | { url: string; localPath?: string; name: string } | null;\n baseUrl: string;\n generatedSubdir: string;\n localSourceFactory?: (configDir: string) => ContractSource;\n}): Promise<ContractSource> {\n if (opts.key === \"api\") {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"BaseApiContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return localApiContractSource(opts.configDir);\n }\n }\n\n if (opts.key === \"auth\" && opts.localSourceFactory) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"authContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return opts.localSourceFactory(opts.configDir);\n }\n }\n\n if (\n opts.source &&\n \"localPath\" in opts.source &&\n opts.source.localPath != null &&\n opts.source.localPath !== \"\"\n ) {\n return {\n key: opts.key,\n importName: `${sanitizeIdentifier(opts.key)}Contract`,\n sourceFilePath: join(opts.source.localPath, \"src\", \"contract.ts\"),\n };\n }\n\n return remoteContractSource({\n configDir: opts.configDir,\n runtimeDir: opts.runtimeDir,\n name: opts.key,\n baseUrl: opts.baseUrl,\n generatedSubdir: opts.generatedSubdir,\n });\n}\n\nfunction writeGeneratedFiles(opts: {\n configDir: string;\n sources: ContractSource[];\n pluginKeys: string[];\n authSource: ContractSource | null;\n}) {\n const baseSource = opts.sources.find((source) => source.key === \"api\");\n const pluginSources = opts.pluginKeys\n .map((key) => opts.sources.find((entry) => entry.key === key))\n .filter((source): source is ContractSource => Boolean(source));\n\n if (!baseSource) {\n throw new Error(\"API contract source is required to generate the aggregate contract\");\n }\n\n // --- Generate ui/src/api-contract.gen.ts ---\n const uiContractPath = join(opts.configDir, \"ui\", \"src\", \"api-contract.gen.ts\");\n const uiLines: string[] = [];\n\n for (const source of opts.sources) {\n const importPath = toImportPath(uiContractPath, source.sourceFilePath);\n uiLines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n uiLines.push(\"\");\n\n const compositeParts: string[] = [];\n if (opts.authSource) {\n compositeParts.push(`auth: ${opts.authSource.importName}`);\n }\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);\n compositeParts.push(`${key}: ${source.importName}`);\n }\n\n if (compositeParts.length === 0) {\n uiLines.push(`export type ApiContract = ${baseSource.importName};`);\n } else {\n uiLines.push(`export type ApiContract = ${baseSource.importName} & {`);\n for (const part of compositeParts) {\n uiLines.push(` ${part};`);\n }\n uiLines.push(\"};\");\n }\n mkdirSync(dirname(uiContractPath), { recursive: true });\n writeFileIfChanged(uiContractPath, `${uiLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/plugins-client.gen.ts ---\n const pluginsClientPath = join(opts.configDir, \"api\", \"src\", \"plugins-client.gen.ts\");\n const pluginsClientLines: string[] = [];\n\n for (const source of pluginSources) {\n const importPath = toImportPath(pluginsClientPath, source.sourceFilePath);\n pluginsClientLines.push(\n `import type { ContractType as ${source.importName} } from \"${importPath}\";`,\n );\n }\n\n pluginsClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n pluginsClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n pluginsClientLines.push(\"\");\n\n if (pluginSources.length === 0) {\n pluginsClientLines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n pluginsClientLines.push(\"export type PluginsClient = {\");\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n pluginsClientLines.push(` ${key}: ClientFactory<${source.importName}>;`);\n }\n pluginsClientLines.push(\"};\");\n }\n\n mkdirSync(dirname(pluginsClientPath), { recursive: true });\n writeFileIfChanged(pluginsClientPath, `${pluginsClientLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/auth-client.gen.ts ---\n if (opts.authSource) {\n const authClientPath = join(opts.configDir, \"api\", \"src\", \"auth-client.gen.ts\");\n const authClientLines: string[] = [];\n\n const importPath = toImportPath(authClientPath, opts.authSource.sourceFilePath);\n authClientLines.push(\n `import type { ContractType as ${opts.authSource.importName} } from \"${importPath}\";`,\n );\n authClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n authClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n authClientLines.push(\"\");\n authClientLines.push(`export type AuthClient = ClientFactory<${opts.authSource.importName}>;`);\n\n mkdirSync(dirname(authClientPath), { recursive: true });\n writeFileIfChanged(authClientPath, `${authClientLines.join(\"\\n\")}\\n`);\n }\n\n return uiContractPath;\n}\n\nexport async function syncApiContractBridge(opts: {\n configDir: string;\n runtimeConfig: RuntimeConfig;\n apiBaseUrl: string;\n}): Promise<{\n bridgePath: string;\n generatedPath: string | null;\n manifest: ApiPluginManifest | null;\n source: \"local\" | \"remote\";\n}> {\n const runtimeDir = join(opts.configDir, \".bos\", \"generated\");\n const pluginEntries = Object.entries(opts.runtimeConfig.plugins ?? {}).sort(([a], [b]) =>\n a.localeCompare(b),\n );\n const sources: ContractSource[] = [];\n let manifest: ApiPluginManifest | null = null;\n let generatedPath: string | null = null;\n let authSource: ContractSource | null = null;\n\n const baseSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"api\",\n source: opts.runtimeConfig.api,\n baseUrl: opts.apiBaseUrl,\n generatedSubdir: \"api\",\n });\n sources.push(baseSource);\n\n if (opts.runtimeConfig.auth) {\n authSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"auth\",\n source: opts.runtimeConfig.auth,\n baseUrl: opts.runtimeConfig.auth.url,\n generatedSubdir: \"auth\",\n localSourceFactory: localAuthContractSource,\n });\n sources.push(authSource);\n if (authSource.generatedPath) {\n generatedPath = authSource.generatedPath;\n }\n }\n\n for (const [key, plugin] of pluginEntries) {\n const source = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key,\n source: plugin,\n baseUrl: plugin.url,\n generatedSubdir: `plugins/${key}`,\n });\n sources.push(source);\n if (source.generatedPath) {\n generatedPath = source.generatedPath;\n }\n }\n\n const allPluginKeys = pluginEntries.map(([key]) => key);\n\n writeGeneratedFiles({\n configDir: opts.configDir,\n sources,\n pluginKeys: allPluginKeys,\n authSource,\n });\n\n if (opts.runtimeConfig.api.source !== \"local\") {\n manifest = await fetchApiPluginManifest(opts.apiBaseUrl);\n }\n\n return {\n bridgePath: join(opts.configDir, \"ui\", \"src\", \"api-contract.gen.ts\"),\n generatedPath,\n manifest,\n source: opts.runtimeConfig.api.source,\n };\n}\n"],"mappings":";;;;;AAiCA,SAAS,OAAO,OAAuB;AACrC,QAAO,WAAW,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGzD,SAAS,kBAAkB,OAAuB;AAChD,QAAO,MAAM,QAAQ,OAAO,GAAG;;AAGjC,SAAS,mBAAmB,OAAuB;AACjD,QAAO,MAAM,QAAQ,kBAAkB,IAAI,CAAC,QAAQ,gBAAgB,IAAI;;AAG1E,SAAS,aAAa,UAAkB,YAA4B;CAClE,MAAM,MAAM,SAAS,QAAQ,SAAS,EAAE,WAAW,CAAC,QAAQ,OAAO,IAAI;AACvE,QAAO,IAAI,WAAW,IAA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AE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OACjF,EAAE,cAAc,EAAE,CACnB;CACD,MAAM,UAA4B,EAAE;CACpC,IAAI,WAAqC;CACzC,IAAI,gBAA+B;CACnC,IAAI,aAAoC;CAExC,MAAM,aAAa,MAAM,sBAAsB;EAC7C,WAAW,KAAK;EAChB;EACA,KAAK;EACL,QAAQ,KAAK,cAAc;EAC3B,SAAS,KAAK;EACd,iBAAiB;EAClB,CAAC;AACF,SAAQ,KAAK,WAAW;AAExB,KAAI,KAAK,cAAc,MAAM;AAC3B,eAAa,MAAM,sBAAsB;GACvC,WAAW,KAAK;GAChB;GACA,KAAK;GACL,QAAQ,KAAK,cAAc;GAC3B,SAAS,KAAK,cAAc,KAAK;GACjC,iBAAiB;GACjB,oBAAoB;GACrB,CAAC;AACF,UAAQ,KAAK,WAAW;AACxB,MAAI,WAAW,cACb,iBAAgB,WAAW;;AAI/B,MAAK,MAAM,CAAC,KAAK,WAAW,eAAe;EACzC,MAAM,SAAS,MAAM,sBAAsB;GACzC,WAAW,KAAK;GAChB;GACA;GACA,QAAQ;GACR,SAAS,OAAO;GAChB,iBAAiB,WAAW;GAC7B,CAAC;AACF,UAAQ,KAAK,OAAO;AACpB,MAAI,OAAO,cACT,iBAAgB,OAAO;;CAI3B,MAAM,gBAAgB,cAAc,KAAK,CAAC,SAAS,IAAI;AAEvD,qBAAoB;EAClB,WAAW,KAAK;EAChB;EACA,YAAY;EACZ;EACD,CAAC;AAEF,KAAI,KAAK,cAAc,IAAI,WAAW,QACpC,YAAW,MAAM,uBAAuB,KAAK,WAAW;AAG1D,QAAO;EACL,YAAY,KAAK,KAAK,WAAW,MAAM,OAAO,sBAAsB;EACpE;EACA;EACA,QAAQ,KAAK,cAAc,IAAI;EAChC"}
@@ -1,25 +1,10 @@
1
1
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
- let node_readline = require("node:readline");
2
+ let _clack_prompts = require("@clack/prompts");
3
+ _clack_prompts = require_runtime.__toESM(_clack_prompts, 1);
4
+ let node_process = require("node:process");
5
+ node_process = require_runtime.__toESM(node_process, 1);
3
6
 
4
7
  //#region src/cli/prompts.ts
5
- async function prompt(question, defaultValue) {
6
- const rl = (0, node_readline.createInterface)({
7
- input: process.stdin,
8
- output: process.stdout
9
- });
10
- const fullQuestion = `${question}${defaultValue ? ` [${defaultValue}]` : ""}: `;
11
- return new Promise((resolve) => {
12
- rl.question(fullQuestion, (answer) => {
13
- rl.close();
14
- resolve(answer.trim() || defaultValue || "");
15
- });
16
- });
17
- }
18
- async function promptYesNo(question, defaultVal = false) {
19
- const answer = await prompt(`${question} (${defaultVal ? "Y/n" : "y/N"})`);
20
- if (!answer) return defaultVal;
21
- return answer.toLowerCase() === "y" || answer.toLowerCase() === "yes";
22
- }
23
8
  function parseExtendsRef(ref) {
24
9
  const match = ref.match(/^(?:bos:\/\/)?([^/]+)\/(.+)$/);
25
10
  if (!match) return null;
@@ -34,50 +19,24 @@ function deriveAccountFromDomain(domain, extendsAccount) {
34
19
  return `${firstSegment}.${extendsAccount.includes(".") ? extendsAccount.substring(extendsAccount.indexOf(".") + 1) : extendsAccount}`;
35
20
  }
36
21
  const AVAILABLE_PLUGINS = [{
37
- key: "_template",
38
- label: "template",
39
- description: "Plugin scaffold and boilerplate",
40
- default: true
22
+ value: "_template",
23
+ label: "template"
41
24
  }, {
42
- key: "registry",
43
- label: "registry",
44
- description: "FastKV app discovery and metadata",
45
- default: false
25
+ value: "registry",
26
+ label: "registry"
46
27
  }];
47
- async function promptPluginSelect() {
48
- const selected = new Set(AVAILABLE_PLUGINS.filter((p) => p.default).map((p) => p.key));
49
- console.log();
50
- console.log(" Select plugins (enter number to toggle, enter to confirm):");
51
- for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {
52
- const p = AVAILABLE_PLUGINS[i];
53
- const marker = selected.has(p.key) ? "●" : "○";
54
- console.log(` ${marker} ${i + 1}. ${p.label} — ${p.description}`);
55
- }
56
- console.log();
57
- while (true) {
58
- const answer = await prompt(" Plugins", selected.size > 0 ? Array.from(selected).join(",") : "");
59
- if (!answer) break;
60
- const num = Number.parseInt(answer, 10);
61
- if (num >= 1 && num <= AVAILABLE_PLUGINS.length) {
62
- const plugin = AVAILABLE_PLUGINS[num - 1];
63
- if (selected.has(plugin.key)) selected.delete(plugin.key);
64
- else selected.add(plugin.key);
65
- console.log(" Current selection:");
66
- for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {
67
- const p = AVAILABLE_PLUGINS[i];
68
- const marker = selected.has(p.key) ? "●" : "○";
69
- console.log(` ${marker} ${i + 1}. ${p.label}`);
70
- }
71
- console.log();
72
- continue;
73
- }
74
- break;
75
- }
76
- return Array.from(selected);
77
- }
78
28
  async function promptInitOptions(input) {
79
- const domain = input.domain || await prompt("Project domain");
80
- const extendsInput = input.extends || await prompt("Extend from", "");
29
+ _clack_prompts.intro("Let's build an app...");
30
+ const domain = input.domain ?? await _clack_prompts.text({
31
+ message: "Starting with a domain?",
32
+ placeholder: "no"
33
+ });
34
+ if (_clack_prompts.isCancel(domain)) node_process.default.exit(0);
35
+ const extendsInput = input.extends ?? await _clack_prompts.text({
36
+ message: "Extending an existing app?",
37
+ placeholder: "bos://dev.everything.near/everything.dev"
38
+ });
39
+ if (_clack_prompts.isCancel(extendsInput)) node_process.default.exit(0);
81
40
  let extendsAccount = input.extendsAccount || "";
82
41
  let extendsGateway = input.extendsGateway || "";
83
42
  if (extendsInput) {
@@ -90,10 +49,26 @@ async function promptInitOptions(input) {
90
49
  extendsAccount = extendsAccount || "dev.everything.near";
91
50
  extendsGateway = extendsGateway || "everything.dev";
92
51
  const accountDefault = domain ? deriveAccountFromDomain(domain, extendsAccount) : "";
93
- const account = input.account || await prompt("Project NEAR account", accountDefault);
52
+ const account = input.account ?? await _clack_prompts.text({
53
+ message: "What NEAR account will you publish from?",
54
+ placeholder: accountDefault || "skip",
55
+ defaultValue: accountDefault
56
+ });
57
+ if (_clack_prompts.isCancel(account)) node_process.default.exit(0);
94
58
  const directory = input.directory || domain || extendsGateway;
95
- const plugins = input.plugins || await promptPluginSelect();
96
- const withHost = input.withHost !== void 0 ? input.withHost : await promptYesNo("Include host?", false);
59
+ const plugins = input.plugins ?? await _clack_prompts.multiselect({
60
+ message: "Select plugins:",
61
+ options: AVAILABLE_PLUGINS,
62
+ initialValues: ["_template"],
63
+ required: false
64
+ });
65
+ if (_clack_prompts.isCancel(plugins)) node_process.default.exit(0);
66
+ const go = input.withHost !== void 0 ? true : await _clack_prompts.confirm({
67
+ message: "GO!",
68
+ initialValue: true
69
+ });
70
+ if (_clack_prompts.isCancel(go) || !go) node_process.default.exit(0);
71
+ const withHost = input.withHost ?? false;
97
72
  return {
98
73
  extendsAccount,
99
74
  extendsGateway,
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.cjs","names":[],"sources":["../../src/cli/prompts.ts"],"sourcesContent":["import { createInterface } from \"node:readline\";\n\nexport async function prompt(question: string, defaultValue?: string): Promise<string> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n const suffix = defaultValue ? ` [${defaultValue}]` : \"\";\n const fullQuestion = `${question}${suffix}: `;\n\n return new Promise<string>((resolve) => {\n rl.question(fullQuestion, (answer) => {\n rl.close();\n const trimmed = answer.trim();\n resolve(trimmed || defaultValue || \"\");\n });\n });\n}\n\nexport async function promptYesNo(question: string, defaultVal = false): Promise<boolean> {\n const hint = defaultVal ? \"Y/n\" : \"y/N\";\n const answer = await prompt(`${question} (${hint})`);\n if (!answer) return defaultVal;\n return answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\";\n}\n\nfunction parseExtendsRef(ref: string): { account: string; gateway: string } | null {\n const match = ref.match(/^(?:bos:\\/\\/)?([^/]+)\\/(.+)$/);\n if (!match) return null;\n return { account: match[1], gateway: match[2] };\n}\n\nfunction deriveAccountFromDomain(domain: string, extendsAccount: string): string {\n const firstSegment = domain.split(\".\")[0];\n if (!firstSegment) return \"\";\n const suffix = extendsAccount.includes(\".\")\n ? extendsAccount.substring(extendsAccount.indexOf(\".\") + 1)\n : extendsAccount;\n return `${firstSegment}.${suffix}`;\n}\n\nconst AVAILABLE_PLUGINS = [\n {\n key: \"_template\",\n label: \"template\",\n description: \"Plugin scaffold and boilerplate\",\n default: true,\n },\n {\n key: \"registry\",\n label: \"registry\",\n description: \"FastKV app discovery and metadata\",\n default: false,\n },\n];\n\nasync function promptPluginSelect(): Promise<string[]> {\n const selected = new Set<string>(AVAILABLE_PLUGINS.filter((p) => p.default).map((p) => p.key));\n\n console.log();\n console.log(\" Select plugins (enter number to toggle, enter to confirm):\");\n for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {\n const p = AVAILABLE_PLUGINS[i];\n const marker = selected.has(p.key) ? \"●\" : \"○\";\n console.log(` ${marker} ${i + 1}. ${p.label} — ${p.description}`);\n }\n console.log();\n\n while (true) {\n const answer = await prompt(\n \" Plugins\",\n selected.size > 0 ? Array.from(selected).join(\",\") : \"\",\n );\n if (!answer) break;\n\n const num = Number.parseInt(answer, 10);\n if (num >= 1 && num <= AVAILABLE_PLUGINS.length) {\n const plugin = AVAILABLE_PLUGINS[num - 1];\n if (selected.has(plugin.key)) {\n selected.delete(plugin.key);\n } else {\n selected.add(plugin.key);\n }\n\n console.log(\" Current selection:\");\n for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {\n const p = AVAILABLE_PLUGINS[i];\n const marker = selected.has(p.key) ? \"●\" : \"○\";\n console.log(` ${marker} ${i + 1}. ${p.label}`);\n }\n console.log();\n continue;\n }\n\n break;\n }\n\n return Array.from(selected);\n}\n\nexport async function promptInitOptions(input: {\n extendsAccount?: string;\n extendsGateway?: string;\n extends?: string;\n directory?: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n withHost?: boolean;\n}): Promise<{\n extendsAccount: string;\n extendsGateway: string;\n directory: string;\n account?: string;\n domain?: string;\n plugins: string[];\n withHost: boolean;\n}> {\n const domain = input.domain || (await prompt(\"Project domain\"));\n\n const extendsInput = input.extends || (await prompt(\"Extend from\", \"\"));\n let extendsAccount = input.extendsAccount || \"\";\n let extendsGateway = input.extendsGateway || \"\";\n\n if (extendsInput) {\n const parsed = parseExtendsRef(extendsInput);\n if (parsed) {\n extendsAccount = extendsAccount || parsed.account;\n extendsGateway = extendsGateway || parsed.gateway;\n }\n }\n\n extendsAccount = extendsAccount || \"dev.everything.near\";\n extendsGateway = extendsGateway || \"everything.dev\";\n\n const accountDefault = domain ? deriveAccountFromDomain(domain, extendsAccount) : \"\";\n const account = input.account || (await prompt(\"Project NEAR account\", accountDefault));\n\n const directory = input.directory || domain || extendsGateway;\n\n const plugins = input.plugins || (await promptPluginSelect());\n\n const withHost =\n input.withHost !== undefined ? input.withHost : await promptYesNo(\"Include host?\", false);\n\n return {\n extendsAccount,\n extendsGateway,\n directory,\n account: account || undefined,\n domain: domain || undefined,\n plugins,\n withHost,\n };\n}\n"],"mappings":";;;;AAEA,eAAsB,OAAO,UAAkB,cAAwC;CACrF,MAAM,wCAAqB;EACzB,OAAO,QAAQ;EACf,QAAQ,QAAQ;EACjB,CAAC;CAGF,MAAM,eAAe,GAAG,WADT,eAAe,KAAK,aAAa,KAAK,GACX;AAE1C,QAAO,IAAI,SAAiB,YAAY;AACtC,KAAG,SAAS,eAAe,WAAW;AACpC,MAAG,OAAO;AAEV,WADgB,OAAO,MAAM,IACV,gBAAgB,GAAG;IACtC;GACF;;AAGJ,eAAsB,YAAY,UAAkB,aAAa,OAAyB;CAExF,MAAM,SAAS,MAAM,OAAO,GAAG,SAAS,IAD3B,aAAa,QAAQ,MACe,GAAG;AACpD,KAAI,CAAC,OAAQ,QAAO;AACpB,QAAO,OAAO,aAAa,KAAK,OAAO,OAAO,aAAa,KAAK;;AAGlE,SAAS,gBAAgB,KAA0D;CACjF,MAAM,QAAQ,IAAI,MAAM,+BAA+B;AACvD,KAAI,CAAC,MAAO,QAAO;AACnB,QAAO;EAAE,SAAS,MAAM;EAAI,SAAS,MAAM;EAAI;;AAGjD,SAAS,wBA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MAAM,SAAS,SAAS,IAAI,EAAE,IAAI,GAAG,MAAM;AAC3C,YAAQ,IAAI,OAAO,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,QAAQ;;AAEnD,WAAQ,KAAK;AACb;;AAGF;;AAGF,QAAO,MAAM,KAAK,SAAS;;AAG7B,eAAsB,kBAAkB,OAiBrC;CACD,MAAM,SAAS,MAAM,UAAW,MAAM,OAAO,iBAAiB;CAE9D,MAAM,eAAe,MAAM,WAAY,MAAM,OAAO,eAAe,GAAG;CACtE,IAAI,iBAAiB,MAAM,kBAAkB;CAC7C,IAAI,iBAAiB,MAAM,kBAAkB;AAE7C,KAAI,cAAc;EAChB,MAAM,SAAS,gBAAgB,aAAa;AAC5C,MAAI,QAAQ;AACV,oBAAiB,kBAAkB,OAAO;AAC1C,oBAAiB,kBAAkB,OAAO;;;AAI9C,kBAAiB,kBAAkB;AACnC,kBAAiB,kBAAkB;CAEnC,MAAM,iBAAiB,SAAS,wBAAwB,QAAQ,eAAe,GAAG;CAClF,MAAM,UAAU,MAAM,WAAY,MAAM,OAAO,wBAAwB,eAAe;CAEtF,MAAM,YAAY,MAAM,aAAa,UAAU;CAE/C,MAAM,UAAU,MAAM,WAAY,MAAM,oBAAoB;CAE5D,MAAM,WACJ,MAAM,aAAa,SAAY,MAAM,WAAW,MAAM,YAAY,iBAAiB,MAAM;AAE3F,QAAO;EACL;EACA;EACA;EACA,SAAS,WAAW;EACpB,QAAQ,UAAU;EAClB;EACA;EACD"}
1
+ {"version":3,"file":"prompts.cjs","names":["p"],"sources":["../../src/cli/prompts.ts"],"sourcesContent":["import process from \"node:process\";\nimport * as p from \"@clack/prompts\";\n\nfunction parseExtendsRef(ref: string): { account: string; gateway: string } | null {\n const match = ref.match(/^(?:bos:\\/\\/)?([^/]+)\\/(.+)$/);\n if (!match) return null;\n return { account: match[1], gateway: match[2] };\n}\n\nfunction deriveAccountFromDomain(domain: string, extendsAccount: string): string {\n const firstSegment = domain.split(\".\")[0];\n if (!firstSegment) return \"\";\n const suffix = extendsAccount.includes(\".\")\n ? extendsAccount.substring(extendsAccount.indexOf(\".\") + 1)\n : extendsAccount;\n return `${firstSegment}.${suffix}`;\n}\n\nconst AVAILABLE_PLUGINS = [\n { value: \"_template\", label: \"template\" },\n { value: \"registry\", label: \"registry\" },\n];\n\nexport async function promptInitOptions(input: {\n extendsAccount?: string;\n extendsGateway?: string;\n extends?: string;\n directory?: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n withHost?: boolean;\n}): Promise<{\n extendsAccount: string;\n extendsGateway: string;\n directory: string;\n account?: string;\n domain?: string;\n plugins: string[];\n withHost: boolean;\n}> {\n p.intro(\"Let's build an app...\");\n\n const domain =\n input.domain ??\n ((await p.text({\n message: \"Starting with a domain?\",\n placeholder: \"no\",\n })) as string);\n\n if (p.isCancel(domain)) process.exit(0);\n\n const extendsPlaceholder = \"bos://dev.everything.near/everything.dev\";\n const extendsInput =\n input.extends ??\n ((await p.text({\n message: \"Extending an existing app?\",\n placeholder: extendsPlaceholder,\n })) as string);\n\n if (p.isCancel(extendsInput)) process.exit(0);\n\n let extendsAccount = input.extendsAccount || \"\";\n let extendsGateway = input.extendsGateway || \"\";\n\n if (extendsInput) {\n const parsed = parseExtendsRef(extendsInput);\n if (parsed) {\n extendsAccount = extendsAccount || parsed.account;\n extendsGateway = extendsGateway || parsed.gateway;\n }\n }\n\n extendsAccount = extendsAccount || \"dev.everything.near\";\n extendsGateway = extendsGateway || \"everything.dev\";\n\n const accountDefault = domain ? deriveAccountFromDomain(domain, extendsAccount) : \"\";\n const account =\n input.account ??\n ((await p.text({\n message: \"What NEAR account will you publish from?\",\n placeholder: accountDefault || \"skip\",\n defaultValue: accountDefault,\n })) as string);\n\n if (p.isCancel(account)) process.exit(0);\n\n const directory = input.directory || domain || extendsGateway;\n\n const plugins =\n input.plugins ??\n ((await p.multiselect({\n message: \"Select plugins:\",\n options: AVAILABLE_PLUGINS,\n initialValues: [\"_template\"],\n required: false,\n })) as string[]);\n\n if (p.isCancel(plugins)) process.exit(0);\n\n const go =\n input.withHost !== undefined\n ? true\n : await p.confirm({\n message: \"GO!\",\n initialValue: true,\n });\n\n if (p.isCancel(go) || !go) process.exit(0);\n\n const withHost = input.withHost ?? false;\n\n return {\n extendsAccount,\n extendsGateway,\n directory,\n account: account || undefined,\n domain: domain || undefined,\n plugins,\n withHost,\n };\n}\n"],"mappings":";;;;;;;AAGA,SAAS,gBAAgB,KAA0D;CACjF,MAAM,QAAQ,IAAI,MAAM,+BAA+B;AACvD,KAAI,CAAC,MAAO,QAAO;AACnB,QAAO;EAAE,SAAS,MAAM;EAAI,SAAS,MAAM;EAAI;;AAGjD,SAAS,wBAAwB,QAAgB,gBAAgC;CAC/E,MAAM,eAAe,OAAO,MAAM,IAAI,CAAC;AACvC,KAAI,CAAC,aAAc,QAAO;AAI1B,QAAO,GAAG,aAAa,GAHR,eAAe,SAAS,IAAI,GACvC,eAAe,UAAU,eAAe,QAAQ,IAAI,GAAG,EAAE,GACzD;;AAIN,MAAM,oBAAoB,CACxB;CAAE,OAAO;CAAa,OAAO;CAAY,EACzC;CAAE,OAAO;CAAY,OAAO;CAAY,CACzC;AAED,eAAsB,kBAAkB,OAiBrC;AACD,gBAAE,MAAM,wBAAwB;CAEhC,MAAM,SACJ,MAAM,UACJ,MAAMA,eAAE,KAAK;EACb,SAAS;EACT,aAAa;EACd,CAAC;AAEJ,KAAIA,eAAE,SAAS,OAAO,CAAE,sBAAQ,KAAK,EAAE;CAGvC,MAAM,eACJ,MAAM,WACJ,MAAMA,eAAE,KAAK;EACb,SAAS;EACT,aALuB;EAMxB,CAAC;AAEJ,KAAIA,eAAE,SAAS,aAAa,CAAE,sBAAQ,KAAK,EAAE;CAE7C,IAAI,iBAAiB,MAAM,kBAAkB;CAC7C,IAAI,iBAAiB,MAAM,kBAAkB;AAE7C,KAAI,cAAc;EAChB,MAAM,SAAS,gBAAgB,aAAa;AAC5C,MAAI,QAAQ;AACV,oBAAiB,kBAAkB,OAAO;AAC1C,oBAAiB,kBAAkB,OAAO;;;AAI9C,kBAAiB,kBAAkB;AACnC,kBAAiB,kBAAkB;CAEnC,MAAM,iBAAiB,SAAS,wBAAwB,QAAQ,eAAe,GAAG;CAClF,MAAM,UACJ,MAAM,WACJ,MAAMA,eAAE,KAAK;EACb,SAAS;EACT,aAAa,kBAAkB;EAC/B,cAAc;EACf,CAAC;AAEJ,KAAIA,eAAE,SAAS,QAAQ,CAAE,sBAAQ,KAAK,EAAE;CAExC,MAAM,YAAY,MAAM,aAAa,UAAU;CAE/C,MAAM,UACJ,MAAM,WACJ,MAAMA,eAAE,YAAY;EACpB,SAAS;EACT,SAAS;EACT,eAAe,CAAC,YAAY;EAC5B,UAAU;EACX,CAAC;AAEJ,KAAIA,eAAE,SAAS,QAAQ,CAAE,sBAAQ,KAAK,EAAE;CAExC,MAAM,KACJ,MAAM,aAAa,SACf,OACA,MAAMA,eAAE,QAAQ;EACd,SAAS;EACT,cAAc;EACf,CAAC;AAER,KAAIA,eAAE,SAAS,GAAG,IAAI,CAAC,GAAI,sBAAQ,KAAK,EAAE;CAE1C,MAAM,WAAW,MAAM,YAAY;AAEnC,QAAO;EACL;EACA;EACA;EACA,SAAS,WAAW;EACpB,QAAQ,UAAU;EAClB;EACA;EACD"}
@@ -1,24 +1,7 @@
1
- import { createInterface } from "node:readline";
1
+ import * as p from "@clack/prompts";
2
+ import process from "node:process";
2
3
 
3
4
  //#region src/cli/prompts.ts
4
- async function prompt(question, defaultValue) {
5
- const rl = createInterface({
6
- input: process.stdin,
7
- output: process.stdout
8
- });
9
- const fullQuestion = `${question}${defaultValue ? ` [${defaultValue}]` : ""}: `;
10
- return new Promise((resolve) => {
11
- rl.question(fullQuestion, (answer) => {
12
- rl.close();
13
- resolve(answer.trim() || defaultValue || "");
14
- });
15
- });
16
- }
17
- async function promptYesNo(question, defaultVal = false) {
18
- const answer = await prompt(`${question} (${defaultVal ? "Y/n" : "y/N"})`);
19
- if (!answer) return defaultVal;
20
- return answer.toLowerCase() === "y" || answer.toLowerCase() === "yes";
21
- }
22
5
  function parseExtendsRef(ref) {
23
6
  const match = ref.match(/^(?:bos:\/\/)?([^/]+)\/(.+)$/);
24
7
  if (!match) return null;
@@ -33,50 +16,24 @@ function deriveAccountFromDomain(domain, extendsAccount) {
33
16
  return `${firstSegment}.${extendsAccount.includes(".") ? extendsAccount.substring(extendsAccount.indexOf(".") + 1) : extendsAccount}`;
34
17
  }
35
18
  const AVAILABLE_PLUGINS = [{
36
- key: "_template",
37
- label: "template",
38
- description: "Plugin scaffold and boilerplate",
39
- default: true
19
+ value: "_template",
20
+ label: "template"
40
21
  }, {
41
- key: "registry",
42
- label: "registry",
43
- description: "FastKV app discovery and metadata",
44
- default: false
22
+ value: "registry",
23
+ label: "registry"
45
24
  }];
46
- async function promptPluginSelect() {
47
- const selected = new Set(AVAILABLE_PLUGINS.filter((p) => p.default).map((p) => p.key));
48
- console.log();
49
- console.log(" Select plugins (enter number to toggle, enter to confirm):");
50
- for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {
51
- const p = AVAILABLE_PLUGINS[i];
52
- const marker = selected.has(p.key) ? "●" : "○";
53
- console.log(` ${marker} ${i + 1}. ${p.label} — ${p.description}`);
54
- }
55
- console.log();
56
- while (true) {
57
- const answer = await prompt(" Plugins", selected.size > 0 ? Array.from(selected).join(",") : "");
58
- if (!answer) break;
59
- const num = Number.parseInt(answer, 10);
60
- if (num >= 1 && num <= AVAILABLE_PLUGINS.length) {
61
- const plugin = AVAILABLE_PLUGINS[num - 1];
62
- if (selected.has(plugin.key)) selected.delete(plugin.key);
63
- else selected.add(plugin.key);
64
- console.log(" Current selection:");
65
- for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {
66
- const p = AVAILABLE_PLUGINS[i];
67
- const marker = selected.has(p.key) ? "●" : "○";
68
- console.log(` ${marker} ${i + 1}. ${p.label}`);
69
- }
70
- console.log();
71
- continue;
72
- }
73
- break;
74
- }
75
- return Array.from(selected);
76
- }
77
25
  async function promptInitOptions(input) {
78
- const domain = input.domain || await prompt("Project domain");
79
- const extendsInput = input.extends || await prompt("Extend from", "");
26
+ p.intro("Let's build an app...");
27
+ const domain = input.domain ?? await p.text({
28
+ message: "Starting with a domain?",
29
+ placeholder: "no"
30
+ });
31
+ if (p.isCancel(domain)) process.exit(0);
32
+ const extendsInput = input.extends ?? await p.text({
33
+ message: "Extending an existing app?",
34
+ placeholder: "bos://dev.everything.near/everything.dev"
35
+ });
36
+ if (p.isCancel(extendsInput)) process.exit(0);
80
37
  let extendsAccount = input.extendsAccount || "";
81
38
  let extendsGateway = input.extendsGateway || "";
82
39
  if (extendsInput) {
@@ -89,10 +46,26 @@ async function promptInitOptions(input) {
89
46
  extendsAccount = extendsAccount || "dev.everything.near";
90
47
  extendsGateway = extendsGateway || "everything.dev";
91
48
  const accountDefault = domain ? deriveAccountFromDomain(domain, extendsAccount) : "";
92
- const account = input.account || await prompt("Project NEAR account", accountDefault);
49
+ const account = input.account ?? await p.text({
50
+ message: "What NEAR account will you publish from?",
51
+ placeholder: accountDefault || "skip",
52
+ defaultValue: accountDefault
53
+ });
54
+ if (p.isCancel(account)) process.exit(0);
93
55
  const directory = input.directory || domain || extendsGateway;
94
- const plugins = input.plugins || await promptPluginSelect();
95
- const withHost = input.withHost !== void 0 ? input.withHost : await promptYesNo("Include host?", false);
56
+ const plugins = input.plugins ?? await p.multiselect({
57
+ message: "Select plugins:",
58
+ options: AVAILABLE_PLUGINS,
59
+ initialValues: ["_template"],
60
+ required: false
61
+ });
62
+ if (p.isCancel(plugins)) process.exit(0);
63
+ const go = input.withHost !== void 0 ? true : await p.confirm({
64
+ message: "GO!",
65
+ initialValue: true
66
+ });
67
+ if (p.isCancel(go) || !go) process.exit(0);
68
+ const withHost = input.withHost ?? false;
96
69
  return {
97
70
  extendsAccount,
98
71
  extendsGateway,
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.mjs","names":[],"sources":["../../src/cli/prompts.ts"],"sourcesContent":["import { createInterface } from \"node:readline\";\n\nexport async function prompt(question: string, defaultValue?: string): Promise<string> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n const suffix = defaultValue ? ` [${defaultValue}]` : \"\";\n const fullQuestion = `${question}${suffix}: `;\n\n return new Promise<string>((resolve) => {\n rl.question(fullQuestion, (answer) => {\n rl.close();\n const trimmed = answer.trim();\n resolve(trimmed || defaultValue || \"\");\n });\n });\n}\n\nexport async function promptYesNo(question: string, defaultVal = false): Promise<boolean> {\n const hint = defaultVal ? \"Y/n\" : \"y/N\";\n const answer = await prompt(`${question} (${hint})`);\n if (!answer) return defaultVal;\n return answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\";\n}\n\nfunction parseExtendsRef(ref: string): { account: string; gateway: string } | null {\n const match = ref.match(/^(?:bos:\\/\\/)?([^/]+)\\/(.+)$/);\n if (!match) return null;\n return { account: match[1], gateway: match[2] };\n}\n\nfunction deriveAccountFromDomain(domain: string, extendsAccount: string): string {\n const firstSegment = domain.split(\".\")[0];\n if (!firstSegment) return \"\";\n const suffix = extendsAccount.includes(\".\")\n ? extendsAccount.substring(extendsAccount.indexOf(\".\") + 1)\n : extendsAccount;\n return `${firstSegment}.${suffix}`;\n}\n\nconst AVAILABLE_PLUGINS = [\n {\n key: \"_template\",\n label: \"template\",\n description: \"Plugin scaffold and boilerplate\",\n default: true,\n },\n {\n key: \"registry\",\n label: \"registry\",\n description: \"FastKV app discovery and metadata\",\n default: false,\n },\n];\n\nasync function promptPluginSelect(): Promise<string[]> {\n const selected = new Set<string>(AVAILABLE_PLUGINS.filter((p) => p.default).map((p) => p.key));\n\n console.log();\n console.log(\" Select plugins (enter number to toggle, enter to confirm):\");\n for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {\n const p = AVAILABLE_PLUGINS[i];\n const marker = selected.has(p.key) ? \"●\" : \"○\";\n console.log(` ${marker} ${i + 1}. ${p.label} — ${p.description}`);\n }\n console.log();\n\n while (true) {\n const answer = await prompt(\n \" Plugins\",\n selected.size > 0 ? Array.from(selected).join(\",\") : \"\",\n );\n if (!answer) break;\n\n const num = Number.parseInt(answer, 10);\n if (num >= 1 && num <= AVAILABLE_PLUGINS.length) {\n const plugin = AVAILABLE_PLUGINS[num - 1];\n if (selected.has(plugin.key)) {\n selected.delete(plugin.key);\n } else {\n selected.add(plugin.key);\n }\n\n console.log(\" Current selection:\");\n for (let i = 0; i < AVAILABLE_PLUGINS.length; i++) {\n const p = AVAILABLE_PLUGINS[i];\n const marker = selected.has(p.key) ? \"●\" : \"○\";\n console.log(` ${marker} ${i + 1}. ${p.label}`);\n }\n console.log();\n continue;\n }\n\n break;\n }\n\n return Array.from(selected);\n}\n\nexport async function promptInitOptions(input: {\n extendsAccount?: string;\n extendsGateway?: string;\n extends?: string;\n directory?: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n withHost?: boolean;\n}): Promise<{\n extendsAccount: string;\n extendsGateway: string;\n directory: string;\n account?: string;\n domain?: string;\n plugins: string[];\n withHost: boolean;\n}> {\n const domain = input.domain || (await prompt(\"Project domain\"));\n\n const extendsInput = input.extends || (await prompt(\"Extend from\", \"\"));\n let extendsAccount = input.extendsAccount || \"\";\n let extendsGateway = input.extendsGateway || \"\";\n\n if (extendsInput) {\n const parsed = parseExtendsRef(extendsInput);\n if (parsed) {\n extendsAccount = extendsAccount || parsed.account;\n extendsGateway = extendsGateway || parsed.gateway;\n }\n }\n\n extendsAccount = extendsAccount || \"dev.everything.near\";\n extendsGateway = extendsGateway || \"everything.dev\";\n\n const accountDefault = domain ? deriveAccountFromDomain(domain, extendsAccount) : \"\";\n const account = input.account || (await prompt(\"Project NEAR account\", accountDefault));\n\n const directory = input.directory || domain || extendsGateway;\n\n const plugins = input.plugins || (await promptPluginSelect());\n\n const withHost =\n input.withHost !== undefined ? input.withHost : await promptYesNo(\"Include host?\", false);\n\n return {\n extendsAccount,\n extendsGateway,\n directory,\n account: account || undefined,\n domain: domain || undefined,\n plugins,\n withHost,\n };\n}\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AkB;AACnC,kBAAiB,kBAAkB;CAEnC,MAAM,iBAAiB,SAAS,wBAAwB,QAAQ,eAAe,GAAG;CAClF,MAAM,UAAU,MAAM,WAAY,MAAM,OAAO,wBAAwB,eAAe;CAEtF,MAAM,YAAY,MAAM,aAAa,UAAU;CAE/C,MAAM,UAAU,MAAM,WAAY,MAAM,oBAAoB;CAE5D,MAAM,WACJ,MAAM,aAAa,SAAY,MAAM,WAAW,MAAM,YAAY,iBAAiB,MAAM;AAE3F,QAAO;EACL;EACA;EACA;EACA,SAAS,WAAW;EACpB,QAAQ,UAAU;EAClB;EACA;EACD"}
1
+ {"version":3,"file":"prompts.mjs","names":[],"sources":["../../src/cli/prompts.ts"],"sourcesContent":["import process from \"node:process\";\nimport * as p from \"@clack/prompts\";\n\nfunction parseExtendsRef(ref: string): { account: string; gateway: string } | null {\n const match = ref.match(/^(?:bos:\\/\\/)?([^/]+)\\/(.+)$/);\n if (!match) return null;\n return { account: match[1], gateway: match[2] };\n}\n\nfunction deriveAccountFromDomain(domain: string, extendsAccount: string): string {\n const firstSegment = domain.split(\".\")[0];\n if (!firstSegment) return \"\";\n const suffix = extendsAccount.includes(\".\")\n ? extendsAccount.substring(extendsAccount.indexOf(\".\") + 1)\n : extendsAccount;\n return `${firstSegment}.${suffix}`;\n}\n\nconst AVAILABLE_PLUGINS = [\n { value: \"_template\", label: \"template\" },\n { value: \"registry\", label: \"registry\" },\n];\n\nexport async function promptInitOptions(input: {\n extendsAccount?: string;\n extendsGateway?: string;\n extends?: string;\n directory?: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n withHost?: boolean;\n}): Promise<{\n extendsAccount: string;\n extendsGateway: string;\n directory: string;\n account?: string;\n domain?: string;\n plugins: string[];\n withHost: boolean;\n}> {\n p.intro(\"Let's build an app...\");\n\n const domain =\n input.domain ??\n ((await p.text({\n message: \"Starting with a domain?\",\n placeholder: \"no\",\n })) as string);\n\n if (p.isCancel(domain)) process.exit(0);\n\n const extendsPlaceholder = \"bos://dev.everything.near/everything.dev\";\n const extendsInput =\n input.extends ??\n ((await p.text({\n message: \"Extending an existing app?\",\n placeholder: extendsPlaceholder,\n })) as string);\n\n if (p.isCancel(extendsInput)) process.exit(0);\n\n let extendsAccount = input.extendsAccount || \"\";\n let extendsGateway = input.extendsGateway || \"\";\n\n if (extendsInput) {\n const parsed = parseExtendsRef(extendsInput);\n if (parsed) {\n extendsAccount = extendsAccount || parsed.account;\n extendsGateway = extendsGateway || parsed.gateway;\n }\n }\n\n extendsAccount = extendsAccount || \"dev.everything.near\";\n extendsGateway = extendsGateway || \"everything.dev\";\n\n const accountDefault = domain ? deriveAccountFromDomain(domain, extendsAccount) : \"\";\n const account =\n input.account ??\n ((await p.text({\n message: \"What NEAR account will you publish from?\",\n placeholder: accountDefault || \"skip\",\n defaultValue: accountDefault,\n })) as string);\n\n if (p.isCancel(account)) process.exit(0);\n\n const directory = input.directory || domain || extendsGateway;\n\n const plugins =\n input.plugins ??\n ((await p.multiselect({\n message: \"Select plugins:\",\n options: AVAILABLE_PLUGINS,\n initialValues: [\"_template\"],\n required: false,\n })) as string[]);\n\n if (p.isCancel(plugins)) process.exit(0);\n\n const go =\n input.withHost !== undefined\n ? true\n : await p.confirm({\n message: \"GO!\",\n initialValue: true,\n });\n\n if (p.isCancel(go) || !go) process.exit(0);\n\n const withHost = input.withHost ?? false;\n\n return {\n extendsAccount,\n extendsGateway,\n directory,\n account: account || undefined,\n domain: domain || undefined,\n plugins,\n withHost,\n };\n}\n"],"mappings":";;;;AAGA,SAAS,gBAAgB,KAA0D;CACjF,MAAM,QAAQ,IAAI,MAAM,+BAA+B;AACvD,KAAI,CAAC,MAAO,QAAO;AACnB,QAAO;EAAE,SAAS,MAAM;EAAI,SAAS,MAAM;EAAI;;AAGjD,SAAS,wBAAwB,QAAgB,gBAAgC;CAC/E,MAAM,eAAe,OAAO,MAAM,IAAI,CAAC;AACvC,KAAI,CAAC,aAAc,QAAO;AAI1B,QAAO,GAAG,aAAa,GAHR,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EAAE,QAAQ;EACd,SAAS;EACT,cAAc;EACf,CAAC;AAER,KAAI,EAAE,SAAS,GAAG,IAAI,CAAC,GAAI,SAAQ,KAAK,EAAE;CAE1C,MAAM,WAAW,MAAM,YAAY;AAEnC,QAAO;EACL;EACA;EACA;EACA,SAAS,WAAW;EACpB,QAAQ,UAAU;EAClB;EACA;EACD"}
@@ -26,8 +26,8 @@ declare const DevOptionsSchema: z.ZodObject<{
26
26
  }, z.core.$strip>;
27
27
  declare const DevResultSchema: z.ZodObject<{
28
28
  status: z.ZodEnum<{
29
- error: "error";
30
29
  started: "started";
30
+ error: "error";
31
31
  }>;
32
32
  description: z.ZodString;
33
33
  processes: z.ZodArray<z.ZodString>;
@@ -358,8 +358,8 @@ declare const bosContract: {
358
358
  interactive: z.ZodOptional<z.ZodBoolean>;
359
359
  }, z.core.$strip>, z.ZodObject<{
360
360
  status: z.ZodEnum<{
361
- error: "error";
362
361
  started: "started";
362
+ error: "error";
363
363
  }>;
364
364
  description: z.ZodString;
365
365
  processes: z.ZodArray<z.ZodString>;