@bitbybit-dev/create-app 1.4.0 → 1.5.0-rc.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 (63) hide show
  1. package/README.md +1 -0
  2. package/dist/index.js +31 -21
  3. package/dist/index.js.map +1 -1
  4. package/dist/scaffold.d.ts.map +1 -1
  5. package/dist/scaffold.js +16 -8
  6. package/dist/scaffold.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/index.test.ts +290 -10
  9. package/src/index.ts +42 -25
  10. package/src/scaffold.ts +23 -8
  11. package/templates/apps/drone-assembly/package.json +3 -3
  12. package/templates/apps/drone-assembly/scripts/smoke.ts +3 -3
  13. package/templates/apps/drone-assembly/src/parts.ts +3 -3
  14. package/templates/apps/ifc-house/AGENTS.section.md +19 -0
  15. package/templates/apps/ifc-house/README.md +36 -0
  16. package/templates/apps/ifc-house/eslint.config.js +47 -0
  17. package/templates/apps/ifc-house/index.html +22 -0
  18. package/templates/apps/ifc-house/package.json +36 -0
  19. package/templates/apps/ifc-house/public/favicon.ico +0 -0
  20. package/templates/apps/ifc-house/public/logo.png +0 -0
  21. package/templates/apps/ifc-house/scripts/smoke.ts +118 -0
  22. package/templates/apps/ifc-house/src/export/step-export.ts +29 -0
  23. package/templates/apps/ifc-house/src/house/build-house.ts +194 -0
  24. package/templates/apps/ifc-house/src/house/details.ts +393 -0
  25. package/templates/apps/ifc-house/src/house/house-plan.ts +400 -0
  26. package/templates/apps/ifc-house/src/house/house-types.ts +192 -0
  27. package/templates/apps/ifc-house/src/main.ts +138 -0
  28. package/templates/apps/ifc-house/src/scene/draw-house.ts +92 -0
  29. package/templates/apps/ifc-house/src/scene/scene-types.ts +30 -0
  30. package/templates/apps/ifc-house/src/scene/stage.ts +64 -0
  31. package/templates/apps/ifc-house/src/style.css +347 -0
  32. package/templates/apps/ifc-house/src/ui/panel.ts +144 -0
  33. package/templates/apps/ifc-house/src/ui/room-labels.ts +75 -0
  34. package/templates/apps/ifc-house/src/ui/ui-types.ts +14 -0
  35. package/templates/apps/ifc-house/src/vite-env.d.ts +1 -0
  36. package/templates/apps/ifc-house/src/workers/ifc.worker.ts +7 -0
  37. package/templates/apps/ifc-house/src/workers/manifold.worker.ts +16 -0
  38. package/templates/apps/ifc-house/src/workers/occt.worker.ts +17 -0
  39. package/templates/apps/ifc-house/tsconfig.json +29 -0
  40. package/templates/apps/laser-cut-box/package.json +2 -2
  41. package/templates/apps/laser-cut-box/scripts/smoke.ts +2 -1
  42. package/templates/apps/laser-cut-box/src/panels.ts +2 -0
  43. package/templates/apps/product-configurator/package.json +2 -2
  44. package/templates/apps/product-configurator/scripts/smoke.ts +4 -3
  45. package/templates/apps/sheet-metal-unfold/backend/package.json +1 -1
  46. package/templates/apps/sheet-metal-unfold/frontend/package.json +2 -2
  47. package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +4 -3
  48. package/templates/apps/step-to-gltf-cli/package.json +2 -2
  49. package/templates/apps/step-to-gltf-cli/src/convert.ts +7 -2
  50. package/templates/cloud/backends/hono-rest/package.json +1 -1
  51. package/templates/cloud/backends/hono-sdk/package.json +2 -2
  52. package/templates/cloud/backends/nodejs-rest/package.json +1 -1
  53. package/templates/cloud/backends/nodejs-sdk/package.json +2 -2
  54. package/templates/cloud/frontend/package.json +1 -1
  55. package/templates/vite/babylonjs/typescript/AGENTS.section.md +1 -1
  56. package/templates/vite/babylonjs/typescript/package.json +2 -2
  57. package/templates/vite/babylonjs/typescript/scripts/smoke.ts +4 -3
  58. package/templates/vite/playcanvas/typescript/AGENTS.section.md +1 -1
  59. package/templates/vite/playcanvas/typescript/package.json +2 -2
  60. package/templates/vite/playcanvas/typescript/scripts/smoke.ts +4 -3
  61. package/templates/vite/threejs/typescript/AGENTS.section.md +1 -1
  62. package/templates/vite/threejs/typescript/package.json +2 -2
  63. package/templates/vite/threejs/typescript/scripts/smoke.ts +4 -3
package/src/index.test.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { describe, it, expect, beforeAll, afterAll } from "vitest";
2
- import { spawnSync } from "node:child_process";
3
- import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { spawn, spawnSync } from "node:child_process";
3
+ import { createHash } from "node:crypto";
4
+ import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, mkdirSync, statSync, writeFileSync } from "node:fs";
4
5
  import { tmpdir } from "node:os";
5
6
  import path from "node:path";
6
7
  import { fileURLToPath } from "node:url";
