@ebay-dt/bonfire-cli 0.2.1 → 0.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/command.js CHANGED
@@ -35,11 +35,12 @@ function parsePrepareArgs(argv) {
35
35
  function parseContextArgs(argv) {
36
36
  const context = argv[1];
37
37
  if (context !== "sync" && context !== "install") {
38
- throw new CliSyntaxError("Usage: bonfire context sync [--check] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>]");
38
+ throw new CliSyntaxError("Usage: bonfire context sync [--check] [--skip-prototypes] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>]");
39
39
  }
40
40
  let root = process.cwd();
41
41
  let appId;
42
42
  let check = false;
43
+ let skipPrototypes = false;
43
44
  let rootProvided = false;
44
45
  let appIdProvided = false;
45
46
  let checkProvided = false;
@@ -54,6 +55,14 @@ function parseContextArgs(argv) {
54
55
  index += 1;
55
56
  continue;
56
57
  }
58
+ if (option === "--skip-prototypes" && context === "sync") {
59
+ if (skipPrototypes) {
60
+ throw new CliSyntaxError("The --skip-prototypes option may only be provided once");
61
+ }
62
+ skipPrototypes = true;
63
+ index += 1;
64
+ continue;
65
+ }
57
66
  if (option === "--root") {
58
67
  if (rootProvided) {
59
68
  throw new CliSyntaxError("The --root option may only be provided once");
@@ -88,7 +97,7 @@ function parseContextArgs(argv) {
88
97
  if (appId !== undefined) {
89
98
  throw new CliSyntaxError("The --app-id option is only valid for install");
90
99
  }
91
- return { command: "context", context, root, check };
100
+ return { command: "context", context, root, check, skipPrototypes };
92
101
  }
93
102
  function parseConvertArgs(argv) {
94
103
  const defaults = defaultConvertOptions();
@@ -97,7 +106,6 @@ function parseConvertArgs(argv) {
97
106
  let name;
98
107
  let packageName = defaults.packageName;
99
108
  let hostname = convertDefaults.hostname;
100
- let port = convertDefaults.port;
101
109
  let deploymentEndpoint = convertDefaults.deploymentEndpoint;
102
110
  let withoutData = false;
103
111
  let dryRun = false;
@@ -141,14 +149,6 @@ function parseConvertArgs(argv) {
141
149
  "--deployment-endpoint": (value) => {
142
150
  deploymentEndpoint = value;
143
151
  },
144
- "--port": (value) => {
145
- if (!/^\d+$/u.test(value) ||
146
- Number(value) < 1 ||
147
- Number(value) > 65535) {
148
- throw new CliSyntaxError("--port must be a number between 1 and 65535");
149
- }
150
- port = Number(value);
151
- },
152
152
  };
153
153
  const setter = setters[option];
154
154
  if (!setter)
@@ -163,7 +163,7 @@ function parseConvertArgs(argv) {
163
163
  index += 2;
164
164
  }
165
165
  if (!root || !appId) {
166
- throw new CliSyntaxError("Usage: bonfire convert --root <next-app> --app-id <app-id> [--name <display-name>] [--hostname <hostname>] [--port <port>] [--without-data] [--dry-run] [--skip-install]");
166
+ throw new CliSyntaxError("Usage: bonfire convert --root <next-app> --app-id <app-id> [--name <display-name>] [--hostname <hostname>] [--without-data] [--dry-run] [--skip-install]");
167
167
  }
168
168
  return {
169
169
  command: "convert",
@@ -172,7 +172,6 @@ function parseConvertArgs(argv) {
172
172
  name: name ?? humanizeAppId(appId),
173
173
  packageName,
174
174
  hostname,
175
- port,
176
175
  deploymentEndpoint,
177
176
  withItemData: !withoutData,
178
177
  dryRun,
@@ -277,7 +276,7 @@ export function parseArgs(argv) {
277
276
  if (argv[0] === "branch" && argv[1] === "prepare") {
278
277
  return parseBranchPrepareArgs(argv);
279
278
  }
280
- throw new CliSyntaxError("Usage: bonfire convert --root <next-app> --app-id <app-id> [options] | bonfire context sync [--check] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>] | bonfire prepare [--root <application-root>] | bonfire branch prepare --root <application-root> [--hostname <hostname>] [--default-hostname <hostname>] [--prototype-root <root>] [--remote <name>] [--primary <branch>]");
279
+ throw new CliSyntaxError("Usage: bonfire convert --root <next-app> --app-id <app-id> [options] | bonfire context sync [--check] [--skip-prototypes] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>] | bonfire prepare [--root <application-root>] | bonfire branch prepare --root <application-root> [--hostname <hostname>] [--default-hostname <hostname>] [--prototype-root <root>] [--remote <name>] [--primary <branch>]");
281
280
  }
282
281
  function printContextIssues(result) {
283
282
  for (const issue of result.issues) {
@@ -322,7 +321,10 @@ async function runContextCommand(options, dependencies) {
322
321
  return 0;
323
322
  }
324
323
  if (options.check) {
325
- const result = await checkContext({ repositoryRoot: options.root });
324
+ const result = await checkContext({
325
+ repositoryRoot: options.root,
326
+ skipPrototypes: options.skipPrototypes,
327
+ });
326
328
  if (!result.ok) {
327
329
  console.error("Context sync check failed:");
328
330
  printContextIssues(result);
@@ -331,7 +333,10 @@ async function runContextCommand(options, dependencies) {
331
333
  console.log("Context sync check passed.");
332
334
  return 0;
333
335
  }
334
- const result = await syncContext({ repositoryRoot: options.root });
336
+ const result = await syncContext({
337
+ repositoryRoot: options.root,
338
+ skipPrototypes: options.skipPrototypes,
339
+ });
335
340
  if (!result.ok) {
336
341
  console.error("Context sync failed:");
337
342
  printContextIssues(result);
@@ -1 +1 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,cAAc,EACd,WAAW,GAKZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,aAAa,GAEd,MAAM,cAAc,CAAC;AAEtB,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAiDD,SAAS,eAAe,CACtB,IAAuB,EACvB,KAAa;IAEb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CA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YACvE,OAAO,CAAC,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;YACpD,OAAO,CAAC,CAAC;QACX,CAAC;QAED,MAAM,OAAO,GACX,KAAK,YAAY,YAAY,IAAI,KAAK,YAAY,KAAK;YACrD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,2BAA2B,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;QACpD,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC","sourcesContent":["import {\n checkContext,\n checkContextInstallation,\n installContext,\n syncContext,\n type ContextInstallCheckResult,\n type ContextInstallResult,\n type ContextInstallOptions,\n type ContextSyncResult,\n} from \"@ebay-dt/bonfire-context\";\nimport { prepare, PrepareError } from \"./prepare.js\";\nimport {\n BranchPrepareError,\n runBranchPrepare,\n type BranchPrepareDependencies,\n} from \"./branch-prepare.js\";\nimport {\n convert,\n convertDefaults,\n defaultConvertOptions,\n humanizeAppId,\n type ConvertOptions,\n} from \"./convert.js\";\n\nexport class CliSyntaxError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CliSyntaxError\";\n }\n}\n\nexport type PrepareCommandOptions = {\n command: \"prepare\";\n root: string;\n};\n\nexport type BranchPrepareCommandOptions = {\n command: \"branch\";\n root: string;\n hostname?: string;\n defaultHostname?: string;\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n};\n\nexport type ContextCommandOptions =\n | {\n command: \"context\";\n context: \"sync\";\n root: string;\n check: boolean;\n }\n | {\n command: \"context\";\n context: \"install\";\n root: string;\n appId: string;\n check: boolean;\n };\n\nexport type ConvertCommandOptions = ConvertOptions & { command: \"convert\" };\n\ntype CliCommandOptions =\n | PrepareCommandOptions\n | BranchPrepareCommandOptions\n | ContextCommandOptions\n | ConvertCommandOptions;\n\nexport type CliDependencies = BranchPrepareDependencies & {\n contextInstall?: (\n options: ContextInstallOptions,\n ) => Promise<ContextInstallResult>;\n contextInstallCheck?: (\n options: ContextInstallOptions,\n ) => Promise<ContextInstallCheckResult>;\n};\n\nfunction parseRootOption(\n argv: readonly string[],\n start: number,\n): { root: string; nextIndex: number } {\n const value = argv[start + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(\"The --root option requires a value\");\n }\n return { root: value, nextIndex: start + 2 };\n}\n\nfunction parsePrepareArgs(argv: readonly string[]): PrepareCommandOptions {\n let root = process.cwd();\n let rootProvided = false;\n for (let index = 1; index < argv.length;) {\n if (argv[index] !== \"--root\") {\n throw new CliSyntaxError(`Unknown option: ${argv[index]}`);\n }\n if (rootProvided) {\n throw new CliSyntaxError(\"The --root option may only be provided once\");\n }\n const parsed = parseRootOption(argv, index);\n root = parsed.root;\n rootProvided = true;\n index = parsed.nextIndex;\n }\n return { command: \"prepare\", root };\n}\n\nfunction parseContextArgs(argv: readonly string[]): ContextCommandOptions {\n const context = argv[1];\n if (context !== \"sync\" && context !== \"install\") {\n throw new CliSyntaxError(\n \"Usage: bonfire context sync [--check] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>]\",\n );\n }\n\n let root = process.cwd();\n let appId: string | undefined;\n let check = false;\n let rootProvided = false;\n let appIdProvided = false;\n let checkProvided = false;\n\n for (let index = 2; index < argv.length;) {\n const option = argv[index];\n if (option === \"--check\") {\n if (checkProvided) {\n throw new CliSyntaxError(\n \"The --check option may only be provided once\",\n );\n }\n check = true;\n checkProvided = true;\n index += 1;\n continue;\n }\n if (option === \"--root\") {\n if (rootProvided) {\n throw new CliSyntaxError(\"The --root option may only be provided once\");\n }\n const parsed = parseRootOption(argv, index);\n root = parsed.root;\n rootProvided = true;\n index = parsed.nextIndex;\n continue;\n }\n if (option === \"--app-id\") {\n if (appIdProvided) {\n throw new CliSyntaxError(\n \"The --app-id option may only be provided once\",\n );\n }\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(\"The --app-id option requires a value\");\n }\n appId = value;\n appIdProvided = true;\n index += 2;\n continue;\n }\n throw new CliSyntaxError(`Unknown option: ${option}`);\n }\n\n if (context === \"install\") {\n if (appId === undefined) {\n throw new CliSyntaxError(\n \"Usage: bonfire context install [--check] --app-id <app-id> [--root <root>]\",\n );\n }\n return { command: \"context\", context, root, appId, check };\n }\n if (appId !== undefined) {\n throw new CliSyntaxError(\"The --app-id option is only valid for install\");\n }\n return { command: \"context\", context, root, check };\n}\n\nfunction parseConvertArgs(argv: readonly string[]): ConvertCommandOptions {\n const defaults = defaultConvertOptions();\n let root: string | undefined;\n let appId: string | undefined;\n let name: string | undefined;\n let packageName = defaults.packageName;\n let hostname = convertDefaults.hostname;\n let port = convertDefaults.port;\n let deploymentEndpoint = convertDefaults.deploymentEndpoint;\n let withoutData = false;\n let dryRun = false;\n let skipInstall = false;\n const seen = new Set<string>();\n\n for (let index = 1; index < argv.length;) {\n const option = argv[index];\n if (!option) throw new CliSyntaxError(\"Missing convert option\");\n if (\n option === \"--without-data\" ||\n option === \"--dry-run\" ||\n option === \"--skip-install\"\n ) {\n if (seen.has(option))\n throw new CliSyntaxError(`${option} may only be provided once`);\n seen.add(option);\n if (option === \"--without-data\") withoutData = true;\n if (option === \"--dry-run\") dryRun = true;\n if (option === \"--skip-install\") skipInstall = true;\n index += 1;\n continue;\n }\n const setters: Record<string, (value: string) => void> = {\n \"--root\": (value) => {\n root = value;\n },\n \"--app-id\": (value) => {\n appId = value;\n },\n \"--name\": (value) => {\n name = value;\n },\n \"--package-name\": (value) => {\n packageName = value;\n },\n \"--hostname\": (value) => {\n hostname = value;\n },\n \"--deployment-endpoint\": (value) => {\n deploymentEndpoint = value;\n },\n \"--port\": (value) => {\n if (\n !/^\\d+$/u.test(value) ||\n Number(value) < 1 ||\n Number(value) > 65535\n ) {\n throw new CliSyntaxError(\n \"--port must be a number between 1 and 65535\",\n );\n }\n port = Number(value);\n },\n };\n const setter = setters[option];\n if (!setter) throw new CliSyntaxError(`Unknown option: ${option}`);\n if (seen.has(option))\n throw new CliSyntaxError(`${option} may only be provided once`);\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\"))\n throw new CliSyntaxError(`${option} requires a value`);\n seen.add(option);\n setter(value);\n index += 2;\n }\n if (!root || !appId) {\n throw new CliSyntaxError(\n \"Usage: bonfire convert --root <next-app> --app-id <app-id> [--name <display-name>] [--hostname <hostname>] [--port <port>] [--without-data] [--dry-run] [--skip-install]\",\n );\n }\n return {\n command: \"convert\",\n root,\n appId,\n name: name ?? humanizeAppId(appId),\n packageName,\n hostname,\n port,\n deploymentEndpoint,\n withItemData: !withoutData,\n dryRun,\n skipInstall,\n };\n}\n\nfunction parseBranchPrepareArgs(\n argv: readonly string[],\n): BranchPrepareCommandOptions {\n let root = process.cwd();\n let hostname: string | undefined;\n let defaultHostname: string | undefined;\n let prototypeRoot: string | undefined;\n let remote: string | undefined;\n let primaryBranch: string | undefined;\n let rootProvided = false;\n let hostnameProvided = false;\n let defaultHostnameProvided = false;\n let prototypeRootProvided = false;\n let remoteProvided = false;\n let primaryBranchProvided = false;\n\n for (let index = 2; index < argv.length;) {\n const option = argv[index];\n if (option === \"--root\") {\n if (rootProvided) {\n throw new CliSyntaxError(\"The --root option may only be provided once\");\n }\n const parsed = parseRootOption(argv, index);\n root = parsed.root;\n rootProvided = true;\n index = parsed.nextIndex;\n continue;\n }\n if (\n option === \"--prototype-root\" ||\n option === \"--remote\" ||\n option === \"--primary\"\n ) {\n const provided =\n option === \"--prototype-root\"\n ? prototypeRootProvided\n : option === \"--remote\"\n ? remoteProvided\n : primaryBranchProvided;\n if (provided) {\n throw new CliSyntaxError(`${option} may only be provided once`);\n }\n if (option === \"--prototype-root\") prototypeRootProvided = true;\n if (option === \"--remote\") remoteProvided = true;\n if (option === \"--primary\") primaryBranchProvided = true;\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(`${option} requires a value`);\n }\n if (option === \"--prototype-root\") prototypeRoot = value;\n if (option === \"--remote\") remote = value;\n if (option === \"--primary\") primaryBranch = value;\n index += 2;\n continue;\n }\n if (option === \"--hostname\" || option === \"--default-hostname\") {\n const isDefault = option === \"--default-hostname\";\n const provided = isDefault ? defaultHostnameProvided : hostnameProvided;\n if (provided) {\n throw new CliSyntaxError(\n `The ${option} option may only be provided once`,\n );\n }\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(`The ${option} option requires a value`);\n }\n if (isDefault) {\n defaultHostname = value;\n defaultHostnameProvided = true;\n } else {\n hostname = value;\n hostnameProvided = true;\n }\n index += 2;\n continue;\n }\n throw new CliSyntaxError(`Unknown option: ${option}`);\n }\n\n return {\n command: \"branch\",\n root,\n ...(hostname === undefined ? {} : { hostname }),\n ...(defaultHostname === undefined ? {} : { defaultHostname }),\n ...(prototypeRoot === undefined ? {} : { prototypeRoot }),\n ...(remote === undefined ? {} : { remote }),\n ...(primaryBranch === undefined ? {} : { primaryBranch }),\n };\n}\n\nexport function parseArgs(argv: readonly string[]): CliCommandOptions {\n if (argv[0] === \"convert\") return parseConvertArgs(argv);\n if (argv[0] === \"context\") return parseContextArgs(argv);\n if (argv[0] === \"prepare\") return parsePrepareArgs(argv);\n if (argv[0] === \"branch\" && argv[1] === \"prepare\") {\n return parseBranchPrepareArgs(argv);\n }\n throw new CliSyntaxError(\n \"Usage: bonfire convert --root <next-app> --app-id <app-id> [options] | bonfire context sync [--check] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>] | bonfire prepare [--root <application-root>] | bonfire branch prepare --root <application-root> [--hostname <hostname>] [--default-hostname <hostname>] [--prototype-root <root>] [--remote <name>] [--primary <branch>]\",\n );\n}\n\nfunction printContextIssues(result: {\n issues: readonly { kind: string; path: string }[];\n}) {\n for (const issue of result.issues) {\n console.error(`- ${issue.kind}: ${issue.path}`);\n }\n}\n\nfunction printContextSyncSummary(result: ContextSyncResult) {\n if (result.written.length > 0) {\n console.log(`Written: ${result.written.join(\", \")}`);\n }\n if (result.removed.length > 0) {\n console.log(`Removed: ${result.removed.join(\", \")}`);\n }\n}\n\nasync function runContextCommand(\n options: ContextCommandOptions,\n dependencies: CliDependencies,\n): Promise<number> {\n if (options.context === \"install\") {\n if (options.check) {\n const result = await (\n dependencies.contextInstallCheck ?? checkContextInstallation\n )({\n repositoryRoot: options.root,\n appId: options.appId,\n });\n if (!result.ok) {\n console.error(\"Context install check failed:\");\n printContextIssues(result);\n return 1;\n }\n console.log(\"Context install check passed.\");\n return 0;\n }\n const result = await (dependencies.contextInstall ?? installContext)({\n repositoryRoot: options.root,\n appId: options.appId,\n });\n const skills = result.skills.map(\n (skill) => `${skill.name} (${skill.status})`,\n );\n const mcp = result.mcp.map((server) => `${server.name} (${server.status})`);\n console.log(\n skills.length > 0\n ? `Context skills: ${skills.join(\", \")}`\n : \"No context skills configured.\",\n );\n if (mcp.length > 0) console.log(`Context MCP: ${mcp.join(\", \")}`);\n console.log(\"Context install complete.\");\n return 0;\n }\n\n if (options.check) {\n const result = await checkContext({ repositoryRoot: options.root });\n if (!result.ok) {\n console.error(\"Context sync check failed:\");\n printContextIssues(result);\n return 1;\n }\n console.log(\"Context sync check passed.\");\n return 0;\n }\n\n const result = await syncContext({ repositoryRoot: options.root });\n if (!result.ok) {\n console.error(\"Context sync failed:\");\n printContextIssues(result);\n return 1;\n }\n printContextSyncSummary(result);\n console.log(\"Context sync complete.\");\n return 0;\n}\n\nexport async function run(\n argv: readonly string[] = process.argv.slice(2),\n dependencies: CliDependencies = {},\n): Promise<number> {\n const isBranchPrepare = argv[0] === \"branch\";\n const isContext = argv[0] === \"context\";\n const isConvert = argv[0] === \"convert\";\n try {\n const options = parseArgs(argv);\n switch (options.command) {\n case \"context\":\n return await runContextCommand(options, dependencies);\n case \"convert\":\n await convert(options);\n return 0;\n case \"branch\":\n return await runBranchPrepare(options, dependencies);\n case \"prepare\": {\n const result = await prepare(options);\n const descriptions = {\n environment: \"the process environment\",\n existing: \".env.local\",\n generated: \"a newly generated value in .env.local\",\n } as const;\n console.log(\n `Bonfire preparation complete; BF_SESSION_SECRET came from ${descriptions[result.source]}.`,\n );\n return 0;\n }\n }\n } catch (error) {\n if (error instanceof CliSyntaxError) {\n console.error(`bonfire: ${error.message}`);\n return 2;\n }\n if (isContext) {\n const message =\n error instanceof Error ? error.message : \"an unknown error occurred\";\n console.error(`bonfire context failed: ${message}`);\n return 1;\n }\n if (isBranchPrepare) {\n const message =\n error instanceof BranchPrepareError\n ? error.message\n : \"Unable to load branch preparation configuration.\";\n console.error(`bonfire branch prepare failed: ${message}`);\n return 1;\n }\n if (isConvert) {\n const message =\n error instanceof Error ? error.message : \"an unknown error occurred\";\n console.error(`bonfire convert failed: ${message}`);\n return 1;\n }\n\n const message =\n error instanceof PrepareError || error instanceof Error\n ? error.message\n : \"an unknown error occurred\";\n console.error(`bonfire prepare failed: ${message}`);\n return 1;\n }\n}\n"]}
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,cAAc,EACd,WAAW,GAKZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,aAAa,GAEd,MAAM,cAAc,CAAC;AAEtB,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAkDD,SAAS,eAAe,CACtB,IAAuB,EACvB,KAAa;IAEb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC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AM,OAAO,GACX,KAAK,YAAY,YAAY,IAAI,KAAK,YAAY,KAAK;YACrD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,2BAA2B,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;QACpD,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC","sourcesContent":["import {\n checkContext,\n checkContextInstallation,\n installContext,\n syncContext,\n type ContextInstallCheckResult,\n type ContextInstallResult,\n type ContextInstallOptions,\n type ContextSyncResult,\n} from \"@ebay-dt/bonfire-context\";\nimport { prepare, PrepareError } from \"./prepare.js\";\nimport {\n BranchPrepareError,\n runBranchPrepare,\n type BranchPrepareDependencies,\n} from \"./branch-prepare.js\";\nimport {\n convert,\n convertDefaults,\n defaultConvertOptions,\n humanizeAppId,\n type ConvertOptions,\n} from \"./convert.js\";\n\nexport class CliSyntaxError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CliSyntaxError\";\n }\n}\n\nexport type PrepareCommandOptions = {\n command: \"prepare\";\n root: string;\n};\n\nexport type BranchPrepareCommandOptions = {\n command: \"branch\";\n root: string;\n hostname?: string;\n defaultHostname?: string;\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n};\n\nexport type ContextCommandOptions =\n | {\n command: \"context\";\n context: \"sync\";\n root: string;\n check: boolean;\n skipPrototypes: boolean;\n }\n | {\n command: \"context\";\n context: \"install\";\n root: string;\n appId: string;\n check: boolean;\n };\n\nexport type ConvertCommandOptions = ConvertOptions & { command: \"convert\" };\n\ntype CliCommandOptions =\n | PrepareCommandOptions\n | BranchPrepareCommandOptions\n | ContextCommandOptions\n | ConvertCommandOptions;\n\nexport type CliDependencies = BranchPrepareDependencies & {\n contextInstall?: (\n options: ContextInstallOptions,\n ) => Promise<ContextInstallResult>;\n contextInstallCheck?: (\n options: ContextInstallOptions,\n ) => Promise<ContextInstallCheckResult>;\n};\n\nfunction parseRootOption(\n argv: readonly string[],\n start: number,\n): { root: string; nextIndex: number } {\n const value = argv[start + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(\"The --root option requires a value\");\n }\n return { root: value, nextIndex: start + 2 };\n}\n\nfunction parsePrepareArgs(argv: readonly string[]): PrepareCommandOptions {\n let root = process.cwd();\n let rootProvided = false;\n for (let index = 1; index < argv.length;) {\n if (argv[index] !== \"--root\") {\n throw new CliSyntaxError(`Unknown option: ${argv[index]}`);\n }\n if (rootProvided) {\n throw new CliSyntaxError(\"The --root option may only be provided once\");\n }\n const parsed = parseRootOption(argv, index);\n root = parsed.root;\n rootProvided = true;\n index = parsed.nextIndex;\n }\n return { command: \"prepare\", root };\n}\n\nfunction parseContextArgs(argv: readonly string[]): ContextCommandOptions {\n const context = argv[1];\n if (context !== \"sync\" && context !== \"install\") {\n throw new CliSyntaxError(\n \"Usage: bonfire context sync [--check] [--skip-prototypes] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>]\",\n );\n }\n\n let root = process.cwd();\n let appId: string | undefined;\n let check = false;\n let skipPrototypes = false;\n let rootProvided = false;\n let appIdProvided = false;\n let checkProvided = false;\n\n for (let index = 2; index < argv.length;) {\n const option = argv[index];\n if (option === \"--check\") {\n if (checkProvided) {\n throw new CliSyntaxError(\n \"The --check option may only be provided once\",\n );\n }\n check = true;\n checkProvided = true;\n index += 1;\n continue;\n }\n if (option === \"--skip-prototypes\" && context === \"sync\") {\n if (skipPrototypes) {\n throw new CliSyntaxError(\n \"The --skip-prototypes option may only be provided once\",\n );\n }\n skipPrototypes = true;\n index += 1;\n continue;\n }\n if (option === \"--root\") {\n if (rootProvided) {\n throw new CliSyntaxError(\"The --root option may only be provided once\");\n }\n const parsed = parseRootOption(argv, index);\n root = parsed.root;\n rootProvided = true;\n index = parsed.nextIndex;\n continue;\n }\n if (option === \"--app-id\") {\n if (appIdProvided) {\n throw new CliSyntaxError(\n \"The --app-id option may only be provided once\",\n );\n }\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(\"The --app-id option requires a value\");\n }\n appId = value;\n appIdProvided = true;\n index += 2;\n continue;\n }\n throw new CliSyntaxError(`Unknown option: ${option}`);\n }\n\n if (context === \"install\") {\n if (appId === undefined) {\n throw new CliSyntaxError(\n \"Usage: bonfire context install [--check] --app-id <app-id> [--root <root>]\",\n );\n }\n return { command: \"context\", context, root, appId, check };\n }\n if (appId !== undefined) {\n throw new CliSyntaxError(\"The --app-id option is only valid for install\");\n }\n return { command: \"context\", context, root, check, skipPrototypes };\n}\n\nfunction parseConvertArgs(argv: readonly string[]): ConvertCommandOptions {\n const defaults = defaultConvertOptions();\n let root: string | undefined;\n let appId: string | undefined;\n let name: string | undefined;\n let packageName = defaults.packageName;\n let hostname = convertDefaults.hostname;\n let deploymentEndpoint = convertDefaults.deploymentEndpoint;\n let withoutData = false;\n let dryRun = false;\n let skipInstall = false;\n const seen = new Set<string>();\n\n for (let index = 1; index < argv.length;) {\n const option = argv[index];\n if (!option) throw new CliSyntaxError(\"Missing convert option\");\n if (\n option === \"--without-data\" ||\n option === \"--dry-run\" ||\n option === \"--skip-install\"\n ) {\n if (seen.has(option))\n throw new CliSyntaxError(`${option} may only be provided once`);\n seen.add(option);\n if (option === \"--without-data\") withoutData = true;\n if (option === \"--dry-run\") dryRun = true;\n if (option === \"--skip-install\") skipInstall = true;\n index += 1;\n continue;\n }\n const setters: Record<string, (value: string) => void> = {\n \"--root\": (value) => {\n root = value;\n },\n \"--app-id\": (value) => {\n appId = value;\n },\n \"--name\": (value) => {\n name = value;\n },\n \"--package-name\": (value) => {\n packageName = value;\n },\n \"--hostname\": (value) => {\n hostname = value;\n },\n \"--deployment-endpoint\": (value) => {\n deploymentEndpoint = value;\n },\n };\n const setter = setters[option];\n if (!setter) throw new CliSyntaxError(`Unknown option: ${option}`);\n if (seen.has(option))\n throw new CliSyntaxError(`${option} may only be provided once`);\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\"))\n throw new CliSyntaxError(`${option} requires a value`);\n seen.add(option);\n setter(value);\n index += 2;\n }\n if (!root || !appId) {\n throw new CliSyntaxError(\n \"Usage: bonfire convert --root <next-app> --app-id <app-id> [--name <display-name>] [--hostname <hostname>] [--without-data] [--dry-run] [--skip-install]\",\n );\n }\n return {\n command: \"convert\",\n root,\n appId,\n name: name ?? humanizeAppId(appId),\n packageName,\n hostname,\n deploymentEndpoint,\n withItemData: !withoutData,\n dryRun,\n skipInstall,\n };\n}\n\nfunction parseBranchPrepareArgs(\n argv: readonly string[],\n): BranchPrepareCommandOptions {\n let root = process.cwd();\n let hostname: string | undefined;\n let defaultHostname: string | undefined;\n let prototypeRoot: string | undefined;\n let remote: string | undefined;\n let primaryBranch: string | undefined;\n let rootProvided = false;\n let hostnameProvided = false;\n let defaultHostnameProvided = false;\n let prototypeRootProvided = false;\n let remoteProvided = false;\n let primaryBranchProvided = false;\n\n for (let index = 2; index < argv.length;) {\n const option = argv[index];\n if (option === \"--root\") {\n if (rootProvided) {\n throw new CliSyntaxError(\"The --root option may only be provided once\");\n }\n const parsed = parseRootOption(argv, index);\n root = parsed.root;\n rootProvided = true;\n index = parsed.nextIndex;\n continue;\n }\n if (\n option === \"--prototype-root\" ||\n option === \"--remote\" ||\n option === \"--primary\"\n ) {\n const provided =\n option === \"--prototype-root\"\n ? prototypeRootProvided\n : option === \"--remote\"\n ? remoteProvided\n : primaryBranchProvided;\n if (provided) {\n throw new CliSyntaxError(`${option} may only be provided once`);\n }\n if (option === \"--prototype-root\") prototypeRootProvided = true;\n if (option === \"--remote\") remoteProvided = true;\n if (option === \"--primary\") primaryBranchProvided = true;\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(`${option} requires a value`);\n }\n if (option === \"--prototype-root\") prototypeRoot = value;\n if (option === \"--remote\") remote = value;\n if (option === \"--primary\") primaryBranch = value;\n index += 2;\n continue;\n }\n if (option === \"--hostname\" || option === \"--default-hostname\") {\n const isDefault = option === \"--default-hostname\";\n const provided = isDefault ? defaultHostnameProvided : hostnameProvided;\n if (provided) {\n throw new CliSyntaxError(\n `The ${option} option may only be provided once`,\n );\n }\n const value = argv[index + 1];\n if (!value || value.startsWith(\"--\")) {\n throw new CliSyntaxError(`The ${option} option requires a value`);\n }\n if (isDefault) {\n defaultHostname = value;\n defaultHostnameProvided = true;\n } else {\n hostname = value;\n hostnameProvided = true;\n }\n index += 2;\n continue;\n }\n throw new CliSyntaxError(`Unknown option: ${option}`);\n }\n\n return {\n command: \"branch\",\n root,\n ...(hostname === undefined ? {} : { hostname }),\n ...(defaultHostname === undefined ? {} : { defaultHostname }),\n ...(prototypeRoot === undefined ? {} : { prototypeRoot }),\n ...(remote === undefined ? {} : { remote }),\n ...(primaryBranch === undefined ? {} : { primaryBranch }),\n };\n}\n\nexport function parseArgs(argv: readonly string[]): CliCommandOptions {\n if (argv[0] === \"convert\") return parseConvertArgs(argv);\n if (argv[0] === \"context\") return parseContextArgs(argv);\n if (argv[0] === \"prepare\") return parsePrepareArgs(argv);\n if (argv[0] === \"branch\" && argv[1] === \"prepare\") {\n return parseBranchPrepareArgs(argv);\n }\n throw new CliSyntaxError(\n \"Usage: bonfire convert --root <next-app> --app-id <app-id> [options] | bonfire context sync [--check] [--skip-prototypes] [--root <root>] | bonfire context install [--check] --app-id <app-id> [--root <root>] | bonfire prepare [--root <application-root>] | bonfire branch prepare --root <application-root> [--hostname <hostname>] [--default-hostname <hostname>] [--prototype-root <root>] [--remote <name>] [--primary <branch>]\",\n );\n}\n\nfunction printContextIssues(result: {\n issues: readonly { kind: string; path: string }[];\n}) {\n for (const issue of result.issues) {\n console.error(`- ${issue.kind}: ${issue.path}`);\n }\n}\n\nfunction printContextSyncSummary(result: ContextSyncResult) {\n if (result.written.length > 0) {\n console.log(`Written: ${result.written.join(\", \")}`);\n }\n if (result.removed.length > 0) {\n console.log(`Removed: ${result.removed.join(\", \")}`);\n }\n}\n\nasync function runContextCommand(\n options: ContextCommandOptions,\n dependencies: CliDependencies,\n): Promise<number> {\n if (options.context === \"install\") {\n if (options.check) {\n const result = await (\n dependencies.contextInstallCheck ?? checkContextInstallation\n )({\n repositoryRoot: options.root,\n appId: options.appId,\n });\n if (!result.ok) {\n console.error(\"Context install check failed:\");\n printContextIssues(result);\n return 1;\n }\n console.log(\"Context install check passed.\");\n return 0;\n }\n const result = await (dependencies.contextInstall ?? installContext)({\n repositoryRoot: options.root,\n appId: options.appId,\n });\n const skills = result.skills.map(\n (skill) => `${skill.name} (${skill.status})`,\n );\n const mcp = result.mcp.map((server) => `${server.name} (${server.status})`);\n console.log(\n skills.length > 0\n ? `Context skills: ${skills.join(\", \")}`\n : \"No context skills configured.\",\n );\n if (mcp.length > 0) console.log(`Context MCP: ${mcp.join(\", \")}`);\n console.log(\"Context install complete.\");\n return 0;\n }\n\n if (options.check) {\n const result = await checkContext({\n repositoryRoot: options.root,\n skipPrototypes: options.skipPrototypes,\n });\n if (!result.ok) {\n console.error(\"Context sync check failed:\");\n printContextIssues(result);\n return 1;\n }\n console.log(\"Context sync check passed.\");\n return 0;\n }\n\n const result = await syncContext({\n repositoryRoot: options.root,\n skipPrototypes: options.skipPrototypes,\n });\n if (!result.ok) {\n console.error(\"Context sync failed:\");\n printContextIssues(result);\n return 1;\n }\n printContextSyncSummary(result);\n console.log(\"Context sync complete.\");\n return 0;\n}\n\nexport async function run(\n argv: readonly string[] = process.argv.slice(2),\n dependencies: CliDependencies = {},\n): Promise<number> {\n const isBranchPrepare = argv[0] === \"branch\";\n const isContext = argv[0] === \"context\";\n const isConvert = argv[0] === \"convert\";\n try {\n const options = parseArgs(argv);\n switch (options.command) {\n case \"context\":\n return await runContextCommand(options, dependencies);\n case \"convert\":\n await convert(options);\n return 0;\n case \"branch\":\n return await runBranchPrepare(options, dependencies);\n case \"prepare\": {\n const result = await prepare(options);\n const descriptions = {\n environment: \"the process environment\",\n existing: \".env.local\",\n generated: \"a newly generated value in .env.local\",\n } as const;\n console.log(\n `Bonfire preparation complete; BF_SESSION_SECRET came from ${descriptions[result.source]}.`,\n );\n return 0;\n }\n }\n } catch (error) {\n if (error instanceof CliSyntaxError) {\n console.error(`bonfire: ${error.message}`);\n return 2;\n }\n if (isContext) {\n const message =\n error instanceof Error ? error.message : \"an unknown error occurred\";\n console.error(`bonfire context failed: ${message}`);\n return 1;\n }\n if (isBranchPrepare) {\n const message =\n error instanceof BranchPrepareError\n ? error.message\n : \"Unable to load branch preparation configuration.\";\n console.error(`bonfire branch prepare failed: ${message}`);\n return 1;\n }\n if (isConvert) {\n const message =\n error instanceof Error ? error.message : \"an unknown error occurred\";\n console.error(`bonfire convert failed: ${message}`);\n return 1;\n }\n\n const message =\n error instanceof PrepareError || error instanceof Error\n ? error.message\n : \"an unknown error occurred\";\n console.error(`bonfire prepare failed: ${message}`);\n return 1;\n }\n}\n"]}
package/dist/convert.d.ts CHANGED
@@ -4,7 +4,6 @@ export type ConvertOptions = Readonly<{
4
4
  name: string;
5
5
  packageName?: string;
6
6
  hostname: string;
7
- port: number;
8
7
  deploymentEndpoint: string;
9
8
  withItemData: boolean;
10
9
  dryRun: boolean;
@@ -40,7 +39,6 @@ export declare function defaultConvertOptions(root?: string): ConvertOptions;
40
39
  export declare const convertDefaults: {
41
40
  hostname: string;
42
41
  deploymentEndpoint: string;
43
- port: number;
44
42
  };
45
43
  export {};
46
44
  //# sourceMappingURL=convert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAyBA,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,MAA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;;;;CAI3B,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport {\n chmod,\n lstat,\n mkdir,\n readFile,\n readdir,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { fileURLToPath } from \"node:url\";\nimport { syncContext } from \"@ebay-dt/bonfire-context\";\nimport { BONFIRE_VERSION, PRESET_VERSION } from \"./release-versions.js\";\n\nconst execFileAsync = promisify(execFile);\nconst TEMPLATE_ROOT = fileURLToPath(\n new URL(\"../templates/instance/\", import.meta.url),\n);\nconst DEFAULT_HOSTNAME = \"github.corp.ebay.com\";\nconst DEFAULT_DEPLOYMENT_ENDPOINT =\n \"https://dtsvc.vip.qa.ebay.com/dt/v1/bonfire-deploy\";\nconst DEFAULT_PORT = 1995;\n\nexport type ConvertOptions = Readonly<{\n root: string;\n appId: string;\n name: string;\n packageName?: string;\n hostname: string;\n port: number;\n deploymentEndpoint: string;\n withItemData: boolean;\n dryRun: boolean;\n skipInstall: boolean;\n}>;\n\ntype PackageJson = {\n name?: unknown;\n scripts?: Record<string, unknown>;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n engines?: Record<string, string>;\n [key: string]: unknown;\n};\n\ntype PlannedChange = Readonly<{\n kind: \"add\" | \"update\" | \"remove\";\n path: string;\n reason: string;\n}>;\n\ntype ConversionPlan = Readonly<{\n root: string;\n changes: readonly PlannedChange[];\n writes: ReadonlyMap<string, string>;\n removals: readonly string[];\n packageJson: PackageJson;\n}>;\n\nexport function humanizeAppId(appId: string) {\n return appId\n .replace(/([a-z0-9])([A-Z])/gu, \"$1 $2\")\n .replace(/[._-]+/gu, \" \")\n .trim()\n .split(/\\s+/u)\n .filter(Boolean)\n .map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`)\n .join(\" \");\n}\n\nexport class ConvertError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ConvertError\";\n }\n}\n\nfunction displayPath(root: string, path: string) {\n return relative(root, path) || \".\";\n}\n\nfunction parseVersion(value: unknown, label: string) {\n if (typeof value !== \"string\") {\n throw new ConvertError(`${label} must be declared in package.json`);\n }\n const match = value.match(/(\\d+)\\.(\\d+)\\.(\\d+)/u);\n if (!match) {\n throw new ConvertError(`${label} has an unsupported version: ${value}`);\n }\n return {\n major: Number(match[1]),\n minor: Number(match[2]),\n patch: Number(match[3]),\n };\n}\n\nfunction dependencyVersion(packageJson: PackageJson, name: string) {\n return (\n packageJson.dependencies?.[name] ?? packageJson.devDependencies?.[name]\n );\n}\n\nfunction validateStartingScaffold(packageJson: PackageJson) {\n const next = parseVersion(dependencyVersion(packageJson, \"next\"), \"next\");\n if (next.major !== 16 || next.minor < 2) {\n throw new ConvertError(\n `next must be 16.2 or newer within the 16.x line (found ${next.major}.${next.minor}.${next.patch})`,\n );\n }\n const react = parseVersion(dependencyVersion(packageJson, \"react\"), \"react\");\n if (react.major !== 19 || react.minor < 2) {\n throw new ConvertError(\n `react must be 19.2 or newer within the 19.x line (found ${react.major}.${react.minor}.${react.patch})`,\n );\n }\n if (!dependencyVersion(packageJson, \"typescript\")) {\n throw new ConvertError(\"typescript must be declared in package.json\");\n }\n\n if (Number(process.versions.node.split(\".\")[0]) < 24) {\n throw new ConvertError(\n \"Bonfire instance conversion requires Node.js 24 or newer\",\n );\n }\n return next;\n}\n\nasync function readJson(path: string) {\n try {\n return JSON.parse(await readFile(path, \"utf8\")) as PackageJson;\n } catch (error) {\n if (error instanceof SyntaxError) {\n throw new ConvertError(\n `${displayPath(dirname(path), path)} is not valid JSON`,\n );\n }\n throw error;\n }\n}\n\nasync function exists(path: string) {\n try {\n await lstat(path);\n return true;\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n throw error;\n }\n}\n\nasync function fileContent(path: string) {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return undefined;\n }\n throw error;\n }\n}\n\nfunction addChange(\n changes: PlannedChange[],\n root: string,\n path: string,\n kind: PlannedChange[\"kind\"],\n reason: string,\n) {\n changes.push({ kind, path: displayPath(root, path), reason });\n}\n\nasync function planFile(\n root: string,\n path: string,\n content: string,\n reason: string,\n writes: Map<string, string>,\n changes: PlannedChange[],\n) {\n const existing = await fileContent(path);\n if (existing === undefined) {\n writes.set(path, content);\n addChange(changes, root, path, \"add\", reason);\n return;\n }\n if (existing === content) return;\n throw new ConvertError(\n `${displayPath(root, path)} already exists and differs from the Bonfire scaffold; resolve it before converting`,\n );\n}\n\nfunction looksLikeNextStarter(path: string, content: string) {\n if (path.endsWith(\"/page.tsx\")) {\n return /Create Next App|[Gg]et started|Looking for a starting point|create-next-app/u.test(\n content,\n );\n }\n if (path.endsWith(\"/layout.tsx\")) {\n return /next\\/font|Geist|Create Next App/u.test(content);\n }\n if (path.endsWith(\"/page.module.css\")) {\n return /\\.page|\\.main|\\.footer|\\.grid/u.test(content);\n }\n if (path.endsWith(\"/globals.css\")) {\n return /--background|--foreground|@import [\"']tailwindcss/u.test(content);\n }\n if (path.endsWith(\"/README.md\")) {\n return /bootstrapped with[\\s\\S]*create-next-app/u.test(content);\n }\n if (path.endsWith(\"/next.config.ts\")) {\n return /config options here/u.test(content);\n }\n return false;\n}\n\nfunction looksLikeStarterAsset(path: string, content: string) {\n const name = path.slice(path.lastIndexOf(\"/\") + 1);\n if (\n ![\"file.svg\", \"globe.svg\", \"next.svg\", \"vercel.svg\", \"window.svg\"].includes(\n name,\n )\n ) {\n return false;\n }\n return /<svg[\\s\\S]*viewBox=/u.test(content);\n}\n\nasync function planRemoveStarter(\n root: string,\n path: string,\n reason: string,\n removals: string[],\n changes: PlannedChange[],\n) {\n const content = await fileContent(path);\n if (content === undefined) return;\n if (\n content.includes(\"@ebay-dt/bonfire-next\") ||\n content.includes(\"A Bonfire instance for creating\") ||\n content.includes(\"outputFileTracingIncludes\")\n ) {\n return;\n }\n if (\n !looksLikeNextStarter(path, content) &&\n !looksLikeStarterAsset(path, content)\n ) {\n throw new ConvertError(\n `${displayPath(root, path)} is customized; it will not be removed automatically`,\n );\n }\n removals.push(path);\n addChange(changes, root, path, \"remove\", reason);\n}\n\nfunction replaceIdentity(content: string, options: ConvertOptions) {\n return content\n .replaceAll(\"design-sandbox-next\", () => options.appId)\n .replaceAll(\"Design Sandbox\", () => options.name)\n .replaceAll(\"github.corp.ebay.com\", () => options.hostname)\n .replaceAll(DEFAULT_DEPLOYMENT_ENDPOINT, () => options.deploymentEndpoint);\n}\n\nfunction withoutItemGuidance(content: string) {\n const start = content.indexOf(\"### Data fetching\");\n const end = content.indexOf(\"### Viewport sizing\");\n if (start < 0 || end < 0 || end <= start) return content;\n return `${content.slice(0, start)}${content.slice(end)}`;\n}\n\nasync function templateFiles(options: ConvertOptions) {\n const files: Array<{ relativePath: string; content: string }> = [];\n async function visit(directory: string) {\n const entries = await readdir(directory, { withFileTypes: true });\n for (const entry of entries.sort((left, right) =>\n left.name.localeCompare(right.name),\n )) {\n const path = join(directory, entry.name);\n const relativePath = relative(TEMPLATE_ROOT, path);\n if (\n !options.withItemData &&\n (relativePath.startsWith(\"src/app/api/items/\") ||\n relativePath.startsWith(\"src/lib/items/\") ||\n relativePath === \"context/skills/item-data/SKILL.md\")\n ) {\n continue;\n }\n if (entry.isDirectory()) {\n await visit(path);\n } else if (entry.isFile()) {\n let content = await readFile(path, \"utf8\");\n content = replaceIdentity(content, options);\n if (!options.withItemData && relativePath === \"context/PROTOTYPE.md\") {\n content = withoutItemGuidance(content);\n }\n files.push({ relativePath, content });\n }\n }\n }\n await visit(TEMPLATE_ROOT);\n return files;\n}\n\nfunction starterReadme(options: ConvertOptions) {\n return `# ${options.name}\\n\\nA Bonfire instance for creating, editing, and sharing prototypes.\\n\\n## Development\\n\\nUse Node.js 24+, install dependencies with pnpm, then run:\\n\\n~~~sh\\npnpm dev\\n~~~\\n\\nThe development command prepares the Bonfire session secret and the local identity branch before starting Next.js on port ${options.port}.\\n\\nRun pnpm context:install once on a machine where agent tooling is desired.\\n`;\n}\n\nfunction addDependency(\n packageJson: PackageJson,\n section: \"dependencies\" | \"devDependencies\",\n name: string,\n version: string,\n) {\n const target = (packageJson[section] ??= {});\n const existing = target[name];\n if (existing !== undefined) {\n if (existing !== version && name.startsWith(\"@ebay-dt/bonfire-\")) {\n throw new ConvertError(\n `${name} is already declared as ${existing}; expected ${version}. Update it explicitly before converting`,\n );\n }\n return;\n }\n target[name] = version;\n}\n\nfunction addScript(\n packageJson: PackageJson,\n name: string,\n value: string,\n allowedExisting: readonly string[] = [],\n) {\n const scripts = (packageJson.scripts ??= {});\n const existing = scripts[name];\n if (existing !== undefined) {\n if (existing !== value && !allowedExisting.includes(String(existing))) {\n throw new ConvertError(\n `package.json script ${name} is customized (${String(existing)}); resolve it before converting`,\n );\n }\n scripts[name] = value;\n return;\n }\n scripts[name] = value;\n}\n\nfunction mergeLines(existing: string | undefined, required: readonly string[]) {\n let result = existing ?? \"\";\n for (const line of required) {\n if (result.split(/\\r?\\n/u).some((entry) => entry.trim() === line)) continue;\n if (result.length > 0 && !result.endsWith(\"\\n\")) result += \"\\n\";\n result += `${line}\\n`;\n }\n return result;\n}\n\nfunction mergeWorkspace(existing: string | undefined) {\n let result = existing ?? \"\";\n if (!/^minimumReleaseAge:/mu.test(result)) {\n result = `# Bonfire publishes lockstep alpha packages that must be installable immediately.\\nminimumReleaseAge: 0\\n${result}`;\n } else if (!/^minimumReleaseAge:\\s*0\\s*$/mu.test(result)) {\n throw new ConvertError(\n \"pnpm-workspace.yaml has a conflicting minimumReleaseAge\",\n );\n }\n const required = [\n \" esbuild: true\",\n \" sharp: true\",\n \" unrs-resolver: true\",\n ];\n for (const line of required) {\n const key = line.trim().split(\":\")[0] ?? \"\";\n const match = result.match(new RegExp(`^\\\\s+${key}:\\\\s*(\\\\S+)\\\\s*$`, \"mu\"));\n if (match && match[1] !== \"true\") {\n // create-next-app currently writes these two false entries. They are\n // starter policy, not an instance decision, so normalize them to the\n // Bonfire installation policy.\n if (match[1] !== \"false\" || ![\"sharp\", \"unrs-resolver\"].includes(key)) {\n throw new ConvertError(\n `pnpm-workspace.yaml has a conflicting allowBuilds.${key} setting`,\n );\n }\n result = result.replace(\n new RegExp(`(^\\\\s+${key}:\\\\s*)false(\\\\s*$)`, \"mu\"),\n \"$1true$2\",\n );\n }\n if (!match) {\n if (!result.endsWith(\"\\n\")) result += \"\\n\";\n result += `${line}\\n`;\n }\n }\n return result;\n}\n\nasync function planPackageJson(\n root: string,\n options: ConvertOptions,\n packageJson: PackageJson,\n nextVersion: { major: number; minor: number; patch: number },\n writes: Map<string, string>,\n changes: PlannedChange[],\n) {\n const packageName =\n options.packageName ??\n (typeof packageJson.name === \"string\" ? packageJson.name : options.appId);\n if (!/^[a-z0-9][a-z0-9._-]*$/u.test(packageName)) {\n throw new ConvertError(`package name is invalid: ${packageName}`);\n }\n packageJson.name = packageName;\n const engines = (packageJson.engines ??= {});\n if (\n engines.node !== undefined &&\n !/^(?:\\^|~|>=)?\\s*2[4-9]|[3-9]\\d/u.test(engines.node)\n ) {\n throw new ConvertError(\n \"package.json engines.node must allow Node.js 24 or newer\",\n );\n }\n engines.node = \">=24\";\n\n const dev = `bonfire prepare --root . && bonfire branch prepare --root . --default-hostname \"${options.hostname}\" && next dev -p ${options.port}`;\n addScript(packageJson, \"dev\", dev, [\"next dev\"]);\n addScript(packageJson, \"context:sync\", \"bonfire context sync\");\n addScript(\n packageJson,\n \"context:install\",\n `bonfire context install --app-id ${options.appId}`,\n );\n addScript(\n packageJson,\n \"check\",\n \"tsc --noEmit --project tsconfig.check.json && pnpm context:sync --check\",\n );\n addScript(packageJson, \"format\", \"prettier --write .\");\n addScript(packageJson, \"build\", \"next build\", [\"next build\"]);\n addScript(packageJson, \"start\", \"next start\", [\"next start\"]);\n addScript(packageJson, \"lint\", \"eslint\", [\"eslint\", \"eslint .\"]);\n\n const nextExact = `${nextVersion.major}.${nextVersion.minor}.${nextVersion.patch}`;\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-context\",\n BONFIRE_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-core\",\n BONFIRE_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-next\",\n BONFIRE_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-preset-ebay\",\n PRESET_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-react\",\n BONFIRE_VERSION,\n );\n addDependency(packageJson, \"dependencies\", \"@ebay/ui-core-react\", \"9.13.0\");\n addDependency(packageJson, \"dependencies\", \"@evo-web/react\", \"0.4.4\");\n addDependency(\n packageJson,\n \"dependencies\",\n \"react-dom\",\n dependencyVersion(packageJson, \"react-dom\") ?? \"19.2.8\",\n );\n addDependency(packageJson, \"dependencies\", \"server-only\", \"^0.0.1\");\n addDependency(\n packageJson,\n \"devDependencies\",\n \"@ebay-dt/bonfire-cli\",\n BONFIRE_VERSION,\n );\n addDependency(packageJson, \"devDependencies\", \"@types/node\", \"^20\");\n addDependency(packageJson, \"devDependencies\", \"@types/react\", \"^19\");\n addDependency(packageJson, \"devDependencies\", \"@types/react-dom\", \"^19\");\n addDependency(packageJson, \"devDependencies\", \"eslint\", \"^9\");\n addDependency(\n packageJson,\n \"devDependencies\",\n \"eslint-config-next\",\n nextExact,\n );\n addDependency(packageJson, \"devDependencies\", \"prettier\", \"^3.9.5\");\n if (options.withItemData) {\n addDependency(\n packageJson,\n \"dependencies\",\n \"@tanstack/react-query\",\n \"^5.104.0\",\n );\n addDependency(packageJson, \"dependencies\", \"zod\", \"^4.4.3\");\n }\n\n const path = join(root, \"package.json\");\n const content = `${JSON.stringify(packageJson, null, 2)}\\n`;\n const existing = await readFile(path, \"utf8\");\n if (JSON.stringify(JSON.parse(existing)) !== JSON.stringify(packageJson)) {\n writes.set(path, content);\n addChange(\n changes,\n root,\n path,\n \"update\",\n \"merge Bonfire scripts and dependencies\",\n );\n }\n}\n\nexport async function planConversion(\n options: ConvertOptions,\n): Promise<ConversionPlan> {\n const root = resolve(options.root);\n if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(options.appId)) {\n throw new ConvertError(\n \"app id must contain only letters, numbers, dots, underscores, and hyphens\",\n );\n }\n if (!options.name.trim())\n throw new ConvertError(\"display name must not be empty\");\n const packagePath = join(root, \"package.json\");\n const packageJson = await readJson(packagePath);\n const nextVersion = validateStartingScaffold(packageJson);\n if (!(await exists(join(root, \"src\", \"app\")))) {\n throw new ConvertError(\n \"the starting scaffold must use the src/app App Router\",\n );\n }\n\n const writes = new Map<string, string>();\n const changes: PlannedChange[] = [];\n const removals: string[] = [];\n\n const starterPaths = [\n join(root, \"src/app/layout.tsx\"),\n join(root, \"src/app/page.tsx\"),\n join(root, \"src/app/page.module.css\"),\n join(root, \"src/app/globals.css\"),\n join(root, \"next.config.ts\"),\n join(root, \"README.md\"),\n ...[\"file.svg\", \"globe.svg\", \"next.svg\", \"vercel.svg\", \"window.svg\"].map(\n (name) => join(root, \"public\", name),\n ),\n ];\n for (const path of starterPaths) {\n await planRemoveStarter(\n root,\n path,\n \"remove unmodified create-next-app content\",\n removals,\n changes,\n );\n }\n const nextBuildDirectory = join(root, \".next\");\n if (await exists(nextBuildDirectory)) {\n removals.push(nextBuildDirectory);\n addChange(\n changes,\n root,\n nextBuildDirectory,\n \"remove\",\n \"clear generated Next.js output\",\n );\n }\n\n const resolvedOptions = { ...options, root };\n const templates = await templateFiles(resolvedOptions);\n for (const file of templates) {\n const path = join(root, file.relativePath);\n if (removals.includes(path)) {\n writes.set(path, file.content);\n addChange(\n changes,\n root,\n path,\n \"update\",\n \"replace unmodified create-next-app content\",\n );\n continue;\n }\n await planFile(\n root,\n path,\n file.content,\n \"add Bonfire instance scaffold\",\n writes,\n changes,\n );\n }\n\n await planPackageJson(\n root,\n options,\n packageJson,\n nextVersion,\n writes,\n changes,\n );\n\n const tsconfigPath = join(root, \"tsconfig.json\");\n const existingTsconfig = await readFile(tsconfigPath, \"utf8\");\n const tsconfig = await readJson(tsconfigPath);\n const compilerOptions = (tsconfig.compilerOptions ?? {}) as Record<\n string,\n unknown\n >;\n tsconfig.compilerOptions = compilerOptions;\n const paths = compilerOptions[\"paths\"] as Record<string, unknown> | undefined;\n if (paths && JSON.stringify(paths[\"@/*\"]) !== JSON.stringify([\"./src/*\"])) {\n throw new ConvertError(\"tsconfig.json has a conflicting @/* path alias\");\n }\n compilerOptions[\"paths\"] = { ...(paths ?? {}), \"@/*\": [\"./src/*\"] };\n const nextTsconfig = `${JSON.stringify(tsconfig, null, 2)}\\n`;\n if (\n JSON.stringify(JSON.parse(existingTsconfig)) !== JSON.stringify(tsconfig)\n ) {\n writes.set(tsconfigPath, nextTsconfig);\n addChange(\n changes,\n root,\n tsconfigPath,\n \"update\",\n \"retain the Bonfire @/* source alias\",\n );\n }\n\n await planFile(\n root,\n join(root, \"tsconfig.check.json\"),\n '{\\n \"extends\": \"./tsconfig.json\",\\n \"exclude\": [\"node_modules\", \".next\"]\\n}\\n',\n \"add the clean TypeScript check project\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \".prettierrc\"),\n '{\\n \"semi\": false,\\n \"singleQuote\": true,\\n \"trailingComma\": \"es5\",\\n \"printWidth\": 80\\n}\\n',\n \"add Bonfire formatting conventions\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \".prettierignore\"),\n \"# Generated and external files\\n.next/\\nnode_modules/\\npnpm-lock.yaml\\nsrc/app/(prototypes)/**/.claude/settings.json\\n\",\n \"add formatter exclusions\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \".env.local.example\"),\n \"# Bonfire generates this secret during `pnpm dev`.\\n# Do NOT manually modify or remove this variable.\\nBF_SESSION_SECRET=\\n\\n# Set exactly to lowercase `true` to skip automatic identity-branch preparation.\\nBF_DISABLE_AUTO_BRANCH_SWITCH=\\n\\n# Set to `managed` or `manual` for Bonfire Git management.\\nBF_GIT_MODE=\\n\",\n \"document Bonfire environment setup\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \"public/.gitkeep\"),\n \"\",\n \"retain an explicit public directory\",\n writes,\n changes,\n );\n\n const gitignorePath = join(root, \".gitignore\");\n const gitignore = await fileContent(gitignorePath);\n const mergedGitignore = mergeLines(gitignore, [\n \"# Bonfire local secrets\",\n \".env.local\",\n ]);\n if (mergedGitignore !== (gitignore ?? \"\")) {\n writes.set(gitignorePath, mergedGitignore);\n addChange(\n changes,\n root,\n gitignorePath,\n \"update\",\n \"ignore the generated local session secret\",\n );\n }\n\n const workspacePath = join(root, \"pnpm-workspace.yaml\");\n const workspace = await fileContent(workspacePath);\n const mergedWorkspace = mergeWorkspace(workspace);\n if (mergedWorkspace !== (workspace ?? \"\")) {\n writes.set(workspacePath, mergedWorkspace);\n addChange(\n changes,\n root,\n workspacePath,\n \"update\",\n \"retain the Bonfire pnpm installation policy\",\n );\n }\n const npmrcPath = join(root, \".npmrc\");\n const npmrc = await fileContent(npmrcPath);\n if (\n npmrc &&\n /@ebay-dt:\\s*registry=/u.test(npmrc) &&\n !npmrc.includes(\"@ebay-dt:registry=https://registry.npmjs.org/\")\n ) {\n throw new ConvertError(\".npmrc has a conflicting @ebay-dt registry\");\n }\n const mergedNpmrc = mergeLines(npmrc, [\n \"@ebay-dt:registry=https://registry.npmjs.org/\",\n ]);\n if (mergedNpmrc !== (npmrc ?? \"\")) {\n writes.set(npmrcPath, mergedNpmrc);\n addChange(\n changes,\n root,\n npmrcPath,\n \"update\",\n \"resolve Bonfire packages from public npm\",\n );\n }\n const nvmrcPath = join(root, \".nvmrc\");\n const nvmrc = await fileContent(nvmrcPath);\n if (nvmrc === undefined) {\n await planFile(\n root,\n nvmrcPath,\n \"24\\n\",\n \"select Node.js 24 or newer\",\n writes,\n changes,\n );\n }\n\n const readmePath = join(root, \"README.md\");\n if (removals.includes(readmePath)) {\n writes.set(readmePath, starterReadme(options));\n addChange(\n changes,\n root,\n readmePath,\n \"update\",\n \"replace unmodified create-next-app documentation\",\n );\n } else if (\n !writes.has(readmePath) &&\n (await fileContent(readmePath)) === undefined\n ) {\n await planFile(\n root,\n readmePath,\n starterReadme(options),\n \"add instance setup documentation\",\n writes,\n changes,\n );\n }\n\n return { root, changes, writes, removals, packageJson };\n}\n\nexport async function convert(options: ConvertOptions) {\n const plan = await planConversion(options);\n for (const change of plan.changes) {\n console.log(\n `${options.dryRun ? \"Would \" : \"\"}${change.kind} ${change.path} (${change.reason})`,\n );\n }\n if (options.dryRun) return;\n\n for (const path of plan.removals) {\n await rm(path, {\n force: true,\n recursive: path === join(plan.root, \".next\"),\n });\n }\n for (const [path, content] of plan.writes) {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content);\n if (path.endsWith(\"context/hooks/block-env-reads.mjs\")) {\n await chmod(path, 0o755);\n }\n }\n\n if (!options.skipInstall) {\n console.log(\"Installing dependencies and updating pnpm-lock.yaml...\");\n await execFileAsync(\"pnpm\", [\"install\"], {\n cwd: plan.root,\n maxBuffer: 10 * 1024 * 1024,\n });\n }\n\n if (!options.skipInstall) {\n const formatPaths = [...plan.writes.keys()]\n .map((path) => displayPath(plan.root, path))\n .filter((path) => /\\.(?:json|mjs|md|ts|tsx|yaml|yml)$/u.test(path));\n if (formatPaths.length > 0) {\n await execFileAsync(\n \"pnpm\",\n [\"exec\", \"prettier\", \"--write\", ...formatPaths],\n {\n cwd: plan.root,\n maxBuffer: 10 * 1024 * 1024,\n },\n );\n }\n await execFileAsync(\"pnpm\", [\"exec\", \"next\", \"typegen\"], {\n cwd: plan.root,\n maxBuffer: 10 * 1024 * 1024,\n });\n }\n\n const contextResult = await syncContext({ repositoryRoot: plan.root });\n if (contextResult.written.length > 0 || contextResult.removed.length > 0) {\n console.log(\n `Context synchronized (${contextResult.written.length} written, ${contextResult.removed.length} removed).`,\n );\n }\n console.log(\"Bonfire instance conversion complete.\");\n}\n\nexport function defaultConvertOptions(root = process.cwd()): ConvertOptions {\n const appId = \"bonfire-instance\";\n return {\n root,\n appId,\n name: \"Bonfire Instance\",\n hostname: DEFAULT_HOSTNAME,\n port: DEFAULT_PORT,\n deploymentEndpoint: DEFAULT_DEPLOYMENT_ENDPOINT,\n withItemData: true,\n dryRun: false,\n skipInstall: false,\n };\n}\n\nexport const convertDefaults = {\n hostname: DEFAULT_HOSTNAME,\n deploymentEndpoint: DEFAULT_DEPLOYMENT_ENDPOINT,\n port: DEFAULT_PORT,\n};\n"]}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAwBA,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC,CAAC;AAEH,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,KAAK,aAAa,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH,KAAK,cAAc,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC,CAAC;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,UAS1C;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAqdD,wBAAsB,cAAc,CAClC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,cAAc,CAAC,CA0PzB;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,cAAc,iBA0DpD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,SAAgB,GAAG,cAAc,CAY1E;AAED,eAAO,MAAM,eAAe;;;CAG3B,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport {\n chmod,\n lstat,\n mkdir,\n readFile,\n readdir,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { fileURLToPath } from \"node:url\";\nimport { syncContext } from \"@ebay-dt/bonfire-context\";\nimport { BONFIRE_VERSION, PRESET_VERSION } from \"./release-versions.js\";\n\nconst execFileAsync = promisify(execFile);\nconst TEMPLATE_ROOT = fileURLToPath(\n new URL(\"../templates/instance/\", import.meta.url),\n);\nconst DEFAULT_HOSTNAME = \"github.corp.ebay.com\";\nconst DEFAULT_DEPLOYMENT_ENDPOINT =\n \"https://dtsvc.vip.qa.ebay.com/dt/v1/bonfire-deploy\";\n\nexport type ConvertOptions = Readonly<{\n root: string;\n appId: string;\n name: string;\n packageName?: string;\n hostname: string;\n deploymentEndpoint: string;\n withItemData: boolean;\n dryRun: boolean;\n skipInstall: boolean;\n}>;\n\ntype PackageJson = {\n name?: unknown;\n scripts?: Record<string, unknown>;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n engines?: Record<string, string>;\n [key: string]: unknown;\n};\n\ntype PlannedChange = Readonly<{\n kind: \"add\" | \"update\" | \"remove\";\n path: string;\n reason: string;\n}>;\n\ntype ConversionPlan = Readonly<{\n root: string;\n changes: readonly PlannedChange[];\n writes: ReadonlyMap<string, string>;\n removals: readonly string[];\n packageJson: PackageJson;\n}>;\n\nexport function humanizeAppId(appId: string) {\n return appId\n .replace(/([a-z0-9])([A-Z])/gu, \"$1 $2\")\n .replace(/[._-]+/gu, \" \")\n .trim()\n .split(/\\s+/u)\n .filter(Boolean)\n .map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`)\n .join(\" \");\n}\n\nexport class ConvertError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ConvertError\";\n }\n}\n\nfunction displayPath(root: string, path: string) {\n return relative(root, path) || \".\";\n}\n\nfunction parseVersion(value: unknown, label: string) {\n if (typeof value !== \"string\") {\n throw new ConvertError(`${label} must be declared in package.json`);\n }\n const match = value.match(/(\\d+)\\.(\\d+)\\.(\\d+)/u);\n if (!match) {\n throw new ConvertError(`${label} has an unsupported version: ${value}`);\n }\n return {\n major: Number(match[1]),\n minor: Number(match[2]),\n patch: Number(match[3]),\n };\n}\n\nfunction dependencyVersion(packageJson: PackageJson, name: string) {\n return (\n packageJson.dependencies?.[name] ?? packageJson.devDependencies?.[name]\n );\n}\n\nfunction validateStartingScaffold(packageJson: PackageJson) {\n const next = parseVersion(dependencyVersion(packageJson, \"next\"), \"next\");\n if (next.major !== 16 || next.minor < 2) {\n throw new ConvertError(\n `next must be 16.2 or newer within the 16.x line (found ${next.major}.${next.minor}.${next.patch})`,\n );\n }\n const react = parseVersion(dependencyVersion(packageJson, \"react\"), \"react\");\n if (react.major !== 19 || react.minor < 2) {\n throw new ConvertError(\n `react must be 19.2 or newer within the 19.x line (found ${react.major}.${react.minor}.${react.patch})`,\n );\n }\n if (!dependencyVersion(packageJson, \"typescript\")) {\n throw new ConvertError(\"typescript must be declared in package.json\");\n }\n\n if (Number(process.versions.node.split(\".\")[0]) < 24) {\n throw new ConvertError(\n \"Bonfire instance conversion requires Node.js 24 or newer\",\n );\n }\n return next;\n}\n\nasync function readJson(path: string) {\n try {\n return JSON.parse(await readFile(path, \"utf8\")) as PackageJson;\n } catch (error) {\n if (error instanceof SyntaxError) {\n throw new ConvertError(\n `${displayPath(dirname(path), path)} is not valid JSON`,\n );\n }\n throw error;\n }\n}\n\nasync function exists(path: string) {\n try {\n await lstat(path);\n return true;\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n throw error;\n }\n}\n\nasync function fileContent(path: string) {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return undefined;\n }\n throw error;\n }\n}\n\nfunction addChange(\n changes: PlannedChange[],\n root: string,\n path: string,\n kind: PlannedChange[\"kind\"],\n reason: string,\n) {\n changes.push({ kind, path: displayPath(root, path), reason });\n}\n\nasync function planFile(\n root: string,\n path: string,\n content: string,\n reason: string,\n writes: Map<string, string>,\n changes: PlannedChange[],\n) {\n const existing = await fileContent(path);\n if (existing === undefined) {\n writes.set(path, content);\n addChange(changes, root, path, \"add\", reason);\n return;\n }\n if (existing === content) return;\n throw new ConvertError(\n `${displayPath(root, path)} already exists and differs from the Bonfire scaffold; resolve it before converting`,\n );\n}\n\nfunction looksLikeNextStarter(path: string, content: string) {\n if (path.endsWith(\"/page.tsx\")) {\n return /Create Next App|[Gg]et started|Looking for a starting point|create-next-app/u.test(\n content,\n );\n }\n if (path.endsWith(\"/layout.tsx\")) {\n return /next\\/font|Geist|Create Next App/u.test(content);\n }\n if (path.endsWith(\"/page.module.css\")) {\n return /\\.page|\\.main|\\.footer|\\.grid/u.test(content);\n }\n if (path.endsWith(\"/globals.css\")) {\n return /--background|--foreground|@import [\"']tailwindcss/u.test(content);\n }\n if (path.endsWith(\"/README.md\")) {\n return /bootstrapped with[\\s\\S]*create-next-app/u.test(content);\n }\n if (path.endsWith(\"/next.config.ts\")) {\n return /config options here/u.test(content);\n }\n return false;\n}\n\nfunction looksLikeStarterAsset(path: string, content: string) {\n const name = path.slice(path.lastIndexOf(\"/\") + 1);\n if (\n ![\"file.svg\", \"globe.svg\", \"next.svg\", \"vercel.svg\", \"window.svg\"].includes(\n name,\n )\n ) {\n return false;\n }\n return /<svg[\\s\\S]*viewBox=/u.test(content);\n}\n\nasync function planRemoveStarter(\n root: string,\n path: string,\n reason: string,\n removals: string[],\n changes: PlannedChange[],\n) {\n const content = await fileContent(path);\n if (content === undefined) return;\n if (\n content.includes(\"@ebay-dt/bonfire-next\") ||\n content.includes(\"A Bonfire instance for creating\") ||\n content.includes(\"outputFileTracingIncludes\")\n ) {\n return;\n }\n if (\n !looksLikeNextStarter(path, content) &&\n !looksLikeStarterAsset(path, content)\n ) {\n throw new ConvertError(\n `${displayPath(root, path)} is customized; it will not be removed automatically`,\n );\n }\n removals.push(path);\n addChange(changes, root, path, \"remove\", reason);\n}\n\nfunction replaceIdentity(content: string, options: ConvertOptions) {\n return content\n .replaceAll(\"design-sandbox-next\", () => options.appId)\n .replaceAll(\"Design Sandbox\", () => options.name)\n .replaceAll(\"github.corp.ebay.com\", () => options.hostname)\n .replaceAll(DEFAULT_DEPLOYMENT_ENDPOINT, () => options.deploymentEndpoint);\n}\n\nfunction withoutItemGuidance(content: string) {\n const start = content.indexOf(\"### Data fetching\");\n const end = content.indexOf(\"### Viewport sizing\");\n if (start < 0 || end < 0 || end <= start) return content;\n return `${content.slice(0, start)}${content.slice(end)}`;\n}\n\nasync function templateFiles(options: ConvertOptions) {\n const files: Array<{ relativePath: string; content: string }> = [];\n async function visit(directory: string) {\n const entries = await readdir(directory, { withFileTypes: true });\n for (const entry of entries.sort((left, right) =>\n left.name.localeCompare(right.name),\n )) {\n const path = join(directory, entry.name);\n const relativePath = relative(TEMPLATE_ROOT, path);\n if (\n !options.withItemData &&\n (relativePath.startsWith(\"src/app/api/items/\") ||\n relativePath.startsWith(\"src/lib/items/\") ||\n relativePath === \"context/skills/item-data/SKILL.md\")\n ) {\n continue;\n }\n if (entry.isDirectory()) {\n await visit(path);\n } else if (entry.isFile()) {\n let content = await readFile(path, \"utf8\");\n content = replaceIdentity(content, options);\n if (!options.withItemData && relativePath === \"context/PROTOTYPE.md\") {\n content = withoutItemGuidance(content);\n }\n files.push({ relativePath, content });\n }\n }\n }\n await visit(TEMPLATE_ROOT);\n return files;\n}\n\nfunction starterReadme(options: ConvertOptions) {\n return `# ${options.name}\\n\\nA Bonfire instance for creating, editing, and sharing prototypes.\\n\\n## Development\\n\\nUse Node.js 24+, install dependencies with pnpm, then run:\\n\\n~~~sh\\npnpm dev\\n~~~\\n\\nThe development command prepares the Bonfire session secret and the local identity branch before starting Next.js.\\n\\nRun pnpm context:install once on a machine where agent tooling is desired.\\n`;\n}\n\nfunction addDependency(\n packageJson: PackageJson,\n section: \"dependencies\" | \"devDependencies\",\n name: string,\n version: string,\n) {\n const target = (packageJson[section] ??= {});\n const existing = target[name];\n if (existing !== undefined) {\n if (existing !== version && name.startsWith(\"@ebay-dt/bonfire-\")) {\n throw new ConvertError(\n `${name} is already declared as ${existing}; expected ${version}. Update it explicitly before converting`,\n );\n }\n return;\n }\n target[name] = version;\n}\n\nfunction addScript(\n packageJson: PackageJson,\n name: string,\n value: string,\n allowedExisting: readonly string[] = [],\n) {\n const scripts = (packageJson.scripts ??= {});\n const existing = scripts[name];\n if (existing !== undefined) {\n if (\n existing !== value &&\n !allowedExisting.includes(String(existing)) &&\n !(\n name === \"dev\" &&\n typeof existing === \"string\" &&\n /^bonfire prepare --root \\. && bonfire branch prepare --root \\. --default-hostname \"[^\"\\n]+\" && next dev(?: -p \\d+)?$/u.test(\n existing,\n )\n )\n ) {\n throw new ConvertError(\n `package.json script ${name} is customized (${String(existing)}); resolve it before converting`,\n );\n }\n scripts[name] = value;\n return;\n }\n scripts[name] = value;\n}\n\nfunction mergeLines(existing: string | undefined, required: readonly string[]) {\n let result = existing ?? \"\";\n for (const line of required) {\n if (result.split(/\\r?\\n/u).some((entry) => entry.trim() === line)) continue;\n if (result.length > 0 && !result.endsWith(\"\\n\")) result += \"\\n\";\n result += `${line}\\n`;\n }\n return result;\n}\n\nfunction mergeWorkspace(existing: string | undefined) {\n let result = existing ?? \"\";\n if (!/^minimumReleaseAge:/mu.test(result)) {\n result = `# Bonfire publishes lockstep alpha packages that must be installable immediately.\\nminimumReleaseAge: 0\\n${result}`;\n } else if (!/^minimumReleaseAge:\\s*0\\s*$/mu.test(result)) {\n throw new ConvertError(\n \"pnpm-workspace.yaml has a conflicting minimumReleaseAge\",\n );\n }\n const required = [\n \" esbuild: true\",\n \" sharp: true\",\n \" unrs-resolver: true\",\n ];\n for (const line of required) {\n const key = line.trim().split(\":\")[0] ?? \"\";\n const match = result.match(new RegExp(`^\\\\s+${key}:\\\\s*(\\\\S+)\\\\s*$`, \"mu\"));\n if (match && match[1] !== \"true\") {\n // create-next-app currently writes these two false entries. They are\n // starter policy, not an instance decision, so normalize them to the\n // Bonfire installation policy.\n if (match[1] !== \"false\" || ![\"sharp\", \"unrs-resolver\"].includes(key)) {\n throw new ConvertError(\n `pnpm-workspace.yaml has a conflicting allowBuilds.${key} setting`,\n );\n }\n result = result.replace(\n new RegExp(`(^\\\\s+${key}:\\\\s*)false(\\\\s*$)`, \"mu\"),\n \"$1true$2\",\n );\n }\n if (!match) {\n if (!result.endsWith(\"\\n\")) result += \"\\n\";\n result += `${line}\\n`;\n }\n }\n return result;\n}\n\nasync function planPackageJson(\n root: string,\n options: ConvertOptions,\n packageJson: PackageJson,\n nextVersion: { major: number; minor: number; patch: number },\n writes: Map<string, string>,\n changes: PlannedChange[],\n) {\n const packageName =\n options.packageName ??\n (typeof packageJson.name === \"string\" ? packageJson.name : options.appId);\n if (!/^[a-z0-9][a-z0-9._-]*$/u.test(packageName)) {\n throw new ConvertError(`package name is invalid: ${packageName}`);\n }\n packageJson.name = packageName;\n const engines = (packageJson.engines ??= {});\n if (\n engines.node !== undefined &&\n !/^(?:\\^|~|>=)?\\s*2[4-9]|[3-9]\\d/u.test(engines.node)\n ) {\n throw new ConvertError(\n \"package.json engines.node must allow Node.js 24 or newer\",\n );\n }\n engines.node = \">=24\";\n\n const dev = `bonfire prepare --root . && bonfire branch prepare --root . --default-hostname \"${options.hostname}\" && next dev`;\n addScript(packageJson, \"dev\", dev, [\"next dev\"]);\n addScript(packageJson, \"context:sync\", \"bonfire context sync\");\n addScript(\n packageJson,\n \"context:install\",\n `bonfire context install --app-id ${options.appId}`,\n );\n addScript(\n packageJson,\n \"check\",\n \"tsc --noEmit --project tsconfig.check.json && pnpm context:sync --check --skip-prototypes\",\n [\"tsc --noEmit --project tsconfig.check.json && pnpm context:sync --check\"],\n );\n addScript(packageJson, \"format\", \"prettier --write .\");\n addScript(packageJson, \"build\", \"next build\", [\"next build\"]);\n addScript(packageJson, \"start\", \"next start\", [\"next start\"]);\n addScript(packageJson, \"lint\", \"eslint\", [\"eslint\", \"eslint .\"]);\n\n const nextExact = `${nextVersion.major}.${nextVersion.minor}.${nextVersion.patch}`;\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-context\",\n BONFIRE_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-core\",\n BONFIRE_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-next\",\n BONFIRE_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-preset-ebay\",\n PRESET_VERSION,\n );\n addDependency(\n packageJson,\n \"dependencies\",\n \"@ebay-dt/bonfire-react\",\n BONFIRE_VERSION,\n );\n addDependency(packageJson, \"dependencies\", \"@ebay/ui-core-react\", \"9.13.0\");\n addDependency(packageJson, \"dependencies\", \"@evo-web/react\", \"0.4.4\");\n addDependency(\n packageJson,\n \"dependencies\",\n \"react-dom\",\n dependencyVersion(packageJson, \"react-dom\") ?? \"19.2.8\",\n );\n addDependency(packageJson, \"dependencies\", \"server-only\", \"^0.0.1\");\n addDependency(\n packageJson,\n \"devDependencies\",\n \"@ebay-dt/bonfire-cli\",\n BONFIRE_VERSION,\n );\n addDependency(packageJson, \"devDependencies\", \"@types/node\", \"^20\");\n addDependency(packageJson, \"devDependencies\", \"@types/react\", \"^19\");\n addDependency(packageJson, \"devDependencies\", \"@types/react-dom\", \"^19\");\n addDependency(packageJson, \"devDependencies\", \"eslint\", \"^9\");\n addDependency(\n packageJson,\n \"devDependencies\",\n \"eslint-config-next\",\n nextExact,\n );\n addDependency(packageJson, \"devDependencies\", \"prettier\", \"^3.9.5\");\n if (options.withItemData) {\n addDependency(\n packageJson,\n \"dependencies\",\n \"@tanstack/react-query\",\n \"^5.104.0\",\n );\n addDependency(packageJson, \"dependencies\", \"zod\", \"^4.4.3\");\n }\n\n const path = join(root, \"package.json\");\n const content = `${JSON.stringify(packageJson, null, 2)}\\n`;\n const existing = await readFile(path, \"utf8\");\n if (JSON.stringify(JSON.parse(existing)) !== JSON.stringify(packageJson)) {\n writes.set(path, content);\n addChange(\n changes,\n root,\n path,\n \"update\",\n \"merge Bonfire scripts and dependencies\",\n );\n }\n}\n\nexport async function planConversion(\n options: ConvertOptions,\n): Promise<ConversionPlan> {\n const root = resolve(options.root);\n if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(options.appId)) {\n throw new ConvertError(\n \"app id must contain only letters, numbers, dots, underscores, and hyphens\",\n );\n }\n if (!options.name.trim())\n throw new ConvertError(\"display name must not be empty\");\n const packagePath = join(root, \"package.json\");\n const packageJson = await readJson(packagePath);\n const nextVersion = validateStartingScaffold(packageJson);\n if (!(await exists(join(root, \"src\", \"app\")))) {\n throw new ConvertError(\n \"the starting scaffold must use the src/app App Router\",\n );\n }\n\n const writes = new Map<string, string>();\n const changes: PlannedChange[] = [];\n const removals: string[] = [];\n\n const starterPaths = [\n join(root, \"src/app/layout.tsx\"),\n join(root, \"src/app/page.tsx\"),\n join(root, \"src/app/page.module.css\"),\n join(root, \"src/app/globals.css\"),\n join(root, \"next.config.ts\"),\n join(root, \"README.md\"),\n ...[\"file.svg\", \"globe.svg\", \"next.svg\", \"vercel.svg\", \"window.svg\"].map(\n (name) => join(root, \"public\", name),\n ),\n ];\n for (const path of starterPaths) {\n await planRemoveStarter(\n root,\n path,\n \"remove unmodified create-next-app content\",\n removals,\n changes,\n );\n }\n const nextBuildDirectory = join(root, \".next\");\n if (await exists(nextBuildDirectory)) {\n removals.push(nextBuildDirectory);\n addChange(\n changes,\n root,\n nextBuildDirectory,\n \"remove\",\n \"clear generated Next.js output\",\n );\n }\n\n const resolvedOptions = { ...options, root };\n const templates = await templateFiles(resolvedOptions);\n for (const file of templates) {\n const path = join(root, file.relativePath);\n if (removals.includes(path)) {\n writes.set(path, file.content);\n addChange(\n changes,\n root,\n path,\n \"update\",\n \"replace unmodified create-next-app content\",\n );\n continue;\n }\n await planFile(\n root,\n path,\n file.content,\n \"add Bonfire instance scaffold\",\n writes,\n changes,\n );\n }\n\n await planPackageJson(\n root,\n options,\n packageJson,\n nextVersion,\n writes,\n changes,\n );\n\n const tsconfigPath = join(root, \"tsconfig.json\");\n const existingTsconfig = await readFile(tsconfigPath, \"utf8\");\n const tsconfig = await readJson(tsconfigPath);\n const compilerOptions = (tsconfig.compilerOptions ?? {}) as Record<\n string,\n unknown\n >;\n tsconfig.compilerOptions = compilerOptions;\n const paths = compilerOptions[\"paths\"] as Record<string, unknown> | undefined;\n if (paths && JSON.stringify(paths[\"@/*\"]) !== JSON.stringify([\"./src/*\"])) {\n throw new ConvertError(\"tsconfig.json has a conflicting @/* path alias\");\n }\n compilerOptions[\"paths\"] = { ...(paths ?? {}), \"@/*\": [\"./src/*\"] };\n const nextTsconfig = `${JSON.stringify(tsconfig, null, 2)}\\n`;\n if (\n JSON.stringify(JSON.parse(existingTsconfig)) !== JSON.stringify(tsconfig)\n ) {\n writes.set(tsconfigPath, nextTsconfig);\n addChange(\n changes,\n root,\n tsconfigPath,\n \"update\",\n \"retain the Bonfire @/* source alias\",\n );\n }\n\n await planFile(\n root,\n join(root, \"tsconfig.check.json\"),\n '{\\n \"extends\": \"./tsconfig.json\",\\n \"exclude\": [\"node_modules\", \".next\"]\\n}\\n',\n \"add the clean TypeScript check project\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \".prettierrc\"),\n '{\\n \"semi\": false,\\n \"singleQuote\": true,\\n \"trailingComma\": \"es5\",\\n \"printWidth\": 80\\n}\\n',\n \"add Bonfire formatting conventions\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \".prettierignore\"),\n \"# Generated and external files\\n.next/\\nnode_modules/\\npnpm-lock.yaml\\nsrc/app/(prototypes)/**/.claude/settings.json\\n\",\n \"add formatter exclusions\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \".env.local.example\"),\n \"# Bonfire generates this secret during `pnpm dev`.\\n# Do NOT manually modify or remove this variable.\\nBF_SESSION_SECRET=\\n\\n# Set exactly to lowercase `true` to skip automatic identity-branch preparation.\\nBF_DISABLE_AUTO_BRANCH_SWITCH=\\n\\n# Set to `managed` or `manual` for Bonfire Git management.\\nBF_GIT_MODE=\\n\",\n \"document Bonfire environment setup\",\n writes,\n changes,\n );\n await planFile(\n root,\n join(root, \"public/.gitkeep\"),\n \"\",\n \"retain an explicit public directory\",\n writes,\n changes,\n );\n\n const gitignorePath = join(root, \".gitignore\");\n const gitignore = await fileContent(gitignorePath);\n const mergedGitignore = mergeLines(gitignore, [\n \"# Bonfire local secrets\",\n \".env.local\",\n \"**/.next/\",\n \"src/app/(prototypes)/*/*/AGENTS.md\",\n \"src/app/(prototypes)/*/*/CLAUDE.md\",\n \"src/app/(prototypes)/*/*/.claude/settings.json\",\n ]);\n if (mergedGitignore !== (gitignore ?? \"\")) {\n writes.set(gitignorePath, mergedGitignore);\n addChange(\n changes,\n root,\n gitignorePath,\n \"update\",\n \"ignore the generated local session secret\",\n );\n }\n\n const workspacePath = join(root, \"pnpm-workspace.yaml\");\n const workspace = await fileContent(workspacePath);\n const mergedWorkspace = mergeWorkspace(workspace);\n if (mergedWorkspace !== (workspace ?? \"\")) {\n writes.set(workspacePath, mergedWorkspace);\n addChange(\n changes,\n root,\n workspacePath,\n \"update\",\n \"retain the Bonfire pnpm installation policy\",\n );\n }\n const npmrcPath = join(root, \".npmrc\");\n const npmrc = await fileContent(npmrcPath);\n if (\n npmrc &&\n /@ebay-dt:\\s*registry=/u.test(npmrc) &&\n !npmrc.includes(\"@ebay-dt:registry=https://registry.npmjs.org/\")\n ) {\n throw new ConvertError(\".npmrc has a conflicting @ebay-dt registry\");\n }\n const mergedNpmrc = mergeLines(npmrc, [\n \"@ebay-dt:registry=https://registry.npmjs.org/\",\n ]);\n if (mergedNpmrc !== (npmrc ?? \"\")) {\n writes.set(npmrcPath, mergedNpmrc);\n addChange(\n changes,\n root,\n npmrcPath,\n \"update\",\n \"resolve Bonfire packages from public npm\",\n );\n }\n const nvmrcPath = join(root, \".nvmrc\");\n const nvmrc = await fileContent(nvmrcPath);\n if (nvmrc === undefined) {\n await planFile(\n root,\n nvmrcPath,\n \"24\\n\",\n \"select Node.js 24 or newer\",\n writes,\n changes,\n );\n }\n\n const readmePath = join(root, \"README.md\");\n if (removals.includes(readmePath)) {\n writes.set(readmePath, starterReadme(options));\n addChange(\n changes,\n root,\n readmePath,\n \"update\",\n \"replace unmodified create-next-app documentation\",\n );\n } else if (\n !writes.has(readmePath) &&\n (await fileContent(readmePath)) === undefined\n ) {\n await planFile(\n root,\n readmePath,\n starterReadme(options),\n \"add instance setup documentation\",\n writes,\n changes,\n );\n }\n\n return { root, changes, writes, removals, packageJson };\n}\n\nexport async function convert(options: ConvertOptions) {\n const plan = await planConversion(options);\n for (const change of plan.changes) {\n console.log(\n `${options.dryRun ? \"Would \" : \"\"}${change.kind} ${change.path} (${change.reason})`,\n );\n }\n if (options.dryRun) return;\n\n for (const path of plan.removals) {\n await rm(path, {\n force: true,\n recursive: path === join(plan.root, \".next\"),\n });\n }\n for (const [path, content] of plan.writes) {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content);\n if (path.endsWith(\"context/hooks/block-env-reads.mjs\")) {\n await chmod(path, 0o755);\n }\n }\n\n if (!options.skipInstall) {\n console.log(\"Installing dependencies and updating pnpm-lock.yaml...\");\n await execFileAsync(\"pnpm\", [\"install\"], {\n cwd: plan.root,\n maxBuffer: 10 * 1024 * 1024,\n });\n }\n\n if (!options.skipInstall) {\n const formatPaths = [...plan.writes.keys()]\n .map((path) => displayPath(plan.root, path))\n .filter((path) => /\\.(?:json|mjs|md|ts|tsx|yaml|yml)$/u.test(path));\n if (formatPaths.length > 0) {\n await execFileAsync(\n \"pnpm\",\n [\"exec\", \"prettier\", \"--write\", ...formatPaths],\n {\n cwd: plan.root,\n maxBuffer: 10 * 1024 * 1024,\n },\n );\n }\n await execFileAsync(\"pnpm\", [\"exec\", \"next\", \"typegen\"], {\n cwd: plan.root,\n maxBuffer: 10 * 1024 * 1024,\n });\n }\n\n const contextResult = await syncContext({ repositoryRoot: plan.root });\n if (contextResult.written.length > 0 || contextResult.removed.length > 0) {\n console.log(\n `Context synchronized (${contextResult.written.length} written, ${contextResult.removed.length} removed).`,\n );\n }\n console.log(\"Bonfire instance conversion complete.\");\n}\n\nexport function defaultConvertOptions(root = process.cwd()): ConvertOptions {\n const appId = \"bonfire-instance\";\n return {\n root,\n appId,\n name: \"Bonfire Instance\",\n hostname: DEFAULT_HOSTNAME,\n deploymentEndpoint: DEFAULT_DEPLOYMENT_ENDPOINT,\n withItemData: true,\n dryRun: false,\n skipInstall: false,\n };\n}\n\nexport const convertDefaults = {\n hostname: DEFAULT_HOSTNAME,\n deploymentEndpoint: DEFAULT_DEPLOYMENT_ENDPOINT,\n};\n"]}
package/dist/convert.js CHANGED
@@ -9,7 +9,6 @@ const execFileAsync = promisify(execFile);
9
9
  const TEMPLATE_ROOT = fileURLToPath(new URL("../templates/instance/", import.meta.url));
10
10
  const DEFAULT_HOSTNAME = "github.corp.ebay.com";
11
11
  const DEFAULT_DEPLOYMENT_ENDPOINT = "https://dtsvc.vip.qa.ebay.com/dt/v1/bonfire-deploy";
12
- const DEFAULT_PORT = 1995;
13
12
  export function humanizeAppId(appId) {
14
13
  return appId
15
14
  .replace(/([a-z0-9])([A-Z])/gu, "$1 $2")
@@ -205,7 +204,7 @@ async function templateFiles(options) {
205
204
  return files;
206
205
  }
207
206
  function starterReadme(options) {
208
- return `# ${options.name}\n\nA Bonfire instance for creating, editing, and sharing prototypes.\n\n## Development\n\nUse Node.js 24+, install dependencies with pnpm, then run:\n\n~~~sh\npnpm dev\n~~~\n\nThe development command prepares the Bonfire session secret and the local identity branch before starting Next.js on port ${options.port}.\n\nRun pnpm context:install once on a machine where agent tooling is desired.\n`;
207
+ return `# ${options.name}\n\nA Bonfire instance for creating, editing, and sharing prototypes.\n\n## Development\n\nUse Node.js 24+, install dependencies with pnpm, then run:\n\n~~~sh\npnpm dev\n~~~\n\nThe development command prepares the Bonfire session secret and the local identity branch before starting Next.js.\n\nRun pnpm context:install once on a machine where agent tooling is desired.\n`;
209
208
  }
210
209
  function addDependency(packageJson, section, name, version) {
211
210
  const target = (packageJson[section] ??= {});
@@ -222,7 +221,11 @@ function addScript(packageJson, name, value, allowedExisting = []) {
222
221
  const scripts = (packageJson.scripts ??= {});
223
222
  const existing = scripts[name];
224
223
  if (existing !== undefined) {
225
- if (existing !== value && !allowedExisting.includes(String(existing))) {
224
+ if (existing !== value &&
225
+ !allowedExisting.includes(String(existing)) &&
226
+ !(name === "dev" &&
227
+ typeof existing === "string" &&
228
+ /^bonfire prepare --root \. && bonfire branch prepare --root \. --default-hostname "[^"\n]+" && next dev(?: -p \d+)?$/u.test(existing))) {
226
229
  throw new ConvertError(`package.json script ${name} is customized (${String(existing)}); resolve it before converting`);
227
230
  }
228
231
  scripts[name] = value;
@@ -287,11 +290,11 @@ async function planPackageJson(root, options, packageJson, nextVersion, writes,
287
290
  throw new ConvertError("package.json engines.node must allow Node.js 24 or newer");
288
291
  }
289
292
  engines.node = ">=24";
290
- const dev = `bonfire prepare --root . && bonfire branch prepare --root . --default-hostname "${options.hostname}" && next dev -p ${options.port}`;
293
+ const dev = `bonfire prepare --root . && bonfire branch prepare --root . --default-hostname "${options.hostname}" && next dev`;
291
294
  addScript(packageJson, "dev", dev, ["next dev"]);
292
295
  addScript(packageJson, "context:sync", "bonfire context sync");
293
296
  addScript(packageJson, "context:install", `bonfire context install --app-id ${options.appId}`);
294
- addScript(packageJson, "check", "tsc --noEmit --project tsconfig.check.json && pnpm context:sync --check");
297
+ addScript(packageJson, "check", "tsc --noEmit --project tsconfig.check.json && pnpm context:sync --check --skip-prototypes", ["tsc --noEmit --project tsconfig.check.json && pnpm context:sync --check"]);
295
298
  addScript(packageJson, "format", "prettier --write .");
296
299
  addScript(packageJson, "build", "next build", ["next build"]);
297
300
  addScript(packageJson, "start", "next start", ["next start"]);
@@ -395,6 +398,10 @@ export async function planConversion(options) {
395
398
  const mergedGitignore = mergeLines(gitignore, [
396
399
  "# Bonfire local secrets",
397
400
  ".env.local",
401
+ "**/.next/",
402
+ "src/app/(prototypes)/*/*/AGENTS.md",
403
+ "src/app/(prototypes)/*/*/CLAUDE.md",
404
+ "src/app/(prototypes)/*/*/.claude/settings.json",
398
405
  ]);
399
406
  if (mergedGitignore !== (gitignore ?? "")) {
400
407
  writes.set(gitignorePath, mergedGitignore);
@@ -492,7 +499,6 @@ export function defaultConvertOptions(root = process.cwd()) {
492
499
  appId,
493
500
  name: "Bonfire Instance",
494
501
  hostname: DEFAULT_HOSTNAME,
495
- port: DEFAULT_PORT,
496
502
  deploymentEndpoint: DEFAULT_DEPLOYMENT_ENDPOINT,
497
503
  withItemData: true,
498
504
  dryRun: false,
@@ -502,6 +508,5 @@ export function defaultConvertOptions(root = process.cwd()) {
502
508
  export const convertDefaults = {
503
509
  hostname: DEFAULT_HOSTNAME,
504
510
  deploymentEndpoint: DEFAULT_DEPLOYMENT_ENDPOINT,
505
- port: DEFAULT_PORT,
506
511
  };
507
512
  //# sourceMappingURL=convert.js.map