everything-dev 1.12.2 → 1.12.4
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/app.cjs +7 -96
- package/dist/app.cjs.map +1 -1
- package/dist/app.mjs +8 -97
- package/dist/app.mjs.map +1 -1
- 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/config.cjs +18 -13
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +10 -1
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +10 -1
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +18 -14
- package/dist/config.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/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- 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/app.ts +8 -113
- 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/config.ts +51 -14
- package/src/host.ts +1 -0
- package/src/internal/manifest-normalizer.ts +13 -0
- package/src/ui/runtime.ts +1 -48
package/dist/cli/sync.cjs
CHANGED
|
@@ -7,6 +7,33 @@ let node_crypto = require("node:crypto");
|
|
|
7
7
|
let glob = require("glob");
|
|
8
8
|
|
|
9
9
|
//#region src/cli/sync.ts
|
|
10
|
+
const FRAMEWORK_OWNED_SYNC_FILES = new Set([
|
|
11
|
+
".gitignore",
|
|
12
|
+
"biome.json",
|
|
13
|
+
"bos.config.json",
|
|
14
|
+
"package.json",
|
|
15
|
+
".github/workflows/release-sync.yml",
|
|
16
|
+
"ui/package.json",
|
|
17
|
+
"ui/postcss.config.mjs",
|
|
18
|
+
"ui/rsbuild.config.ts",
|
|
19
|
+
"ui/tsconfig.json",
|
|
20
|
+
"ui/src/app.ts",
|
|
21
|
+
"ui/src/hydrate.tsx",
|
|
22
|
+
"ui/src/lib/api.ts",
|
|
23
|
+
"ui/src/lib/auth.ts",
|
|
24
|
+
"ui/src/router.server.tsx",
|
|
25
|
+
"ui/src/router.tsx",
|
|
26
|
+
"ui/src/routes/__root.tsx",
|
|
27
|
+
"api/package.json",
|
|
28
|
+
"api/plugin.dev.ts",
|
|
29
|
+
"api/rspack.config.js",
|
|
30
|
+
"api/tsconfig.contract.json",
|
|
31
|
+
"api/tsconfig.json",
|
|
32
|
+
"api/src/lib/auth.ts"
|
|
33
|
+
]);
|
|
34
|
+
function isFrameworkOwnedSyncFile(filePath) {
|
|
35
|
+
return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);
|
|
36
|
+
}
|
|
10
37
|
function readExcludeFile(filePath) {
|
|
11
38
|
if (!(0, node_fs.existsSync)(filePath)) return [];
|
|
12
39
|
return (0, node_fs.readFileSync)(filePath, "utf-8").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
@@ -87,8 +114,33 @@ function mergeBosConfig(local, template) {
|
|
|
87
114
|
for (const key of orderedKeys) merged[key] = mergeJsonValues(local[key], template[key]);
|
|
88
115
|
return merged;
|
|
89
116
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
117
|
+
function mergeStringMaps(local, template) {
|
|
118
|
+
if (!local && !template) return void 0;
|
|
119
|
+
const merged = { ...local ?? {} };
|
|
120
|
+
for (const [name, value] of Object.entries(template ?? {})) merged[name] = value;
|
|
121
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
122
|
+
}
|
|
123
|
+
function mergeWorkspacePackages(local, template) {
|
|
124
|
+
const localPackages = Array.isArray(local) ? local : [];
|
|
125
|
+
const templatePackages = Array.isArray(template) ? template : [];
|
|
126
|
+
if (localPackages.length === 0 && templatePackages.length === 0) return void 0;
|
|
127
|
+
const ordered = /* @__PURE__ */ new Set();
|
|
128
|
+
for (const entry of templatePackages) if (typeof entry === "string" && entry.length > 0) ordered.add(entry);
|
|
129
|
+
for (const entry of localPackages) if (typeof entry === "string" && entry.length > 0) ordered.add(entry);
|
|
130
|
+
return ordered.size > 0 ? [...ordered] : void 0;
|
|
131
|
+
}
|
|
132
|
+
function mergePackageJson(filePath, local, template) {
|
|
133
|
+
const merged = {
|
|
134
|
+
...local,
|
|
135
|
+
...template
|
|
136
|
+
};
|
|
137
|
+
if (filePath === "package.json") {
|
|
138
|
+
for (const key of [
|
|
139
|
+
"name",
|
|
140
|
+
"private",
|
|
141
|
+
"version"
|
|
142
|
+
]) if (key in local) merged[key] = local[key];
|
|
143
|
+
} else if ("version" in local) merged.version = local.version;
|
|
92
144
|
for (const depField of [
|
|
93
145
|
"dependencies",
|
|
94
146
|
"devDependencies",
|
|
@@ -97,17 +149,31 @@ function mergePackageJson(local, template) {
|
|
|
97
149
|
]) {
|
|
98
150
|
const localDeps = local[depField];
|
|
99
151
|
const templateDeps = template[depField];
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
152
|
+
const mergedDeps = mergeStringMaps(localDeps, templateDeps);
|
|
153
|
+
if (mergedDeps) merged[depField] = mergedDeps;
|
|
154
|
+
else delete merged[depField];
|
|
155
|
+
}
|
|
156
|
+
if (local.scripts && typeof local.scripts === "object" || template.scripts && typeof template.scripts === "object") {
|
|
157
|
+
const mergedScripts = mergeStringMaps(local.scripts, template.scripts);
|
|
158
|
+
if (mergedScripts) merged.scripts = mergedScripts;
|
|
159
|
+
else delete merged.scripts;
|
|
160
|
+
}
|
|
161
|
+
if (local.workspaces && typeof local.workspaces === "object" || template.workspaces && typeof template.workspaces === "object") {
|
|
162
|
+
const localWorkspaces = local.workspaces ?? {};
|
|
163
|
+
const templateWorkspaces = template.workspaces ?? {};
|
|
164
|
+
const mergedWorkspaces = {
|
|
165
|
+
...localWorkspaces,
|
|
166
|
+
...templateWorkspaces
|
|
167
|
+
};
|
|
168
|
+
const mergedPackages = mergeWorkspacePackages(localWorkspaces.packages, templateWorkspaces.packages);
|
|
169
|
+
if (mergedPackages) mergedWorkspaces.packages = mergedPackages;
|
|
170
|
+
else delete mergedWorkspaces.packages;
|
|
171
|
+
const mergedCatalog = mergeStringMaps(localWorkspaces.catalog, templateWorkspaces.catalog);
|
|
172
|
+
if (mergedCatalog) mergedWorkspaces.catalog = mergedCatalog;
|
|
173
|
+
else delete mergedWorkspaces.catalog;
|
|
174
|
+
if (Object.keys(mergedWorkspaces).length > 0) merged.workspaces = mergedWorkspaces;
|
|
175
|
+
else delete merged.workspaces;
|
|
106
176
|
}
|
|
107
|
-
if (local.scripts && typeof local.scripts === "object") merged.scripts = {
|
|
108
|
-
...template.scripts ?? {},
|
|
109
|
-
...local.scripts
|
|
110
|
-
};
|
|
111
177
|
return merged;
|
|
112
178
|
}
|
|
113
179
|
function toDestPath(filePath) {
|
|
@@ -115,7 +181,8 @@ function toDestPath(filePath) {
|
|
|
115
181
|
}
|
|
116
182
|
function writeSyncedFile(sourceDir, projectDir, filePath) {
|
|
117
183
|
const src = (0, node_path.join)(sourceDir, filePath);
|
|
118
|
-
const
|
|
184
|
+
const destPath = filePath.startsWith(".github/templates/") ? filePath.replace(/^\.github\/templates\//, ".github/") : filePath;
|
|
185
|
+
const dest = (0, node_path.join)(projectDir, destPath);
|
|
119
186
|
(0, node_fs.mkdirSync)((0, node_path.dirname)(dest), { recursive: true });
|
|
120
187
|
if (filePath.endsWith("bos.config.json")) {
|
|
121
188
|
const localContent = (0, node_fs.existsSync)(dest) ? (0, node_fs.readFileSync)(dest, "utf-8") : null;
|
|
@@ -130,7 +197,7 @@ function writeSyncedFile(sourceDir, projectDir, filePath) {
|
|
|
130
197
|
const localContent = (0, node_fs.existsSync)(dest) ? (0, node_fs.readFileSync)(dest, "utf-8") : null;
|
|
131
198
|
const templateContent = (0, node_fs.readFileSync)(src, "utf-8");
|
|
132
199
|
if (localContent) {
|
|
133
|
-
const merged = mergePackageJson(JSON.parse(localContent), JSON.parse(templateContent));
|
|
200
|
+
const merged = mergePackageJson(destPath, JSON.parse(localContent), JSON.parse(templateContent));
|
|
134
201
|
(0, node_fs.writeFileSync)(dest, `${JSON.stringify(merged, null, 2)}\n`);
|
|
135
202
|
return;
|
|
136
203
|
}
|
|
@@ -215,7 +282,8 @@ async function syncTemplate(projectDir, options) {
|
|
|
215
282
|
const added = [];
|
|
216
283
|
for (const filePath of filteredFiles) {
|
|
217
284
|
const destPath = toDestPath(filePath);
|
|
218
|
-
|
|
285
|
+
const frameworkOwned = isFrameworkOwnedSyncFile(destPath);
|
|
286
|
+
if (isExcluded(destPath, excludePatterns) && !frameworkOwned) continue;
|
|
219
287
|
const localHash = computeLocalHash(projectDir, destPath);
|
|
220
288
|
const sourceContent = (0, node_fs.readFileSync)((0, node_path.join)(sourceDir, filePath));
|
|
221
289
|
const sourceHash = (0, node_crypto.createHash)("sha256").update(sourceContent).digest("hex").substring(0, 16);
|
|
@@ -224,6 +292,10 @@ async function syncTemplate(projectDir, options) {
|
|
|
224
292
|
continue;
|
|
225
293
|
}
|
|
226
294
|
if (localHash === sourceHash) continue;
|
|
295
|
+
if (frameworkOwned) {
|
|
296
|
+
updated.push(destPath);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
227
299
|
const snapshotHash = snapshot?.files[destPath];
|
|
228
300
|
if (snapshotHash === void 0) {
|
|
229
301
|
updated.push(destPath);
|
|
@@ -239,7 +311,7 @@ async function syncTemplate(projectDir, options) {
|
|
|
239
311
|
skipped,
|
|
240
312
|
added
|
|
241
313
|
};
|
|
242
|
-
const filesToWrite = [...updated, ...added].filter((f) => !isExcluded(f, excludePatterns));
|
|
314
|
+
const filesToWrite = [...updated, ...added].filter((f) => isFrameworkOwnedSyncFile(f) || !isExcluded(f, excludePatterns));
|
|
243
315
|
const destToSource = /* @__PURE__ */ new Map();
|
|
244
316
|
for (const filePath of filteredFiles) destToSource.set(toDestPath(filePath), filePath);
|
|
245
317
|
if (filesToWrite.length > 0) {
|
package/dist/cli/sync.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.cjs","names":["resolveSourceDir","readTemplatekeep","readSnapshot","writeSnapshot","personalizeConfig","runBunInstall","runTypesGen"],"sources":["../../src/cli/sync.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport {\n copyFileSync,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { glob } from \"glob\";\nimport type { SyncOptions, SyncResult } from \"../contract\";\nimport {\n personalizeConfig,\n readTemplatekeep,\n resolveSourceDir,\n runBunInstall,\n runTypesGen,\n} from \"./init\";\nimport { readSnapshot, writeSnapshot } from \"./snapshot\";\n\nfunction readExcludeFile(filePath: string): string[] {\n if (!existsSync(filePath)) return [];\n const content = readFileSync(filePath, \"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 readTemplatesyncExclude(sourceDir: string): Promise<string[]> {\n return readExcludeFile(join(sourceDir, \".templatesync-exclude\"));\n}\n\nexport function readLocalSyncExcludes(projectDir: string): string[] {\n return readExcludeFile(join(projectDir, \".bos\", \"sync-local-exclude\"));\n}\n\nfunction isExcluded(filePath: string, excludePatterns: string[]): boolean {\n for (const pattern of excludePatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (pattern.endsWith(\"/*\")) {\n const prefix = pattern.slice(0, -2);\n const slashIdx = filePath.indexOf(\"/\", prefix.length + 1);\n if (filePath.startsWith(`${prefix}/`) && slashIdx === -1) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nfunction computeLocalHash(projectDir: string, filePath: string): string | null {\n const fullPath = join(projectDir, filePath);\n if (!existsSync(fullPath)) return null;\n try {\n const content = readFileSync(fullPath);\n return createHash(\"sha256\").update(content).digest(\"hex\").substring(0, 16);\n } catch {\n return null;\n }\n}\n\nfunction backupFiles(projectDir: string, filePaths: string[]): string | null {\n const filesToBackup = filePaths.filter((f) => existsSync(join(projectDir, f)));\n if (filesToBackup.length === 0) return null;\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n const backupDir = join(projectDir, \".bos\", \"sync-backup\", timestamp);\n\n for (const filePath of filesToBackup) {\n const src = join(projectDir, filePath);\n const dest = join(backupDir, filePath);\n mkdirSync(dirname(dest), { recursive: true });\n copyFileSync(src, dest);\n }\n\n return backupDir;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction mergeJsonValues(local: unknown, template: unknown): unknown {\n if (isPlainObject(local) && isPlainObject(template)) {\n const merged: Record<string, unknown> = {};\n // Preserve local key order first\n for (const key of Object.keys(local)) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n // Append any new template keys at the end\n for (const key of Object.keys(template)) {\n if (!(key in merged)) {\n merged[key] = template[key];\n }\n }\n return merged;\n }\n // For arrays and primitives, local always wins\n return local ?? template;\n}\n\nfunction mergeBosConfig(\n local: Record<string, unknown>,\n template: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = {};\n\n // 1. extends always first\n if (local.extends !== undefined) merged.extends = local.extends;\n else if (template.extends !== undefined) merged.extends = template.extends;\n\n // 2. Fixed trailing group: app, plugins, shared\n const TRAIL_GROUP = [\"app\", \"plugins\", \"shared\"];\n\n const localKeys = Object.keys(local).filter((k) => k !== \"extends\");\n const templateKeys = Object.keys(template).filter(\n (k) => k !== \"extends\" && !localKeys.includes(k),\n );\n\n // Find the first trailing-group key present locally (\"app\" comes first in the group)\n const firstTrailIndex = localKeys.findIndex((k) => TRAIL_GROUP.includes(k));\n\n const orderedKeys: string[] = [];\n\n if (firstTrailIndex >= 0) {\n // Keys before the trail group stay in local order\n orderedKeys.push(...localKeys.slice(0, firstTrailIndex));\n // New template keys inserted right before the trail group\n orderedKeys.push(...templateKeys);\n // Trail group keys (app, plugins, shared) in canonical order, preserving local if present\n for (const trailKey of TRAIL_GROUP) {\n if (localKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n } else {\n // No trail group found locally — keep local order then append new keys and trail group\n orderedKeys.push(...localKeys);\n orderedKeys.push(...templateKeys);\n for (const trailKey of TRAIL_GROUP) {\n if (templateKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n }\n\n // 3. Merge values for each key\n for (const key of orderedKeys) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n\n return merged;\n}\n\nfunction mergePackageJson(\n local: Record<string, unknown>,\n template: Record<string, unknown>,\n): Record<string, unknown> {\n const merged = { ...template };\n\n for (const depField of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"overrides\",\n ] as const) {\n const localDeps = local[depField] as Record<string, string> | undefined;\n const templateDeps = template[depField] as Record<string, string> | undefined;\n\n if (!localDeps && !templateDeps) continue;\n\n const mergedDeps: Record<string, string> = { ...(templateDeps ?? {}) };\n\n if (localDeps) {\n for (const [name, version] of Object.entries(localDeps)) {\n if (!(name in mergedDeps)) {\n mergedDeps[name] = version;\n }\n }\n }\n\n if (Object.keys(mergedDeps).length > 0) {\n merged[depField] = mergedDeps;\n }\n }\n\n if (local.scripts && typeof local.scripts === \"object\") {\n merged.scripts = {\n ...((template.scripts as Record<string, string>) ?? {}),\n ...(local.scripts as Record<string, string>),\n };\n }\n\n return merged;\n}\n\nfunction toDestPath(filePath: string): string {\n return filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n}\n\nfunction writeSyncedFile(sourceDir: string, projectDir: string, filePath: string): void {\n const src = join(sourceDir, filePath);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(projectDir, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n\n if (filePath.endsWith(\"bos.config.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergeBosConfig(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n if (filePath.endsWith(\"package.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergePackageJson(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n writeFileSync(dest, readFileSync(src));\n}\n\nexport async function syncTemplate(projectDir: string, options: SyncOptions): Promise<SyncResult> {\n const localConfig = JSON.parse(\n readFileSync(join(projectDir, \"bos.config.json\"), \"utf-8\"),\n ) as Record<string, unknown>;\n\n const extendsRef = localConfig.extends as string | undefined;\n if (!extendsRef?.startsWith(\"bos://\")) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No extends field found in bos.config.json — cannot determine parent\",\n };\n }\n\n const extendsMatch = extendsRef.match(/^bos:\\/\\/([^/]+)\\/(.+)$/);\n if (!extendsMatch) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: `Invalid extends reference: ${extendsRef}`,\n };\n }\n\n const extendsAccount = extendsMatch[1];\n const extendsGateway = extendsMatch[2];\n\n const { sourceDir, parentConfig, cleanup } = await resolveSourceDir({\n extendsAccount,\n extendsGateway,\n });\n\n try {\n const patterns = await readTemplatekeep(sourceDir);\n if (patterns.length === 0) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No .templatekeep found in template source\",\n };\n }\n\n const parentExcludes = await readTemplatesyncExclude(sourceDir);\n const localExcludes = readLocalSyncExcludes(projectDir);\n const excludePatterns = [...parentExcludes, ...localExcludes];\n\n const allTemplateFiles = new Set<string>();\n for (const pattern of patterns) {\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 allTemplateFiles.add(match);\n }\n }\n\n const childPlugins =\n localConfig.plugins && typeof localConfig.plugins === \"object\"\n ? Object.keys(localConfig.plugins as Record<string, unknown>)\n : [];\n\n const pluginRoutes: Record<string, string[]> = {};\n if (parentConfig.plugins) {\n for (const [key, ref] of Object.entries(parentConfig.plugins)) {\n if (ref.routes && ref.routes.length > 0) {\n pluginRoutes[key] = ref.routes;\n }\n }\n }\n\n const excludedRoutePatterns: string[] = [];\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n\n const filteredFiles = new Set<string>();\n for (const filePath of allTemplateFiles) {\n const pluginMatch = filePath.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !childPlugins.includes(pluginMatch[1])) continue;\n if (isExcluded(filePath, excludedRoutePatterns)) continue;\n filteredFiles.add(filePath);\n }\n\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) 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 (!isExcluded(match, excludedRoutePatterns)) {\n filteredFiles.add(match);\n }\n }\n }\n }\n\n const snapshot = await readSnapshot(projectDir);\n\n const updated: string[] = [];\n const skipped: string[] = [];\n const added: string[] = [];\n\n for (const filePath of filteredFiles) {\n const destPath = toDestPath(filePath);\n if (isExcluded(destPath, excludePatterns)) continue;\n\n const localHash = computeLocalHash(projectDir, destPath);\n const sourceContent = readFileSync(join(sourceDir, filePath));\n const sourceHash = createHash(\"sha256\").update(sourceContent).digest(\"hex\").substring(0, 16);\n\n if (localHash === null) {\n added.push(destPath);\n continue;\n }\n\n if (localHash === sourceHash) continue;\n\n const snapshotHash = snapshot?.files[destPath];\n\n if (snapshotHash === undefined) {\n updated.push(destPath);\n continue;\n }\n\n if (localHash === snapshotHash) {\n updated.push(destPath);\n } else {\n if (options.force) {\n updated.push(destPath);\n } else {\n skipped.push(destPath);\n }\n }\n }\n\n if (options.dryRun) {\n return {\n status: \"dry-run\",\n updated,\n skipped,\n added,\n };\n }\n\n const filesToWrite = [...updated, ...added].filter((f) => !isExcluded(f, excludePatterns));\n\n const destToSource = new Map<string, string>();\n for (const filePath of filteredFiles) {\n destToSource.set(toDestPath(filePath), filePath);\n }\n\n if (filesToWrite.length > 0) {\n backupFiles(projectDir, filesToWrite);\n\n for (const destPath of filesToWrite) {\n const sourcePath = destToSource.get(destPath) ?? destPath;\n writeSyncedFile(sourceDir, projectDir, sourcePath);\n }\n }\n\n const newSnapshotFiles: Record<string, string> = {};\n for (const filePath of filteredFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n newSnapshotFiles[toDestPath(filePath)] = createHash(\"sha256\")\n .update(content)\n .digest(\"hex\")\n .substring(0, 16);\n }\n\n await writeSnapshot(projectDir, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: newSnapshotFiles,\n });\n\n const account = (localConfig.account as string) || extendsAccount;\n const domain = (localConfig.domain as string) || extendsGateway;\n\n await personalizeConfig(projectDir, {\n extendsAccount,\n extendsGateway,\n account,\n domain,\n plugins: childPlugins,\n pluginRoutes,\n workspaceOpts: { sourceDir },\n mode: \"sync\",\n });\n\n if (!options.noInstall) {\n await runBunInstall(projectDir);\n await runTypesGen(projectDir);\n }\n\n return {\n status: \"synced\",\n updated,\n skipped,\n added,\n };\n } finally {\n await cleanup();\n }\n}\n"],"mappings":";;;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S,IAAI,SACC;;EAItD,MAAM,mBAA2C,EAAE;AACnD,OAAK,MAAM,YAAY,eAAe;GACpC,MAAM,0BAAW,WAAW,SAAS;AAErC,OAAI,wBADmB,IAAI,CACjB,QAAQ,CAAE;GACpB,MAAM,oCAAuB,IAAI;AACjC,oBAAiB,WAAW,SAAS,gCAAe,SAAS,CAC1D,OAAO,QAAQ,CACf,OAAO,MAAM,CACb,UAAU,GAAG,GAAG;;AAGrB,QAAMC,+BAAc,YAAY;GAC9B,WAAW,SAAS,eAAe,GAAG;GACtC,OAAO;GACR,CAAC;AAKF,QAAMC,mCAAkB,YAAY;GAClC;GACA;GACA,SANe,YAAY,WAAsB;GAOjD,QANc,YAAY,UAAqB;GAO/C,SAAS;GACT;GACA,eAAe,EAAE,WAAW;GAC5B,MAAM;GACP,CAAC;AAEF,MAAI,CAAC,QAAQ,WAAW;AACtB,SAAMC,+BAAc,WAAW;AAC/B,SAAMC,6BAAY,WAAW;;AAG/B,SAAO;GACL,QAAQ;GACR;GACA;GACA;GACD;WACO;AACR,QAAM,SAAS"}
|
|
1
|
+
{"version":3,"file":"sync.cjs","names":["resolveSourceDir","readTemplatekeep","readSnapshot","writeSnapshot","personalizeConfig","runBunInstall","runTypesGen"],"sources":["../../src/cli/sync.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport {\n copyFileSync,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { glob } from \"glob\";\nimport type { SyncOptions, SyncResult } from \"../contract\";\nimport {\n personalizeConfig,\n readTemplatekeep,\n resolveSourceDir,\n runBunInstall,\n runTypesGen,\n} from \"./init\";\nimport { readSnapshot, writeSnapshot } from \"./snapshot\";\n\nconst FRAMEWORK_OWNED_SYNC_FILES = new Set([\n \".gitignore\",\n \"biome.json\",\n \"bos.config.json\",\n \"package.json\",\n \".github/workflows/release-sync.yml\",\n \"ui/package.json\",\n \"ui/postcss.config.mjs\",\n \"ui/rsbuild.config.ts\",\n \"ui/tsconfig.json\",\n \"ui/src/app.ts\",\n \"ui/src/hydrate.tsx\",\n \"ui/src/lib/api.ts\",\n \"ui/src/lib/auth.ts\",\n \"ui/src/router.server.tsx\",\n \"ui/src/router.tsx\",\n \"ui/src/routes/__root.tsx\",\n \"api/package.json\",\n \"api/plugin.dev.ts\",\n \"api/rspack.config.js\",\n \"api/tsconfig.contract.json\",\n \"api/tsconfig.json\",\n \"api/src/lib/auth.ts\",\n]);\n\ntype PackageJson = Record<string, unknown>;\n\nexport function isFrameworkOwnedSyncFile(filePath: string): boolean {\n return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);\n}\n\nfunction readExcludeFile(filePath: string): string[] {\n if (!existsSync(filePath)) return [];\n const content = readFileSync(filePath, \"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 readTemplatesyncExclude(sourceDir: string): Promise<string[]> {\n return readExcludeFile(join(sourceDir, \".templatesync-exclude\"));\n}\n\nexport function readLocalSyncExcludes(projectDir: string): string[] {\n return readExcludeFile(join(projectDir, \".bos\", \"sync-local-exclude\"));\n}\n\nfunction isExcluded(filePath: string, excludePatterns: string[]): boolean {\n for (const pattern of excludePatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (pattern.endsWith(\"/*\")) {\n const prefix = pattern.slice(0, -2);\n const slashIdx = filePath.indexOf(\"/\", prefix.length + 1);\n if (filePath.startsWith(`${prefix}/`) && slashIdx === -1) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nfunction computeLocalHash(projectDir: string, filePath: string): string | null {\n const fullPath = join(projectDir, filePath);\n if (!existsSync(fullPath)) return null;\n try {\n const content = readFileSync(fullPath);\n return createHash(\"sha256\").update(content).digest(\"hex\").substring(0, 16);\n } catch {\n return null;\n }\n}\n\nfunction backupFiles(projectDir: string, filePaths: string[]): string | null {\n const filesToBackup = filePaths.filter((f) => existsSync(join(projectDir, f)));\n if (filesToBackup.length === 0) return null;\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n const backupDir = join(projectDir, \".bos\", \"sync-backup\", timestamp);\n\n for (const filePath of filesToBackup) {\n const src = join(projectDir, filePath);\n const dest = join(backupDir, filePath);\n mkdirSync(dirname(dest), { recursive: true });\n copyFileSync(src, dest);\n }\n\n return backupDir;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction mergeJsonValues(local: unknown, template: unknown): unknown {\n if (isPlainObject(local) && isPlainObject(template)) {\n const merged: Record<string, unknown> = {};\n // Preserve local key order first\n for (const key of Object.keys(local)) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n // Append any new template keys at the end\n for (const key of Object.keys(template)) {\n if (!(key in merged)) {\n merged[key] = template[key];\n }\n }\n return merged;\n }\n // For arrays and primitives, local always wins\n return local ?? template;\n}\n\nfunction mergeBosConfig(\n local: Record<string, unknown>,\n template: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = {};\n\n // 1. extends always first\n if (local.extends !== undefined) merged.extends = local.extends;\n else if (template.extends !== undefined) merged.extends = template.extends;\n\n // 2. Fixed trailing group: app, plugins, shared\n const TRAIL_GROUP = [\"app\", \"plugins\", \"shared\"];\n\n const localKeys = Object.keys(local).filter((k) => k !== \"extends\");\n const templateKeys = Object.keys(template).filter(\n (k) => k !== \"extends\" && !localKeys.includes(k),\n );\n\n // Find the first trailing-group key present locally (\"app\" comes first in the group)\n const firstTrailIndex = localKeys.findIndex((k) => TRAIL_GROUP.includes(k));\n\n const orderedKeys: string[] = [];\n\n if (firstTrailIndex >= 0) {\n // Keys before the trail group stay in local order\n orderedKeys.push(...localKeys.slice(0, firstTrailIndex));\n // New template keys inserted right before the trail group\n orderedKeys.push(...templateKeys);\n // Trail group keys (app, plugins, shared) in canonical order, preserving local if present\n for (const trailKey of TRAIL_GROUP) {\n if (localKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n } else {\n // No trail group found locally — keep local order then append new keys and trail group\n orderedKeys.push(...localKeys);\n orderedKeys.push(...templateKeys);\n for (const trailKey of TRAIL_GROUP) {\n if (templateKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n }\n\n // 3. Merge values for each key\n for (const key of orderedKeys) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n\n return merged;\n}\n\nfunction mergeStringMaps(\n local: Record<string, string> | undefined,\n template: Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!local && !template) return undefined;\n\n const merged: Record<string, string> = { ...(local ?? {}) };\n for (const [name, value] of Object.entries(template ?? {})) {\n merged[name] = value;\n }\n\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction mergeWorkspacePackages(local: unknown, template: unknown): string[] | undefined {\n const localPackages = Array.isArray(local) ? local : [];\n const templatePackages = Array.isArray(template) ? template : [];\n if (localPackages.length === 0 && templatePackages.length === 0) return undefined;\n\n const ordered = new Set<string>();\n for (const entry of templatePackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n for (const entry of localPackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n\n return ordered.size > 0 ? [...ordered] : undefined;\n}\n\nexport function mergePackageJson(\n filePath: string,\n local: PackageJson,\n template: PackageJson,\n): PackageJson {\n const merged: PackageJson = { ...local, ...template };\n\n if (filePath === \"package.json\") {\n for (const key of [\"name\", \"private\", \"version\"] as const) {\n if (key in local) {\n merged[key] = local[key];\n }\n }\n } else if (\"version\" in local) {\n merged.version = local.version;\n }\n\n for (const depField of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"overrides\",\n ] as const) {\n const localDeps = local[depField] as Record<string, string> | undefined;\n const templateDeps = template[depField] as Record<string, string> | undefined;\n\n const mergedDeps = mergeStringMaps(localDeps, templateDeps);\n if (mergedDeps) {\n merged[depField] = mergedDeps;\n } else {\n delete merged[depField];\n }\n }\n\n if (\n (local.scripts && typeof local.scripts === \"object\") ||\n (template.scripts && typeof template.scripts === \"object\")\n ) {\n const mergedScripts = mergeStringMaps(\n local.scripts as Record<string, string> | undefined,\n template.scripts as Record<string, string> | undefined,\n );\n if (mergedScripts) {\n merged.scripts = mergedScripts;\n } else {\n delete merged.scripts;\n }\n }\n\n if (\n (local.workspaces && typeof local.workspaces === \"object\") ||\n (template.workspaces && typeof template.workspaces === \"object\")\n ) {\n const localWorkspaces = (local.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n const templateWorkspaces = (template.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n const mergedWorkspaces: { packages?: string[]; catalog?: Record<string, string> } = {\n ...localWorkspaces,\n ...templateWorkspaces,\n };\n\n const mergedPackages = mergeWorkspacePackages(\n localWorkspaces.packages,\n templateWorkspaces.packages,\n );\n if (mergedPackages) {\n mergedWorkspaces.packages = mergedPackages;\n } else {\n delete mergedWorkspaces.packages;\n }\n\n const mergedCatalog = mergeStringMaps(localWorkspaces.catalog, templateWorkspaces.catalog);\n if (mergedCatalog) {\n mergedWorkspaces.catalog = mergedCatalog;\n } else {\n delete mergedWorkspaces.catalog;\n }\n\n if (Object.keys(mergedWorkspaces).length > 0) {\n merged.workspaces = mergedWorkspaces;\n } else {\n delete merged.workspaces;\n }\n }\n\n return merged;\n}\n\nfunction toDestPath(filePath: string): string {\n return filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n}\n\nfunction writeSyncedFile(sourceDir: string, projectDir: string, filePath: string): void {\n const src = join(sourceDir, filePath);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(projectDir, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n\n if (filePath.endsWith(\"bos.config.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergeBosConfig(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n if (filePath.endsWith(\"package.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergePackageJson(destPath, local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n writeFileSync(dest, readFileSync(src));\n}\n\nexport async function syncTemplate(projectDir: string, options: SyncOptions): Promise<SyncResult> {\n const localConfig = JSON.parse(\n readFileSync(join(projectDir, \"bos.config.json\"), \"utf-8\"),\n ) as Record<string, unknown>;\n\n const extendsRef = localConfig.extends as string | undefined;\n if (!extendsRef?.startsWith(\"bos://\")) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No extends field found in bos.config.json — cannot determine parent\",\n };\n }\n\n const extendsMatch = extendsRef.match(/^bos:\\/\\/([^/]+)\\/(.+)$/);\n if (!extendsMatch) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: `Invalid extends reference: ${extendsRef}`,\n };\n }\n\n const extendsAccount = extendsMatch[1];\n const extendsGateway = extendsMatch[2];\n\n const { sourceDir, parentConfig, cleanup } = await resolveSourceDir({\n extendsAccount,\n extendsGateway,\n });\n\n try {\n const patterns = await readTemplatekeep(sourceDir);\n if (patterns.length === 0) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No .templatekeep found in template source\",\n };\n }\n\n const parentExcludes = await readTemplatesyncExclude(sourceDir);\n const localExcludes = readLocalSyncExcludes(projectDir);\n const excludePatterns = [...parentExcludes, ...localExcludes];\n\n const allTemplateFiles = new Set<string>();\n for (const pattern of patterns) {\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 allTemplateFiles.add(match);\n }\n }\n\n const childPlugins =\n localConfig.plugins && typeof localConfig.plugins === \"object\"\n ? Object.keys(localConfig.plugins as Record<string, unknown>)\n : [];\n\n const pluginRoutes: Record<string, string[]> = {};\n if (parentConfig.plugins) {\n for (const [key, ref] of Object.entries(parentConfig.plugins)) {\n if (ref.routes && ref.routes.length > 0) {\n pluginRoutes[key] = ref.routes;\n }\n }\n }\n\n const excludedRoutePatterns: string[] = [];\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n\n const filteredFiles = new Set<string>();\n for (const filePath of allTemplateFiles) {\n const pluginMatch = filePath.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !childPlugins.includes(pluginMatch[1])) continue;\n if (isExcluded(filePath, excludedRoutePatterns)) continue;\n filteredFiles.add(filePath);\n }\n\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) 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 (!isExcluded(match, excludedRoutePatterns)) {\n filteredFiles.add(match);\n }\n }\n }\n }\n\n const snapshot = await readSnapshot(projectDir);\n\n const updated: string[] = [];\n const skipped: string[] = [];\n const added: string[] = [];\n\n for (const filePath of filteredFiles) {\n const destPath = toDestPath(filePath);\n const frameworkOwned = isFrameworkOwnedSyncFile(destPath);\n if (isExcluded(destPath, excludePatterns) && !frameworkOwned) continue;\n\n const localHash = computeLocalHash(projectDir, destPath);\n const sourceContent = readFileSync(join(sourceDir, filePath));\n const sourceHash = createHash(\"sha256\").update(sourceContent).digest(\"hex\").substring(0, 16);\n\n if (localHash === null) {\n added.push(destPath);\n continue;\n }\n\n if (localHash === sourceHash) continue;\n\n if (frameworkOwned) {\n updated.push(destPath);\n continue;\n }\n\n const snapshotHash = snapshot?.files[destPath];\n\n if (snapshotHash === undefined) {\n updated.push(destPath);\n continue;\n }\n\n if (localHash === snapshotHash) {\n updated.push(destPath);\n } else {\n if (options.force) {\n updated.push(destPath);\n } else {\n skipped.push(destPath);\n }\n }\n }\n\n if (options.dryRun) {\n return {\n status: \"dry-run\",\n updated,\n skipped,\n added,\n };\n }\n\n const filesToWrite = [...updated, ...added].filter(\n (f) => isFrameworkOwnedSyncFile(f) || !isExcluded(f, excludePatterns),\n );\n\n const destToSource = new Map<string, string>();\n for (const filePath of filteredFiles) {\n destToSource.set(toDestPath(filePath), filePath);\n }\n\n if (filesToWrite.length > 0) {\n backupFiles(projectDir, filesToWrite);\n\n for (const destPath of filesToWrite) {\n const sourcePath = destToSource.get(destPath) ?? destPath;\n writeSyncedFile(sourceDir, projectDir, sourcePath);\n }\n }\n\n const newSnapshotFiles: Record<string, string> = {};\n for (const filePath of filteredFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n newSnapshotFiles[toDestPath(filePath)] = createHash(\"sha256\")\n .update(content)\n .digest(\"hex\")\n .substring(0, 16);\n }\n\n await writeSnapshot(projectDir, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: newSnapshotFiles,\n });\n\n const account = (localConfig.account as string) || extendsAccount;\n const domain = (localConfig.domain as string) || extendsGateway;\n\n await personalizeConfig(projectDir, {\n extendsAccount,\n extendsGateway,\n account,\n domain,\n plugins: childPlugins,\n pluginRoutes,\n workspaceOpts: { sourceDir },\n mode: \"sync\",\n });\n\n if (!options.noInstall) {\n await runBunInstall(projectDir);\n await runTypesGen(projectDir);\n }\n\n return {\n status: \"synced\",\n updated,\n skipped,\n added,\n };\n } finally {\n await cleanup();\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAM,6BAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAIF,SAAgB,yBAAyB,UAA2B;AAClE,QAAO,2BAA2B,IAAI,SAAS;;AAGjD,SAAS,gBAAgB,UAA4B;AACnD,KAAI,yBAAY,SAAS,CAAE,QAAO,EAAE;AAEpC,kCAD6B,UAAU,QAAQ,CAE5C,MAAM,KAAK,CACX,KAAK,SAAS,KAAK,MAAM,CAAC,CAC1B,QAAQ,SAAS,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,IAAI,CAAC;;AAG/D,eAAsB,wBAAwB,WAAsC;AAClF,QAAO,oCAAqB,WAAW,wBAAwB,CAAC;;AAGlE,SAAgB,sBAAsB,YAA8B;AAClE,QAAO,oCAAqB,YAAY,QAAQ,qBAAqB,CAAC;;AAGxE,SAAS,WAAW,UAAkB,iBAAoC;AACxE,MAAK,MAAM,WAAW,gBACpB,KAAI,QAAQ,SAAS,MAAM,EAAE;EAC3B,MAAM,SAAS,QAAQ,MAAM,GAAG,GAAG;AACnC,MAAI,SAAS,WAAW,GAAG,OAAO,GAAG,IAAI,aAAa,OAAQ,QAAO;YAC5D,QAAQ,SAAS,KAAK,EAAE;EACjC,MAAM,SAAS,QAAQ,MAAM,GAAG,GAAG;EACnC,MAAM,WAAW,SAAS,QAAQ,KAAK,OAAO,SAAS,EAAE;AACzD,MAAI,SAAS,WAAW,GAAG,OAAO,GAAG,IAAI,aAAa,GAAI,QAAO;YACxD,aAAa,WAAW,SAAS,WAAW,GAAG,QAAQ,GAAG,CACnE,QAAO;AAGX,QAAO;;AAGT,SAAS,iBAAiB,YAAoB,UA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"}
|
package/dist/cli/sync.mjs
CHANGED
|
@@ -6,6 +6,33 @@ import { createHash } from "node:crypto";
|
|
|
6
6
|
import { glob } from "glob";
|
|
7
7
|
|
|
8
8
|
//#region src/cli/sync.ts
|
|
9
|
+
const FRAMEWORK_OWNED_SYNC_FILES = new Set([
|
|
10
|
+
".gitignore",
|
|
11
|
+
"biome.json",
|
|
12
|
+
"bos.config.json",
|
|
13
|
+
"package.json",
|
|
14
|
+
".github/workflows/release-sync.yml",
|
|
15
|
+
"ui/package.json",
|
|
16
|
+
"ui/postcss.config.mjs",
|
|
17
|
+
"ui/rsbuild.config.ts",
|
|
18
|
+
"ui/tsconfig.json",
|
|
19
|
+
"ui/src/app.ts",
|
|
20
|
+
"ui/src/hydrate.tsx",
|
|
21
|
+
"ui/src/lib/api.ts",
|
|
22
|
+
"ui/src/lib/auth.ts",
|
|
23
|
+
"ui/src/router.server.tsx",
|
|
24
|
+
"ui/src/router.tsx",
|
|
25
|
+
"ui/src/routes/__root.tsx",
|
|
26
|
+
"api/package.json",
|
|
27
|
+
"api/plugin.dev.ts",
|
|
28
|
+
"api/rspack.config.js",
|
|
29
|
+
"api/tsconfig.contract.json",
|
|
30
|
+
"api/tsconfig.json",
|
|
31
|
+
"api/src/lib/auth.ts"
|
|
32
|
+
]);
|
|
33
|
+
function isFrameworkOwnedSyncFile(filePath) {
|
|
34
|
+
return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);
|
|
35
|
+
}
|
|
9
36
|
function readExcludeFile(filePath) {
|
|
10
37
|
if (!existsSync(filePath)) return [];
|
|
11
38
|
return readFileSync(filePath, "utf-8").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
@@ -86,8 +113,33 @@ function mergeBosConfig(local, template) {
|
|
|
86
113
|
for (const key of orderedKeys) merged[key] = mergeJsonValues(local[key], template[key]);
|
|
87
114
|
return merged;
|
|
88
115
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
116
|
+
function mergeStringMaps(local, template) {
|
|
117
|
+
if (!local && !template) return void 0;
|
|
118
|
+
const merged = { ...local ?? {} };
|
|
119
|
+
for (const [name, value] of Object.entries(template ?? {})) merged[name] = value;
|
|
120
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
121
|
+
}
|
|
122
|
+
function mergeWorkspacePackages(local, template) {
|
|
123
|
+
const localPackages = Array.isArray(local) ? local : [];
|
|
124
|
+
const templatePackages = Array.isArray(template) ? template : [];
|
|
125
|
+
if (localPackages.length === 0 && templatePackages.length === 0) return void 0;
|
|
126
|
+
const ordered = /* @__PURE__ */ new Set();
|
|
127
|
+
for (const entry of templatePackages) if (typeof entry === "string" && entry.length > 0) ordered.add(entry);
|
|
128
|
+
for (const entry of localPackages) if (typeof entry === "string" && entry.length > 0) ordered.add(entry);
|
|
129
|
+
return ordered.size > 0 ? [...ordered] : void 0;
|
|
130
|
+
}
|
|
131
|
+
function mergePackageJson(filePath, local, template) {
|
|
132
|
+
const merged = {
|
|
133
|
+
...local,
|
|
134
|
+
...template
|
|
135
|
+
};
|
|
136
|
+
if (filePath === "package.json") {
|
|
137
|
+
for (const key of [
|
|
138
|
+
"name",
|
|
139
|
+
"private",
|
|
140
|
+
"version"
|
|
141
|
+
]) if (key in local) merged[key] = local[key];
|
|
142
|
+
} else if ("version" in local) merged.version = local.version;
|
|
91
143
|
for (const depField of [
|
|
92
144
|
"dependencies",
|
|
93
145
|
"devDependencies",
|
|
@@ -96,17 +148,31 @@ function mergePackageJson(local, template) {
|
|
|
96
148
|
]) {
|
|
97
149
|
const localDeps = local[depField];
|
|
98
150
|
const templateDeps = template[depField];
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
151
|
+
const mergedDeps = mergeStringMaps(localDeps, templateDeps);
|
|
152
|
+
if (mergedDeps) merged[depField] = mergedDeps;
|
|
153
|
+
else delete merged[depField];
|
|
154
|
+
}
|
|
155
|
+
if (local.scripts && typeof local.scripts === "object" || template.scripts && typeof template.scripts === "object") {
|
|
156
|
+
const mergedScripts = mergeStringMaps(local.scripts, template.scripts);
|
|
157
|
+
if (mergedScripts) merged.scripts = mergedScripts;
|
|
158
|
+
else delete merged.scripts;
|
|
159
|
+
}
|
|
160
|
+
if (local.workspaces && typeof local.workspaces === "object" || template.workspaces && typeof template.workspaces === "object") {
|
|
161
|
+
const localWorkspaces = local.workspaces ?? {};
|
|
162
|
+
const templateWorkspaces = template.workspaces ?? {};
|
|
163
|
+
const mergedWorkspaces = {
|
|
164
|
+
...localWorkspaces,
|
|
165
|
+
...templateWorkspaces
|
|
166
|
+
};
|
|
167
|
+
const mergedPackages = mergeWorkspacePackages(localWorkspaces.packages, templateWorkspaces.packages);
|
|
168
|
+
if (mergedPackages) mergedWorkspaces.packages = mergedPackages;
|
|
169
|
+
else delete mergedWorkspaces.packages;
|
|
170
|
+
const mergedCatalog = mergeStringMaps(localWorkspaces.catalog, templateWorkspaces.catalog);
|
|
171
|
+
if (mergedCatalog) mergedWorkspaces.catalog = mergedCatalog;
|
|
172
|
+
else delete mergedWorkspaces.catalog;
|
|
173
|
+
if (Object.keys(mergedWorkspaces).length > 0) merged.workspaces = mergedWorkspaces;
|
|
174
|
+
else delete merged.workspaces;
|
|
105
175
|
}
|
|
106
|
-
if (local.scripts && typeof local.scripts === "object") merged.scripts = {
|
|
107
|
-
...template.scripts ?? {},
|
|
108
|
-
...local.scripts
|
|
109
|
-
};
|
|
110
176
|
return merged;
|
|
111
177
|
}
|
|
112
178
|
function toDestPath(filePath) {
|
|
@@ -114,7 +180,8 @@ function toDestPath(filePath) {
|
|
|
114
180
|
}
|
|
115
181
|
function writeSyncedFile(sourceDir, projectDir, filePath) {
|
|
116
182
|
const src = join(sourceDir, filePath);
|
|
117
|
-
const
|
|
183
|
+
const destPath = filePath.startsWith(".github/templates/") ? filePath.replace(/^\.github\/templates\//, ".github/") : filePath;
|
|
184
|
+
const dest = join(projectDir, destPath);
|
|
118
185
|
mkdirSync(dirname(dest), { recursive: true });
|
|
119
186
|
if (filePath.endsWith("bos.config.json")) {
|
|
120
187
|
const localContent = existsSync(dest) ? readFileSync(dest, "utf-8") : null;
|
|
@@ -129,7 +196,7 @@ function writeSyncedFile(sourceDir, projectDir, filePath) {
|
|
|
129
196
|
const localContent = existsSync(dest) ? readFileSync(dest, "utf-8") : null;
|
|
130
197
|
const templateContent = readFileSync(src, "utf-8");
|
|
131
198
|
if (localContent) {
|
|
132
|
-
const merged = mergePackageJson(JSON.parse(localContent), JSON.parse(templateContent));
|
|
199
|
+
const merged = mergePackageJson(destPath, JSON.parse(localContent), JSON.parse(templateContent));
|
|
133
200
|
writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\n`);
|
|
134
201
|
return;
|
|
135
202
|
}
|
|
@@ -214,7 +281,8 @@ async function syncTemplate(projectDir, options) {
|
|
|
214
281
|
const added = [];
|
|
215
282
|
for (const filePath of filteredFiles) {
|
|
216
283
|
const destPath = toDestPath(filePath);
|
|
217
|
-
|
|
284
|
+
const frameworkOwned = isFrameworkOwnedSyncFile(destPath);
|
|
285
|
+
if (isExcluded(destPath, excludePatterns) && !frameworkOwned) continue;
|
|
218
286
|
const localHash = computeLocalHash(projectDir, destPath);
|
|
219
287
|
const sourceContent = readFileSync(join(sourceDir, filePath));
|
|
220
288
|
const sourceHash = createHash("sha256").update(sourceContent).digest("hex").substring(0, 16);
|
|
@@ -223,6 +291,10 @@ async function syncTemplate(projectDir, options) {
|
|
|
223
291
|
continue;
|
|
224
292
|
}
|
|
225
293
|
if (localHash === sourceHash) continue;
|
|
294
|
+
if (frameworkOwned) {
|
|
295
|
+
updated.push(destPath);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
226
298
|
const snapshotHash = snapshot?.files[destPath];
|
|
227
299
|
if (snapshotHash === void 0) {
|
|
228
300
|
updated.push(destPath);
|
|
@@ -238,7 +310,7 @@ async function syncTemplate(projectDir, options) {
|
|
|
238
310
|
skipped,
|
|
239
311
|
added
|
|
240
312
|
};
|
|
241
|
-
const filesToWrite = [...updated, ...added].filter((f) => !isExcluded(f, excludePatterns));
|
|
313
|
+
const filesToWrite = [...updated, ...added].filter((f) => isFrameworkOwnedSyncFile(f) || !isExcluded(f, excludePatterns));
|
|
242
314
|
const destToSource = /* @__PURE__ */ new Map();
|
|
243
315
|
for (const filePath of filteredFiles) destToSource.set(toDestPath(filePath), filePath);
|
|
244
316
|
if (filesToWrite.length > 0) {
|
package/dist/cli/sync.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.mjs","names":[],"sources":["../../src/cli/sync.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport {\n copyFileSync,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { glob } from \"glob\";\nimport type { SyncOptions, SyncResult } from \"../contract\";\nimport {\n personalizeConfig,\n readTemplatekeep,\n resolveSourceDir,\n runBunInstall,\n runTypesGen,\n} from \"./init\";\nimport { readSnapshot, writeSnapshot } from \"./snapshot\";\n\nfunction readExcludeFile(filePath: string): string[] {\n if (!existsSync(filePath)) return [];\n const content = readFileSync(filePath, \"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 readTemplatesyncExclude(sourceDir: string): Promise<string[]> {\n return readExcludeFile(join(sourceDir, \".templatesync-exclude\"));\n}\n\nexport function readLocalSyncExcludes(projectDir: string): string[] {\n return readExcludeFile(join(projectDir, \".bos\", \"sync-local-exclude\"));\n}\n\nfunction isExcluded(filePath: string, excludePatterns: string[]): boolean {\n for (const pattern of excludePatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (pattern.endsWith(\"/*\")) {\n const prefix = pattern.slice(0, -2);\n const slashIdx = filePath.indexOf(\"/\", prefix.length + 1);\n if (filePath.startsWith(`${prefix}/`) && slashIdx === -1) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nfunction computeLocalHash(projectDir: string, filePath: string): string | null {\n const fullPath = join(projectDir, filePath);\n if (!existsSync(fullPath)) return null;\n try {\n const content = readFileSync(fullPath);\n return createHash(\"sha256\").update(content).digest(\"hex\").substring(0, 16);\n } catch {\n return null;\n }\n}\n\nfunction backupFiles(projectDir: string, filePaths: string[]): string | null {\n const filesToBackup = filePaths.filter((f) => existsSync(join(projectDir, f)));\n if (filesToBackup.length === 0) return null;\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n const backupDir = join(projectDir, \".bos\", \"sync-backup\", timestamp);\n\n for (const filePath of filesToBackup) {\n const src = join(projectDir, filePath);\n const dest = join(backupDir, filePath);\n mkdirSync(dirname(dest), { recursive: true });\n copyFileSync(src, dest);\n }\n\n return backupDir;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction mergeJsonValues(local: unknown, template: unknown): unknown {\n if (isPlainObject(local) && isPlainObject(template)) {\n const merged: Record<string, unknown> = {};\n // Preserve local key order first\n for (const key of Object.keys(local)) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n // Append any new template keys at the end\n for (const key of Object.keys(template)) {\n if (!(key in merged)) {\n merged[key] = template[key];\n }\n }\n return merged;\n }\n // For arrays and primitives, local always wins\n return local ?? template;\n}\n\nfunction mergeBosConfig(\n local: Record<string, unknown>,\n template: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = {};\n\n // 1. extends always first\n if (local.extends !== undefined) merged.extends = local.extends;\n else if (template.extends !== undefined) merged.extends = template.extends;\n\n // 2. Fixed trailing group: app, plugins, shared\n const TRAIL_GROUP = [\"app\", \"plugins\", \"shared\"];\n\n const localKeys = Object.keys(local).filter((k) => k !== \"extends\");\n const templateKeys = Object.keys(template).filter(\n (k) => k !== \"extends\" && !localKeys.includes(k),\n );\n\n // Find the first trailing-group key present locally (\"app\" comes first in the group)\n const firstTrailIndex = localKeys.findIndex((k) => TRAIL_GROUP.includes(k));\n\n const orderedKeys: string[] = [];\n\n if (firstTrailIndex >= 0) {\n // Keys before the trail group stay in local order\n orderedKeys.push(...localKeys.slice(0, firstTrailIndex));\n // New template keys inserted right before the trail group\n orderedKeys.push(...templateKeys);\n // Trail group keys (app, plugins, shared) in canonical order, preserving local if present\n for (const trailKey of TRAIL_GROUP) {\n if (localKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n } else {\n // No trail group found locally — keep local order then append new keys and trail group\n orderedKeys.push(...localKeys);\n orderedKeys.push(...templateKeys);\n for (const trailKey of TRAIL_GROUP) {\n if (templateKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n }\n\n // 3. Merge values for each key\n for (const key of orderedKeys) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n\n return merged;\n}\n\nfunction mergePackageJson(\n local: Record<string, unknown>,\n template: Record<string, unknown>,\n): Record<string, unknown> {\n const merged = { ...template };\n\n for (const depField of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"overrides\",\n ] as const) {\n const localDeps = local[depField] as Record<string, string> | undefined;\n const templateDeps = template[depField] as Record<string, string> | undefined;\n\n if (!localDeps && !templateDeps) continue;\n\n const mergedDeps: Record<string, string> = { ...(templateDeps ?? {}) };\n\n if (localDeps) {\n for (const [name, version] of Object.entries(localDeps)) {\n if (!(name in mergedDeps)) {\n mergedDeps[name] = version;\n }\n }\n }\n\n if (Object.keys(mergedDeps).length > 0) {\n merged[depField] = mergedDeps;\n }\n }\n\n if (local.scripts && typeof local.scripts === \"object\") {\n merged.scripts = {\n ...((template.scripts as Record<string, string>) ?? {}),\n ...(local.scripts as Record<string, string>),\n };\n }\n\n return merged;\n}\n\nfunction toDestPath(filePath: string): string {\n return filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n}\n\nfunction writeSyncedFile(sourceDir: string, projectDir: string, filePath: string): void {\n const src = join(sourceDir, filePath);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(projectDir, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n\n if (filePath.endsWith(\"bos.config.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergeBosConfig(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n if (filePath.endsWith(\"package.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergePackageJson(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n writeFileSync(dest, readFileSync(src));\n}\n\nexport async function syncTemplate(projectDir: string, options: SyncOptions): Promise<SyncResult> {\n const localConfig = JSON.parse(\n readFileSync(join(projectDir, \"bos.config.json\"), \"utf-8\"),\n ) as Record<string, unknown>;\n\n const extendsRef = localConfig.extends as string | undefined;\n if (!extendsRef?.startsWith(\"bos://\")) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No extends field found in bos.config.json — cannot determine parent\",\n };\n }\n\n const extendsMatch = extendsRef.match(/^bos:\\/\\/([^/]+)\\/(.+)$/);\n if (!extendsMatch) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: `Invalid extends reference: ${extendsRef}`,\n };\n }\n\n const extendsAccount = extendsMatch[1];\n const extendsGateway = extendsMatch[2];\n\n const { sourceDir, parentConfig, cleanup } = await resolveSourceDir({\n extendsAccount,\n extendsGateway,\n });\n\n try {\n const patterns = await readTemplatekeep(sourceDir);\n if (patterns.length === 0) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No .templatekeep found in template source\",\n };\n }\n\n const parentExcludes = await readTemplatesyncExclude(sourceDir);\n const localExcludes = readLocalSyncExcludes(projectDir);\n const excludePatterns = [...parentExcludes, ...localExcludes];\n\n const allTemplateFiles = new Set<string>();\n for (const pattern of patterns) {\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 allTemplateFiles.add(match);\n }\n }\n\n const childPlugins =\n localConfig.plugins && typeof localConfig.plugins === \"object\"\n ? Object.keys(localConfig.plugins as Record<string, unknown>)\n : [];\n\n const pluginRoutes: Record<string, string[]> = {};\n if (parentConfig.plugins) {\n for (const [key, ref] of Object.entries(parentConfig.plugins)) {\n if (ref.routes && ref.routes.length > 0) {\n pluginRoutes[key] = ref.routes;\n }\n }\n }\n\n const excludedRoutePatterns: string[] = [];\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n\n const filteredFiles = new Set<string>();\n for (const filePath of allTemplateFiles) {\n const pluginMatch = filePath.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !childPlugins.includes(pluginMatch[1])) continue;\n if (isExcluded(filePath, excludedRoutePatterns)) continue;\n filteredFiles.add(filePath);\n }\n\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) 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 (!isExcluded(match, excludedRoutePatterns)) {\n filteredFiles.add(match);\n }\n }\n }\n }\n\n const snapshot = await readSnapshot(projectDir);\n\n const updated: string[] = [];\n const skipped: string[] = [];\n const added: string[] = [];\n\n for (const filePath of filteredFiles) {\n const destPath = toDestPath(filePath);\n if (isExcluded(destPath, excludePatterns)) continue;\n\n const localHash = computeLocalHash(projectDir, destPath);\n const sourceContent = readFileSync(join(sourceDir, filePath));\n const sourceHash = createHash(\"sha256\").update(sourceContent).digest(\"hex\").substring(0, 16);\n\n if (localHash === null) {\n added.push(destPath);\n continue;\n }\n\n if (localHash === sourceHash) continue;\n\n const snapshotHash = snapshot?.files[destPath];\n\n if (snapshotHash === undefined) {\n updated.push(destPath);\n continue;\n }\n\n if (localHash === snapshotHash) {\n updated.push(destPath);\n } else {\n if (options.force) {\n updated.push(destPath);\n } else {\n skipped.push(destPath);\n }\n }\n }\n\n if (options.dryRun) {\n return {\n status: \"dry-run\",\n updated,\n skipped,\n added,\n };\n }\n\n const filesToWrite = [...updated, ...added].filter((f) => !isExcluded(f, excludePatterns));\n\n const destToSource = new Map<string, string>();\n for (const filePath of filteredFiles) {\n destToSource.set(toDestPath(filePath), filePath);\n }\n\n if (filesToWrite.length > 0) {\n backupFiles(projectDir, filesToWrite);\n\n for (const destPath of filesToWrite) {\n const sourcePath = destToSource.get(destPath) ?? destPath;\n writeSyncedFile(sourceDir, projectDir, sourcePath);\n }\n }\n\n const newSnapshotFiles: Record<string, string> = {};\n for (const filePath of filteredFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n newSnapshotFiles[toDestPath(filePath)] = createHash(\"sha256\")\n .update(content)\n .digest(\"hex\")\n .substring(0, 16);\n }\n\n await writeSnapshot(projectDir, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: newSnapshotFiles,\n });\n\n const account = (localConfig.account as string) || extendsAccount;\n const domain = (localConfig.domain as string) || extendsGateway;\n\n await personalizeConfig(projectDir, {\n extendsAccount,\n extendsGateway,\n account,\n domain,\n plugins: childPlugins,\n pluginRoutes,\n workspaceOpts: { sourceDir },\n mode: \"sync\",\n });\n\n if (!options.noInstall) {\n await runBunInstall(projectDir);\n await runTypesGen(projectDir);\n }\n\n return {\n status: \"synced\",\n updated,\n skipped,\n added,\n };\n } finally {\n await cleanup();\n }\n}\n"],"mappings":";;;;;;;;AAqBA,SAAS,gBAAgB,UAA4B;AACnD,KAAI,CAAC,WAAW,SAAS,CAAE,QAAO,EAAE;AAEpC,QADgB,aAAa,UAAU,QAAQ,CAE5C,MAAM,KAAK,CACX,KAAK,SAAS,KAAK,MAAM,CAAC,CAC1B,QAAQ,SAAS,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,IAAI,CAAC;;AAG/D,eAAsB,wBAAwB,WAAsC;AAClF,QAAO,gBAAgB,KAAK,WAAW,wBAAwB,CAAC;;AAGlE,SAAgB,sBAAsB,YAA8B;AAClE,QAAO,gBAAgB,KAAK,YAAY,QAAQ,qBAAqB,CAAC;;AAGxE,SAAS,WAAW,UAAkB,iBAAoC;AACxE,MAAK,MAAM,WAAW,gBACpB,KAAI,QAAQ,SAAS,MAAM,EAAE;EAC3B,MAAM,SAAS,QAAQ,MAAM,GAAG,GAAG;AACnC,MAAI,SAAS,WAAW,GAAG,OAAO,GAAG,IAAI,aAAa,OAAQ,QAAO;YAC5D,QAAQ,SAAS,KAAK,EAAE;EACjC,MAAM,SAAS,QAAQ,MAAM,GAAG,GAAG;EACnC,MAAM,WAAW,SAAS,QAAQ,KAAK,OAAO,SAAS,EAAE;AACzD,MAAI,SAAS,WAAW,GAAG,OAAO,GAAG,IAAI,aAAa,GAAI,QAAO;YACxD,aAAa,WAAW,SAAS,WAAW,GAAG,QAAQ,GAAG,CACnE,QAAO;AAGX,QAAO;;AAGT,SAAS,iBAAiB,YAAoB,UAAiC;CAC7E,MAAM,WAAW,KAAK,YAAY,SAAS;AAC3C,KAAI,CAAC,WAAW,SAAS,CAAE,QAAO;AAClC,KAAI;EACF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GACL,QAAQ;GACR;GACA;GACA;GACD;EAGH,MAAM,eAAe,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,MAAM,CAAC,WAAW,GAAG,gBAAgB,CAAC;EAE1F,MAAM,+BAAe,IAAI,KAAqB;AAC9C,OAAK,MAAM,YAAY,cACrB,cAAa,IAAI,WAAW,SAAS,EAAE,SAAS;AAGlD,MAAI,aAAa,SAAS,GAAG;AAC3B,eAAY,YAAY,aAAa;AAErC,QAAK,MAAM,YAAY,aAErB,iBAAgB,WAAW,YADR,aAAa,IAAI,SAAS,IAAI,SACC;;EAItD,MAAM,mBAA2C,EAAE;AACnD,OAAK,MAAM,YAAY,eAAe;GACpC,MAAM,MAAM,KAAK,WAAW,SAAS;AAErC,OAAI,CADS,UAAU,IAAI,CACjB,QAAQ,CAAE;GACpB,MAAM,UAAU,aAAa,IAAI;AACjC,oBAAiB,WAAW,SAAS,IAAI,WAAW,SAAS,CAC1D,OAAO,QAAQ,CACf,OAAO,MAAM,CACb,UAAU,GAAG,GAAG;;AAGrB,QAAM,cAAc,YAAY;GAC9B,WAAW,SAAS,eAAe,GAAG;GACtC,OAAO;GACR,CAAC;AAKF,QAAM,kBAAkB,YAAY;GAClC;GACA;GACA,SANe,YAAY,WAAsB;GAOjD,QANc,YAAY,UAAqB;GAO/C,SAAS;GACT;GACA,eAAe,EAAE,WAAW;GAC5B,MAAM;GACP,CAAC;AAEF,MAAI,CAAC,QAAQ,WAAW;AACtB,SAAM,cAAc,WAAW;AAC/B,SAAM,YAAY,WAAW;;AAG/B,SAAO;GACL,QAAQ;GACR;GACA;GACA;GACD;WACO;AACR,QAAM,SAAS"}
|
|
1
|
+
{"version":3,"file":"sync.mjs","names":[],"sources":["../../src/cli/sync.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport {\n copyFileSync,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { glob } from \"glob\";\nimport type { SyncOptions, SyncResult } from \"../contract\";\nimport {\n personalizeConfig,\n readTemplatekeep,\n resolveSourceDir,\n runBunInstall,\n runTypesGen,\n} from \"./init\";\nimport { readSnapshot, writeSnapshot } from \"./snapshot\";\n\nconst FRAMEWORK_OWNED_SYNC_FILES = new Set([\n \".gitignore\",\n \"biome.json\",\n \"bos.config.json\",\n \"package.json\",\n \".github/workflows/release-sync.yml\",\n \"ui/package.json\",\n \"ui/postcss.config.mjs\",\n \"ui/rsbuild.config.ts\",\n \"ui/tsconfig.json\",\n \"ui/src/app.ts\",\n \"ui/src/hydrate.tsx\",\n \"ui/src/lib/api.ts\",\n \"ui/src/lib/auth.ts\",\n \"ui/src/router.server.tsx\",\n \"ui/src/router.tsx\",\n \"ui/src/routes/__root.tsx\",\n \"api/package.json\",\n \"api/plugin.dev.ts\",\n \"api/rspack.config.js\",\n \"api/tsconfig.contract.json\",\n \"api/tsconfig.json\",\n \"api/src/lib/auth.ts\",\n]);\n\ntype PackageJson = Record<string, unknown>;\n\nexport function isFrameworkOwnedSyncFile(filePath: string): boolean {\n return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);\n}\n\nfunction readExcludeFile(filePath: string): string[] {\n if (!existsSync(filePath)) return [];\n const content = readFileSync(filePath, \"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 readTemplatesyncExclude(sourceDir: string): Promise<string[]> {\n return readExcludeFile(join(sourceDir, \".templatesync-exclude\"));\n}\n\nexport function readLocalSyncExcludes(projectDir: string): string[] {\n return readExcludeFile(join(projectDir, \".bos\", \"sync-local-exclude\"));\n}\n\nfunction isExcluded(filePath: string, excludePatterns: string[]): boolean {\n for (const pattern of excludePatterns) {\n if (pattern.endsWith(\"/**\")) {\n const prefix = pattern.slice(0, -3);\n if (filePath.startsWith(`${prefix}/`) || filePath === prefix) return true;\n } else if (pattern.endsWith(\"/*\")) {\n const prefix = pattern.slice(0, -2);\n const slashIdx = filePath.indexOf(\"/\", prefix.length + 1);\n if (filePath.startsWith(`${prefix}/`) && slashIdx === -1) return true;\n } else if (filePath === pattern || filePath.startsWith(`${pattern}/`)) {\n return true;\n }\n }\n return false;\n}\n\nfunction computeLocalHash(projectDir: string, filePath: string): string | null {\n const fullPath = join(projectDir, filePath);\n if (!existsSync(fullPath)) return null;\n try {\n const content = readFileSync(fullPath);\n return createHash(\"sha256\").update(content).digest(\"hex\").substring(0, 16);\n } catch {\n return null;\n }\n}\n\nfunction backupFiles(projectDir: string, filePaths: string[]): string | null {\n const filesToBackup = filePaths.filter((f) => existsSync(join(projectDir, f)));\n if (filesToBackup.length === 0) return null;\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n const backupDir = join(projectDir, \".bos\", \"sync-backup\", timestamp);\n\n for (const filePath of filesToBackup) {\n const src = join(projectDir, filePath);\n const dest = join(backupDir, filePath);\n mkdirSync(dirname(dest), { recursive: true });\n copyFileSync(src, dest);\n }\n\n return backupDir;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction mergeJsonValues(local: unknown, template: unknown): unknown {\n if (isPlainObject(local) && isPlainObject(template)) {\n const merged: Record<string, unknown> = {};\n // Preserve local key order first\n for (const key of Object.keys(local)) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n // Append any new template keys at the end\n for (const key of Object.keys(template)) {\n if (!(key in merged)) {\n merged[key] = template[key];\n }\n }\n return merged;\n }\n // For arrays and primitives, local always wins\n return local ?? template;\n}\n\nfunction mergeBosConfig(\n local: Record<string, unknown>,\n template: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = {};\n\n // 1. extends always first\n if (local.extends !== undefined) merged.extends = local.extends;\n else if (template.extends !== undefined) merged.extends = template.extends;\n\n // 2. Fixed trailing group: app, plugins, shared\n const TRAIL_GROUP = [\"app\", \"plugins\", \"shared\"];\n\n const localKeys = Object.keys(local).filter((k) => k !== \"extends\");\n const templateKeys = Object.keys(template).filter(\n (k) => k !== \"extends\" && !localKeys.includes(k),\n );\n\n // Find the first trailing-group key present locally (\"app\" comes first in the group)\n const firstTrailIndex = localKeys.findIndex((k) => TRAIL_GROUP.includes(k));\n\n const orderedKeys: string[] = [];\n\n if (firstTrailIndex >= 0) {\n // Keys before the trail group stay in local order\n orderedKeys.push(...localKeys.slice(0, firstTrailIndex));\n // New template keys inserted right before the trail group\n orderedKeys.push(...templateKeys);\n // Trail group keys (app, plugins, shared) in canonical order, preserving local if present\n for (const trailKey of TRAIL_GROUP) {\n if (localKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n } else {\n // No trail group found locally — keep local order then append new keys and trail group\n orderedKeys.push(...localKeys);\n orderedKeys.push(...templateKeys);\n for (const trailKey of TRAIL_GROUP) {\n if (templateKeys.includes(trailKey)) orderedKeys.push(trailKey);\n }\n }\n\n // 3. Merge values for each key\n for (const key of orderedKeys) {\n merged[key] = mergeJsonValues(local[key], template[key]);\n }\n\n return merged;\n}\n\nfunction mergeStringMaps(\n local: Record<string, string> | undefined,\n template: Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!local && !template) return undefined;\n\n const merged: Record<string, string> = { ...(local ?? {}) };\n for (const [name, value] of Object.entries(template ?? {})) {\n merged[name] = value;\n }\n\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction mergeWorkspacePackages(local: unknown, template: unknown): string[] | undefined {\n const localPackages = Array.isArray(local) ? local : [];\n const templatePackages = Array.isArray(template) ? template : [];\n if (localPackages.length === 0 && templatePackages.length === 0) return undefined;\n\n const ordered = new Set<string>();\n for (const entry of templatePackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n for (const entry of localPackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n\n return ordered.size > 0 ? [...ordered] : undefined;\n}\n\nexport function mergePackageJson(\n filePath: string,\n local: PackageJson,\n template: PackageJson,\n): PackageJson {\n const merged: PackageJson = { ...local, ...template };\n\n if (filePath === \"package.json\") {\n for (const key of [\"name\", \"private\", \"version\"] as const) {\n if (key in local) {\n merged[key] = local[key];\n }\n }\n } else if (\"version\" in local) {\n merged.version = local.version;\n }\n\n for (const depField of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"overrides\",\n ] as const) {\n const localDeps = local[depField] as Record<string, string> | undefined;\n const templateDeps = template[depField] as Record<string, string> | undefined;\n\n const mergedDeps = mergeStringMaps(localDeps, templateDeps);\n if (mergedDeps) {\n merged[depField] = mergedDeps;\n } else {\n delete merged[depField];\n }\n }\n\n if (\n (local.scripts && typeof local.scripts === \"object\") ||\n (template.scripts && typeof template.scripts === \"object\")\n ) {\n const mergedScripts = mergeStringMaps(\n local.scripts as Record<string, string> | undefined,\n template.scripts as Record<string, string> | undefined,\n );\n if (mergedScripts) {\n merged.scripts = mergedScripts;\n } else {\n delete merged.scripts;\n }\n }\n\n if (\n (local.workspaces && typeof local.workspaces === \"object\") ||\n (template.workspaces && typeof template.workspaces === \"object\")\n ) {\n const localWorkspaces = (local.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n const templateWorkspaces = (template.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n const mergedWorkspaces: { packages?: string[]; catalog?: Record<string, string> } = {\n ...localWorkspaces,\n ...templateWorkspaces,\n };\n\n const mergedPackages = mergeWorkspacePackages(\n localWorkspaces.packages,\n templateWorkspaces.packages,\n );\n if (mergedPackages) {\n mergedWorkspaces.packages = mergedPackages;\n } else {\n delete mergedWorkspaces.packages;\n }\n\n const mergedCatalog = mergeStringMaps(localWorkspaces.catalog, templateWorkspaces.catalog);\n if (mergedCatalog) {\n mergedWorkspaces.catalog = mergedCatalog;\n } else {\n delete mergedWorkspaces.catalog;\n }\n\n if (Object.keys(mergedWorkspaces).length > 0) {\n merged.workspaces = mergedWorkspaces;\n } else {\n delete merged.workspaces;\n }\n }\n\n return merged;\n}\n\nfunction toDestPath(filePath: string): string {\n return filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n}\n\nfunction writeSyncedFile(sourceDir: string, projectDir: string, filePath: string): void {\n const src = join(sourceDir, filePath);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(projectDir, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n\n if (filePath.endsWith(\"bos.config.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergeBosConfig(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n if (filePath.endsWith(\"package.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergePackageJson(destPath, local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n writeFileSync(dest, readFileSync(src));\n}\n\nexport async function syncTemplate(projectDir: string, options: SyncOptions): Promise<SyncResult> {\n const localConfig = JSON.parse(\n readFileSync(join(projectDir, \"bos.config.json\"), \"utf-8\"),\n ) as Record<string, unknown>;\n\n const extendsRef = localConfig.extends as string | undefined;\n if (!extendsRef?.startsWith(\"bos://\")) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No extends field found in bos.config.json — cannot determine parent\",\n };\n }\n\n const extendsMatch = extendsRef.match(/^bos:\\/\\/([^/]+)\\/(.+)$/);\n if (!extendsMatch) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: `Invalid extends reference: ${extendsRef}`,\n };\n }\n\n const extendsAccount = extendsMatch[1];\n const extendsGateway = extendsMatch[2];\n\n const { sourceDir, parentConfig, cleanup } = await resolveSourceDir({\n extendsAccount,\n extendsGateway,\n });\n\n try {\n const patterns = await readTemplatekeep(sourceDir);\n if (patterns.length === 0) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No .templatekeep found in template source\",\n };\n }\n\n const parentExcludes = await readTemplatesyncExclude(sourceDir);\n const localExcludes = readLocalSyncExcludes(projectDir);\n const excludePatterns = [...parentExcludes, ...localExcludes];\n\n const allTemplateFiles = new Set<string>();\n for (const pattern of patterns) {\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 allTemplateFiles.add(match);\n }\n }\n\n const childPlugins =\n localConfig.plugins && typeof localConfig.plugins === \"object\"\n ? Object.keys(localConfig.plugins as Record<string, unknown>)\n : [];\n\n const pluginRoutes: Record<string, string[]> = {};\n if (parentConfig.plugins) {\n for (const [key, ref] of Object.entries(parentConfig.plugins)) {\n if (ref.routes && ref.routes.length > 0) {\n pluginRoutes[key] = ref.routes;\n }\n }\n }\n\n const excludedRoutePatterns: string[] = [];\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n\n const filteredFiles = new Set<string>();\n for (const filePath of allTemplateFiles) {\n const pluginMatch = filePath.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !childPlugins.includes(pluginMatch[1])) continue;\n if (isExcluded(filePath, excludedRoutePatterns)) continue;\n filteredFiles.add(filePath);\n }\n\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) 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 (!isExcluded(match, excludedRoutePatterns)) {\n filteredFiles.add(match);\n }\n }\n }\n }\n\n const snapshot = await readSnapshot(projectDir);\n\n const updated: string[] = [];\n const skipped: string[] = [];\n const added: string[] = [];\n\n for (const filePath of filteredFiles) {\n const destPath = toDestPath(filePath);\n const frameworkOwned = isFrameworkOwnedSyncFile(destPath);\n if (isExcluded(destPath, excludePatterns) && !frameworkOwned) continue;\n\n const localHash = computeLocalHash(projectDir, destPath);\n const sourceContent = readFileSync(join(sourceDir, filePath));\n const sourceHash = createHash(\"sha256\").update(sourceContent).digest(\"hex\").substring(0, 16);\n\n if (localHash === null) {\n added.push(destPath);\n continue;\n }\n\n if (localHash === sourceHash) continue;\n\n if (frameworkOwned) {\n updated.push(destPath);\n continue;\n }\n\n const snapshotHash = snapshot?.files[destPath];\n\n if (snapshotHash === undefined) {\n updated.push(destPath);\n continue;\n }\n\n if (localHash === snapshotHash) {\n updated.push(destPath);\n } else {\n if (options.force) {\n updated.push(destPath);\n } else {\n skipped.push(destPath);\n }\n }\n }\n\n if (options.dryRun) {\n return {\n status: \"dry-run\",\n updated,\n skipped,\n added,\n };\n }\n\n const filesToWrite = [...updated, ...added].filter(\n (f) => isFrameworkOwnedSyncFile(f) || !isExcluded(f, excludePatterns),\n );\n\n const destToSource = new Map<string, string>();\n for (const filePath of filteredFiles) {\n destToSource.set(toDestPath(filePath), filePath);\n }\n\n if (filesToWrite.length > 0) {\n backupFiles(projectDir, filesToWrite);\n\n for (const destPath of filesToWrite) {\n const sourcePath = destToSource.get(destPath) ?? destPath;\n writeSyncedFile(sourceDir, projectDir, sourcePath);\n }\n }\n\n const newSnapshotFiles: Record<string, string> = {};\n for (const filePath of filteredFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n newSnapshotFiles[toDestPath(filePath)] = createHash(\"sha256\")\n .update(content)\n .digest(\"hex\")\n .substring(0, 16);\n }\n\n await writeSnapshot(projectDir, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: newSnapshotFiles,\n });\n\n const account = (localConfig.account as string) || extendsAccount;\n const domain = (localConfig.domain as string) || extendsGateway;\n\n await personalizeConfig(projectDir, {\n extendsAccount,\n extendsGateway,\n account,\n domain,\n plugins: childPlugins,\n pluginRoutes,\n workspaceOpts: { sourceDir },\n mode: \"sync\",\n });\n\n if (!options.noInstall) {\n await runBunInstall(projectDir);\n await runTypesGen(projectDir);\n }\n\n return {\n status: \"synced\",\n updated,\n skipped,\n added,\n };\n } finally {\n await cleanup();\n }\n}\n"],"mappings":";;;;;;;;AAqBA,MAAM,6BAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAIF,SAAgB,yBAAyB,UAA2B;AAClE,QAAO,2BAA2B,IAAI,SAAS;;AAGjD,SAAS,gBAAgB,UAA4B;AACnD,KAAI,CAAC,WAAW,SAAS,CAAE,QAAO,EAAE;AAEpC,QADgB,aAAa,UAAU,QAAQ,CAE5C,MAAM,KAAK,CACX,KAAK,SAAS,KAAK,MAAM,CAAC,CAC1B,QAAQ,SAAS,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,IAAI,CAAC;;AAG/D,eAAsB,wBAAwB,WAAsC;AAClF,QAAO,gBAAgB,KAAK,WAAW,wBAAwB,CAAC;;AAGlE,SAAgB,sBAAsB,YAA8B;AAClE,QAAO,gBAAgB,KAAK,YAAY,QAAQ,qBAAqB,CAAC;;AAGxE,SAAS,WAAW,UAAkB,iBAAoC;AACxE,MAAK,MAAM,WAAW,gBACpB,KAAI,QAAQ,SAAS,MAAM,EAAE;EAC3B,MAAM,SAAS,QAAQ,MAAM,GAAG,GAAG;AACnC,MAAI,SAAS,WAAW,GAAG,OAAO,GAAG,IAAI,aAAa,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