@bitbybit-dev/create-app 1.3.2 → 1.4.0

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.
Files changed (190) hide show
  1. package/README.md +47 -124
  2. package/dist/index.js +253 -21
  3. package/dist/index.js.map +1 -1
  4. package/dist/scaffold.d.ts +30 -0
  5. package/dist/scaffold.d.ts.map +1 -0
  6. package/dist/scaffold.js +107 -0
  7. package/dist/scaffold.js.map +1 -0
  8. package/package.json +4 -3
  9. package/src/index.test.ts +309 -8
  10. package/src/index.ts +285 -24
  11. package/src/scaffold.test.ts +177 -0
  12. package/src/scaffold.ts +99 -0
  13. package/templates/_agent/AGENTS.md +39 -0
  14. package/templates/_agent/CLAUDE.md +1 -0
  15. package/templates/_agent/_dot-cursor/mcp.json +5 -0
  16. package/templates/_agent/_dot-gitignore +7 -0
  17. package/templates/_agent/_dot-mcp.json +5 -0
  18. package/templates/_agent/_dot-vscode/mcp.json +5 -0
  19. package/templates/apps/drone-assembly/AGENTS.section.md +20 -0
  20. package/templates/apps/drone-assembly/README.md +35 -0
  21. package/templates/apps/drone-assembly/eslint.config.js +47 -0
  22. package/templates/apps/drone-assembly/index.html +17 -0
  23. package/templates/apps/drone-assembly/package.json +31 -0
  24. package/templates/apps/drone-assembly/public/favicon.ico +0 -0
  25. package/templates/apps/drone-assembly/public/logo.png +0 -0
  26. package/templates/apps/drone-assembly/scripts/smoke.ts +172 -0
  27. package/templates/apps/drone-assembly/src/assembly.ts +99 -0
  28. package/templates/apps/drone-assembly/src/exports.ts +10 -0
  29. package/templates/apps/drone-assembly/src/kernel.ts +14 -0
  30. package/templates/apps/drone-assembly/src/main.ts +298 -0
  31. package/templates/apps/drone-assembly/src/materials.ts +58 -0
  32. package/templates/apps/drone-assembly/src/model.ts +280 -0
  33. package/templates/apps/drone-assembly/src/parts.ts +343 -0
  34. package/templates/apps/drone-assembly/src/style.css +219 -0
  35. package/templates/apps/drone-assembly/src/ui.ts +180 -0
  36. package/templates/apps/drone-assembly/src/vite-env.d.ts +1 -0
  37. package/templates/apps/drone-assembly/tsconfig.json +29 -0
  38. package/templates/apps/laser-cut-box/AGENTS.section.md +17 -0
  39. package/templates/apps/laser-cut-box/README.md +34 -0
  40. package/templates/apps/laser-cut-box/eslint.config.js +47 -0
  41. package/templates/apps/laser-cut-box/index.html +17 -0
  42. package/templates/apps/laser-cut-box/package.json +30 -0
  43. package/templates/apps/laser-cut-box/public/favicon.ico +0 -0
  44. package/templates/apps/laser-cut-box/public/logo.png +0 -0
  45. package/templates/apps/laser-cut-box/scripts/smoke.ts +106 -0
  46. package/templates/apps/laser-cut-box/src/exports.ts +28 -0
  47. package/templates/apps/laser-cut-box/src/main.ts +176 -0
  48. package/templates/apps/laser-cut-box/src/model.ts +92 -0
  49. package/templates/apps/laser-cut-box/src/panels.ts +229 -0
  50. package/templates/apps/laser-cut-box/src/style.css +223 -0
  51. package/templates/apps/laser-cut-box/src/ui.ts +136 -0
  52. package/templates/apps/laser-cut-box/src/vite-env.d.ts +1 -0
  53. package/templates/apps/laser-cut-box/tsconfig.json +29 -0
  54. package/templates/apps/product-configurator/AGENTS.section.md +19 -0
  55. package/templates/apps/product-configurator/README.md +33 -0
  56. package/templates/apps/product-configurator/eslint.config.js +47 -0
  57. package/templates/apps/product-configurator/index.html +17 -0
  58. package/templates/apps/product-configurator/package.json +30 -0
  59. package/templates/apps/product-configurator/public/favicon.ico +0 -0
  60. package/templates/apps/product-configurator/public/logo.png +0 -0
  61. package/templates/apps/product-configurator/scripts/smoke.ts +69 -0
  62. package/templates/apps/product-configurator/src/catalog.ts +56 -0
  63. package/templates/apps/product-configurator/src/exports.ts +19 -0
  64. package/templates/apps/product-configurator/src/main.ts +134 -0
  65. package/templates/apps/product-configurator/src/model.ts +153 -0
  66. package/templates/apps/product-configurator/src/style.css +177 -0
  67. package/templates/apps/product-configurator/src/ui.ts +150 -0
  68. package/templates/apps/product-configurator/src/vite-env.d.ts +1 -0
  69. package/templates/apps/product-configurator/tsconfig.json +29 -0
  70. package/templates/apps/sheet-metal-unfold/AGENTS.section.md +26 -0
  71. package/templates/apps/sheet-metal-unfold/README.md +41 -0
  72. package/templates/apps/sheet-metal-unfold/backend/_dot-env.example +5 -0
  73. package/templates/apps/sheet-metal-unfold/backend/eslint.config.js +47 -0
  74. package/templates/apps/sheet-metal-unfold/backend/package.json +28 -0
  75. package/templates/apps/sheet-metal-unfold/backend/scripts/smoke.ts +52 -0
  76. package/templates/apps/sheet-metal-unfold/backend/src/app.ts +65 -0
  77. package/templates/apps/sheet-metal-unfold/backend/src/cloud.ts +42 -0
  78. package/templates/apps/sheet-metal-unfold/backend/src/index.ts +13 -0
  79. package/templates/apps/sheet-metal-unfold/backend/tsconfig.build.json +9 -0
  80. package/templates/apps/sheet-metal-unfold/backend/tsconfig.json +27 -0
  81. package/templates/apps/sheet-metal-unfold/frontend/eslint.config.js +47 -0
  82. package/templates/apps/sheet-metal-unfold/frontend/index.html +17 -0
  83. package/templates/apps/sheet-metal-unfold/frontend/package.json +30 -0
  84. package/templates/apps/sheet-metal-unfold/frontend/public/favicon.ico +0 -0
  85. package/templates/apps/sheet-metal-unfold/frontend/public/logo.png +0 -0
  86. package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +84 -0
  87. package/templates/apps/sheet-metal-unfold/frontend/src/cloud-access.ts +37 -0
  88. package/templates/apps/sheet-metal-unfold/frontend/src/exports.ts +10 -0
  89. package/templates/apps/sheet-metal-unfold/frontend/src/flat.ts +71 -0
  90. package/templates/apps/sheet-metal-unfold/frontend/src/main.ts +193 -0
  91. package/templates/apps/sheet-metal-unfold/frontend/src/model.ts +166 -0
  92. package/templates/apps/sheet-metal-unfold/frontend/src/style.css +291 -0
  93. package/templates/apps/sheet-metal-unfold/frontend/src/ui.ts +150 -0
  94. package/templates/apps/sheet-metal-unfold/frontend/src/vite-env.d.ts +1 -0
  95. package/templates/apps/sheet-metal-unfold/frontend/tsconfig.json +29 -0
  96. package/templates/apps/sheet-metal-unfold/frontend/vite.config.ts +9 -0
  97. package/templates/apps/sheet-metal-unfold/package.json +18 -0
  98. package/templates/apps/step-to-gltf-cli/AGENTS.section.md +20 -0
  99. package/templates/apps/step-to-gltf-cli/README.md +34 -0
  100. package/templates/apps/step-to-gltf-cli/eslint.config.js +47 -0
  101. package/templates/apps/step-to-gltf-cli/package.json +26 -0
  102. package/templates/apps/step-to-gltf-cli/samples/bracket.step +2545 -0
  103. package/templates/apps/step-to-gltf-cli/scripts/smoke.ts +49 -0
  104. package/templates/apps/step-to-gltf-cli/src/cli.ts +106 -0
  105. package/templates/apps/step-to-gltf-cli/src/cloud.ts +34 -0
  106. package/templates/apps/step-to-gltf-cli/src/convert.ts +65 -0
  107. package/templates/apps/step-to-gltf-cli/src/kernel.ts +14 -0
  108. package/templates/apps/step-to-gltf-cli/tsconfig.json +27 -0
  109. package/templates/cloud/AGENTS.section.md +22 -0
  110. package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +22 -50
  111. package/templates/cloud/backends/dotnet-rest/Program.cs +1 -11
  112. package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +4 -1
  113. package/templates/cloud/backends/hono-rest/eslint.config.js +47 -0
  114. package/templates/cloud/backends/hono-rest/package.json +11 -4
  115. package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +34 -45
  116. package/templates/cloud/backends/hono-rest/src/index.ts +1 -11
  117. package/templates/cloud/backends/hono-rest/tsconfig.json +19 -8
  118. package/templates/cloud/backends/hono-sdk/eslint.config.js +47 -0
  119. package/templates/cloud/backends/hono-sdk/package.json +12 -5
  120. package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +6 -37
  121. package/templates/cloud/backends/hono-sdk/src/index.ts +1 -12
  122. package/templates/cloud/backends/hono-sdk/tsconfig.json +19 -8
  123. package/templates/cloud/backends/nodejs-rest/eslint.config.js +47 -0
  124. package/templates/cloud/backends/nodejs-rest/package.json +12 -5
  125. package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +6 -35
  126. package/templates/cloud/backends/nodejs-rest/src/index.ts +6 -16
  127. package/templates/cloud/backends/nodejs-rest/tsconfig.build.json +9 -0
  128. package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -7
  129. package/templates/cloud/backends/nodejs-sdk/eslint.config.js +47 -0
  130. package/templates/cloud/backends/nodejs-sdk/package.json +14 -7
  131. package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +8 -33
  132. package/templates/cloud/backends/nodejs-sdk/src/index.ts +5 -16
  133. package/templates/cloud/backends/nodejs-sdk/tsconfig.build.json +9 -0
  134. package/templates/cloud/backends/nodejs-sdk/tsconfig.json +19 -9
  135. package/templates/cloud/frontend/eslint.config.js +50 -0
  136. package/templates/cloud/frontend/index.html +3 -1
  137. package/templates/cloud/frontend/package.json +13 -4
  138. package/templates/cloud/frontend/public/favicon.ico +0 -0
  139. package/templates/cloud/frontend/public/logo.png +0 -0
  140. package/templates/cloud/frontend/src/App.tsx +11 -9
  141. package/templates/cloud/frontend/src/api.ts +31 -0
  142. package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +28 -25
  143. package/templates/cloud/frontend/src/components/Header.tsx +4 -2
  144. package/templates/cloud/frontend/src/components/Tabs.tsx +4 -3
  145. package/templates/cloud/frontend/src/components/Viewer.tsx +57 -77
  146. package/templates/cloud/frontend/src/main.tsx +6 -1
  147. package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +65 -73
  148. package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +82 -83
  149. package/templates/cloud/frontend/src/vite-env.d.ts +1 -0
  150. package/templates/cloud/frontend/tsconfig.json +19 -7
  151. package/templates/vite/babylonjs/typescript/AGENTS.section.md +13 -0
  152. package/templates/vite/babylonjs/typescript/eslint.config.js +47 -0
  153. package/templates/vite/babylonjs/typescript/index.html +4 -2
  154. package/templates/vite/babylonjs/typescript/package.json +14 -4
  155. package/templates/vite/babylonjs/typescript/public/favicon.ico +0 -0
  156. package/templates/vite/babylonjs/typescript/public/logo.png +0 -0
  157. package/templates/vite/babylonjs/typescript/scripts/smoke.ts +41 -0
  158. package/templates/vite/babylonjs/typescript/src/main.ts +8 -17
  159. package/templates/vite/babylonjs/typescript/src/model.ts +24 -0
  160. package/templates/vite/babylonjs/typescript/tsconfig.json +16 -12
  161. package/templates/vite/playcanvas/typescript/AGENTS.section.md +13 -0
  162. package/templates/vite/playcanvas/typescript/eslint.config.js +47 -0
  163. package/templates/vite/playcanvas/typescript/index.html +4 -2
  164. package/templates/vite/playcanvas/typescript/package.json +14 -4
  165. package/templates/vite/playcanvas/typescript/public/favicon.ico +0 -0
  166. package/templates/vite/playcanvas/typescript/public/logo.png +0 -0
  167. package/templates/vite/playcanvas/typescript/scripts/smoke.ts +41 -0
  168. package/templates/vite/playcanvas/typescript/src/main.ts +11 -22
  169. package/templates/vite/playcanvas/typescript/src/model.ts +24 -0
  170. package/templates/vite/playcanvas/typescript/tsconfig.json +16 -12
  171. package/templates/vite/threejs/typescript/AGENTS.section.md +13 -0
  172. package/templates/vite/threejs/typescript/eslint.config.js +47 -0
  173. package/templates/vite/threejs/typescript/index.html +4 -2
  174. package/templates/vite/threejs/typescript/package.json +16 -6
  175. package/templates/vite/threejs/typescript/public/favicon.ico +0 -0
  176. package/templates/vite/threejs/typescript/public/logo.png +0 -0
  177. package/templates/vite/threejs/typescript/scripts/smoke.ts +41 -0
  178. package/templates/vite/threejs/typescript/src/main.ts +11 -22
  179. package/templates/vite/threejs/typescript/src/model.ts +24 -0
  180. package/templates/vite/threejs/typescript/tsconfig.json +16 -12
  181. package/templates/vite/babylonjs/typescript/public/vite.svg +0 -1
  182. package/templates/vite/playcanvas/typescript/public/vite.svg +0 -1
  183. package/templates/vite/threejs/typescript/public/vite.svg +0 -1
  184. /package/templates/cloud/backends/dotnet-rest/{_gitignore → _dot-gitignore} +0 -0
  185. /package/templates/cloud/backends/hono-rest/{_gitignore → _dot-gitignore} +0 -0
  186. /package/templates/cloud/backends/hono-sdk/{_gitignore → _dot-gitignore} +0 -0
  187. /package/templates/cloud/backends/nodejs-rest/{.env.example → _dot-env.example} +0 -0
  188. /package/templates/cloud/backends/nodejs-rest/{_gitignore → _dot-gitignore} +0 -0
  189. /package/templates/cloud/backends/nodejs-sdk/{.env.example → _dot-env.example} +0 -0
  190. /package/templates/cloud/backends/nodejs-sdk/{_gitignore → _dot-gitignore} +0 -0
