everything-dev 1.12.1 → 1.12.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.
- package/dist/cli/framework-version.cjs +35 -0
- package/dist/cli/framework-version.cjs.map +1 -0
- package/dist/cli/framework-version.mjs +34 -0
- package/dist/cli/framework-version.mjs.map +1 -0
- package/dist/cli/init.cjs +14 -3
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.d.cts.map +1 -1
- package/dist/cli/init.d.mts.map +1 -1
- package/dist/cli/init.mjs +14 -3
- package/dist/cli/init.mjs.map +1 -1
- package/dist/cli/status.cjs +2 -9
- package/dist/cli/status.cjs.map +1 -1
- package/dist/cli/status.mjs +2 -9
- package/dist/cli/status.mjs.map +1 -1
- package/dist/cli/sync.cjs +88 -16
- package/dist/cli/sync.cjs.map +1 -1
- package/dist/cli/sync.mjs +88 -16
- package/dist/cli/sync.mjs.map +1 -1
- package/dist/cli/upgrade.cjs +85 -48
- package/dist/cli/upgrade.cjs.map +1 -1
- package/dist/cli/upgrade.mjs +85 -48
- package/dist/cli/upgrade.mjs.map +1 -1
- package/dist/contract.d.cts +2 -2
- package/dist/contract.d.mts +2 -2
- package/dist/host.cjs +1 -0
- 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 +1 -0
- package/dist/host.mjs.map +1 -1
- package/dist/internal/manifest-normalizer.cjs +7 -0
- package/dist/internal/manifest-normalizer.cjs.map +1 -1
- package/dist/internal/manifest-normalizer.mjs +7 -0
- package/dist/internal/manifest-normalizer.mjs.map +1 -1
- package/dist/orchestrator.d.cts +1 -1
- package/dist/orchestrator.d.mts +1 -1
- package/dist/plugin.d.cts +1 -1
- package/dist/plugin.d.mts +1 -1
- package/dist/ui/index.cjs +0 -9
- package/dist/ui/index.d.cts +2 -2
- package/dist/ui/index.d.mts +2 -2
- package/dist/ui/index.mjs +2 -2
- package/dist/ui/runtime.cjs +1 -43
- package/dist/ui/runtime.cjs.map +1 -1
- package/dist/ui/runtime.d.cts +1 -16
- package/dist/ui/runtime.d.cts.map +1 -1
- package/dist/ui/runtime.d.mts +1 -16
- package/dist/ui/runtime.d.mts.map +1 -1
- package/dist/ui/runtime.mjs +2 -36
- package/dist/ui/runtime.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli/framework-version.ts +61 -0
- package/src/cli/init.ts +16 -4
- package/src/cli/status.ts +2 -15
- package/src/cli/sync.ts +145 -24
- package/src/cli/upgrade.ts +94 -72
- package/src/host.ts +1 -0
- package/src/internal/manifest-normalizer.ts +13 -0
- package/src/ui/runtime.ts +1 -48
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
|
|
5
|
+
//#region src/cli/framework-version.ts
|
|
6
|
+
function stripVersionPrefix(version) {
|
|
7
|
+
return version.replace(/^[\^~>=]+/, "");
|
|
8
|
+
}
|
|
9
|
+
function readRootCatalogVersion(projectDir, packageName) {
|
|
10
|
+
const pkgPath = (0, node_path.join)(projectDir, "package.json");
|
|
11
|
+
if (!(0, node_fs.existsSync)(pkgPath)) return void 0;
|
|
12
|
+
const version = JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf-8")).workspaces?.catalog?.[packageName];
|
|
13
|
+
return version ? stripVersionPrefix(version) : void 0;
|
|
14
|
+
}
|
|
15
|
+
function readNodeModulesVersion(projectDir, packageName) {
|
|
16
|
+
const pkgPath = (0, node_path.join)(projectDir, "node_modules", packageName, "package.json");
|
|
17
|
+
if (!(0, node_fs.existsSync)(pkgPath)) return void 0;
|
|
18
|
+
return JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf-8")).version;
|
|
19
|
+
}
|
|
20
|
+
function readInstalledFrameworkVersion(projectDir, packageName) {
|
|
21
|
+
const pkgPath = (0, node_path.join)(projectDir, "package.json");
|
|
22
|
+
if (!(0, node_fs.existsSync)(pkgPath)) return void 0;
|
|
23
|
+
const pkg = JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf-8"));
|
|
24
|
+
const deps = pkg.dependencies ?? {};
|
|
25
|
+
const devDeps = pkg.devDependencies ?? {};
|
|
26
|
+
const version = deps[packageName] || devDeps[packageName];
|
|
27
|
+
if (!version) return readRootCatalogVersion(projectDir, packageName) ?? readNodeModulesVersion(projectDir, packageName);
|
|
28
|
+
if (version.startsWith("catalog:")) return readRootCatalogVersion(projectDir, packageName) ?? readNodeModulesVersion(projectDir, packageName);
|
|
29
|
+
if (version.startsWith("workspace:") || version.startsWith("file:")) return readNodeModulesVersion(projectDir, packageName);
|
|
30
|
+
return stripVersionPrefix(version);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.readInstalledFrameworkVersion = readInstalledFrameworkVersion;
|
|
35
|
+
//# sourceMappingURL=framework-version.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-version.cjs","names":[],"sources":["../../src/cli/framework-version.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nfunction stripVersionPrefix(version: string): string {\n return version.replace(/^[\\^~>=]+/, \"\");\n}\n\nexport function readRootCatalogVersion(\n projectDir: string,\n packageName: string,\n): string | undefined {\n const pkgPath = join(projectDir, \"package.json\");\n if (!existsSync(pkgPath)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as {\n workspaces?: { catalog?: Record<string, string> };\n };\n const version = pkg.workspaces?.catalog?.[packageName];\n return version ? stripVersionPrefix(version) : undefined;\n}\n\nexport function readNodeModulesVersion(\n projectDir: string,\n packageName: string,\n): string | undefined {\n const pkgPath = join(projectDir, \"node_modules\", packageName, \"package.json\");\n if (!existsSync(pkgPath)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as { version?: string };\n return pkg.version;\n}\n\nexport function readInstalledFrameworkVersion(\n projectDir: string,\n packageName: string,\n): string | undefined {\n const pkgPath = join(projectDir, \"package.json\");\n if (!existsSync(pkgPath)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n const deps = (pkg.dependencies ?? {}) as Record<string, string>;\n const devDeps = (pkg.devDependencies ?? {}) as Record<string, string>;\n const version = deps[packageName] || devDeps[packageName];\n\n if (!version) {\n return (\n readRootCatalogVersion(projectDir, packageName) ??\n readNodeModulesVersion(projectDir, packageName)\n );\n }\n\n if (version.startsWith(\"catalog:\")) {\n return (\n readRootCatalogVersion(projectDir, packageName) ??\n readNodeModulesVersion(projectDir, packageName)\n );\n }\n\n if (version.startsWith(\"workspace:\") || version.startsWith(\"file:\")) {\n return readNodeModulesVersion(projectDir, packageName);\n }\n\n return stripVersionPrefix(version);\n}\n"],"mappings":";;;;;AAGA,SAAS,mBAAmB,SAAyB;AACnD,QAAO,QAAQ,QAAQ,aAAa,GAAG;;AAGzC,SAAgB,uBACd,YACA,aACoB;CACpB,MAAM,8BAAe,YAAY,eAAe;AAChD,KAAI,yBAAY,QAAQ,CAAE,QAAO;CAIjC,MAAM,UAHM,KAAK,gCAAmB,SAAS,QAAQ,CAAC,CAGlC,YAAY,UAAU;AAC1C,QAAO,UAAU,mBAAmB,QAAQ,GAAG;;AAGjD,SAAgB,uBACd,YACA,aACoB;CACpB,MAAM,8BAAe,YAAY,gBAAgB,aAAa,eAAe;AAC7E,KAAI,yBAAY,QAAQ,CAAE,QAAO;AAEjC,QADY,KAAK,gCAAmB,SAAS,QAAQ,CAAC,CAC3C;;AAGb,SAAgB,8BACd,YACA,aACoB;CACpB,MAAM,8BAAe,YAAY,eAAe;AAChD,KAAI,yBAAY,QAAQ,CAAE,QAAO;CACjC,MAAM,MAAM,KAAK,gCAAmB,SAAS,QAAQ,CAAC;CACtD,MAAM,OAAQ,IAAI,gBAAgB,EAAE;CACpC,MAAM,UAAW,IAAI,mBAAmB,EAAE;CAC1C,MAAM,UAAU,KAAK,gBAAgB,QAAQ;AAE7C,KAAI,CAAC,QACH,QACE,uBAAuB,YAAY,YAAY,IAC/C,uBAAuB,YAAY,YAAY;AAInD,KAAI,QAAQ,WAAW,WAAW,CAChC,QACE,uBAAuB,YAAY,YAAY,IAC/C,uBAAuB,YAAY,YAAY;AAInD,KAAI,QAAQ,WAAW,aAAa,IAAI,QAAQ,WAAW,QAAQ,CACjE,QAAO,uBAAuB,YAAY,YAAY;AAGxD,QAAO,mBAAmB,QAAQ"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/framework-version.ts
|
|
5
|
+
function stripVersionPrefix(version) {
|
|
6
|
+
return version.replace(/^[\^~>=]+/, "");
|
|
7
|
+
}
|
|
8
|
+
function readRootCatalogVersion(projectDir, packageName) {
|
|
9
|
+
const pkgPath = join(projectDir, "package.json");
|
|
10
|
+
if (!existsSync(pkgPath)) return void 0;
|
|
11
|
+
const version = JSON.parse(readFileSync(pkgPath, "utf-8")).workspaces?.catalog?.[packageName];
|
|
12
|
+
return version ? stripVersionPrefix(version) : void 0;
|
|
13
|
+
}
|
|
14
|
+
function readNodeModulesVersion(projectDir, packageName) {
|
|
15
|
+
const pkgPath = join(projectDir, "node_modules", packageName, "package.json");
|
|
16
|
+
if (!existsSync(pkgPath)) return void 0;
|
|
17
|
+
return JSON.parse(readFileSync(pkgPath, "utf-8")).version;
|
|
18
|
+
}
|
|
19
|
+
function readInstalledFrameworkVersion(projectDir, packageName) {
|
|
20
|
+
const pkgPath = join(projectDir, "package.json");
|
|
21
|
+
if (!existsSync(pkgPath)) return void 0;
|
|
22
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
23
|
+
const deps = pkg.dependencies ?? {};
|
|
24
|
+
const devDeps = pkg.devDependencies ?? {};
|
|
25
|
+
const version = deps[packageName] || devDeps[packageName];
|
|
26
|
+
if (!version) return readRootCatalogVersion(projectDir, packageName) ?? readNodeModulesVersion(projectDir, packageName);
|
|
27
|
+
if (version.startsWith("catalog:")) return readRootCatalogVersion(projectDir, packageName) ?? readNodeModulesVersion(projectDir, packageName);
|
|
28
|
+
if (version.startsWith("workspace:") || version.startsWith("file:")) return readNodeModulesVersion(projectDir, packageName);
|
|
29
|
+
return stripVersionPrefix(version);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { readInstalledFrameworkVersion };
|
|
34
|
+
//# sourceMappingURL=framework-version.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-version.mjs","names":[],"sources":["../../src/cli/framework-version.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nfunction stripVersionPrefix(version: string): string {\n return version.replace(/^[\\^~>=]+/, \"\");\n}\n\nexport function readRootCatalogVersion(\n projectDir: string,\n packageName: string,\n): string | undefined {\n const pkgPath = join(projectDir, \"package.json\");\n if (!existsSync(pkgPath)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as {\n workspaces?: { catalog?: Record<string, string> };\n };\n const version = pkg.workspaces?.catalog?.[packageName];\n return version ? stripVersionPrefix(version) : undefined;\n}\n\nexport function readNodeModulesVersion(\n projectDir: string,\n packageName: string,\n): string | undefined {\n const pkgPath = join(projectDir, \"node_modules\", packageName, \"package.json\");\n if (!existsSync(pkgPath)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as { version?: string };\n return pkg.version;\n}\n\nexport function readInstalledFrameworkVersion(\n projectDir: string,\n packageName: string,\n): string | undefined {\n const pkgPath = join(projectDir, \"package.json\");\n if (!existsSync(pkgPath)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n const deps = (pkg.dependencies ?? {}) as Record<string, string>;\n const devDeps = (pkg.devDependencies ?? {}) as Record<string, string>;\n const version = deps[packageName] || devDeps[packageName];\n\n if (!version) {\n return (\n readRootCatalogVersion(projectDir, packageName) ??\n readNodeModulesVersion(projectDir, packageName)\n );\n }\n\n if (version.startsWith(\"catalog:\")) {\n return (\n readRootCatalogVersion(projectDir, packageName) ??\n readNodeModulesVersion(projectDir, packageName)\n );\n }\n\n if (version.startsWith(\"workspace:\") || version.startsWith(\"file:\")) {\n return readNodeModulesVersion(projectDir, packageName);\n }\n\n return stripVersionPrefix(version);\n}\n"],"mappings":";;;;AAGA,SAAS,mBAAmB,SAAyB;AACnD,QAAO,QAAQ,QAAQ,aAAa,GAAG;;AAGzC,SAAgB,uBACd,YACA,aACoB;CACpB,MAAM,UAAU,KAAK,YAAY,eAAe;AAChD,KAAI,CAAC,WAAW,QAAQ,CAAE,QAAO;CAIjC,MAAM,UAHM,KAAK,MAAM,aAAa,SAAS,QAAQ,CAAC,CAGlC,YAAY,UAAU;AAC1C,QAAO,UAAU,mBAAmB,QAAQ,GAAG;;AAGjD,SAAgB,uBACd,YACA,aACoB;CACpB,MAAM,UAAU,KAAK,YAAY,gBAAgB,aAAa,eAAe;AAC7E,KAAI,CAAC,WAAW,QAAQ,CAAE,QAAO;AAEjC,QADY,KAAK,MAAM,aAAa,SAAS,QAAQ,CAAC,CAC3C;;AAGb,SAAgB,8BACd,YACA,aACoB;CACpB,MAAM,UAAU,KAAK,YAAY,eAAe;AAChD,KAAI,CAAC,WAAW,QAAQ,CAAE,QAAO;CACjC,MAAM,MAAM,KAAK,MAAM,aAAa,SAAS,QAAQ,CAAC;CACtD,MAAM,OAAQ,IAAI,gBAAgB,EAAE;CACpC,MAAM,UAAW,IAAI,mBAAmB,EAAE;CAC1C,MAAM,UAAU,KAAK,gBAAgB,QAAQ;AAE7C,KAAI,CAAC,QACH,QACE,uBAAuB,YAAY,YAAY,IAC/C,uBAAuB,YAAY,YAAY;AAInD,KAAI,QAAQ,WAAW,WAAW,CAChC,QACE,uBAAuB,YAAY,YAAY,IAC/C,uBAAuB,YAAY,YAAY;AAInD,KAAI,QAAQ,WAAW,aAAa,IAAI,QAAQ,WAAW,QAAQ,CACjE,QAAO,uBAAuB,YAAY,YAAY;AAGxD,QAAO,mBAAmB,QAAQ"}
|
package/dist/cli/init.cjs
CHANGED
|
@@ -272,11 +272,21 @@ async function personalizeConfig(destination, opts) {
|
|
|
272
272
|
delete deps["every-plugin"];
|
|
273
273
|
delete deps["everything-dev"];
|
|
274
274
|
}
|
|
275
|
+
if (!pkg.workspaces || typeof pkg.workspaces !== "object") pkg.workspaces = {
|
|
276
|
+
packages: [],
|
|
277
|
+
catalog: {}
|
|
278
|
+
};
|
|
279
|
+
const workspaces = pkg.workspaces;
|
|
280
|
+
if (!workspaces.catalog || typeof workspaces.catalog !== "object") workspaces.catalog = {};
|
|
275
281
|
if (!pkg.dependencies) pkg.dependencies = {};
|
|
276
282
|
const deps = pkg.dependencies;
|
|
277
283
|
const spec = opts.workspaceOpts?.sourceDir ? require_manifest_normalizer.loadManifestNormalizationSpec(opts.workspaceOpts.sourceDir) : null;
|
|
278
|
-
if (
|
|
279
|
-
|
|
284
|
+
if (spec) {
|
|
285
|
+
workspaces.catalog["everything-dev"] = spec.rootCatalog["everything-dev"];
|
|
286
|
+
workspaces.catalog["every-plugin"] = spec.rootCatalog["every-plugin"];
|
|
287
|
+
}
|
|
288
|
+
if (!deps["everything-dev"] && spec) deps["everything-dev"] = "catalog:";
|
|
289
|
+
if (!deps["every-plugin"] && spec) deps["every-plugin"] = "catalog:";
|
|
280
290
|
(0, node_fs.writeFileSync)(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
281
291
|
}
|
|
282
292
|
const apiTsConfigPath = (0, node_path.join)(destination, "api", "tsconfig.json");
|
|
@@ -332,7 +342,8 @@ async function resolveWorkspaceRefs(destination, options) {
|
|
|
332
342
|
await require_manifest_normalizer.normalizePackageManifestsInTree({
|
|
333
343
|
sourceRootDir: options?.sourceDir ?? destination,
|
|
334
344
|
targetDir: destination,
|
|
335
|
-
resolveCatalogRefs:
|
|
345
|
+
resolveCatalogRefs: false,
|
|
346
|
+
preserveCatalogRefs: true,
|
|
336
347
|
removeWorkspaceDeps: ["host"]
|
|
337
348
|
});
|
|
338
349
|
if (options?.localOverrides && options.sourceDir) {
|
package/dist/cli/init.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.cjs","names":["require","fetchBosConfigFromFastKv","loadManifestNormalizationSpec","normalizePackageManifestsInTree","writeSnapshot"],"sources":["../../src/cli/init.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport {\n createWriteStream,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { glob } from \"glob\";\nimport { fetchBosConfigFromFastKv } from \"../fastkv\";\nimport {\n loadManifestNormalizationSpec,\n normalizePackageManifestsInTree,\n} from \"../internal/manifest-normalizer\";\nimport type { BosConfig } from \"../types\";\nimport { writeSnapshot } from \"./snapshot\";\n\nconst require = createRequire(import.meta.url);\n\nconst BOS_CONFIG_ORDER = [\n \"extends\",\n \"account\",\n \"domain\",\n \"testnet\",\n \"staging\",\n \"repository\",\n \"app\",\n \"plugins\",\n \"shared\",\n];\n\nfunction rebuildOrderedConfig(config: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n\n for (const key of BOS_CONFIG_ORDER) {\n if (key in config) {\n ordered[key] = config[key];\n }\n }\n\n for (const key of Object.keys(config)) {\n if (!BOS_CONFIG_ORDER.includes(key)) {\n ordered[key] = config[key];\n }\n }\n\n return ordered;\n}\n\ninterface SourceResult {\n sourceDir: string;\n parentConfig: BosConfig;\n cleanup: () => Promise<void>;\n}\n\nexport async function resolveSourceDir(opts: {\n extendsAccount: string;\n extendsGateway: string;\n source?: string;\n}): Promise<SourceResult> {\n if (opts.source) {\n const sourceDir = resolve(opts.source);\n if (!existsSync(join(sourceDir, \"bos.config.json\"))) {\n throw new Error(`No bos.config.json found in source directory: ${sourceDir}`);\n }\n const parentConfig = JSON.parse(\n readFileSync(join(sourceDir, \"bos.config.json\"), \"utf-8\"),\n ) as BosConfig;\n return { sourceDir, parentConfig, cleanup: async () => {} };\n }\n\n const parentConfig = await fetchParentConfig(opts.extendsAccount, opts.extendsGateway);\n\n if (!parentConfig.repository) {\n throw new Error(\"Parent config has no repository field — cannot locate template source\");\n }\n\n const { dir: sourceDir, cleanup } = await downloadTarball(parentConfig.repository);\n return { sourceDir, parentConfig, cleanup };\n}\n\nexport async function fetchParentConfig(\n extendsAccount: string,\n extendsGateway: string,\n): Promise<BosConfig> {\n const bosUrl = `bos://${extendsAccount}/${extendsGateway}`;\n return fetchBosConfigFromFastKv<BosConfig>(bosUrl);\n}\n\nexport async function downloadTarball(\n repoUrl: string,\n): Promise<{ dir: string; cleanup: () => Promise<void> }> {\n const parsed = parseGitHubUrl(repoUrl);\n if (!parsed) {\n throw new Error(`Cannot parse repository URL: ${repoUrl}`);\n }\n\n const { owner, repo, branch } = parsed;\n const tarballUrl = `https://api.github.com/repos/${owner}/${repo}/tarball/${branch}`;\n\n const tmpDir = mkTmpDir(\"bos-init-tarball-\");\n const tarballPath = join(tmpDir, \"source.tar.gz\");\n\n const response = await fetch(tarballUrl, {\n headers: { \"User-Agent\": \"everything-dev\" },\n redirect: \"follow\",\n });\n\n if (!response.ok) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(`GitHub tarball download failed: ${response.status} ${response.statusText}`);\n }\n\n if (!response.body) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(\"GitHub tarball download returned empty body\");\n }\n\n const fileStream = createWriteStream(tarballPath);\n const reader = response.body as unknown as NodeJS.ReadableStream;\n await pipeline(reader, fileStream);\n\n const extractDir = mkTmpDir(\"bos-init-extract-\");\n try {\n const tar = require(\"tar\") as {\n extract: (opts: { cwd: string; file: string; strip: number }) => Promise<void>;\n };\n await tar.extract({ cwd: extractDir, file: tarballPath, strip: 1 });\n } catch {\n await execCommand(\"tar\", [\"-xzf\", tarballPath, \"--strip-components=1\", \"-C\", extractDir]);\n }\n\n rmSync(tmpDir, { recursive: true, force: true });\n\n return {\n dir: extractDir,\n cleanup: async () => {\n rmSync(extractDir, { recursive: true, force: true });\n },\n };\n}\n\nfunction parseGitHubUrl(url: string): { owner: string; repo: string; branch: string } | null {\n const httpsMatch = url.match(/^https?:\\/\\/github\\.com\\/([^/]+)\\/([^/]+?)(?:\\.git)?(?:\\/.*)?$/);\n if (httpsMatch) {\n return { owner: httpsMatch[1], repo: httpsMatch[2], branch: \"main\" };\n }\n\n const sshMatch = url.match(/^git@github\\.com:([^/]+)\\/([^/]+?)(?:\\.git)?$/);\n if (sshMatch) {\n return { owner: sshMatch[1], repo: sshMatch[2], branch: \"main\" };\n }\n\n return null;\n}\n\nexport async function readTemplatekeep(sourceDir: string): Promise<string[]> {\n const keepFile = join(sourceDir, \".templatekeep\");\n if (!existsSync(keepFile)) {\n return [];\n }\n\n const content = readFileSync(keepFile, \"utf-8\");\n return content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0 && !line.startsWith(\"#\"));\n}\n\nexport async function copyFilteredFiles(\n sourceDir: string,\n destination: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<number> {\n if (patterns.length === 0) {\n return 0;\n }\n\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const filteredPatterns = effectivePatterns.filter((p) => {\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (!pluginMatch) return true;\n const pluginName = pluginMatch[1];\n return options.plugins?.includes(pluginName) ?? true;\n });\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of filteredPatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) {\n const pluginName = pluginMatch[1];\n if (!(options.plugins?.includes(pluginName) ?? true)) continue;\n }\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n const routeFiles = new Set<string>();\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n routeFiles.add(match);\n }\n }\n }\n }\n }\n\n for (const f of routeFiles) allFiles.add(f);\n\n mkdirSync(destination, { recursive: true });\n\n let count = 0;\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(destination, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n const content = readFileSync(src);\n writeFileSync(dest, content);\n count++;\n }\n\n return count;\n}\n\nfunction isRouteExcluded(filePath: string, excludedPatterns: string[]): boolean {\n if (excludedPatterns.length === 0) return false;\n for (const pattern of excludedPatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nexport async function personalizeConfig(\n destination: string,\n opts: {\n extendsAccount: string;\n extendsGateway: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n pluginRoutes?: Record<string, string[]>;\n workspaceOpts?: { localOverrides?: boolean; sourceDir?: string };\n mode?: \"init\" | \"sync\";\n withHost?: boolean;\n },\n): Promise<void> {\n const isInit = opts.mode !== \"sync\";\n const configPath = join(destination, \"bos.config.json\");\n if (existsSync(configPath)) {\n const config = JSON.parse(readFileSync(configPath, \"utf-8\")) as Record<string, unknown>;\n\n config.extends = `bos://${opts.extendsAccount}/${opts.extendsGateway}`;\n\n if (opts.account) {\n config.account = opts.account;\n }\n if (opts.domain) {\n config.domain = opts.domain;\n }\n\n if (isInit && config.app && typeof config.app === \"object\") {\n const app = config.app as Record<string, unknown>;\n\n for (const entryKey of Object.keys(app)) {\n const entry = app[entryKey];\n if (entry && typeof entry === \"object\") {\n const e = entry as Record<string, unknown>;\n delete e.production;\n delete e.integrity;\n delete e.ssr;\n delete e.ssrIntegrity;\n }\n }\n }\n\n if (config.plugins && typeof config.plugins === \"object\") {\n const plugins = config.plugins as Record<string, unknown>;\n\n if (opts.plugins && opts.plugins.length > 0) {\n for (const pluginKey of Object.keys(plugins)) {\n if (!opts.plugins.includes(pluginKey)) {\n delete plugins[pluginKey];\n }\n }\n }\n\n if (isInit) {\n for (const pluginKey of Object.keys(plugins)) {\n const plugin = plugins[pluginKey];\n if (plugin && typeof plugin === \"object\") {\n const p = plugin as Record<string, unknown>;\n delete p.production;\n delete p.integrity;\n }\n }\n }\n\n if (Object.keys(plugins).length === 0) {\n config.plugins = {};\n }\n }\n\n writeFileSync(configPath, `${JSON.stringify(rebuildOrderedConfig(config), null, 2)}\\n`);\n }\n\n const pkgPath = join(destination, \"package.json\");\n if (existsSync(pkgPath)) {\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const ws = pkg.workspaces as { packages?: string[] };\n if (Array.isArray(ws.packages)) {\n ws.packages = ws.packages.filter((p: string) => {\n if (p.startsWith(\"packages/\")) return false;\n if (p === \"host\") return opts.withHost ?? false;\n if (p === \"plugins/*\") return (opts.plugins?.length ?? 0) > 0;\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) return opts.plugins?.includes(pluginMatch[1]) ?? true;\n return true;\n });\n }\n }\n\n if (pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n const rewrite = (key: string, from: string, to: string) => {\n if (scripts[key]?.includes(from)) {\n scripts[key] = scripts[key].replaceAll(from, to);\n }\n };\n rewrite(\"dev\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:ui\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:api\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:proxy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"build\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"deploy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"publish\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"start\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n\n scripts.postinstall = \"node_modules/.bin/bos types gen || true\";\n scripts[\"types:gen\"] = \"node_modules/.bin/bos types gen\";\n if (scripts.typecheck) {\n scripts.typecheck = scripts.typecheck\n .replace(\"bun run types:gen && \", \"\")\n .replace(/bun run --cwd packages\\/everything-dev typecheck & ?/, \"\");\n if (!opts.withHost) {\n scripts.typecheck = scripts.typecheck.replace(/bun run --cwd host tsc --noEmit & ?/, \"\");\n }\n }\n }\n\n if (pkg.devDependencies && typeof pkg.devDependencies === \"object\") {\n const deps = pkg.devDependencies as Record<string, string>;\n delete deps[\"every-plugin\"];\n delete deps[\"everything-dev\"];\n }\n\n if (!pkg.dependencies) pkg.dependencies = {};\n const deps = pkg.dependencies as Record<string, string>;\n const spec = opts.workspaceOpts?.sourceDir\n ? loadManifestNormalizationSpec(opts.workspaceOpts.sourceDir)\n : null;\n if (!deps[\"everything-dev\"] && spec)\n deps[\"everything-dev\"] = spec.rootCatalog[\"everything-dev\"];\n if (!deps[\"every-plugin\"] && spec) deps[\"every-plugin\"] = spec.rootCatalog[\"every-plugin\"];\n\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n\n const apiTsConfigPath = join(destination, \"api\", \"tsconfig.json\");\n if (existsSync(apiTsConfigPath)) {\n const apiTsConfig = JSON.parse(readFileSync(apiTsConfigPath, \"utf-8\")) as {\n files?: string[];\n [key: string]: unknown;\n };\n if (apiTsConfig.files) {\n const validFiles = apiTsConfig.files.filter((f) => existsSync(join(destination, \"api\", f)));\n if (validFiles.length !== apiTsConfig.files.length) {\n if (validFiles.length === 0) {\n delete apiTsConfig.files;\n } else {\n apiTsConfig.files = validFiles;\n }\n writeFileSync(apiTsConfigPath, `${JSON.stringify(apiTsConfig, null, 2)}\\n`);\n }\n }\n }\n\n await resolveWorkspaceRefs(destination, opts.workspaceOpts);\n\n const genContractPath = join(destination, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\");\n if (!existsSync(genContractPath)) {\n mkdirSync(dirname(genContractPath), { recursive: true });\n writeFileSync(genContractPath, `export type ApiContract = Record<string, never>;\\n`);\n }\n\n const pluginsClientGenPath = join(destination, \"api\", \"src\", \"lib\", \"plugins-types.gen.ts\");\n if (!existsSync(pluginsClientGenPath)) {\n mkdirSync(dirname(pluginsClientGenPath), { recursive: true });\n writeFileSync(\n pluginsClientGenPath,\n `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`,\n );\n }\n\n const authTypesGenPath = join(destination, \"ui\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(authTypesGenPath)) {\n mkdirSync(dirname(authTypesGenPath), { recursive: true });\n writeFileSync(\n authTypesGenPath,\n `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`,\n );\n }\n\n const apiAuthTypesGenPath = join(destination, \"api\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(apiAuthTypesGenPath)) {\n mkdirSync(dirname(apiAuthTypesGenPath), { recursive: true });\n writeFileSync(\n apiAuthTypesGenPath,\n `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`,\n );\n }\n\n const hostAuthTypesGenPath = join(destination, \"host\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (existsSync(join(destination, \"host\", \"src\")) && !existsSync(hostAuthTypesGenPath)) {\n mkdirSync(dirname(hostAuthTypesGenPath), { recursive: true });\n writeFileSync(\n hostAuthTypesGenPath,\n `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`,\n );\n }\n}\n\nexport async function runBunInstall(destination: string): Promise<void> {\n await execCommand(\"bun\", [\"install\", \"--ignore-scripts\"], destination);\n}\n\nexport async function runTypesGen(destination: string): Promise<void> {\n await execCommand(\"node_modules/.bin/bos\", [\"types\", \"gen\"], destination);\n}\n\nconst WORKSPACE_LOCAL_PATHS: Record<string, string> = {\n \"everything-dev\": \"packages/everything-dev\",\n \"every-plugin\": \"packages/every-plugin\",\n};\n\nasync function resolveWorkspaceRefs(\n destination: string,\n options?: { localOverrides?: boolean; sourceDir?: string },\n): Promise<void> {\n await normalizePackageManifestsInTree({\n sourceRootDir: options?.sourceDir ?? destination,\n targetDir: destination,\n resolveCatalogRefs: true,\n removeWorkspaceDeps: [\"host\"],\n });\n\n if (options?.localOverrides && options.sourceDir) {\n const rootPkgPath = join(destination, \"package.json\");\n if (existsSync(rootPkgPath)) {\n const pkg = JSON.parse(readFileSync(rootPkgPath, \"utf-8\")) as Record<string, unknown>;\n if (!pkg.overrides) pkg.overrides = {};\n const overrides = pkg.overrides as Record<string, string>;\n\n const rootWorkspaces = ((pkg.workspaces as Record<string, string[]>)?.packages ?? []).filter(\n Boolean,\n );\n\n for (const [name, relPath] of Object.entries(WORKSPACE_LOCAL_PATHS)) {\n if (!rootWorkspaces.some((ws) => ws === relPath || ws === `plugins/${name}`)) {\n const srcPkgPath = join(options.sourceDir, relPath, \"package.json\");\n if (existsSync(srcPkgPath)) {\n overrides[name] = `file:${relPath}`;\n rootWorkspaces.push(relPath);\n }\n }\n }\n\n if (rootWorkspaces.length > 0) {\n if (!pkg.workspaces) pkg.workspaces = {};\n (pkg.workspaces as Record<string, string[]>).packages = rootWorkspaces;\n }\n\n writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n }\n}\n\nexport async function writeInitSnapshot(\n destination: string,\n extendsAccount: string,\n extendsGateway: string,\n sourceDir: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<void> {\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of effectivePatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !(options.plugins?.includes(pluginMatch[1]) ?? true)) continue;\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n allFiles.add(match);\n }\n }\n }\n }\n }\n\n const fileHashes: Record<string, string> = {};\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n fileHashes[destPath] = computeHash(content);\n }\n\n await writeSnapshot(destination, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: fileHashes,\n });\n}\n\nfunction computeHash(data: Uint8Array): string {\n return createHash(\"sha256\").update(data).digest(\"hex\").substring(0, 16);\n}\n\nfunction mkTmpDir(prefix: string): string {\n const base = join(tmpdir(), prefix);\n let attempt = 0;\n while (true) {\n const dir = `${base}-${Date.now()}-${attempt}`;\n try {\n mkdirSync(dir, { recursive: true });\n return dir;\n } catch {\n attempt++;\n if (attempt > 10) throw new Error(\"Failed to create temp directory\");\n }\n }\n}\n\nexport async function generateDatabaseMigrations(destination: string): Promise<void> {\n const drizzleConfigs = await glob(\"**/drizzle.config.ts\", {\n cwd: destination,\n nodir: true,\n dot: false,\n absolute: false,\n ignore: [\"**/node_modules/**\"],\n });\n\n for (const configPath of drizzleConfigs) {\n const workspaceDir = dirname(configPath);\n const pkgPath = join(destination, workspaceDir, \"package.json\");\n if (!existsSync(pkgPath)) continue;\n\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n const scripts = pkg.scripts as Record<string, string> | undefined;\n if (!scripts?.[\"db:generate\"]) continue;\n\n const cwd = join(destination, workspaceDir);\n await execCommand(\"bun\", [\"run\", \"db:generate\"], cwd);\n }\n}\n\nexport function execCommand(command: string, args: string[], cwd?: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n cwd,\n stdio: \"pipe\",\n shell: true,\n });\n let stderr = \"\";\n child.stderr?.on(\"data\", (data: Buffer) => {\n stderr += data.toString();\n });\n child.on(\"close\", (code) => {\n if (code === 0) resolve();\n else\n reject(\n new Error(\n `Command '${command} ${args.join(\" \")}' failed with exit code ${code}: ${stderr}`,\n ),\n );\n });\n child.on(\"error\", reject);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAMA,yFAAwC;AAE9C,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,qBAAqB,QAA0D;CACtF,MAAM,UAAmC,EAAE;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AI,CAAC,0BAA0B,KAAK,IAAI,SAC1E,CACF;IACH;AACF,QAAM,GAAG,SAAS,OAAO;GACzB"}
|
|
1
|
+
{"version":3,"file":"init.cjs","names":["require","fetchBosConfigFromFastKv","loadManifestNormalizationSpec","normalizePackageManifestsInTree","writeSnapshot"],"sources":["../../src/cli/init.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport {\n createWriteStream,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { glob } from \"glob\";\nimport { fetchBosConfigFromFastKv } from \"../fastkv\";\nimport {\n loadManifestNormalizationSpec,\n normalizePackageManifestsInTree,\n} from \"../internal/manifest-normalizer\";\nimport type { BosConfig } from \"../types\";\nimport { writeSnapshot } from \"./snapshot\";\n\nconst require = createRequire(import.meta.url);\n\nconst BOS_CONFIG_ORDER = [\n \"extends\",\n \"account\",\n \"domain\",\n \"testnet\",\n \"staging\",\n \"repository\",\n \"app\",\n \"plugins\",\n \"shared\",\n];\n\nfunction rebuildOrderedConfig(config: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n\n for (const key of BOS_CONFIG_ORDER) {\n if (key in config) {\n ordered[key] = config[key];\n }\n }\n\n for (const key of Object.keys(config)) {\n if (!BOS_CONFIG_ORDER.includes(key)) {\n ordered[key] = config[key];\n }\n }\n\n return ordered;\n}\n\ninterface SourceResult {\n sourceDir: string;\n parentConfig: BosConfig;\n cleanup: () => Promise<void>;\n}\n\nexport async function resolveSourceDir(opts: {\n extendsAccount: string;\n extendsGateway: string;\n source?: string;\n}): Promise<SourceResult> {\n if (opts.source) {\n const sourceDir = resolve(opts.source);\n if (!existsSync(join(sourceDir, \"bos.config.json\"))) {\n throw new Error(`No bos.config.json found in source directory: ${sourceDir}`);\n }\n const parentConfig = JSON.parse(\n readFileSync(join(sourceDir, \"bos.config.json\"), \"utf-8\"),\n ) as BosConfig;\n return { sourceDir, parentConfig, cleanup: async () => {} };\n }\n\n const parentConfig = await fetchParentConfig(opts.extendsAccount, opts.extendsGateway);\n\n if (!parentConfig.repository) {\n throw new Error(\"Parent config has no repository field — cannot locate template source\");\n }\n\n const { dir: sourceDir, cleanup } = await downloadTarball(parentConfig.repository);\n return { sourceDir, parentConfig, cleanup };\n}\n\nexport async function fetchParentConfig(\n extendsAccount: string,\n extendsGateway: string,\n): Promise<BosConfig> {\n const bosUrl = `bos://${extendsAccount}/${extendsGateway}`;\n return fetchBosConfigFromFastKv<BosConfig>(bosUrl);\n}\n\nexport async function downloadTarball(\n repoUrl: string,\n): Promise<{ dir: string; cleanup: () => Promise<void> }> {\n const parsed = parseGitHubUrl(repoUrl);\n if (!parsed) {\n throw new Error(`Cannot parse repository URL: ${repoUrl}`);\n }\n\n const { owner, repo, branch } = parsed;\n const tarballUrl = `https://api.github.com/repos/${owner}/${repo}/tarball/${branch}`;\n\n const tmpDir = mkTmpDir(\"bos-init-tarball-\");\n const tarballPath = join(tmpDir, \"source.tar.gz\");\n\n const response = await fetch(tarballUrl, {\n headers: { \"User-Agent\": \"everything-dev\" },\n redirect: \"follow\",\n });\n\n if (!response.ok) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(`GitHub tarball download failed: ${response.status} ${response.statusText}`);\n }\n\n if (!response.body) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(\"GitHub tarball download returned empty body\");\n }\n\n const fileStream = createWriteStream(tarballPath);\n const reader = response.body as unknown as NodeJS.ReadableStream;\n await pipeline(reader, fileStream);\n\n const extractDir = mkTmpDir(\"bos-init-extract-\");\n try {\n const tar = require(\"tar\") as {\n extract: (opts: { cwd: string; file: string; strip: number }) => Promise<void>;\n };\n await tar.extract({ cwd: extractDir, file: tarballPath, strip: 1 });\n } catch {\n await execCommand(\"tar\", [\"-xzf\", tarballPath, \"--strip-components=1\", \"-C\", extractDir]);\n }\n\n rmSync(tmpDir, { recursive: true, force: true });\n\n return {\n dir: extractDir,\n cleanup: async () => {\n rmSync(extractDir, { recursive: true, force: true });\n },\n };\n}\n\nfunction parseGitHubUrl(url: string): { owner: string; repo: string; branch: string } | null {\n const httpsMatch = url.match(/^https?:\\/\\/github\\.com\\/([^/]+)\\/([^/]+?)(?:\\.git)?(?:\\/.*)?$/);\n if (httpsMatch) {\n return { owner: httpsMatch[1], repo: httpsMatch[2], branch: \"main\" };\n }\n\n const sshMatch = url.match(/^git@github\\.com:([^/]+)\\/([^/]+?)(?:\\.git)?$/);\n if (sshMatch) {\n return { owner: sshMatch[1], repo: sshMatch[2], branch: \"main\" };\n }\n\n return null;\n}\n\nexport async function readTemplatekeep(sourceDir: string): Promise<string[]> {\n const keepFile = join(sourceDir, \".templatekeep\");\n if (!existsSync(keepFile)) {\n return [];\n }\n\n const content = readFileSync(keepFile, \"utf-8\");\n return content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0 && !line.startsWith(\"#\"));\n}\n\nexport async function copyFilteredFiles(\n sourceDir: string,\n destination: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<number> {\n if (patterns.length === 0) {\n return 0;\n }\n\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const filteredPatterns = effectivePatterns.filter((p) => {\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (!pluginMatch) return true;\n const pluginName = pluginMatch[1];\n return options.plugins?.includes(pluginName) ?? true;\n });\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of filteredPatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) {\n const pluginName = pluginMatch[1];\n if (!(options.plugins?.includes(pluginName) ?? true)) continue;\n }\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n const routeFiles = new Set<string>();\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n routeFiles.add(match);\n }\n }\n }\n }\n }\n\n for (const f of routeFiles) allFiles.add(f);\n\n mkdirSync(destination, { recursive: true });\n\n let count = 0;\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(destination, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n const content = readFileSync(src);\n writeFileSync(dest, content);\n count++;\n }\n\n return count;\n}\n\nfunction isRouteExcluded(filePath: string, excludedPatterns: string[]): boolean {\n if (excludedPatterns.length === 0) return false;\n for (const pattern of excludedPatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nexport async function personalizeConfig(\n destination: string,\n opts: {\n extendsAccount: string;\n extendsGateway: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n pluginRoutes?: Record<string, string[]>;\n workspaceOpts?: { localOverrides?: boolean; sourceDir?: string };\n mode?: \"init\" | \"sync\";\n withHost?: boolean;\n },\n): Promise<void> {\n const isInit = opts.mode !== \"sync\";\n const configPath = join(destination, \"bos.config.json\");\n if (existsSync(configPath)) {\n const config = JSON.parse(readFileSync(configPath, \"utf-8\")) as Record<string, unknown>;\n\n config.extends = `bos://${opts.extendsAccount}/${opts.extendsGateway}`;\n\n if (opts.account) {\n config.account = opts.account;\n }\n if (opts.domain) {\n config.domain = opts.domain;\n }\n\n if (isInit && config.app && typeof config.app === \"object\") {\n const app = config.app as Record<string, unknown>;\n\n for (const entryKey of Object.keys(app)) {\n const entry = app[entryKey];\n if (entry && typeof entry === \"object\") {\n const e = entry as Record<string, unknown>;\n delete e.production;\n delete e.integrity;\n delete e.ssr;\n delete e.ssrIntegrity;\n }\n }\n }\n\n if (config.plugins && typeof config.plugins === \"object\") {\n const plugins = config.plugins as Record<string, unknown>;\n\n if (opts.plugins && opts.plugins.length > 0) {\n for (const pluginKey of Object.keys(plugins)) {\n if (!opts.plugins.includes(pluginKey)) {\n delete plugins[pluginKey];\n }\n }\n }\n\n if (isInit) {\n for (const pluginKey of Object.keys(plugins)) {\n const plugin = plugins[pluginKey];\n if (plugin && typeof plugin === \"object\") {\n const p = plugin as Record<string, unknown>;\n delete p.production;\n delete p.integrity;\n }\n }\n }\n\n if (Object.keys(plugins).length === 0) {\n config.plugins = {};\n }\n }\n\n writeFileSync(configPath, `${JSON.stringify(rebuildOrderedConfig(config), null, 2)}\\n`);\n }\n\n const pkgPath = join(destination, \"package.json\");\n if (existsSync(pkgPath)) {\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const ws = pkg.workspaces as { packages?: string[] };\n if (Array.isArray(ws.packages)) {\n ws.packages = ws.packages.filter((p: string) => {\n if (p.startsWith(\"packages/\")) return false;\n if (p === \"host\") return opts.withHost ?? false;\n if (p === \"plugins/*\") return (opts.plugins?.length ?? 0) > 0;\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) return opts.plugins?.includes(pluginMatch[1]) ?? true;\n return true;\n });\n }\n }\n\n if (pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n const rewrite = (key: string, from: string, to: string) => {\n if (scripts[key]?.includes(from)) {\n scripts[key] = scripts[key].replaceAll(from, to);\n }\n };\n rewrite(\"dev\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:ui\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:api\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:proxy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"build\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"deploy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"publish\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"start\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n\n scripts.postinstall = \"node_modules/.bin/bos types gen || true\";\n scripts[\"types:gen\"] = \"node_modules/.bin/bos types gen\";\n if (scripts.typecheck) {\n scripts.typecheck = scripts.typecheck\n .replace(\"bun run types:gen && \", \"\")\n .replace(/bun run --cwd packages\\/everything-dev typecheck & ?/, \"\");\n if (!opts.withHost) {\n scripts.typecheck = scripts.typecheck.replace(/bun run --cwd host tsc --noEmit & ?/, \"\");\n }\n }\n }\n\n if (pkg.devDependencies && typeof pkg.devDependencies === \"object\") {\n const deps = pkg.devDependencies as Record<string, string>;\n delete deps[\"every-plugin\"];\n delete deps[\"everything-dev\"];\n }\n\n if (!pkg.workspaces || typeof pkg.workspaces !== \"object\") {\n pkg.workspaces = { packages: [], catalog: {} };\n }\n const workspaces = pkg.workspaces as { packages?: string[]; catalog?: Record<string, string> };\n if (!workspaces.catalog || typeof workspaces.catalog !== \"object\") {\n workspaces.catalog = {};\n }\n\n if (!pkg.dependencies) pkg.dependencies = {};\n const deps = pkg.dependencies as Record<string, string>;\n const spec = opts.workspaceOpts?.sourceDir\n ? loadManifestNormalizationSpec(opts.workspaceOpts.sourceDir)\n : null;\n if (spec) {\n workspaces.catalog[\"everything-dev\"] = spec.rootCatalog[\"everything-dev\"];\n workspaces.catalog[\"every-plugin\"] = spec.rootCatalog[\"every-plugin\"];\n }\n if (!deps[\"everything-dev\"] && spec) deps[\"everything-dev\"] = \"catalog:\";\n if (!deps[\"every-plugin\"] && spec) deps[\"every-plugin\"] = \"catalog:\";\n\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n\n const apiTsConfigPath = join(destination, \"api\", \"tsconfig.json\");\n if (existsSync(apiTsConfigPath)) {\n const apiTsConfig = JSON.parse(readFileSync(apiTsConfigPath, \"utf-8\")) as {\n files?: string[];\n [key: string]: unknown;\n };\n if (apiTsConfig.files) {\n const validFiles = apiTsConfig.files.filter((f) => existsSync(join(destination, \"api\", f)));\n if (validFiles.length !== apiTsConfig.files.length) {\n if (validFiles.length === 0) {\n delete apiTsConfig.files;\n } else {\n apiTsConfig.files = validFiles;\n }\n writeFileSync(apiTsConfigPath, `${JSON.stringify(apiTsConfig, null, 2)}\\n`);\n }\n }\n }\n\n await resolveWorkspaceRefs(destination, opts.workspaceOpts);\n\n const genContractPath = join(destination, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\");\n if (!existsSync(genContractPath)) {\n mkdirSync(dirname(genContractPath), { recursive: true });\n writeFileSync(genContractPath, `export type ApiContract = Record<string, never>;\\n`);\n }\n\n const pluginsClientGenPath = join(destination, \"api\", \"src\", \"lib\", \"plugins-types.gen.ts\");\n if (!existsSync(pluginsClientGenPath)) {\n mkdirSync(dirname(pluginsClientGenPath), { recursive: true });\n writeFileSync(\n pluginsClientGenPath,\n `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`,\n );\n }\n\n const authTypesGenPath = join(destination, \"ui\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(authTypesGenPath)) {\n mkdirSync(dirname(authTypesGenPath), { recursive: true });\n writeFileSync(\n authTypesGenPath,\n `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`,\n );\n }\n\n const apiAuthTypesGenPath = join(destination, \"api\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(apiAuthTypesGenPath)) {\n mkdirSync(dirname(apiAuthTypesGenPath), { recursive: true });\n writeFileSync(\n apiAuthTypesGenPath,\n `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`,\n );\n }\n\n const hostAuthTypesGenPath = join(destination, \"host\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (existsSync(join(destination, \"host\", \"src\")) && !existsSync(hostAuthTypesGenPath)) {\n mkdirSync(dirname(hostAuthTypesGenPath), { recursive: true });\n writeFileSync(\n hostAuthTypesGenPath,\n `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`,\n );\n }\n}\n\nexport async function runBunInstall(destination: string): Promise<void> {\n await execCommand(\"bun\", [\"install\", \"--ignore-scripts\"], destination);\n}\n\nexport async function runTypesGen(destination: string): Promise<void> {\n await execCommand(\"node_modules/.bin/bos\", [\"types\", \"gen\"], destination);\n}\n\nconst WORKSPACE_LOCAL_PATHS: Record<string, string> = {\n \"everything-dev\": \"packages/everything-dev\",\n \"every-plugin\": \"packages/every-plugin\",\n};\n\nasync function resolveWorkspaceRefs(\n destination: string,\n options?: { localOverrides?: boolean; sourceDir?: string },\n): Promise<void> {\n await normalizePackageManifestsInTree({\n sourceRootDir: options?.sourceDir ?? destination,\n targetDir: destination,\n resolveCatalogRefs: false,\n preserveCatalogRefs: true,\n removeWorkspaceDeps: [\"host\"],\n });\n\n if (options?.localOverrides && options.sourceDir) {\n const rootPkgPath = join(destination, \"package.json\");\n if (existsSync(rootPkgPath)) {\n const pkg = JSON.parse(readFileSync(rootPkgPath, \"utf-8\")) as Record<string, unknown>;\n if (!pkg.overrides) pkg.overrides = {};\n const overrides = pkg.overrides as Record<string, string>;\n\n const rootWorkspaces = ((pkg.workspaces as Record<string, string[]>)?.packages ?? []).filter(\n Boolean,\n );\n\n for (const [name, relPath] of Object.entries(WORKSPACE_LOCAL_PATHS)) {\n if (!rootWorkspaces.some((ws) => ws === relPath || ws === `plugins/${name}`)) {\n const srcPkgPath = join(options.sourceDir, relPath, \"package.json\");\n if (existsSync(srcPkgPath)) {\n overrides[name] = `file:${relPath}`;\n rootWorkspaces.push(relPath);\n }\n }\n }\n\n if (rootWorkspaces.length > 0) {\n if (!pkg.workspaces) pkg.workspaces = {};\n (pkg.workspaces as Record<string, string[]>).packages = rootWorkspaces;\n }\n\n writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n }\n}\n\nexport async function writeInitSnapshot(\n destination: string,\n extendsAccount: string,\n extendsGateway: string,\n sourceDir: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<void> {\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of effectivePatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !(options.plugins?.includes(pluginMatch[1]) ?? true)) continue;\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n allFiles.add(match);\n }\n }\n }\n }\n }\n\n const fileHashes: Record<string, string> = {};\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n fileHashes[destPath] = computeHash(content);\n }\n\n await writeSnapshot(destination, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: fileHashes,\n });\n}\n\nfunction computeHash(data: Uint8Array): string {\n return createHash(\"sha256\").update(data).digest(\"hex\").substring(0, 16);\n}\n\nfunction mkTmpDir(prefix: string): string {\n const base = join(tmpdir(), prefix);\n let attempt = 0;\n while (true) {\n const dir = `${base}-${Date.now()}-${attempt}`;\n try {\n mkdirSync(dir, { recursive: true });\n return dir;\n } catch {\n attempt++;\n if (attempt > 10) throw new Error(\"Failed to create temp directory\");\n }\n }\n}\n\nexport async function generateDatabaseMigrations(destination: string): Promise<void> {\n const drizzleConfigs = await glob(\"**/drizzle.config.ts\", {\n cwd: destination,\n nodir: true,\n dot: false,\n absolute: false,\n ignore: [\"**/node_modules/**\"],\n });\n\n for (const configPath of drizzleConfigs) {\n const workspaceDir = dirname(configPath);\n const pkgPath = join(destination, workspaceDir, \"package.json\");\n if (!existsSync(pkgPath)) continue;\n\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n const scripts = pkg.scripts as Record<string, string> | undefined;\n if (!scripts?.[\"db:generate\"]) continue;\n\n const cwd = join(destination, workspaceDir);\n await execCommand(\"bun\", [\"run\", \"db:generate\"], cwd);\n }\n}\n\nexport function execCommand(command: string, args: string[], cwd?: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n cwd,\n stdio: \"pipe\",\n shell: true,\n });\n let stderr = \"\";\n child.stderr?.on(\"data\", (data: Buffer) => {\n stderr += data.toString();\n });\n child.on(\"close\", (code) => {\n if (code === 0) resolve();\n else\n reject(\n new Error(\n `Command '${command} ${args.join(\" \")}' failed with exit code ${code}: ${stderr}`,\n ),\n );\n });\n child.on(\"error\", reject);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAMA,yFAAwC;AAE9C,MAAM,mBAAmB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,CAAC,OAAO,cAAc,sBAD9B,aAAa,aAAa,CACU;;;AAIzD,SAAgB,YAAY,SAAiB,MAAgB,KAA6B;AACxF,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,sCAAc,SAAS,MAAM;GACjC;GACA,OAAO;GACP,OAAO;GACR,CAAC;EACF,IAAI,SAAS;AACb,QAAM,QAAQ,GAAG,SAAS,SAAiB;AACzC,aAAU,KAAK,UAAU;IACzB;AACF,QAAM,GAAG,UAAU,SAAS;AAC1B,OAAI,SAAS,EAAG,UAAS;OAEvB,wBACE,IAAI,MACF,YAAY,QAAQ,GAAG,KAAK,KAAK,IAAI,CAAC,0BAA0B,KAAK,IAAI,SAC1E,CACF;IACH;AACF,QAAM,GAAG,SAAS,OAAO;GACzB"}
|
package/dist/cli/init.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.cts","names":[],"sources":["../../src/cli/init.ts"],"mappings":";;;UAwDU,YAAA;EACR,SAAA;EACA,YAAA,EAAc,SAAA;EACd,OAAA,QAAe,OAAA;AAAA;AAAA,iBAGK,gBAAA,CAAiB,IAAA;EACrC,cAAA;EACA,cAAA;EACA,MAAA;AAAA,IACE,OAAA,CAAQ,YAAA;AAAA,iBAsBU,iBAAA,CACpB,cAAA,UACA,cAAA,WACC,OAAA,CAAQ,SAAA;AAAA,iBAKW,eAAA,CACpB,OAAA,WACC,OAAA;EAAU,GAAA;EAAa,OAAA,QAAe,OAAA;AAAA;AAAA,iBAiEnB,gBAAA,CAAiB,SAAA,WAAoB,OAAA;AAAA,iBAarC,iBAAA,CACpB,SAAA,UACA,WAAA,UACA,QAAA,YACA,OAAA;EAAW,QAAA;EAAmB,OAAA;EAAoB,YAAA,GAAe,MAAA;AAAA,IAChE,OAAA;AAAA,iBAoGmB,iBAAA,CACpB,WAAA,UACA,IAAA;EACE,cAAA;EACA,cAAA;EACA,OAAA;EACA,MAAA;EACA,OAAA;EACA,YAAA,GAAe,MAAA;E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A,YAAe,OAAA"}
|
package/dist/cli/init.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.mts","names":[],"sources":["../../src/cli/init.ts"],"mappings":";;;UAwDU,YAAA;EACR,SAAA;EACA,YAAA,EAAc,SAAA;EACd,OAAA,QAAe,OAAA;AAAA;AAAA,iBAGK,gBAAA,CAAiB,IAAA;EACrC,cAAA;EACA,cAAA;EACA,MAAA;AAAA,IACE,OAAA,CAAQ,YAAA;AAAA,iBAsBU,iBAAA,CACpB,cAAA,UACA,cAAA,WACC,OAAA,CAAQ,SAAA;AAAA,iBAKW,eAAA,CACpB,OAAA,WACC,OAAA;EAAU,GAAA;EAAa,OAAA,QAAe,OAAA;AAAA;AAAA,iBAiEnB,gBAAA,CAAiB,SAAA,WAAoB,OAAA;AAAA,iBAarC,iBAAA,CACpB,SAAA,UACA,WAAA,UACA,QAAA,YACA,OAAA;EAAW,QAAA;EAAmB,OAAA;EAAoB,YAAA,GAAe,MAAA;AAAA,IAChE,OAAA;AAAA,iBAoGmB,iBAAA,CACpB,WAAA,UACA,IAAA;EACE,cAAA;EACA,cAAA;EACA,OAAA;EACA,MAAA;EACA,OAAA;EACA,YAAA,GAAe,MAAA;EACf,aAAA;IAAkB,cAAA;IAA0B,SAAA;EAAA;EAC5C,IAAA;EACA,QAAA;AAAA,IAED,OAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"init.d.mts","names":[],"sources":["../../src/cli/init.ts"],"mappings":";;;UAwDU,YAAA;EACR,SAAA;EACA,YAAA,EAAc,SAAA;EACd,OAAA,QAAe,OAAA;AAAA;AAAA,iBAGK,gBAAA,CAAiB,IAAA;EACrC,cAAA;EACA,cAAA;EACA,MAAA;AAAA,IACE,OAAA,CAAQ,YAAA;AAAA,iBAsBU,iBAAA,CACpB,cAAA,UACA,cAAA,WACC,OAAA,CAAQ,SAAA;AAAA,iBAKW,eAAA,CACpB,OAAA,WACC,OAAA;EAAU,GAAA;EAAa,OAAA,QAAe,OAAA;AAAA;AAAA,iBAiEnB,gBAAA,CAAiB,SAAA,WAAoB,OAAA;AAAA,iBAarC,iBAAA,CACpB,SAAA,UACA,WAAA,UACA,QAAA,YACA,OAAA;EAAW,QAAA;EAAmB,OAAA;EAAoB,YAAA,GAAe,MAAA;AAAA,IAChE,OAAA;AAAA,iBAoGmB,iBAAA,CACpB,WAAA,UACA,IAAA;EACE,cAAA;EACA,cAAA;EACA,OAAA;EACA,MAAA;EACA,OAAA;EACA,YAAA,GAAe,MAAA;EACf,aAAA;IAAkB,cAAA;IAA0B,SAAA;EAAA;EAC5C,IAAA;EACA,QAAA;AAAA,IAED,OAAA;AAAA,iBAuMmB,aAAA,CAAc,WAAA,WAAsB,OAAA;AAAA,iBAIpC,WAAA,CAAY,WAAA,WAAsB,OAAA;AAAA,iBAoDlC,iBAAA,CACpB,WAAA,UACA,cAAA,UACA,cAAA,UACA,SAAA,UACA,QAAA,YACA,OAAA;EAAW,QAAA;EAAmB,OAAA;EAAoB,YAAA,GAAe,MAAA;AAAA,IAChE,OAAA;AAAA,iBAsFmB,0BAAA,CAA2B,WAAA,WAAsB,OAAA;AAAA,iBAuBvD,WAAA,CAAY,OAAA,UAAiB,IAAA,YAAgB,GAAA,YAAe,OAAA"}
|
package/dist/cli/init.mjs
CHANGED
|
@@ -270,11 +270,21 @@ async function personalizeConfig(destination, opts) {
|
|
|
270
270
|
delete deps["every-plugin"];
|
|
271
271
|
delete deps["everything-dev"];
|
|
272
272
|
}
|
|
273
|
+
if (!pkg.workspaces || typeof pkg.workspaces !== "object") pkg.workspaces = {
|
|
274
|
+
packages: [],
|
|
275
|
+
catalog: {}
|
|
276
|
+
};
|
|
277
|
+
const workspaces = pkg.workspaces;
|
|
278
|
+
if (!workspaces.catalog || typeof workspaces.catalog !== "object") workspaces.catalog = {};
|
|
273
279
|
if (!pkg.dependencies) pkg.dependencies = {};
|
|
274
280
|
const deps = pkg.dependencies;
|
|
275
281
|
const spec = opts.workspaceOpts?.sourceDir ? loadManifestNormalizationSpec(opts.workspaceOpts.sourceDir) : null;
|
|
276
|
-
if (
|
|
277
|
-
|
|
282
|
+
if (spec) {
|
|
283
|
+
workspaces.catalog["everything-dev"] = spec.rootCatalog["everything-dev"];
|
|
284
|
+
workspaces.catalog["every-plugin"] = spec.rootCatalog["every-plugin"];
|
|
285
|
+
}
|
|
286
|
+
if (!deps["everything-dev"] && spec) deps["everything-dev"] = "catalog:";
|
|
287
|
+
if (!deps["every-plugin"] && spec) deps["every-plugin"] = "catalog:";
|
|
278
288
|
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
279
289
|
}
|
|
280
290
|
const apiTsConfigPath = join(destination, "api", "tsconfig.json");
|
|
@@ -330,7 +340,8 @@ async function resolveWorkspaceRefs(destination, options) {
|
|
|
330
340
|
await normalizePackageManifestsInTree({
|
|
331
341
|
sourceRootDir: options?.sourceDir ?? destination,
|
|
332
342
|
targetDir: destination,
|
|
333
|
-
resolveCatalogRefs:
|
|
343
|
+
resolveCatalogRefs: false,
|
|
344
|
+
preserveCatalogRefs: true,
|
|
334
345
|
removeWorkspaceDeps: ["host"]
|
|
335
346
|
});
|
|
336
347
|
if (options?.localOverrides && options.sourceDir) {
|
package/dist/cli/init.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.mjs","names":[],"sources":["../../src/cli/init.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport {\n createWriteStream,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { glob } from \"glob\";\nimport { fetchBosConfigFromFastKv } from \"../fastkv\";\nimport {\n loadManifestNormalizationSpec,\n normalizePackageManifestsInTree,\n} from \"../internal/manifest-normalizer\";\nimport type { BosConfig } from \"../types\";\nimport { writeSnapshot } from \"./snapshot\";\n\nconst require = createRequire(import.meta.url);\n\nconst BOS_CONFIG_ORDER = [\n \"extends\",\n \"account\",\n \"domain\",\n \"testnet\",\n \"staging\",\n \"repository\",\n \"app\",\n \"plugins\",\n \"shared\",\n];\n\nfunction rebuildOrderedConfig(config: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n\n for (const key of BOS_CONFIG_ORDER) {\n if (key in config) {\n ordered[key] = config[key];\n }\n }\n\n for (const key of Object.keys(config)) {\n if (!BOS_CONFIG_ORDER.includes(key)) {\n ordered[key] = config[key];\n }\n }\n\n return ordered;\n}\n\ninterface SourceResult {\n sourceDir: string;\n parentConfig: BosConfig;\n cleanup: () => Promise<void>;\n}\n\nexport async function resolveSourceDir(opts: {\n extendsAccount: string;\n extendsGateway: string;\n source?: string;\n}): Promise<SourceResult> {\n if (opts.source) {\n const sourceDir = resolve(opts.source);\n if (!existsSync(join(sourceDir, \"bos.config.json\"))) {\n throw new Error(`No bos.config.json found in source directory: ${sourceDir}`);\n }\n const parentConfig = JSON.parse(\n readFileSync(join(sourceDir, \"bos.config.json\"), \"utf-8\"),\n ) as BosConfig;\n return { sourceDir, parentConfig, cleanup: async () => {} };\n }\n\n const parentConfig = await fetchParentConfig(opts.extendsAccount, opts.extendsGateway);\n\n if (!parentConfig.repository) {\n throw new Error(\"Parent config has no repository field — cannot locate template source\");\n }\n\n const { dir: sourceDir, cleanup } = await downloadTarball(parentConfig.repository);\n return { sourceDir, parentConfig, cleanup };\n}\n\nexport async function fetchParentConfig(\n extendsAccount: string,\n extendsGateway: string,\n): Promise<BosConfig> {\n const bosUrl = `bos://${extendsAccount}/${extendsGateway}`;\n return fetchBosConfigFromFastKv<BosConfig>(bosUrl);\n}\n\nexport async function downloadTarball(\n repoUrl: string,\n): Promise<{ dir: string; cleanup: () => Promise<void> }> {\n const parsed = parseGitHubUrl(repoUrl);\n if (!parsed) {\n throw new Error(`Cannot parse repository URL: ${repoUrl}`);\n }\n\n const { owner, repo, branch } = parsed;\n const tarballUrl = `https://api.github.com/repos/${owner}/${repo}/tarball/${branch}`;\n\n const tmpDir = mkTmpDir(\"bos-init-tarball-\");\n const tarballPath = join(tmpDir, \"source.tar.gz\");\n\n const response = await fetch(tarballUrl, {\n headers: { \"User-Agent\": \"everything-dev\" },\n redirect: \"follow\",\n });\n\n if (!response.ok) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(`GitHub tarball download failed: ${response.status} ${response.statusText}`);\n }\n\n if (!response.body) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(\"GitHub tarball download returned empty body\");\n }\n\n const fileStream = createWriteStream(tarballPath);\n const reader = response.body as unknown as NodeJS.ReadableStream;\n await pipeline(reader, fileStream);\n\n const extractDir = mkTmpDir(\"bos-init-extract-\");\n try {\n const tar = require(\"tar\") as {\n extract: (opts: { cwd: string; file: string; strip: number }) => Promise<void>;\n };\n await tar.extract({ cwd: extractDir, file: tarballPath, strip: 1 });\n } catch {\n await execCommand(\"tar\", [\"-xzf\", tarballPath, \"--strip-components=1\", \"-C\", extractDir]);\n }\n\n rmSync(tmpDir, { recursive: true, force: true });\n\n return {\n dir: extractDir,\n cleanup: async () => {\n rmSync(extractDir, { recursive: true, force: true });\n },\n };\n}\n\nfunction parseGitHubUrl(url: string): { owner: string; repo: string; branch: string } | null {\n const httpsMatch = url.match(/^https?:\\/\\/github\\.com\\/([^/]+)\\/([^/]+?)(?:\\.git)?(?:\\/.*)?$/);\n if (httpsMatch) {\n return { owner: httpsMatch[1], repo: httpsMatch[2], branch: \"main\" };\n }\n\n const sshMatch = url.match(/^git@github\\.com:([^/]+)\\/([^/]+?)(?:\\.git)?$/);\n if (sshMatch) {\n return { owner: sshMatch[1], repo: sshMatch[2], branch: \"main\" };\n }\n\n return null;\n}\n\nexport async function readTemplatekeep(sourceDir: string): Promise<string[]> {\n const keepFile = join(sourceDir, \".templatekeep\");\n if (!existsSync(keepFile)) {\n return [];\n }\n\n const content = readFileSync(keepFile, \"utf-8\");\n return content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0 && !line.startsWith(\"#\"));\n}\n\nexport async function copyFilteredFiles(\n sourceDir: string,\n destination: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<number> {\n if (patterns.length === 0) {\n return 0;\n }\n\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const filteredPatterns = effectivePatterns.filter((p) => {\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (!pluginMatch) return true;\n const pluginName = pluginMatch[1];\n return options.plugins?.includes(pluginName) ?? true;\n });\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of filteredPatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) {\n const pluginName = pluginMatch[1];\n if (!(options.plugins?.includes(pluginName) ?? true)) continue;\n }\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n const routeFiles = new Set<string>();\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n routeFiles.add(match);\n }\n }\n }\n }\n }\n\n for (const f of routeFiles) allFiles.add(f);\n\n mkdirSync(destination, { recursive: true });\n\n let count = 0;\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(destination, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n const content = readFileSync(src);\n writeFileSync(dest, content);\n count++;\n }\n\n return count;\n}\n\nfunction isRouteExcluded(filePath: string, excludedPatterns: string[]): boolean {\n if (excludedPatterns.length === 0) return false;\n for (const pattern of excludedPatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nexport async function personalizeConfig(\n destination: string,\n opts: {\n extendsAccount: string;\n extendsGateway: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n pluginRoutes?: Record<string, string[]>;\n workspaceOpts?: { localOverrides?: boolean; sourceDir?: string };\n mode?: \"init\" | \"sync\";\n withHost?: boolean;\n },\n): Promise<void> {\n const isInit = opts.mode !== \"sync\";\n const configPath = join(destination, \"bos.config.json\");\n if (existsSync(configPath)) {\n const config = JSON.parse(readFileSync(configPath, \"utf-8\")) as Record<string, unknown>;\n\n config.extends = `bos://${opts.extendsAccount}/${opts.extendsGateway}`;\n\n if (opts.account) {\n config.account = opts.account;\n }\n if (opts.domain) {\n config.domain = opts.domain;\n }\n\n if (isInit && config.app && typeof config.app === \"object\") {\n const app = config.app as Record<string, unknown>;\n\n for (const entryKey of Object.keys(app)) {\n const entry = app[entryKey];\n if (entry && typeof entry === \"object\") {\n const e = entry as Record<string, unknown>;\n delete e.production;\n delete e.integrity;\n delete e.ssr;\n delete e.ssrIntegrity;\n }\n }\n }\n\n if (config.plugins && typeof config.plugins === \"object\") {\n const plugins = config.plugins as Record<string, unknown>;\n\n if (opts.plugins && opts.plugins.length > 0) {\n for (const pluginKey of Object.keys(plugins)) {\n if (!opts.plugins.includes(pluginKey)) {\n delete plugins[pluginKey];\n }\n }\n }\n\n if (isInit) {\n for (const pluginKey of Object.keys(plugins)) {\n const plugin = plugins[pluginKey];\n if (plugin && typeof plugin === \"object\") {\n const p = plugin as Record<string, unknown>;\n delete p.production;\n delete p.integrity;\n }\n }\n }\n\n if (Object.keys(plugins).length === 0) {\n config.plugins = {};\n }\n }\n\n writeFileSync(configPath, `${JSON.stringify(rebuildOrderedConfig(config), null, 2)}\\n`);\n }\n\n const pkgPath = join(destination, \"package.json\");\n if (existsSync(pkgPath)) {\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const ws = pkg.workspaces as { packages?: string[] };\n if (Array.isArray(ws.packages)) {\n ws.packages = ws.packages.filter((p: string) => {\n if (p.startsWith(\"packages/\")) return false;\n if (p === \"host\") return opts.withHost ?? false;\n if (p === \"plugins/*\") return (opts.plugins?.length ?? 0) > 0;\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) return opts.plugins?.includes(pluginMatch[1]) ?? true;\n return true;\n });\n }\n }\n\n if (pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n const rewrite = (key: string, from: string, to: string) => {\n if (scripts[key]?.includes(from)) {\n scripts[key] = scripts[key].replaceAll(from, to);\n }\n };\n rewrite(\"dev\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:ui\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:api\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:proxy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"build\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"deploy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"publish\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"start\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n\n scripts.postinstall = \"node_modules/.bin/bos types gen || true\";\n scripts[\"types:gen\"] = \"node_modules/.bin/bos types gen\";\n if (scripts.typecheck) {\n scripts.typecheck = scripts.typecheck\n .replace(\"bun run types:gen && \", \"\")\n .replace(/bun run --cwd packages\\/everything-dev typecheck & ?/, \"\");\n if (!opts.withHost) {\n scripts.typecheck = scripts.typecheck.replace(/bun run --cwd host tsc --noEmit & ?/, \"\");\n }\n }\n }\n\n if (pkg.devDependencies && typeof pkg.devDependencies === \"object\") {\n const deps = pkg.devDependencies as Record<string, string>;\n delete deps[\"every-plugin\"];\n delete deps[\"everything-dev\"];\n }\n\n if (!pkg.dependencies) pkg.dependencies = {};\n const deps = pkg.dependencies as Record<string, string>;\n const spec = opts.workspaceOpts?.sourceDir\n ? loadManifestNormalizationSpec(opts.workspaceOpts.sourceDir)\n : null;\n if (!deps[\"everything-dev\"] && spec)\n deps[\"everything-dev\"] = spec.rootCatalog[\"everything-dev\"];\n if (!deps[\"every-plugin\"] && spec) deps[\"every-plugin\"] = spec.rootCatalog[\"every-plugin\"];\n\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n\n const apiTsConfigPath = join(destination, \"api\", \"tsconfig.json\");\n if (existsSync(apiTsConfigPath)) {\n const apiTsConfig = JSON.parse(readFileSync(apiTsConfigPath, \"utf-8\")) as {\n files?: string[];\n [key: string]: unknown;\n };\n if (apiTsConfig.files) {\n const validFiles = apiTsConfig.files.filter((f) => existsSync(join(destination, \"api\", f)));\n if (validFiles.length !== apiTsConfig.files.length) {\n if (validFiles.length === 0) {\n delete apiTsConfig.files;\n } else {\n apiTsConfig.files = validFiles;\n }\n writeFileSync(apiTsConfigPath, `${JSON.stringify(apiTsConfig, null, 2)}\\n`);\n }\n }\n }\n\n await resolveWorkspaceRefs(destination, opts.workspaceOpts);\n\n const genContractPath = join(destination, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\");\n if (!existsSync(genContractPath)) {\n mkdirSync(dirname(genContractPath), { recursive: true });\n writeFileSync(genContractPath, `export type ApiContract = Record<string, never>;\\n`);\n }\n\n const pluginsClientGenPath = join(destination, \"api\", \"src\", \"lib\", \"plugins-types.gen.ts\");\n if (!existsSync(pluginsClientGenPath)) {\n mkdirSync(dirname(pluginsClientGenPath), { recursive: true });\n writeFileSync(\n pluginsClientGenPath,\n `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`,\n );\n }\n\n const authTypesGenPath = join(destination, \"ui\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(authTypesGenPath)) {\n mkdirSync(dirname(authTypesGenPath), { recursive: true });\n writeFileSync(\n authTypesGenPath,\n `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`,\n );\n }\n\n const apiAuthTypesGenPath = join(destination, \"api\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(apiAuthTypesGenPath)) {\n mkdirSync(dirname(apiAuthTypesGenPath), { recursive: true });\n writeFileSync(\n apiAuthTypesGenPath,\n `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`,\n );\n }\n\n const hostAuthTypesGenPath = join(destination, \"host\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (existsSync(join(destination, \"host\", \"src\")) && !existsSync(hostAuthTypesGenPath)) {\n mkdirSync(dirname(hostAuthTypesGenPath), { recursive: true });\n writeFileSync(\n hostAuthTypesGenPath,\n `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`,\n );\n }\n}\n\nexport async function runBunInstall(destination: string): Promise<void> {\n await execCommand(\"bun\", [\"install\", \"--ignore-scripts\"], destination);\n}\n\nexport async function runTypesGen(destination: string): Promise<void> {\n await execCommand(\"node_modules/.bin/bos\", [\"types\", \"gen\"], destination);\n}\n\nconst WORKSPACE_LOCAL_PATHS: Record<string, string> = {\n \"everything-dev\": \"packages/everything-dev\",\n \"every-plugin\": \"packages/every-plugin\",\n};\n\nasync function resolveWorkspaceRefs(\n destination: string,\n options?: { localOverrides?: boolean; sourceDir?: string },\n): Promise<void> {\n await normalizePackageManifestsInTree({\n sourceRootDir: options?.sourceDir ?? destination,\n targetDir: destination,\n resolveCatalogRefs: true,\n removeWorkspaceDeps: [\"host\"],\n });\n\n if (options?.localOverrides && options.sourceDir) {\n const rootPkgPath = join(destination, \"package.json\");\n if (existsSync(rootPkgPath)) {\n const pkg = JSON.parse(readFileSync(rootPkgPath, \"utf-8\")) as Record<string, unknown>;\n if (!pkg.overrides) pkg.overrides = {};\n const overrides = pkg.overrides as Record<string, string>;\n\n const rootWorkspaces = ((pkg.workspaces as Record<string, string[]>)?.packages ?? []).filter(\n Boolean,\n );\n\n for (const [name, relPath] of Object.entries(WORKSPACE_LOCAL_PATHS)) {\n if (!rootWorkspaces.some((ws) => ws === relPath || ws === `plugins/${name}`)) {\n const srcPkgPath = join(options.sourceDir, relPath, \"package.json\");\n if (existsSync(srcPkgPath)) {\n overrides[name] = `file:${relPath}`;\n rootWorkspaces.push(relPath);\n }\n }\n }\n\n if (rootWorkspaces.length > 0) {\n if (!pkg.workspaces) pkg.workspaces = {};\n (pkg.workspaces as Record<string, string[]>).packages = rootWorkspaces;\n }\n\n writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n }\n}\n\nexport async function writeInitSnapshot(\n destination: string,\n extendsAccount: string,\n extendsGateway: string,\n sourceDir: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<void> {\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of effectivePatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !(options.plugins?.includes(pluginMatch[1]) ?? true)) continue;\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n allFiles.add(match);\n }\n }\n }\n }\n }\n\n const fileHashes: Record<string, string> = {};\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n fileHashes[destPath] = computeHash(content);\n }\n\n await writeSnapshot(destination, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: fileHashes,\n });\n}\n\nfunction computeHash(data: Uint8Array): string {\n return createHash(\"sha256\").update(data).digest(\"hex\").substring(0, 16);\n}\n\nfunction mkTmpDir(prefix: string): string {\n const base = join(tmpdir(), prefix);\n let attempt = 0;\n while (true) {\n const dir = `${base}-${Date.now()}-${attempt}`;\n try {\n mkdirSync(dir, { recursive: true });\n return dir;\n } catch {\n attempt++;\n if (attempt > 10) throw new Error(\"Failed to create temp directory\");\n }\n }\n}\n\nexport async function generateDatabaseMigrations(destination: string): Promise<void> {\n const drizzleConfigs = await glob(\"**/drizzle.config.ts\", {\n cwd: destination,\n nodir: true,\n dot: false,\n absolute: false,\n ignore: [\"**/node_modules/**\"],\n });\n\n for (const configPath of drizzleConfigs) {\n const workspaceDir = dirname(configPath);\n const pkgPath = join(destination, workspaceDir, \"package.json\");\n if (!existsSync(pkgPath)) continue;\n\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n const scripts = pkg.scripts as Record<string, string> | undefined;\n if (!scripts?.[\"db:generate\"]) continue;\n\n const cwd = join(destination, workspaceDir);\n await execCommand(\"bun\", [\"run\", \"db:generate\"], cwd);\n }\n}\n\nexport function execCommand(command: string, args: string[], cwd?: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n cwd,\n stdio: \"pipe\",\n shell: true,\n });\n let stderr = \"\";\n child.stderr?.on(\"data\", (data: Buffer) => {\n stderr += data.toString();\n });\n child.on(\"close\", (code) => {\n if (code === 0) resolve();\n else\n reject(\n new Error(\n `Command '${command} ${args.join(\" \")}' failed with exit code ${code}: ${stderr}`,\n ),\n );\n });\n child.on(\"error\", reject);\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,qBAAqB,QAA0D;CACtF,MAAM,UAAmC,EAAE;AAE3C,MAAK,MAAM,OAAO,iBAChB,KAAI,OAAO,OACT,SAAQ,OAAO,OAAO;AAI1B,MAAK,MAAM,OAAO,OAAO,KAAK,OAAO,CACnC,KAAI,CAAC,iBAAiB,SAAS,IAAI,CACjC,SAAQ,OAAO,OAAO;AAI1B,QAAO;;AAST,eAAsB,iBAAiB,MAIb;AACxB,KAAI,KAAK,QAAQ;EACf,MAAM,YAAY,QAAQ,KAAK,OAAO;AACtC,MAAI,CAAC,WAAW,KAAK,WAAW,kBAAkB,CAAC,CACjD,OAAM,IAAI,MAAM,iDAAiD,YAAY;AAK/E,SAAO;GAAE;GAAW,cAHC,KAAK,MACxB,aAAa,KAAK,WAAW,kBAAkB,EAAE,QAAQ,CAC1D;GACiC,SAAS,YAAY;GAAI;;CAG7D,MAAM,eAAe,MAAM,kBAAkB,KAAK,gBAAgB,KAAK,eAAe;AAEtF,KAAI,CAAC,aAAa,WAChB,OAAM,IAAI,MAAM,wEAAwE;CAG1F,MAAM,EAAE,KAAK,WAAW,YAAY,MAAM,gBAAgB,aAAa,WAAW;AAClF,QAAO;EAAE;EAAW;EAAc;EAAS;;AAG7C,eAAsB,kBACpB,gBACA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1E,eAAsB,2BAA2B,aAAoC;CACnF,MAAM,iBAAiB,MAAM,KAAK,wBAAwB;EACxD,KAAK;EACL,OAAO;EACP,KAAK;EACL,UAAU;EACV,QAAQ,CAAC,qBAAqB;EAC/B,CAAC;AAEF,MAAK,MAAM,cAAc,gBAAgB;EACvC,MAAM,eAAe,QAAQ,WAAW;EACxC,MAAM,UAAU,KAAK,aAAa,cAAc,eAAe;AAC/D,MAAI,CAAC,WAAW,QAAQ,CAAE;AAI1B,MAAI,CAFQ,KAAK,MAAM,aAAa,SAAS,QAAQ,CAAC,CAClC,UACL,eAAgB;AAG/B,QAAM,YAAY,OAAO,CAAC,OAAO,cAAc,EADnC,KAAK,aAAa,aAAa,CACU;;;AAIzD,SAAgB,YAAY,SAAiB,MAAgB,KAA6B;AACxF,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,QAAQ,MAAM,SAAS,MAAM;GACjC;GACA,OAAO;GACP,OAAO;GACR,CAAC;EACF,IAAI,SAAS;AACb,QAAM,QAAQ,GAAG,SAAS,SAAiB;AACzC,aAAU,KAAK,UAAU;IACzB;AACF,QAAM,GAAG,UAAU,SAAS;AAC1B,OAAI,SAAS,EAAG,UAAS;OAEvB,wBACE,IAAI,MACF,YAAY,QAAQ,GAAG,KAAK,KAAK,IAAI,CAAC,0BAA0B,KAAK,IAAI,SAC1E,CACF;IACH;AACF,QAAM,GAAG,SAAS,OAAO;GACzB"}
|
|
1
|
+
{"version":3,"file":"init.mjs","names":[],"sources":["../../src/cli/init.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport {\n createWriteStream,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { glob } from \"glob\";\nimport { fetchBosConfigFromFastKv } from \"../fastkv\";\nimport {\n loadManifestNormalizationSpec,\n normalizePackageManifestsInTree,\n} from \"../internal/manifest-normalizer\";\nimport type { BosConfig } from \"../types\";\nimport { writeSnapshot } from \"./snapshot\";\n\nconst require = createRequire(import.meta.url);\n\nconst BOS_CONFIG_ORDER = [\n \"extends\",\n \"account\",\n \"domain\",\n \"testnet\",\n \"staging\",\n \"repository\",\n \"app\",\n \"plugins\",\n \"shared\",\n];\n\nfunction rebuildOrderedConfig(config: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n\n for (const key of BOS_CONFIG_ORDER) {\n if (key in config) {\n ordered[key] = config[key];\n }\n }\n\n for (const key of Object.keys(config)) {\n if (!BOS_CONFIG_ORDER.includes(key)) {\n ordered[key] = config[key];\n }\n }\n\n return ordered;\n}\n\ninterface SourceResult {\n sourceDir: string;\n parentConfig: BosConfig;\n cleanup: () => Promise<void>;\n}\n\nexport async function resolveSourceDir(opts: {\n extendsAccount: string;\n extendsGateway: string;\n source?: string;\n}): Promise<SourceResult> {\n if (opts.source) {\n const sourceDir = resolve(opts.source);\n if (!existsSync(join(sourceDir, \"bos.config.json\"))) {\n throw new Error(`No bos.config.json found in source directory: ${sourceDir}`);\n }\n const parentConfig = JSON.parse(\n readFileSync(join(sourceDir, \"bos.config.json\"), \"utf-8\"),\n ) as BosConfig;\n return { sourceDir, parentConfig, cleanup: async () => {} };\n }\n\n const parentConfig = await fetchParentConfig(opts.extendsAccount, opts.extendsGateway);\n\n if (!parentConfig.repository) {\n throw new Error(\"Parent config has no repository field — cannot locate template source\");\n }\n\n const { dir: sourceDir, cleanup } = await downloadTarball(parentConfig.repository);\n return { sourceDir, parentConfig, cleanup };\n}\n\nexport async function fetchParentConfig(\n extendsAccount: string,\n extendsGateway: string,\n): Promise<BosConfig> {\n const bosUrl = `bos://${extendsAccount}/${extendsGateway}`;\n return fetchBosConfigFromFastKv<BosConfig>(bosUrl);\n}\n\nexport async function downloadTarball(\n repoUrl: string,\n): Promise<{ dir: string; cleanup: () => Promise<void> }> {\n const parsed = parseGitHubUrl(repoUrl);\n if (!parsed) {\n throw new Error(`Cannot parse repository URL: ${repoUrl}`);\n }\n\n const { owner, repo, branch } = parsed;\n const tarballUrl = `https://api.github.com/repos/${owner}/${repo}/tarball/${branch}`;\n\n const tmpDir = mkTmpDir(\"bos-init-tarball-\");\n const tarballPath = join(tmpDir, \"source.tar.gz\");\n\n const response = await fetch(tarballUrl, {\n headers: { \"User-Agent\": \"everything-dev\" },\n redirect: \"follow\",\n });\n\n if (!response.ok) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(`GitHub tarball download failed: ${response.status} ${response.statusText}`);\n }\n\n if (!response.body) {\n rmSync(tmpDir, { recursive: true, force: true });\n throw new Error(\"GitHub tarball download returned empty body\");\n }\n\n const fileStream = createWriteStream(tarballPath);\n const reader = response.body as unknown as NodeJS.ReadableStream;\n await pipeline(reader, fileStream);\n\n const extractDir = mkTmpDir(\"bos-init-extract-\");\n try {\n const tar = require(\"tar\") as {\n extract: (opts: { cwd: string; file: string; strip: number }) => Promise<void>;\n };\n await tar.extract({ cwd: extractDir, file: tarballPath, strip: 1 });\n } catch {\n await execCommand(\"tar\", [\"-xzf\", tarballPath, \"--strip-components=1\", \"-C\", extractDir]);\n }\n\n rmSync(tmpDir, { recursive: true, force: true });\n\n return {\n dir: extractDir,\n cleanup: async () => {\n rmSync(extractDir, { recursive: true, force: true });\n },\n };\n}\n\nfunction parseGitHubUrl(url: string): { owner: string; repo: string; branch: string } | null {\n const httpsMatch = url.match(/^https?:\\/\\/github\\.com\\/([^/]+)\\/([^/]+?)(?:\\.git)?(?:\\/.*)?$/);\n if (httpsMatch) {\n return { owner: httpsMatch[1], repo: httpsMatch[2], branch: \"main\" };\n }\n\n const sshMatch = url.match(/^git@github\\.com:([^/]+)\\/([^/]+?)(?:\\.git)?$/);\n if (sshMatch) {\n return { owner: sshMatch[1], repo: sshMatch[2], branch: \"main\" };\n }\n\n return null;\n}\n\nexport async function readTemplatekeep(sourceDir: string): Promise<string[]> {\n const keepFile = join(sourceDir, \".templatekeep\");\n if (!existsSync(keepFile)) {\n return [];\n }\n\n const content = readFileSync(keepFile, \"utf-8\");\n return content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0 && !line.startsWith(\"#\"));\n}\n\nexport async function copyFilteredFiles(\n sourceDir: string,\n destination: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<number> {\n if (patterns.length === 0) {\n return 0;\n }\n\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const filteredPatterns = effectivePatterns.filter((p) => {\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (!pluginMatch) return true;\n const pluginName = pluginMatch[1];\n return options.plugins?.includes(pluginName) ?? true;\n });\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of filteredPatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) {\n const pluginName = pluginMatch[1];\n if (!(options.plugins?.includes(pluginName) ?? true)) continue;\n }\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n const routeFiles = new Set<string>();\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n routeFiles.add(match);\n }\n }\n }\n }\n }\n\n for (const f of routeFiles) allFiles.add(f);\n\n mkdirSync(destination, { recursive: true });\n\n let count = 0;\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(destination, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n const content = readFileSync(src);\n writeFileSync(dest, content);\n count++;\n }\n\n return count;\n}\n\nfunction isRouteExcluded(filePath: string, excludedPatterns: string[]): boolean {\n if (excludedPatterns.length === 0) return false;\n for (const pattern of excludedPatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nexport async function personalizeConfig(\n destination: string,\n opts: {\n extendsAccount: string;\n extendsGateway: string;\n account?: string;\n domain?: string;\n plugins?: string[];\n pluginRoutes?: Record<string, string[]>;\n workspaceOpts?: { localOverrides?: boolean; sourceDir?: string };\n mode?: \"init\" | \"sync\";\n withHost?: boolean;\n },\n): Promise<void> {\n const isInit = opts.mode !== \"sync\";\n const configPath = join(destination, \"bos.config.json\");\n if (existsSync(configPath)) {\n const config = JSON.parse(readFileSync(configPath, \"utf-8\")) as Record<string, unknown>;\n\n config.extends = `bos://${opts.extendsAccount}/${opts.extendsGateway}`;\n\n if (opts.account) {\n config.account = opts.account;\n }\n if (opts.domain) {\n config.domain = opts.domain;\n }\n\n if (isInit && config.app && typeof config.app === \"object\") {\n const app = config.app as Record<string, unknown>;\n\n for (const entryKey of Object.keys(app)) {\n const entry = app[entryKey];\n if (entry && typeof entry === \"object\") {\n const e = entry as Record<string, unknown>;\n delete e.production;\n delete e.integrity;\n delete e.ssr;\n delete e.ssrIntegrity;\n }\n }\n }\n\n if (config.plugins && typeof config.plugins === \"object\") {\n const plugins = config.plugins as Record<string, unknown>;\n\n if (opts.plugins && opts.plugins.length > 0) {\n for (const pluginKey of Object.keys(plugins)) {\n if (!opts.plugins.includes(pluginKey)) {\n delete plugins[pluginKey];\n }\n }\n }\n\n if (isInit) {\n for (const pluginKey of Object.keys(plugins)) {\n const plugin = plugins[pluginKey];\n if (plugin && typeof plugin === \"object\") {\n const p = plugin as Record<string, unknown>;\n delete p.production;\n delete p.integrity;\n }\n }\n }\n\n if (Object.keys(plugins).length === 0) {\n config.plugins = {};\n }\n }\n\n writeFileSync(configPath, `${JSON.stringify(rebuildOrderedConfig(config), null, 2)}\\n`);\n }\n\n const pkgPath = join(destination, \"package.json\");\n if (existsSync(pkgPath)) {\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const ws = pkg.workspaces as { packages?: string[] };\n if (Array.isArray(ws.packages)) {\n ws.packages = ws.packages.filter((p: string) => {\n if (p.startsWith(\"packages/\")) return false;\n if (p === \"host\") return opts.withHost ?? false;\n if (p === \"plugins/*\") return (opts.plugins?.length ?? 0) > 0;\n const pluginMatch = p.match(/^plugins\\/([^/]+)/);\n if (pluginMatch) return opts.plugins?.includes(pluginMatch[1]) ?? true;\n return true;\n });\n }\n }\n\n if (pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n const rewrite = (key: string, from: string, to: string) => {\n if (scripts[key]?.includes(from)) {\n scripts[key] = scripts[key].replaceAll(from, to);\n }\n };\n rewrite(\"dev\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:ui\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:api\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"dev:proxy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"build\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"deploy\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"publish\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n rewrite(\"start\", \"packages/everything-dev/cli.js\", \"node_modules/.bin/bos\");\n\n scripts.postinstall = \"node_modules/.bin/bos types gen || true\";\n scripts[\"types:gen\"] = \"node_modules/.bin/bos types gen\";\n if (scripts.typecheck) {\n scripts.typecheck = scripts.typecheck\n .replace(\"bun run types:gen && \", \"\")\n .replace(/bun run --cwd packages\\/everything-dev typecheck & ?/, \"\");\n if (!opts.withHost) {\n scripts.typecheck = scripts.typecheck.replace(/bun run --cwd host tsc --noEmit & ?/, \"\");\n }\n }\n }\n\n if (pkg.devDependencies && typeof pkg.devDependencies === \"object\") {\n const deps = pkg.devDependencies as Record<string, string>;\n delete deps[\"every-plugin\"];\n delete deps[\"everything-dev\"];\n }\n\n if (!pkg.workspaces || typeof pkg.workspaces !== \"object\") {\n pkg.workspaces = { packages: [], catalog: {} };\n }\n const workspaces = pkg.workspaces as { packages?: string[]; catalog?: Record<string, string> };\n if (!workspaces.catalog || typeof workspaces.catalog !== \"object\") {\n workspaces.catalog = {};\n }\n\n if (!pkg.dependencies) pkg.dependencies = {};\n const deps = pkg.dependencies as Record<string, string>;\n const spec = opts.workspaceOpts?.sourceDir\n ? loadManifestNormalizationSpec(opts.workspaceOpts.sourceDir)\n : null;\n if (spec) {\n workspaces.catalog[\"everything-dev\"] = spec.rootCatalog[\"everything-dev\"];\n workspaces.catalog[\"every-plugin\"] = spec.rootCatalog[\"every-plugin\"];\n }\n if (!deps[\"everything-dev\"] && spec) deps[\"everything-dev\"] = \"catalog:\";\n if (!deps[\"every-plugin\"] && spec) deps[\"every-plugin\"] = \"catalog:\";\n\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n\n const apiTsConfigPath = join(destination, \"api\", \"tsconfig.json\");\n if (existsSync(apiTsConfigPath)) {\n const apiTsConfig = JSON.parse(readFileSync(apiTsConfigPath, \"utf-8\")) as {\n files?: string[];\n [key: string]: unknown;\n };\n if (apiTsConfig.files) {\n const validFiles = apiTsConfig.files.filter((f) => existsSync(join(destination, \"api\", f)));\n if (validFiles.length !== apiTsConfig.files.length) {\n if (validFiles.length === 0) {\n delete apiTsConfig.files;\n } else {\n apiTsConfig.files = validFiles;\n }\n writeFileSync(apiTsConfigPath, `${JSON.stringify(apiTsConfig, null, 2)}\\n`);\n }\n }\n }\n\n await resolveWorkspaceRefs(destination, opts.workspaceOpts);\n\n const genContractPath = join(destination, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\");\n if (!existsSync(genContractPath)) {\n mkdirSync(dirname(genContractPath), { recursive: true });\n writeFileSync(genContractPath, `export type ApiContract = Record<string, never>;\\n`);\n }\n\n const pluginsClientGenPath = join(destination, \"api\", \"src\", \"lib\", \"plugins-types.gen.ts\");\n if (!existsSync(pluginsClientGenPath)) {\n mkdirSync(dirname(pluginsClientGenPath), { recursive: true });\n writeFileSync(\n pluginsClientGenPath,\n `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`,\n );\n }\n\n const authTypesGenPath = join(destination, \"ui\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(authTypesGenPath)) {\n mkdirSync(dirname(authTypesGenPath), { recursive: true });\n writeFileSync(\n authTypesGenPath,\n `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`,\n );\n }\n\n const apiAuthTypesGenPath = join(destination, \"api\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (!existsSync(apiAuthTypesGenPath)) {\n mkdirSync(dirname(apiAuthTypesGenPath), { recursive: true });\n writeFileSync(\n apiAuthTypesGenPath,\n `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`,\n );\n }\n\n const hostAuthTypesGenPath = join(destination, \"host\", \"src\", \"lib\", \"auth-types.gen.ts\");\n if (existsSync(join(destination, \"host\", \"src\")) && !existsSync(hostAuthTypesGenPath)) {\n mkdirSync(dirname(hostAuthTypesGenPath), { recursive: true });\n writeFileSync(\n hostAuthTypesGenPath,\n `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`,\n );\n }\n}\n\nexport async function runBunInstall(destination: string): Promise<void> {\n await execCommand(\"bun\", [\"install\", \"--ignore-scripts\"], destination);\n}\n\nexport async function runTypesGen(destination: string): Promise<void> {\n await execCommand(\"node_modules/.bin/bos\", [\"types\", \"gen\"], destination);\n}\n\nconst WORKSPACE_LOCAL_PATHS: Record<string, string> = {\n \"everything-dev\": \"packages/everything-dev\",\n \"every-plugin\": \"packages/every-plugin\",\n};\n\nasync function resolveWorkspaceRefs(\n destination: string,\n options?: { localOverrides?: boolean; sourceDir?: string },\n): Promise<void> {\n await normalizePackageManifestsInTree({\n sourceRootDir: options?.sourceDir ?? destination,\n targetDir: destination,\n resolveCatalogRefs: false,\n preserveCatalogRefs: true,\n removeWorkspaceDeps: [\"host\"],\n });\n\n if (options?.localOverrides && options.sourceDir) {\n const rootPkgPath = join(destination, \"package.json\");\n if (existsSync(rootPkgPath)) {\n const pkg = JSON.parse(readFileSync(rootPkgPath, \"utf-8\")) as Record<string, unknown>;\n if (!pkg.overrides) pkg.overrides = {};\n const overrides = pkg.overrides as Record<string, string>;\n\n const rootWorkspaces = ((pkg.workspaces as Record<string, string[]>)?.packages ?? []).filter(\n Boolean,\n );\n\n for (const [name, relPath] of Object.entries(WORKSPACE_LOCAL_PATHS)) {\n if (!rootWorkspaces.some((ws) => ws === relPath || ws === `plugins/${name}`)) {\n const srcPkgPath = join(options.sourceDir, relPath, \"package.json\");\n if (existsSync(srcPkgPath)) {\n overrides[name] = `file:${relPath}`;\n rootWorkspaces.push(relPath);\n }\n }\n }\n\n if (rootWorkspaces.length > 0) {\n if (!pkg.workspaces) pkg.workspaces = {};\n (pkg.workspaces as Record<string, string[]>).packages = rootWorkspaces;\n }\n\n writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n }\n }\n}\n\nexport async function writeInitSnapshot(\n destination: string,\n extendsAccount: string,\n extendsGateway: string,\n sourceDir: string,\n patterns: string[],\n options: { withHost: boolean; plugins?: string[]; pluginRoutes?: Record<string, string[]> },\n): Promise<void> {\n const effectivePatterns = options.withHost\n ? [...patterns, \"host/**\"]\n : patterns.filter((p) => !p.startsWith(\"host/\") && p !== \"host/**\");\n\n const excludedRoutePatterns: string[] = [];\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n }\n\n const allFiles = new Set<string>();\n for (const pattern of effectivePatterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n const pluginMatch = match.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !(options.plugins?.includes(pluginMatch[1]) ?? true)) continue;\n if (isRouteExcluded(match, excludedRoutePatterns)) continue;\n allFiles.add(match);\n }\n }\n\n if (options.pluginRoutes) {\n for (const [pluginKey, routePatterns] of Object.entries(options.pluginRoutes)) {\n if (!(options.plugins?.includes(pluginKey) ?? true)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isRouteExcluded(match, excludedRoutePatterns)) {\n allFiles.add(match);\n }\n }\n }\n }\n }\n\n const fileHashes: Record<string, string> = {};\n for (const filePath of allFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n fileHashes[destPath] = computeHash(content);\n }\n\n await writeSnapshot(destination, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: fileHashes,\n });\n}\n\nfunction computeHash(data: Uint8Array): string {\n return createHash(\"sha256\").update(data).digest(\"hex\").substring(0, 16);\n}\n\nfunction mkTmpDir(prefix: string): string {\n const base = join(tmpdir(), prefix);\n let attempt = 0;\n while (true) {\n const dir = `${base}-${Date.now()}-${attempt}`;\n try {\n mkdirSync(dir, { recursive: true });\n return dir;\n } catch {\n attempt++;\n if (attempt > 10) throw new Error(\"Failed to create temp directory\");\n }\n }\n}\n\nexport async function generateDatabaseMigrations(destination: string): Promise<void> {\n const drizzleConfigs = await glob(\"**/drizzle.config.ts\", {\n cwd: destination,\n nodir: true,\n dot: false,\n absolute: false,\n ignore: [\"**/node_modules/**\"],\n });\n\n for (const configPath of drizzleConfigs) {\n const workspaceDir = dirname(configPath);\n const pkgPath = join(destination, workspaceDir, \"package.json\");\n if (!existsSync(pkgPath)) continue;\n\n const pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\")) as Record<string, unknown>;\n const scripts = pkg.scripts as Record<string, string> | undefined;\n if (!scripts?.[\"db:generate\"]) continue;\n\n const cwd = join(destination, workspaceDir);\n await execCommand(\"bun\", [\"run\", \"db:generate\"], cwd);\n }\n}\n\nexport function execCommand(command: string, args: string[], cwd?: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n cwd,\n stdio: \"pipe\",\n shell: true,\n });\n let stderr = \"\";\n child.stderr?.on(\"data\", (data: Buffer) => {\n stderr += data.toString();\n });\n child.on(\"close\", (code) => {\n if (code === 0) resolve();\n else\n reject(\n new Error(\n `Command '${command} ${args.join(\" \")}' failed with exit code ${code}: ${stderr}`,\n ),\n );\n });\n child.on(\"error\", reject);\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,qBAAqB,QAA0D;CACtF,MAAM,UAAmC,EAAE;AAE3C,MAAK,MAAM,OAAO,iBAChB,KAAI,OAAO,OACT,SAAQ,OAAO,OAAO;AAI1B,MAAK,MAAM,OAAO,OAAO,KAAK,OAAO,CACnC,KAAI,CAAC,iBAAiB,SAAS,IAAI,CACjC,SAAQ,OAAO,OAAO;AAI1B,QAAO;;AAST,eAAsB,iBAAiB,MAIb;AACxB,KAAI,KAAK,QAAQ;EACf,MAAM,YAAY,QAAQ,KAAK,OAAO;AACtC,MAAI,CAAC,WAAW,KAAK,WAAW,kBAAkB,CAAC,CACjD,OAAM,IAAI,MAAM,iDAAiD,YAAY;AAK/E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