@@ -21,7 +22,7 @@ const BACKEND_MANIFEST: Record<(typeof CLOUD_BACKENDS)[number], string> = {
21
22
  const BACKEND_SECRET: Record<(typeof CLOUD_BACKENDS)[number], string> = {
22
23
  "hono-sdk": ".dev.vars", "hono-rest": ".dev.vars", "nodejs-sdk": ".env", "nodejs-rest": ".env", "dotnet-rest": "appsettings.Development.json",
23
24
  };
24
- const APP_TEMPLATES = ["product-configurator", "laser-cut-box", "sheet-metal-unfold", "step-to-gltf-cli", "drone-assembly"] as const;
25
+ const APP_TEMPLATES = ["product-configurator", "laser-cut-box", "sheet-metal-unfold", "step-to-gltf-cli", "drone-assembly", "ifc-house"] as const;
25
26
  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
27
  const APP_FILES: Record<(typeof APP_TEMPLATES)[number], string[]> = {
27
28
  "product-configurator": SINGLE_APP_FILES,
@@ -33,6 +34,11 @@ const APP_FILES: Record<(typeof APP_TEMPLATES)[number], string[]> = {
33
34
  ],
34
35
  "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
36
  "drone-assembly": [...SINGLE_APP_FILES, "src/parts.ts", "src/assembly.ts", "src/materials.ts", "src/kernel.ts", "src/ui.ts"],
37
+ "ifc-house": [
38
+ "package.json", ...TOOLCHAIN_FILES, "index.html", "README.md", "src/main.ts", "src/style.css", "scripts/smoke.ts", ".gitignore", ...BRAND_FILES, ...AGENT_FILES,
39
+ "src/house/build-house.ts", "src/house/house-plan.ts", "src/house/details.ts", "src/house/house-types.ts", "src/scene/draw-house.ts", "src/scene/stage.ts", "src/ui/panel.ts", "src/export/step-export.ts",
40
+ "src/workers/ifc.worker.ts", "src/workers/manifold.worker.ts", "src/workers/occt.worker.ts",
41
+ ],
36
42
  };
37
43
  const CLOUD_APP_TEMPLATES = ["sheet-metal-unfold"] as const;
38
44
  const MCP_URL = "https://mcp.bitbybit.dev/mcp";
@@ -61,7 +67,9 @@ type EngineTemplate = { engine: string; mainTs: string };
61
67
 
62
68
  const walk = (dir: string): string[] =>
63
69
  readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
64
- if (entry.name === "node_modules") return [];
70
+ if (entry.name === "node_modules") {
71
+ return [];
72
+ }
65
73
  const full = path.join(dir, entry.name);
66
74
  return entry.isDirectory() ? [full, ...walk(full)] : [full];
67
75
  });
@@ -100,6 +108,76 @@ const scaffold = (args: string[]): { status: number | null; output: string } =>
100
108
  return { status: result.status, output: result.stdout + result.stderr };
101
109
  };
102
110
 
111
+ const ARROW_DOWN = "\x1b[B";
112
+ const ENTER = "\r";
113
+ const PROMPT_TIMEOUT_MS = 20_000;
114
+ const PROMPT_TEST_TIMEOUT_MS = 60_000;
115
+ const APP_TYPES = ["frontend", "cloud", "app"] as const;
116
+ const OCCT_ARCHITECTURES = ["32", "64", "64-mt"] as const;
117
+ const INTERACTIVE_PROJECT = "prompted";
118
+ const QUESTION = {
119
+ appType: /What type of application would you like to create\?/,
120
+ projectName: /What is your project name\?/,
121
+ engine: /Which 3D engine would you like to use\?/,
122
+ occtArchitecture: /Which OCCT worker architecture would you like to use\?/,
123
+ backend: /Which backend would you like to use\?/,
124
+ template: /Which app template would you like to start from\?/,
125
+ overwrite: /already exists\. Do you want to overwrite it\?/,
126
+ } as const;
127
+
128
+ type Answer = { question: RegExp; keys: string };
129
+ type PromptRun = { status: number | null; output: string; answered: number };
130
+
131
+ const pick = (question: RegExp, index: number): Answer => ({ question, keys: ARROW_DOWN.repeat(index) + ENTER });
132
+ const type = (question: RegExp, text: string): Answer => ({ question, keys: text + ENTER });
133
+
134
+ const answerPrompts = (cwd: string, args: string[], answers: Answer[]): Promise<PromptRun> =>
135
+ new Promise((resolve) => {
136
+ const child = spawn("node", [CLI, ...args], { cwd, env: { ...process.env, NO_COLOR: "1" } });
137
+ let output = "";
138
+ let searchFrom = 0;
139
+ let answered = 0;
140
+ const timer = setTimeout(() => child.kill(), PROMPT_TIMEOUT_MS);
141
+ const onData = (chunk: Buffer): void => {
142
+ output += chunk.toString();
143
+ const answer = answers[answered];
144
+ if (!answer) {
145
+ return;
146
+ }
147
+ const match = answer.question.exec(output.slice(searchFrom));
148
+ if (!match) {
149
+ return;
150
+ }
151
+ searchFrom += match.index + match[0].length;
152
+ answered += 1;
153
+ child.stdin.write(answer.keys);
154
+ if (answered === answers.length) {
155
+ child.stdin.end();
156
+ }
157
+ };
158
+ child.stdout.on("data", onData);
159
+ child.stderr.on("data", onData);
160
+ child.on("close", (status) => {
161
+ clearTimeout(timer);
162
+ resolve({ status, output, answered });
163
+ });
164
+ });
165
+
166
+ const scaffoldIn = (cwd: string, args: string[]): { status: number | null; output: string } => {
167
+ const result = spawnSync("node", [CLI, ...args], {
168
+ cwd, encoding: "utf8", env: { ...process.env, CI: "1", NO_COLOR: "1" },
169
+ });
170
+ return { status: result.status, output: result.stdout + result.stderr };
171
+ };
172
+
173
+ const fingerprint = (dir: string): Record<string, string> =>
174
+ Object.fromEntries(walk(dir)
175
+ .filter((file) => statSync(file).isFile())
176
+ .map((file) => [path.relative(dir, file), createHash("sha256").update(readFileSync(file)).digest("hex")] as const)
177
+ .sort(([left], [right]) => left.localeCompare(right)));
178
+
179
+ const freshDir = (label: string): string => mkdtempSync(path.join(work, `${label}-`));
180
+
103
181
  const manifestOf = (...segments: string[]): Manifest =>