package/src/index.test.ts CHANGED
@@ -9,11 +9,47 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
9
9
  const CLI = path.join(ROOT, "dist/index.js");
10
10
  const RELEASE_VERSION = (JSON.parse(readFileSync(path.join(ROOT, "package.json"), "utf8")) as { version: string }).version;
11
11
 
12
- const FRONTEND_FILES = ["package.json", "tsconfig.json", "index.html", "src/main.ts", "src/style.css"];
12
+ const AGENT_FILES = ["AGENTS.md", "CLAUDE.md", ".mcp.json", ".cursor/mcp.json", ".vscode/mcp.json"];
13
+ const BRAND_FILES = ["public/favicon.ico", "public/logo.png"];
14
+ const TOOLCHAIN_FILES = ["tsconfig.json", "eslint.config.js"];
15
+ const FRONTEND_FILES = ["package.json", ...TOOLCHAIN_FILES, "index.html", "src/main.ts", "src/model.ts", "src/style.css", "scripts/smoke.ts", ...BRAND_FILES, ...AGENT_FILES];
13
16
  const ENGINES = ["threejs", "babylonjs", "playcanvas"] as const;
14
- const CLOUD_BACKENDS = ["hono-sdk", "hono-rest", "nodejs-sdk", "nodejs-rest"] as const;
17
+ const CLOUD_BACKENDS = ["hono-sdk", "hono-rest", "nodejs-sdk", "nodejs-rest", "dotnet-rest"] as const;
18
+ const BACKEND_MANIFEST: Record<(typeof CLOUD_BACKENDS)[number], string> = {
19
+ "hono-sdk": "package.json", "hono-rest": "package.json", "nodejs-sdk": "package.json", "nodejs-rest": "package.json", "dotnet-rest": "dotnet-rest.csproj",
20
+ };
21
+ const BACKEND_SECRET: Record<(typeof CLOUD_BACKENDS)[number], string> = {
22
+ "hono-sdk": ".dev.vars", "hono-rest": ".dev.vars", "nodejs-sdk": ".env", "nodejs-rest": ".env", "dotnet-rest": "appsettings.Development.json",
23
+ };
24
+ const APP_TEMPLATES = ["product-configurator", "laser-cut-box", "sheet-metal-unfold", "step-to-gltf-cli", "drone-assembly"] as const;
25
+ const SINGLE_APP_FILES = ["package.json", ...TOOLCHAIN_FILES, "index.html", "README.md", "src/main.ts", "src/model.ts", "src/style.css", "scripts/smoke.ts", ".gitignore", ...BRAND_FILES, ...AGENT_FILES];
26
+ const APP_FILES: Record<(typeof APP_TEMPLATES)[number], string[]> = {
27
+ "product-configurator": SINGLE_APP_FILES,
28
+ "laser-cut-box": SINGLE_APP_FILES,
29
+ "sheet-metal-unfold": [
30
+ "package.json", "README.md", ".gitignore", ...AGENT_FILES,
31
+ "frontend/package.json", "frontend/tsconfig.json", "frontend/eslint.config.js", "frontend/vite.config.ts", "frontend/index.html", "frontend/src/main.ts", "frontend/src/model.ts", "frontend/src/cloud-access.ts", "frontend/scripts/smoke.ts", "frontend/public/favicon.ico", "frontend/public/logo.png",
32
+ "backend/package.json", "backend/tsconfig.json", "backend/tsconfig.build.json", "backend/eslint.config.js", "backend/src/app.ts", "backend/src/cloud.ts", "backend/src/index.ts", "backend/scripts/smoke.ts", "backend/.env.example", "backend/.env",
33
+ ],
34
+ "step-to-gltf-cli": ["package.json", ...TOOLCHAIN_FILES, "README.md", ".gitignore", "src/cli.ts", "src/convert.ts", "src/cloud.ts", "src/kernel.ts", "samples/bracket.step", "scripts/smoke.ts", ...AGENT_FILES],
35
+ "drone-assembly": [...SINGLE_APP_FILES, "src/parts.ts", "src/assembly.ts", "src/materials.ts", "src/kernel.ts", "src/ui.ts"],
36
+ };
37
+ const CLOUD_APP_TEMPLATES = ["sheet-metal-unfold"] as const;
38
+ const MCP_URL = "https://mcp.bitbybit.dev/mcp";
39
+ const TEMPLATES_DIR = path.join(ROOT, "templates");
40
+ const PLACEHOLDER = /\{\{[A-Z][A-Z0-9_]*\}\}/;
41
+ const TEXT_FILE = /\.(md|json|jsonc|ts|tsx|mjs|js|html|css|toml|cs|csproj|yml|yaml|env|example|vars)$/;
15
42
  const OCCT_BITNESS = "32";
16
43
  const FAILURE_EXIT = 1;
44
+ const WORKSPACE_MANIFEST = path.join(ROOT, "..", "..", "..", "package.json");
45
+ const REACT_TEMPLATE = path.join(TEMPLATES_DIR, "cloud", "frontend");
46
+ const REFERENCE_LINT_CONFIG = path.join(TEMPLATES_DIR, "vite", "threejs", "typescript", "eslint.config.js");
47
+ const STRICT_FLAGS = [
48
+ "strict", "noUncheckedIndexedAccess", "exactOptionalPropertyTypes", "noImplicitReturns", "noImplicitOverride",
49
+ "noPropertyAccessFromIndexSignature", "noFallthroughCasesInSwitch", "noUnusedLocals", "noUnusedParameters",
50
+ "useUnknownInCatchVariables", "forceConsistentCasingInFileNames", "isolatedModules", "verbatimModuleSyntax",
51
+ "erasableSyntaxOnly", "noUncheckedSideEffectImports", "skipLibCheck",
52
+ ] as const;
17
53
 
18
54
  const ENGINE_TEMPLATES_DIR = path.join(ROOT, "templates", "vite");
19
55
  const TEMPLATE_LANGUAGE = "typescript";
@@ -23,6 +59,13 @@ const LAST_TWO_OPTION_PROPERTIES = /(^[ \t]*\w+:\s*true,\n)(^[ \t]*enableManifol
23
59
 
24
60
  type EngineTemplate = { engine: string; mainTs: string };
25
61
 
62
+ const walk = (dir: string): string[] =>
63
+ readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
64
+ if (entry.name === "node_modules") return [];
65
+ const full = path.join(dir, entry.name);
66
+ return entry.isDirectory() ? [full, ...walk(full)] : [full];
67
+ });
68
+
26
69
  const templateMainTs = (engine: string): string =>