104
182
  JSON.parse(readFileSync(path.join(work, ...segments, "package.json"), "utf8")) as Manifest;
105
183
 
@@ -113,7 +191,9 @@ describe("create-app", () => {
113
191
  }, 120_000);
114
192
 
115
193
  afterAll(() => {
116
- if (work) rmSync(work, { recursive: true, force: true });
194
+ if (work) {
195
+ rmSync(work, { recursive: true, force: true });
196
+ }
117
197
  });
118
198
 
119
199
  describe("a frontend project", () => {
@@ -146,7 +226,9 @@ describe("create-app", () => {
146
226
  const pins = Object.entries({ ...manifest.dependencies, ...manifest.devDependencies })
147
227
  .filter(([dependency]) => dependency.startsWith("@bitbybit-dev/"));
148
228
  expect(pins.map(([dependency]) => dependency).sort()).toEqual(["@bitbybit-dev/occt", "@bitbybit-dev/threejs"]);
149
- for (const [, pinned] of pins) expect(pinned).toBe(RELEASE_VERSION);
229
+ for (const [, pinned] of pins) {
230
+ expect(pinned).toBe(RELEASE_VERSION);
231
+ }
150
232
  });
151
233
  });
152
234
 
@@ -319,7 +401,9 @@ describe("create-app", () => {
319
401
  const manifests = walk(path.join(work, name)).filter((file) => path.basename(file) === "package.json").map((file) => JSON.parse(readFileSync(file, "utf8")) as Manifest);
320
402
  const pins = manifests.flatMap((m) => Object.entries({ ...m.dependencies, ...m.devDependencies })).filter(([dependency]) => dependency.startsWith("@bitbybit-dev/"));
321
403
  expect(pins.length).toBeGreaterThan(0);
322
- for (const [, pinned] of pins) expect(pinned).toBe(RELEASE_VERSION);
404
+ for (const [, pinned] of pins) {
405
+ expect(pinned).toBe(RELEASE_VERSION);
406
+ }
323
407
  expect(pins.map(([dependency]) => dependency)).toContain("@bitbybit-dev/occt");
324
408
  const agents = readFileSync(path.join(work, name, "AGENTS.md"), "utf8");
325
409
  expect(agents).toContain(`\`${template}\` template`);
@@ -375,7 +459,9 @@ describe("create-app", () => {
375
459
  // Assert
376
460
  expect(status).toBe(FAILURE_EXIT);
377
461
  expect(output).toMatch(/space-elevator/);
378
- for (const template of APP_TEMPLATES) expect(output).toContain(template);
462
+ for (const template of APP_TEMPLATES) {
463
+ expect(output).toContain(template);
464
+ }
379
465
  expect(existsSync(path.join(work, "bad-template"))).toBe(false);
380
466
  });
381
467
 
@@ -392,6 +478,17 @@ describe("create-app", () => {
392
478
  expect(listed).toEqual(shipped);
393
479
  expect(shipped).toEqual([...APP_TEMPLATES].sort());
394
480
  });
481
+
482
+ it("should have both smoke lanes scaffold every app template", () => {
483
+ // Arrange
484
+ const lanes = ["smoke.mjs", "smoke-local.mjs"].map((file) => readFileSync(path.join(ROOT, "scripts", file), "utf8"));
485
+
486
+ // Act
487
+ const listed = lanes.map((text) => (/\[("product-configurator"[^\]]*)\]/.exec(text)?.[1] ?? "").split(",").map((id) => id.trim().replace(/"/g, "")).sort());
488
+
489
+ // Assert
490
+ expect(listed).toEqual([[...APP_TEMPLATES].sort(), [...APP_TEMPLATES].sort()]);
491
+ });
395
492
  });
396
493
 
397
494
  describe("the toolchain every template ships", () => {
@@ -419,7 +516,9 @@ describe("create-app", () => {
419
516
  const scripts = readManifest(path.join(dir, "package.json")).scripts ?? {};
420
517
 
421
518
  // Assert
422
- for (const flag of STRICT_FLAGS) expect(tsconfig.compilerOptions[flag], `${relative}: ${flag}`).toBe(true);
519
+ for (const flag of STRICT_FLAGS) {
520
+ expect(tsconfig.compilerOptions[flag], `${relative}: ${flag}`).toBe(true);
521
+ }
423
522
  expect(scripts["typecheck"], relative).toBe("tsc --noEmit");
424
523
  expect(scripts["lint"], relative).toBe("eslint . --max-warnings 0");
425
524
  expect(scripts["smoke"], relative).toMatch(/^npm run typecheck && npm run lint/);
@@ -439,6 +538,185 @@ describe("create-app", () => {
439
538
  });
440
539
  });
441
540
 
541
+ describe("the interactive prompts", () => {
542
+ const MENU_LABELS: Record<(typeof APP_TYPES)[number], string[]> = {
543
+ frontend: ["Frontend App", "CAD Cloud App", "App Template", "Three.js", "Babylon.js", "PlayCanvas", "32-bit", "64-bit", "64-bit MT"],
544
+ cloud: ["Hono + SDK", "Hono + REST", "Node.js + SDK", "Node.js + REST", ".NET + REST"],
545
+ app: ["Product configurator", "Laser-cut box", "Sheet-metal unfold", "STEP to glTF command line", "Drone assembly"],
546
+ };
547
+ const DEFAULT_ANSWERS: Record<(typeof APP_TYPES)[number], Answer[]> = {
548
+ frontend: [pick(QUESTION.engine, 0), pick(QUESTION.occtArchitecture, 0)],
549
+ cloud: [pick(QUESTION.backend, 0)],
550
+ app: [pick(QUESTION.template, 0)],
551
+ };
552
+ const FRONTEND_VARIANTS = ENGINES.flatMap((engine, engineIndex) =>
553
+ OCCT_ARCHITECTURES.map((architecture, architectureIndex) => ({ engine, engineIndex, architecture, architectureIndex })));
554
+ const CLOUD_VARIANTS = CLOUD_BACKENDS.map((backend, backendIndex) => ({ backend, backendIndex }));
555
+ const APP_VARIANTS = APP_TEMPLATES.map((template, templateIndex) => ({ template, templateIndex }));
556
+ const LAST_ANSWERS: Record<(typeof APP_TYPES)[number], { answers: Answer[]; flags: string[] }> = {
557
+ frontend: {
558
+ answers: [pick(QUESTION.engine, ENGINES.length - 1), pick(QUESTION.occtArchitecture, OCCT_ARCHITECTURES.length - 1)],
559
+ flags: ["-t", "frontend", "-e", ENGINES[ENGINES.length - 1]!, "-o", OCCT_ARCHITECTURES[OCCT_ARCHITECTURES.length - 1]!],
560
+ },
561
+ cloud: {
562
+ answers: [pick(QUESTION.backend, CLOUD_BACKENDS.length - 1)],
563
+ flags: ["-t", "cloud", "-b", CLOUD_BACKENDS[CLOUD_BACKENDS.length - 1]!],
564
+ },
565
+ app: {
566
+ answers: [pick(QUESTION.template, APP_TEMPLATES.length - 1)],
567
+ flags: ["-T", APP_TEMPLATES[APP_TEMPLATES.length - 1]!],
568
+ },
569
+ };
570
+
571
+ const referenceProject = (flags: string[]): Record<string, string> => {
572
+ const dir = freshDir("flagged");
573
+ const reference = scaffoldIn(dir, [INTERACTIVE_PROJECT, ...flags]);
574
+ expect(reference.status, reference.output).toBe(0);
575
+ const files = fingerprint(path.join(dir, INTERACTIVE_PROJECT));
576
+ expect(Object.keys(files)).toContain("AGENTS.md");
577
+ return files;
578
+ };
579
+
580
+ const expectAnsweredAndScaffolded = (run: PromptRun, answers: Answer[]): void => {
581
+ expect(run.answered, run.output).toBe(answers.length);
582
+ expect(run.status, run.output).toBe(0);
583
+ };
584
+
585
+ it.each(APP_TYPES)("should list every choice of every %s menu, not fall back to a text answer", async (appType) => {
586
+ // Arrange
587
+ const answers = [pick(QUESTION.appType, APP_TYPES.indexOf(appType)), type(QUESTION.projectName, INTERACTIVE_PROJECT), ...DEFAULT_ANSWERS[appType]];
588
+
589
+ // Act
590
+ const run = await answerPrompts(freshDir("listed"), [], answers);
591
+
592
+ // Assert
593
+ expectAnsweredAndScaffolded(run, answers);
594
+ for (const label of [...MENU_LABELS.frontend.slice(0, APP_TYPES.length), ...MENU_LABELS[appType]]) {
595
+ expect(run.output).toContain(label);
596
+ }
597
+ expect(run.output).not.toMatch(/\(frontend\)/);
598
+ }, PROMPT_TEST_TIMEOUT_MS);
599
+
600
+ it.each(FRONTEND_VARIANTS)("should scaffold the same $engine $architecture-bit project from the menus as from the flags", async ({ engine, engineIndex, architecture, architectureIndex }) => {
601
+ // Arrange
602
+ const expected = referenceProject(["-t", "frontend", "-e", engine, "-o", architecture]);
603
+ const answers = [
604
+ pick(QUESTION.appType, APP_TYPES.indexOf("frontend")),
605
+ type(QUESTION.projectName, INTERACTIVE_PROJECT),
606
+ pick(QUESTION.engine, engineIndex),
607
+ pick(QUESTION.occtArchitecture, architectureIndex),
608
+ ];
609
+ const dir = freshDir("prompted");
610
+
611
+ // Act
612
+ const run = await answerPrompts(dir, [], answers);
613
+
614
+ // Assert
615
+ expectAnsweredAndScaffolded(run, answers);
616
+ expect(fingerprint(path.join(dir, INTERACTIVE_PROJECT))).toEqual(expected);
617
+ }, PROMPT_TEST_TIMEOUT_MS);
618
+
619
+ it.each(CLOUD_VARIANTS)("should scaffold the same $backend cloud project from the menus as from the flags", async ({ backend, backendIndex }) => {
620
+ // Arrange
621
+ const expected = referenceProject(["-t", "cloud", "-b", backend]);
622
+ const answers = [
623
+ pick(QUESTION.appType, APP_TYPES.indexOf("cloud")),
624
+ type(QUESTION.projectName, INTERACTIVE_PROJECT),
625
+ pick(QUESTION.backend, backendIndex),
626
+ ];
627
+ const dir = freshDir("prompted");
628
+
629
+ // Act
630
+ const run = await answerPrompts(dir, [], answers);
631
+
632
+ // Assert
633
+ expectAnsweredAndScaffolded(run, answers);
634
+ expect(fingerprint(path.join(dir, INTERACTIVE_PROJECT))).toEqual(expected);
635
+ }, PROMPT_TEST_TIMEOUT_MS);
636
+
637
+ it.each(APP_VARIANTS)("should scaffold the same $template app template from the menus as from the flags", async ({ template, templateIndex }) => {
638
+ // Arrange
639
+ const expected = referenceProject(["-T", template]);
640
+ const answers = [
641
+ pick(QUESTION.appType, APP_TYPES.indexOf("app")),
642
+ type(QUESTION.projectName, INTERACTIVE_PROJECT),
643
+ pick(QUESTION.template, templateIndex),
644
+ ];
645
+ const dir = freshDir("prompted");
646
+
647
+ // Act
648
+ const run = await answerPrompts(dir, [], answers);
649
+
650
+ // Assert
651
+ expectAnsweredAndScaffolded(run, answers);
652
+ expect(fingerprint(path.join(dir, INTERACTIVE_PROJECT))).toEqual(expected);
653
+ }, PROMPT_TEST_TIMEOUT_MS);
654
+
655
+ it.each(APP_TYPES)("should skip the name question for a %s project named on the command line", async (appType) => {
656
+ // Arrange
657
+ const { answers: rest, flags } = LAST_ANSWERS[appType];
658
+ const expected = referenceProject(flags);
659
+ const answers = [pick(QUESTION.appType, APP_TYPES.indexOf(appType)), ...rest];
660
+ const dir = freshDir("prompted");
661
+
662
+ // Act
663
+ const run = await answerPrompts(dir, [INTERACTIVE_PROJECT], answers);
664
+
665
+ // Assert
666
+ expectAnsweredAndScaffolded(run, answers);
667
+ expect(run.output).not.toMatch(QUESTION.projectName);
668
+ expect(fingerprint(path.join(dir, INTERACTIVE_PROJECT))).toEqual(expected);
669
+ }, PROMPT_TEST_TIMEOUT_MS);
670
+
671
+ it.each(APP_TYPES)("should skip the type question when --type %s is given without a name", async (appType) => {
672
+ // Arrange
673
+ const { answers: rest, flags } = LAST_ANSWERS[appType];
674
+ const expected = referenceProject(flags);
675
+ const answers = [type(QUESTION.projectName, INTERACTIVE_PROJECT), ...rest];
676
+ const dir = freshDir("prompted");
677
+
678
+ // Act
679
+ const run = await answerPrompts(dir, ["-t", appType], answers);
680
+
681
+ // Assert
682
+ expectAnsweredAndScaffolded(run, answers);
683
+ expect(run.output).not.toMatch(QUESTION.appType);
684
+ expect(fingerprint(path.join(dir, INTERACTIVE_PROJECT))).toEqual(expected);
685
+ }, PROMPT_TEST_TIMEOUT_MS);
686
+
687
+ it.each(APP_TYPES)("should keep an existing directory when overwriting a %s project is declined", async (appType) => {
688
+ // Arrange
689
+ const dir = freshDir("declined");
690
+ mkdirSync(path.join(dir, INTERACTIVE_PROJECT));
691
+ writeFileSync(path.join(dir, INTERACTIVE_PROJECT, "mine.txt"), "do not overwrite me");
692
+ const answers = [type(QUESTION.overwrite, "n")];
693
+
694
+ // Act
695
+ const run = await answerPrompts(dir, [INTERACTIVE_PROJECT, ...LAST_ANSWERS[appType].flags], answers);
696
+
697
+ // Assert
698
+ expectAnsweredAndScaffolded(run, answers);
699
+ expect(readdirSync(path.join(dir, INTERACTIVE_PROJECT))).toEqual(["mine.txt"]);
700
+ }, PROMPT_TEST_TIMEOUT_MS);
701
+
702
+ it.each(APP_TYPES)("should replace an existing directory with the %s project when overwriting is accepted", async (appType) => {
703
+ // Arrange
704
+ const { flags } = LAST_ANSWERS[appType];
705
+ const expected = referenceProject(flags);
706
+ const dir = freshDir("accepted");
707
+ mkdirSync(path.join(dir, INTERACTIVE_PROJECT));
708
+ writeFileSync(path.join(dir, INTERACTIVE_PROJECT, "mine.txt"), "overwrite me");
709
+ const answers = [type(QUESTION.overwrite, "y")];
710
+
711
+ // Act
712
+ const run = await answerPrompts(dir, [INTERACTIVE_PROJECT, ...flags], answers);
713
+
714
+ // Assert
715
+ expectAnsweredAndScaffolded(run, answers);
716
+ expect(fingerprint(path.join(dir, INTERACTIVE_PROJECT))).toEqual(expected);
717
+ }, PROMPT_TEST_TIMEOUT_MS);
718
+ });
719
+
442
720
  describe("when the arguments are wrong", () => {
443
721
  it("should refuse an engine it does not have a template for", () => {
444
722
  // Act
@@ -503,7 +781,9 @@ describe("create-app", () => {
503
781
 
504
782
  it("should stop matching once that options object is reordered", () => {
505
783
  const [first] = engineTemplates();
506
- if (!first) throw new Error(`no engine templates under ${ENGINE_TEMPLATES_DIR} - there is nothing left to patch`);
784
+ if (!first) {
785
+ throw new Error(`no engine templates under ${ENGINE_TEMPLATES_DIR} - there is nothing left to patch`);
786
+ }
507
787
  const template = readFileSync(first.mainTs, "utf8");
508
788
  const reordered = template.replace(LAST_TWO_OPTION_PROPERTIES, "$2$1");
509
789
 
package/src/index.ts CHANGED
@@ -13,7 +13,7 @@ import { AGENT_SECTION_FILE, applyAgentLayer, listFiles, restoreTemplateDotfiles
13
13
  const __filename = fileURLToPath(import.meta.url);
14
14
  const __dirname = path.dirname(__filename);
15
15
 
16
- const CLI_VERSION = "1.4.0";
16
+ const CLI_VERSION = "1.5.0-rc.0";
17
17
  const TEMPLATES_ROOT = path.join(__dirname, "..", "templates");
18
18
 
19
19
  const BITBYBIT_LOGO = `
@@ -42,7 +42,7 @@ interface CloudProjectOptions {
42
42
 
43
43
  type AppType = "frontend" | "cloud" | "app";
44
44
 
45
- type AppTemplateId = "product-configurator" | "laser-cut-box" | "sheet-metal-unfold" | "step-to-gltf-cli" | "drone-assembly";
45
+ type AppTemplateId = "product-configurator" | "laser-cut-box" | "sheet-metal-unfold" | "step-to-gltf-cli" | "drone-assembly" | "ifc-house";
46
46
 
47
47
  interface AppTemplate {
48
48
  name: string;
@@ -76,9 +76,16 @@ const APP_TEMPLATES: Record<AppTemplateId, AppTemplate> = {
76
76
  description: "A multirotor built as a real assembly: twenty-seven parts placed through sub-assemblies, physically based materials, spinning propellers, a bill of materials, STEP and GLB exports that keep the tree",
77
77
  cloud: false,
78
78
  },
79
+ "ifc-house": {
80
+ name: "IFC family house",
81
+ description: "A two-storey house written as an IFC4 building model: layered walls, windows and doors, rooms, a roof, terrain and trees, every element clickable, IFC and STEP downloads",
82
+ cloud: false,
83
+ },
79
84
  };
80
85
 
81
86
  const APP_TEMPLATE_IDS = Object.keys(APP_TEMPLATES) as AppTemplateId[];
87
+ const NARROW_TERMINAL_LINES_PER_TEMPLATE_CHOICE = 3;
88
+ const TEMPLATE_MENU_PAGE_SIZE = APP_TEMPLATE_IDS.length * NARROW_TERMINAL_LINES_PER_TEMPLATE_CHOICE;
82
89
 
83
90
  interface AppProjectOptions {
84
91
  projectName: string;
@@ -177,7 +184,7 @@ function displayWelcome(): void {
177
184
  async function promptAppType(): Promise<AppType> {
178
185
  const { appType } = await inquirer.prompt<{ appType: AppType }>([
179
186
  {
180
- type: "list",
187
+ type: "select",
181
188
  name: "appType",
182
189
  message: chalk.cyan("🏗️ What type of application would you like to create?"),
183
190
  choices: [
@@ -205,7 +212,7 @@ async function promptAppType(): Promise<AppType> {
205
212
 
206
213
  async function promptCloudProjectOptions(projectNameArg?: string): Promise<CloudProjectOptions> {
207
214
  interface CloudAnswers {
208
- projectName?: string;
215
+ projectName?: string | undefined;
209
216
  backend: BackendType;
210
217
  }
211
218
 
@@ -247,13 +254,17 @@ async function promptCloudProjectOptions(projectNameArg?: string): Promise<Cloud
247
254
  message: chalk.cyan("📁 What is your project name?"),
248
255
  default: "my-bitbybit-cloud-app",
249
256
  validate: (input: string) => {
250
- if (!input.trim()) return "Project name is required";
251
- if (!/^[a-z0-9-_]+$/i.test(input)) return "Project name can only contain letters, numbers, hyphens, and underscores";
257
+ if (!input.trim()) {
258
+ return "Project name is required";
259
+ }
260
+ if (!/^[a-z0-9-_]+$/i.test(input)) {
261
+ return "Project name can only contain letters, numbers, hyphens, and underscores";
262
+ }
252
263
  return true;
253
264
  }
254
265
  },
255
266
  {
256
- type: "list",
267
+ type: "select",
257
268
  name: "backend",
258
269
  message: chalk.cyan("⚡ Which backend would you like to use?"),
259
270
  choices: backendChoices,
@@ -263,7 +274,7 @@ async function promptCloudProjectOptions(projectNameArg?: string): Promise<Cloud
263
274
  } else {
264
275
  answers = await inquirer.prompt<CloudAnswers>([
265
276
  {
266
- type: "list",
277
+ type: "select",
267
278
  name: "backend",
268
279
  message: chalk.cyan("⚡ Which backend would you like to use?"),
269
280
  choices: backendChoices,
@@ -280,7 +291,7 @@ async function promptCloudProjectOptions(projectNameArg?: string): Promise<Cloud
280
291
 
281
292
  async function promptAppTemplate(projectNameArg?: string): Promise<AppProjectOptions> {
282
293
  interface AppAnswers {
283
- projectName?: string;
294
+ projectName?: string | undefined;
284
295
  template: AppTemplateId;
285
296
  }
286
297
 
@@ -301,17 +312,22 @@ async function promptAppTemplate(projectNameArg?: string): Promise<AppProjectOpt
301
312
  message: chalk.cyan("📁 What is your project name?"),
302
313
  default: "my-bitbybit-app",
303
314
  validate: (input: string) => {
304
- if (!input.trim()) return "Project name is required";
305
- if (!/^[a-z0-9-_]+$/i.test(input)) return "Project name can only contain letters, numbers, hyphens, and underscores";
315
+ if (!input.trim()) {
316
+ return "Project name is required";
317
+ }
318
+ if (!/^[a-z0-9-_]+$/i.test(input)) {
319
+ return "Project name can only contain letters, numbers, hyphens, and underscores";
320
+ }
306
321
  return true;
307
322
  }
308
323
  }]),
309
324
  {
310
- type: "list" as const,
325
+ type: "select" as const,
311
326
  name: "template",
312
327
  message: chalk.cyan("🧩 Which app template would you like to start from?"),
313
328
  choices,
314
329
  default: APP_TEMPLATE_IDS[0],
330
+ pageSize: TEMPLATE_MENU_PAGE_SIZE,
315
331
  },
316
332
  ];
317
333
 
@@ -321,7 +337,7 @@ async function promptAppTemplate(projectNameArg?: string): Promise<AppProjectOpt
321
337
 
322
338
  async function promptProjectOptions(projectNameArg?: string): Promise<ProjectOptions> {
323
339
  interface PromptAnswers {
324
- projectName?: string;
340
+ projectName?: string | undefined;
325
341
  engine: EngineType;
326
342
  occtArchitecture: OcctArchitectureType;
327
343
  }
@@ -364,7 +380,7 @@ async function promptProjectOptions(projectNameArg?: string): Promise<ProjectOpt
364
380
  }
365
381
  },
366
382
  {
367
- type: "list",
383
+ type: "select",
368
384
  name: "engine",
369
385
  message: chalk.cyan("🎮 Which 3D engine would you like to use?"),
370
386
  choices: [
@@ -387,7 +403,7 @@ async function promptProjectOptions(projectNameArg?: string): Promise<ProjectOpt
387
403
  default: "threejs"
388
404
  },
389
405
  {
390
- type: "list",
406
+ type: "select",
391
407
  name: "occtArchitecture",
392
408
  message: chalk.cyan("⚙️ Which OCCT worker architecture would you like to use?"),
393
409
  choices: occtArchitectureChoices,
@@ -397,7 +413,7 @@ async function promptProjectOptions(projectNameArg?: string): Promise<ProjectOpt
397
413
  } else {
398
414
  answers = await inquirer.prompt<PromptAnswers>([
399
415
  {
400
- type: "list",
416
+ type: "select",
401
417
  name: "engine",
402
418
  message: chalk.cyan("🎮 Which 3D engine would you like to use?"),
403
419
  choices: [
@@ -420,7 +436,7 @@ async function promptProjectOptions(projectNameArg?: string): Promise<ProjectOpt
420
436
  default: "threejs"
421
437
  },
422
438
  {
423
- type: "list",
439
+ type: "select",
424
440
  name: "occtArchitecture",
425
441
  message: chalk.cyan("⚙️ Which OCCT worker architecture would you like to use?"),
426
442
  choices: occtArchitectureChoices,
@@ -953,16 +969,15 @@ async function createCloudProject(options: CloudProjectOptions): Promise<void> {
953
969
  }
954
970
  }
955
971
 
956
- /**
957
- * A template that needs a secret ships an .env.example beside the code that reads it; the scaffold
958
- * gets an .env copied from it so the first run finds the file and the variable, empty. The same
959
- * probe the cloud templates use, for any depth.
960
- */
961
972
  async function writeEnvFromExamples(dir: string): Promise<void> {
962
973
  for (const example of await listFiles(dir)) {
963
- if (path.basename(example) !== ".env.example") continue;
974
+ if (path.basename(example) !== ".env.example") {
975
+ continue;
976
+ }
964
977
  const env = path.join(path.dirname(example), ".env");
965
- if (!(await fs.pathExists(env))) await fs.copy(example, env);
978
+ if (!(await fs.pathExists(env))) {
979
+ await fs.copy(example, env);
980
+ }
966
981
  }
967
982
  }
968
983
 
@@ -1114,7 +1129,9 @@ async function main(): Promise<void> {
1114
1129
  appOptions = { projectName, template: cmdOptions.template as AppTemplateId };
1115
1130
  } else {
1116
1131
  appOptions = await promptAppTemplate(projectName);
1117
- if (cmdOptions.template) appOptions.template = cmdOptions.template as AppTemplateId;
1132
+ if (cmdOptions.template) {
1133
+ appOptions.template = cmdOptions.template as AppTemplateId;
1134
+ }
1118
1135
  }
1119
1136
  await createAppProject(appOptions);
1120
1137
  } else if (appType === "cloud") {
package/src/scaffold.ts CHANGED
@@ -21,10 +21,15 @@ export async function listFiles(dir: string): Promise<string[]> {
21
21
  const out: string[] = [];
22
22
  const walk = async (current: string): Promise<void> => {
23
23
  for (const entry of await fs.readdir(current, { withFileTypes: true })) {
24
- if (SKIPPED_DIRS.has(entry.name)) continue;
24
+ if (SKIPPED_DIRS.has(entry.name)) {
25
+ continue;
26
+ }
25
27
  const full = path.join(current, entry.name);
26
- if (entry.isDirectory()) await walk(full);
27
- else out.push(full);
28
+ if (entry.isDirectory()) {
29
+ await walk(full);
30
+ } else {
31
+ out.push(full);
32
+ }
28
33
  }
29
34
  };
30
35
  await walk(dir);
@@ -41,10 +46,16 @@ export async function restoreTemplateDotfiles(dir: string): Promise<string[]> {
41
46
  const restored: string[] = [];
42
47
  const walk = async (current: string): Promise<void> => {
43
48
  for (const entry of await fs.readdir(current, { withFileTypes: true })) {
44
- if (SKIPPED_DIRS.has(entry.name)) continue;
49
+ if (SKIPPED_DIRS.has(entry.name)) {
50
+ continue;
51
+ }
45
52
  const from = path.join(current, entry.name);
46
- if (entry.isDirectory()) await walk(from);
47
- if (!entry.name.startsWith(DOTFILE_PREFIX)) continue;
53
+ if (entry.isDirectory()) {
54
+ await walk(from);
55
+ }
56
+ if (!entry.name.startsWith(DOTFILE_PREFIX)) {
57
+ continue;
58
+ }
48
59
  const to = path.join(current, `.${entry.name.slice(DOTFILE_PREFIX.length)}`);
49
60
  await fs.move(from, to, { overwrite: true });
50
61
  restored.push(to);
@@ -62,7 +73,9 @@ export async function restoreTemplateDotfiles(dir: string): Promise<string[]> {
62
73
  export async function renderPlaceholders(dir: string, values: PlaceholderValues): Promise<void> {
63
74
  const leftovers: string[] = [];
64
75
  for (const file of await listFiles(dir)) {
65
- if (!TEXT_EXTENSIONS.has(path.extname(file))) continue;
76
+ if (!TEXT_EXTENSIONS.has(path.extname(file))) {
77
+ continue;
78
+ }
66
79
  const text = await fs.readFile(file, "utf8");
67
80
  if (!PLACEHOLDER.test(text)) { PLACEHOLDER.lastIndex = 0; continue; }
68
81
  PLACEHOLDER.lastIndex = 0;
@@ -92,7 +105,9 @@ export async function applyAgentLayer(templatesRoot: string, targetDir: string,
92
105
  const agents = path.join(targetDir, AGENTS_FILE);
93
106
  const text = await fs.readFile(section, "utf8");
94
107
  await fs.appendFile(agents, `\n${text.endsWith("\n") ? text : `${text}\n`}`);
95
- if (section === staged) await fs.remove(staged);
108
+ if (section === staged) {
109
+ await fs.remove(staged);
110
+ }
96
111
  }
97
112
  await restoreTemplateDotfiles(targetDir);
98
113
  await renderPlaceholders(targetDir, values);
@@ -12,12 +12,12 @@
12
12
  "lint": "eslint . --max-warnings 0"
13
13
  },
14
14
  "dependencies": {
15
- "@bitbybit-dev/base": "1.4.0",
16
- "@bitbybit-dev/threejs": "1.4.0",
15
+ "@bitbybit-dev/base": "1.5.0-rc.0",
16
+ "@bitbybit-dev/threejs": "1.5.0-rc.0",
17
17
  "three": "0.186.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@bitbybit-dev/occt": "1.4.0",
20
+ "@bitbybit-dev/occt": "1.5.0-rc.0",
21
21
  "@eslint/js": "10.0.1",
22
22
  "@types/node": "22.20.1",
23
23
  "@types/three": "0.186.0",