27
70
  path.join(ENGINE_TEMPLATES_DIR, engine, TEMPLATE_LANGUAGE, "src", "main.ts");
28
71
 
@@ -46,7 +89,7 @@ const cliOptionsPattern = (): RegExp => {
46
89
  return new RegExp(body, (declaration?.[2] ?? "").replace(/[gy]/g, ""));
47
90
  };
48
91
 
49
- type Manifest = { name: string; dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
92
+ type Manifest = { name: string; scripts?: Record<string, string>; dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
50
93
 
51
94
  let work: string;
52
95
 
@@ -99,9 +142,10 @@ describe("create-app", () => {
99
142
  scaffold([name, "-t", "frontend", "-e", "threejs", "-o", OCCT_BITNESS]);
100
143
 
101
144
  // Assert
102
- const pins = Object.entries(manifestOf(name).dependencies ?? {})
145
+ const manifest = manifestOf(name);
146
+ const pins = Object.entries({ ...manifest.dependencies, ...manifest.devDependencies })
103
147
  .filter(([dependency]) => dependency.startsWith("@bitbybit-dev/"));
104
- expect(pins.length).toBeGreaterThan(0);
148
+ expect(pins.map(([dependency]) => dependency).sort()).toEqual(["@bitbybit-dev/occt", "@bitbybit-dev/threejs"]);
105
149
  for (const [, pinned] of pins) expect(pinned).toBe(RELEASE_VERSION);
106
150
  });
107
151
  });
@@ -117,14 +161,39 @@ describe("create-app", () => {
117
161
  // Assert
118
162
  expect(status).toBe(0);
119
163
  expect(existsSync(path.join(work, name, "frontend", "package.json"))).toBe(true);
120
- expect(existsSync(path.join(work, name, "backend", "package.json"))).toBe(true);
164
+ expect(existsSync(path.join(work, name, "frontend", "eslint.config.js"))).toBe(true);
165
+ expect(existsSync(path.join(work, name, "backend", BACKEND_MANIFEST[backend]))).toBe(true);
166
+ expect(existsSync(path.join(work, name, "backend", "eslint.config.js"))).toBe(backend !== "dotnet-rest");
121
167
  expect(existsSync(path.join(work, name, "README.md"))).toBe(true);
168
+ for (const file of AGENT_FILES) {
169
+ expect(existsSync(path.join(work, name, file)), `${name}/${file} is missing`).toBe(true);
170
+ }
171
+ });
172
+
173
+ it.each(CLOUD_BACKENDS)("should tell the agent what needs CAD Cloud in a %s project, in AGENTS.md and the README", (backend) => {
174
+ // Arrange
175
+ const name = `cloud-explained-${backend}`;
176
+
177
+ // Act
178
+ scaffold([name, "-t", "cloud", "-b", backend]);
179
+
180
+ // Assert
181
+ const agents = readFileSync(path.join(work, name, "AGENTS.md"), "utf8");
182
+ const readme = readFileSync(path.join(work, name, "README.md"), "utf8");
183
+ for (const text of [agents, readme]) {
184
+ expect(text).toMatch(/What needs CAD Cloud and where to get it/i);
185
+ expect(text).toContain("https://bitbybit.dev/cad-cloud");
186
+ expect(text).toContain("https://studio.bitbybit.dev/keys/billing");
187
+ expect(text).toContain(`backend/${BACKEND_SECRET[backend]}`);
188
+ }
189
+ expect(agents).toContain(`cloud-${backend}`);
190
+ expect(agents).toContain(backend === "dotnet-rest" ? "dotnet build" : "npm run smoke");
122
191
  });
123
192
 
124
193
  it.each(CLOUD_BACKENDS)("should give the %s backend a .gitignore that covers the secret file the CLI writes beside it", (backend) => {
125
194
  // Arrange
126
195
  const name = `ignored-${backend}`;
127
- const secret = backend.startsWith("hono") ? ".dev.vars" : ".env";
196
+ const secret = BACKEND_SECRET[backend];
128
197
 
129
198
  // Act
130
199
  const { status } = scaffold([name, "-t", "cloud", "-b", backend]);
@@ -133,9 +202,241 @@ describe("create-app", () => {
133
202
  expect(status).toBe(0);
134
203
  const backendDir = path.join(work, name, "backend");
135
204
  expect(existsSync(path.join(backendDir, secret))).toBe(true);
136
- expect(existsSync(path.join(backendDir, "_gitignore"))).toBe(false);
205
+ expect(walk(path.join(work, name)).some((file) => path.basename(file).startsWith("_dot-"))).toBe(false);
137
206
  expect(readFileSync(path.join(backendDir, ".gitignore"), "utf8")).toContain(secret);
138
207
  });
208
+
209
+ it.each(["nodejs-sdk", "nodejs-rest"] as const)("should restore the .env.example the %s backend's .env is copied from", (backend) => {
210
+ // Arrange
211
+ const name = `env-example-${backend}`;
212
+
213
+ // Act
214
+ const { status } = scaffold([name, "-t", "cloud", "-b", backend]);
215
+
216
+ // Assert
217
+ expect(status).toBe(0);
218
+ const backendDir = path.join(work, name, "backend");
219
+ expect(existsSync(path.join(backendDir, ".env.example"))).toBe(true);
220
+ expect(readFileSync(path.join(backendDir, ".env"), "utf8")).toBe(readFileSync(path.join(backendDir, ".env.example"), "utf8"));
221
+ });
222
+ });
223
+
224
+ describe("the agent layer", () => {
225
+ const scaffolds = [
226
+ { name: "agent-frontend", args: ["-t", "frontend", "-e", "threejs", "-o", OCCT_BITNESS], templateId: "vite-threejs" },
227
+ { name: "agent-cloud", args: ["-t", "cloud", "-b", "hono-sdk"], templateId: "cloud-hono-sdk" },
228
+ ];
229
+
230
+ it.each(scaffolds)("should configure the Bitbybit CAD MCP for Claude Code, Cursor and VS Code in $name", ({ name: base, args }) => {
231
+ // Arrange
232
+ const name = `${base}-mcp`;
233
+
234
+ // Act
235
+ const { status } = scaffold([name, ...args]);
236
+
237
+ // Assert
238
+ expect(status).toBe(0);
239
+ const json = (file: string): Record<string, Record<string, Record<string, string>>> =>
240
+ JSON.parse(readFileSync(path.join(work, name, file), "utf8")) as Record<string, Record<string, Record<string, string>>>;
241
+ expect(json(".mcp.json")["mcpServers"]?.["bitbybit"]).toEqual({ type: "http", url: MCP_URL });
242
+ expect(json(".cursor/mcp.json")["mcpServers"]?.["bitbybit"]).toEqual({ url: MCP_URL });
243
+ expect(json(".vscode/mcp.json")["servers"]?.["bitbybit"]).toEqual({ type: "http", url: MCP_URL });
244
+ });
245
+
246
+ it.each(scaffolds)("should write one AGENTS.md for $name, rendered, with the template's section after the shared text, and point CLAUDE.md at it", ({ name: base, args, templateId }) => {
247
+ // Arrange
248
+ const name = `${base}-agents`;
249
+
250
+ // Act
251
+ const { status } = scaffold([name, ...args]);
252
+
253
+ // Assert
254
+ expect(status).toBe(0);
255
+ const agents = readFileSync(path.join(work, name, "AGENTS.md"), "utf8");
256
+ expect(agents.startsWith(`# ${name}\n`)).toBe(true);
257
+ expect(agents).toContain(`\`@bitbybit-dev/create-app\` ${RELEASE_VERSION}`);
258
+ expect(agents).toContain(`\`${templateId}\` template`);
259
+ expect(agents).toContain(MCP_URL);
260
+ expect(agents).toMatch(/npm run smoke/);
261
+ expect(agents.indexOf("## This template")).toBeGreaterThan(agents.indexOf("## The loop"));
262
+ expect(readFileSync(path.join(work, name, "CLAUDE.md"), "utf8")).toBe("@AGENTS.md\n");
263
+ expect(existsSync(path.join(work, name, "AGENTS.section.md"))).toBe(false);
264
+ });
265
+
266
+ it.each(scaffolds)("should leave no placeholder in any text file of $name", ({ name: base, args }) => {
267
+ // Arrange
268
+ const name = `${base}-rendered`;
269
+
270
+ // Act
271
+ scaffold([name, ...args]);
272
+
273
+ // Assert
274
+ const unrendered = walk(path.join(work, name))
275
+ .filter((file) => TEXT_FILE.test(file) && PLACEHOLDER.test(readFileSync(file, "utf8")))
276
+ .map((file) => path.relative(work, file));
277
+ expect(unrendered).toEqual([]);
278
+ });
279
+
280
+ it("should keep every dotfile of every template staged under the _dot- prefix, because npm drops some of them from the tarball", () => {
281
+ // Act
282
+ const dotted = walk(TEMPLATES_DIR)
283
+ .map((file) => path.relative(TEMPLATES_DIR, file))
284
+ .filter((relative) => relative.split(path.sep).some((segment) => segment.startsWith(".") || segment === "_gitignore"));
285
+
286
+ // Assert
287
+ expect(dotted).toEqual([]);
288
+ });
289
+
290
+ it("should give every frontend template the same smoke runner and a smoke script that runs it", () => {
291
+ // Arrange
292
+ const smokes = ENGINES.map((engine) => path.join(TEMPLATES_DIR, "vite", engine, "typescript", "scripts", "smoke.ts"));
293
+
294
+ // Act
295
+ const runners = smokes.map((file) => readFileSync(file, "utf8").replace(/vite-(threejs|babylonjs|playcanvas)/g, "vite-<engine>"));
296
+ const scripts = ENGINES.map((engine) => (JSON.parse(readFileSync(path.join(TEMPLATES_DIR, "vite", engine, "typescript", "package.json"), "utf8")) as { scripts: Record<string, string> }).scripts["smoke"]);
297
+
298
+ // Assert
299
+ expect(new Set(runners).size).toBe(1);
300
+ expect(scripts).toEqual(ENGINES.map(() => "npm run typecheck && npm run lint && tsx scripts/smoke.ts"));
301
+ });
302
+ });
303
+
304
+ describe("an app template project", () => {
305
+ it.each(APP_TEMPLATES)("should scaffold %s with its files, the agent layer and one lockstep pin", (template) => {
306
+ // Arrange
307
+ const name = `app-${template}`;
308
+
309
+ // Act
310
+ const { status, output } = scaffold([name, "-t", "app", "-T", template]);
311
+
312
+ // Assert
313
+ expect(status).toBe(0);
314
+ for (const file of APP_FILES[template]) {
315
+ expect(existsSync(path.join(work, name, file)), `${name}/${file} is missing`).toBe(true);
316
+ }
317
+ const manifest = manifestOf(name);
318
+ expect(manifest.name).toBe(name);
319
+ const manifests = walk(path.join(work, name)).filter((file) => path.basename(file) === "package.json").map((file) => JSON.parse(readFileSync(file, "utf8")) as Manifest);
320
+ const pins = manifests.flatMap((m) => Object.entries({ ...m.dependencies, ...m.devDependencies })).filter(([dependency]) => dependency.startsWith("@bitbybit-dev/"));
321
+ expect(pins.length).toBeGreaterThan(0);
322
+ for (const [, pinned] of pins) expect(pinned).toBe(RELEASE_VERSION);
323
+ expect(pins.map(([dependency]) => dependency)).toContain("@bitbybit-dev/occt");
324
+ const agents = readFileSync(path.join(work, name, "AGENTS.md"), "utf8");
325
+ expect(agents).toContain(`\`${template}\` template`);
326
+ expect(agents.indexOf("## This template")).toBeGreaterThan(agents.indexOf("## The loop"));
327
+ expect(readFileSync(path.join(work, name, "README.md"), "utf8")).toContain(`# ${name}`);
328
+ expect(output).toMatch(/npm run smoke/);
329
+ });
330
+
331
+ it.each(CLOUD_APP_TEMPLATES)("should tell the agent and the user what needs CAD Cloud in %s, and say so when scaffolding", (template) => {
332
+ // Arrange
333
+ const name = `app-cloud-${template}`;
334
+
335
+ // Act
336
+ const { status, output } = scaffold([name, "-t", "app", "-T", template]);
337
+
338
+ // Assert
339
+ expect(status).toBe(0);
340
+ for (const file of ["AGENTS.md", "README.md"]) {
341
+ const text = readFileSync(path.join(work, name, file), "utf8");
342
+ expect(text).toMatch(/What needs CAD Cloud and where to get it/i);
343
+ expect(text).toContain("https://bitbybit.dev/cad-cloud");
344
+ expect(text).toContain("https://studio.bitbybit.dev/keys/billing");
345
+ }
346
+ expect(output).toMatch(/needs an API key/);
347
+ expect(readFileSync(path.join(work, name, "backend", ".env"), "utf8")).toMatch(/^BITBYBIT_API_KEY=$/m);
348
+ expect(readFileSync(path.join(work, name, ".gitignore"), "utf8")).toMatch(/^\.env$/m);
349
+ });
350
+
351
+ it("should take --template alone as the app type", () => {
352
+ // Act
353
+ const { status } = scaffold(["app-implicit", "-T", "product-configurator"]);
354
+
355
+ // Assert
356
+ expect(status).toBe(0);
357
+ expect(existsSync(path.join(work, "app-implicit", "src", "model.ts"))).toBe(true);
358
+ });
359
+
360
+ it("should ignore an engine and an architecture for an app template and say so", () => {
361
+ // Act
362
+ const { status, output } = scaffold(["app-engine-ignored", "-t", "app", "-T", "product-configurator", "-e", "babylonjs", "-o", "64"]);
363
+
364
+ // Assert
365
+ expect(status).toBe(0);
366
+ expect(output).toMatch(/--engine and --occt-architecture .* ignored/);
367
+ expect(readFileSync(path.join(work, "app-engine-ignored", "package.json"), "utf8")).toContain("@bitbybit-dev/threejs");
368
+ expect(existsSync(path.join(work, "app-engine-ignored", "vite.config.ts"))).toBe(false);
369
+ });
370
+
371
+ it("should refuse a template it does not have, list the ones it has, and write nothing", () => {
372
+ // Act
373
+ const { status, output } = scaffold(["bad-template", "-t", "app", "-T", "space-elevator"]);
374
+
375
+ // Assert
376
+ expect(status).toBe(FAILURE_EXIT);
377
+ expect(output).toMatch(/space-elevator/);
378
+ for (const template of APP_TEMPLATES) expect(output).toContain(template);
379
+ expect(existsSync(path.join(work, "bad-template"))).toBe(false);
380
+ });
381
+
382
+ it("should offer exactly the templates that have a directory under templates/apps", () => {
383
+ // Arrange
384
+ const shipped = readdirSync(path.join(TEMPLATES_DIR, "apps"), { withFileTypes: true })
385
+ .filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
386
+
387
+ // Act
388
+ const { output } = scaffold(["list-probe", "-t", "app", "-T", "not-a-template"]);
389
+ const listed = /Valid options: (.+)/.exec(output)?.[1]?.split(",").map((id) => id.trim()).sort();
390
+
391
+ // Assert
392
+ expect(listed).toEqual(shipped);
393
+ expect(shipped).toEqual([...APP_TEMPLATES].sort());
394
+ });
395
+ });
396
+
397
+ describe("the toolchain every template ships", () => {
398
+ const manifests = walk(TEMPLATES_DIR).filter((file) => path.basename(file) === "package.json");
399
+ const projects = manifests.map((file) => path.dirname(file)).filter((dir) => existsSync(path.join(dir, "tsconfig.json")));
400
+ const readManifest = (file: string): Manifest => JSON.parse(readFileSync(file, "utf8")) as Manifest;
401
+
402
+ it("should pin TypeScript at the version the workspace pins, in every template and in this package", () => {
403
+ // Arrange
404
+ const workspacePin = readManifest(WORKSPACE_MANIFEST).devDependencies?.["typescript"];
405
+
406
+ // Assert
407
+ expect(workspacePin).toMatch(/^\d+\.\d+\.\d+$/);
408
+ expect(readManifest(path.join(ROOT, "package.json")).devDependencies?.["typescript"]).toBe(workspacePin);
409
+ for (const dir of projects) {
410
+ expect(readManifest(path.join(dir, "package.json")).devDependencies?.["typescript"], path.relative(TEMPLATES_DIR, dir)).toBe(workspacePin);
411
+ }
412
+ });
413
+
414
+ it("should give every TypeScript project the strict compiler flags, a lint script and a typecheck script the smoke runs first", () => {
415
+ for (const dir of projects) {
416
+ // Arrange
417
+ const relative = path.relative(TEMPLATES_DIR, dir);
418
+ const tsconfig = JSON.parse(readFileSync(path.join(dir, "tsconfig.json"), "utf8")) as { compilerOptions: Record<string, unknown> };
419
+ const scripts = readManifest(path.join(dir, "package.json")).scripts ?? {};
420
+
421
+ // Assert
422
+ for (const flag of STRICT_FLAGS) expect(tsconfig.compilerOptions[flag], `${relative}: ${flag}`).toBe(true);
423
+ expect(scripts["typecheck"], relative).toBe("tsc --noEmit");
424
+ expect(scripts["lint"], relative).toBe("eslint . --max-warnings 0");
425
+ expect(scripts["smoke"], relative).toMatch(/^npm run typecheck && npm run lint/);
426
+ expect(existsSync(path.join(dir, "eslint.config.js")), relative).toBe(true);
427
+ }
428
+ });
429
+
430
+ it("should hold every template but the React one to the one ESLint configuration, and give the React one the hooks rules on top", () => {
431
+ // Arrange
432
+ const reference = readFileSync(REFERENCE_LINT_CONFIG, "utf8");
433
+
434
+ // Assert
435
+ for (const dir of projects.filter((candidate) => candidate !== REACT_TEMPLATE)) {
436
+ expect(readFileSync(path.join(dir, "eslint.config.js"), "utf8"), path.relative(TEMPLATES_DIR, dir)).toBe(reference);
437
+ }
438
+ expect(readFileSync(path.join(REACT_TEMPLATE, "eslint.config.js"), "utf8")).toContain("reactHooks.configs.flat.recommended");
439
+ });
139
440
  });
140
441
 
141
442
  describe("when the arguments are wrong", () => {