@bitbybit-dev/create-app 1.0.0-rc.2 → 1.0.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.
- package/README.md +19 -5
- package/dist/index.js +478 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +371 -0
- package/templates/cloud/backends/dotnet-rest/Program.cs +147 -0
- package/templates/cloud/backends/dotnet-rest/Properties/launchSettings.json +14 -0
- package/templates/cloud/backends/dotnet-rest/appsettings.json +13 -0
- package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +10 -0
- package/templates/cloud/backends/hono-rest/package.json +19 -0
- package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +387 -0
- package/templates/cloud/backends/hono-rest/src/index.ts +128 -0
- package/templates/cloud/backends/hono-rest/src/types.ts +4 -0
- package/templates/cloud/backends/hono-rest/tsconfig.json +16 -0
- package/templates/cloud/backends/hono-rest/wrangler.jsonc +11 -0
- package/templates/cloud/backends/hono-sdk/package.json +19 -0
- package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +239 -0
- package/templates/cloud/backends/hono-sdk/src/index.ts +155 -0
- package/templates/cloud/backends/hono-sdk/src/types.ts +4 -0
- package/templates/cloud/backends/hono-sdk/tsconfig.json +16 -0
- package/templates/cloud/backends/hono-sdk/wrangler.jsonc +11 -0
- package/templates/cloud/backends/nodejs-rest/.env.example +3 -0
- package/templates/cloud/backends/nodejs-rest/package.json +22 -0
- package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +387 -0
- package/templates/cloud/backends/nodejs-rest/src/index.ts +143 -0
- package/templates/cloud/backends/nodejs-rest/src/types.ts +4 -0
- package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -0
- package/templates/cloud/backends/nodejs-sdk/.env.example +3 -0
- package/templates/cloud/backends/nodejs-sdk/package.json +23 -0
- package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +235 -0
- package/templates/cloud/backends/nodejs-sdk/src/index.ts +161 -0
- package/templates/cloud/backends/nodejs-sdk/tsconfig.json +17 -0
- package/templates/cloud/frontend/index.html +13 -0
- package/templates/cloud/frontend/package.json +24 -0
- package/templates/cloud/frontend/src/App.tsx +42 -0
- package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +41 -0
- package/templates/cloud/frontend/src/components/Header.tsx +8 -0
- package/templates/cloud/frontend/src/components/Tabs.tsx +25 -0
- package/templates/cloud/frontend/src/components/Viewer.tsx +155 -0
- package/templates/cloud/frontend/src/main.tsx +10 -0
- package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +134 -0
- package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +213 -0
- package/templates/cloud/frontend/src/styles.css +320 -0
- package/templates/cloud/frontend/tsconfig.json +17 -0
- package/templates/cloud/frontend/vite.config.ts +15 -0
- package/templates/vite/babylonjs/typescript/package.json +1 -1
- package/templates/vite/playcanvas/typescript/package.json +1 -1
- package/templates/vite/threejs/typescript/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @bitbybit-dev/create-app
|
|
2
2
|
|
|
3
|
-
🚀 **CLI tool to scaffold Bit By Bit Developers 3D/CAD projects
|
|
3
|
+
🚀 **CLI tool to scaffold Bit By Bit Developers 3D/CAD projects — browser-based frontend apps and CAD Cloud backend projects**
|
|
4
4
|
|
|
5
|
-
Create stunning 3D/CAD applications with ease using our powerful geometry kernels: OCCT (OpenCascade), JSCAD, and Manifold.
|
|
5
|
+
Create stunning 3D/CAD applications with ease using our powerful geometry kernels: OCCT (OpenCascade), JSCAD, and Manifold. Or scaffold a full-stack project that connects to our [CAD Cloud API](https://learn.bitbybit.dev/api/cloud-api) for server-side model generation and file conversion.
|
|
6
6
|
|
|
7
7
|
## Quick Start
|
|
8
8
|
|
|
@@ -29,8 +29,10 @@ npm init @bitbybit-dev/app my-project
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
You'll be prompted to select:
|
|
32
|
-
-
|
|
33
|
-
-
|
|
32
|
+
- 📦 **App Type**: Frontend (browser 3D app) or Cloud (backend + frontend for CAD Cloud API)
|
|
33
|
+
- 🎮 **Game Engine** (frontend): Three.js, Babylon.js, or PlayCanvas
|
|
34
|
+
- ⚙️ **OCCT Architecture** (frontend): 32-bit, 64-bit, or 64-bit Multi-threaded
|
|
35
|
+
- 🖥️ **Backend Template** (cloud): Hono + SDK, Hono + REST, Node.js + SDK, Node.js + REST, or .NET + REST
|
|
34
36
|
|
|
35
37
|
### CLI Options
|
|
36
38
|
|
|
@@ -62,7 +64,9 @@ When you select 64-bit MT, a `vite.config.ts` is automatically created with thes
|
|
|
62
64
|
|
|
63
65
|
## What You Get
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
### Frontend Projects
|
|
68
|
+
|
|
69
|
+
Each scaffolded frontend project includes:
|
|
66
70
|
|
|
67
71
|
- ⚡ **Vite** - Lightning fast build tool
|
|
68
72
|
- 📘 **TypeScript** - Type-safe development
|
|
@@ -72,6 +76,16 @@ Each scaffolded project includes:
|
|
|
72
76
|
- **Manifold** - Fast mesh boolean operations
|
|
73
77
|
- 🎮 **Your chosen 3D engine** - Three.js, Babylon.js, or PlayCanvas
|
|
74
78
|
|
|
79
|
+
### Cloud Projects
|
|
80
|
+
|
|
81
|
+
Each scaffolded cloud project includes:
|
|
82
|
+
|
|
83
|
+
- 🖥️ **Your chosen backend** - Hono (Cloudflare Workers), Express 5 (Node.js), or ASP.NET Core (.NET 10)
|
|
84
|
+
- 🌐 **React + Three.js frontend** - shared across all backends for visualizing CAD results
|
|
85
|
+
- 🔑 **Secure API key handling** - keys stay on the server; the frontend proxies requests through your backend
|
|
86
|
+
- 📘 **TypeScript SDK or raw REST** - depending on your chosen template
|
|
87
|
+
- 📖 **Ready-to-run examples** - model generation, CAD pipelines, file conversion, and file uploads
|
|
88
|
+
|
|
75
89
|
## After Scaffolding
|
|
76
90
|
|
|
77
91
|
Navigate to your project and start developing:
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,27 @@ const OCCT_ARCHITECTURE_DESCRIPTIONS = {
|
|
|
46
46
|
"64": "May not be supported on all browsers",
|
|
47
47
|
"64-mt": "Requires special server configuration (COOP/COEP headers)"
|
|
48
48
|
};
|
|
49
|
+
const BACKEND_DISPLAY_NAMES = {
|
|
50
|
+
"hono-sdk": "Hono + SDK (Cloudflare Workers)",
|
|
51
|
+
"hono-rest": "Hono + REST (Cloudflare Workers)",
|
|
52
|
+
"nodejs-sdk": "Node.js Express + SDK",
|
|
53
|
+
"nodejs-rest": "Node.js Express + REST",
|
|
54
|
+
"dotnet-rest": "ASP.NET Core + REST (.NET 10)",
|
|
55
|
+
};
|
|
56
|
+
const BACKEND_DESCRIPTIONS = {
|
|
57
|
+
"hono-sdk": "Type-safe SDK on Cloudflare Workers edge runtime",
|
|
58
|
+
"hono-rest": "Raw fetch calls on Cloudflare Workers edge runtime",
|
|
59
|
+
"nodejs-sdk": "Type-safe SDK on Node.js with Express 5",
|
|
60
|
+
"nodejs-rest": "Raw fetch calls on Node.js with Express 5",
|
|
61
|
+
"dotnet-rest": "HttpClient calls on ASP.NET Core minimal API",
|
|
62
|
+
};
|
|
63
|
+
const BACKEND_COLORS = {
|
|
64
|
+
"hono-sdk": chalk.hex("#FF6633"),
|
|
65
|
+
"hono-rest": chalk.hex("#FF6633"),
|
|
66
|
+
"nodejs-sdk": chalk.hex("#68A063"),
|
|
67
|
+
"nodejs-rest": chalk.hex("#68A063"),
|
|
68
|
+
"dotnet-rest": chalk.hex("#512BD4"),
|
|
69
|
+
};
|
|
49
70
|
async function displayWelcome() {
|
|
50
71
|
console.clear();
|
|
51
72
|
// Create a beautiful gold gradient for the logo
|
|
@@ -68,6 +89,98 @@ async function displayWelcome() {
|
|
|
68
89
|
console.log(chalk.gray("─".repeat(72)));
|
|
69
90
|
console.log();
|
|
70
91
|
}
|
|
92
|
+
async function promptAppType() {
|
|
93
|
+
const { appType } = await inquirer.prompt([
|
|
94
|
+
{
|
|
95
|
+
type: "list",
|
|
96
|
+
name: "appType",
|
|
97
|
+
message: chalk.cyan("🏗️ What type of application would you like to create?"),
|
|
98
|
+
choices: [
|
|
99
|
+
{
|
|
100
|
+
name: `${chalk.green("● Frontend App")} ${chalk.gray("- Browser-based 3D/CAD app with a game engine (Three.js, Babylon.js, PlayCanvas)")}`,
|
|
101
|
+
value: "frontend",
|
|
102
|
+
short: "Frontend App"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: `${chalk.hex("#FF6633")("● CAD Cloud App")} ${chalk.gray("- Backend + Frontend using managed Bitbybit CAD Cloud servers")}`,
|
|
106
|
+
value: "cloud",
|
|
107
|
+
short: "CAD Cloud App"
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
default: "frontend"
|
|
111
|
+
}
|
|
112
|
+
]);
|
|
113
|
+
return appType;
|
|
114
|
+
}
|
|
115
|
+
async function promptCloudProjectOptions(projectNameArg) {
|
|
116
|
+
const backendChoices = [
|
|
117
|
+
{
|
|
118
|
+
name: `${BACKEND_COLORS["hono-sdk"]("● Hono + SDK")} ${chalk.gray("- Type-safe SDK on Cloudflare Workers edge runtime")}`,
|
|
119
|
+
value: "hono-sdk",
|
|
120
|
+
short: "Hono + SDK"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: `${BACKEND_COLORS["hono-rest"]("● Hono + REST")} ${chalk.gray("- Raw fetch calls on Cloudflare Workers edge runtime")}`,
|
|
124
|
+
value: "hono-rest",
|
|
125
|
+
short: "Hono + REST"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: `${BACKEND_COLORS["nodejs-sdk"]("● Node.js + SDK")} ${chalk.gray("- Type-safe SDK on Node.js with Express 5")}`,
|
|
129
|
+
value: "nodejs-sdk",
|
|
130
|
+
short: "Node.js + SDK"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: `${BACKEND_COLORS["nodejs-rest"]("● Node.js + REST")} ${chalk.gray("- Raw fetch calls on Node.js with Express 5")}`,
|
|
134
|
+
value: "nodejs-rest",
|
|
135
|
+
short: "Node.js + REST"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: `${BACKEND_COLORS["dotnet-rest"]("● .NET + REST")} ${chalk.gray("- HttpClient calls on ASP.NET Core minimal API (.NET 10)")}`,
|
|
139
|
+
value: "dotnet-rest",
|
|
140
|
+
short: ".NET + REST"
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
let answers;
|
|
144
|
+
if (!projectNameArg) {
|
|
145
|
+
answers = await inquirer.prompt([
|
|
146
|
+
{
|
|
147
|
+
type: "input",
|
|
148
|
+
name: "projectName",
|
|
149
|
+
message: chalk.cyan("📁 What is your project name?"),
|
|
150
|
+
default: "my-bitbybit-cloud-app",
|
|
151
|
+
validate: (input) => {
|
|
152
|
+
if (!input.trim())
|
|
153
|
+
return "Project name is required";
|
|
154
|
+
if (!/^[a-z0-9-_]+$/i.test(input))
|
|
155
|
+
return "Project name can only contain letters, numbers, hyphens, and underscores";
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
type: "list",
|
|
161
|
+
name: "backend",
|
|
162
|
+
message: chalk.cyan("⚡ Which backend would you like to use?"),
|
|
163
|
+
choices: backendChoices,
|
|
164
|
+
default: "hono-sdk"
|
|
165
|
+
},
|
|
166
|
+
]);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
answers = await inquirer.prompt([
|
|
170
|
+
{
|
|
171
|
+
type: "list",
|
|
172
|
+
name: "backend",
|
|
173
|
+
message: chalk.cyan("⚡ Which backend would you like to use?"),
|
|
174
|
+
choices: backendChoices,
|
|
175
|
+
default: "hono-sdk"
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
projectName: projectNameArg || answers.projectName,
|
|
181
|
+
backend: answers.backend,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
71
184
|
async function promptProjectOptions(projectNameArg) {
|
|
72
185
|
const occtArchitectureChoices = [
|
|
73
186
|
{
|
|
@@ -335,55 +448,388 @@ export default defineConfig({
|
|
|
335
448
|
process.exit(1);
|
|
336
449
|
}
|
|
337
450
|
}
|
|
451
|
+
function generateCloudReadme(projectName, backend) {
|
|
452
|
+
const backendName = BACKEND_DISPLAY_NAMES[backend];
|
|
453
|
+
const keyConfigSection = backend === "dotnet-rest"
|
|
454
|
+
? `Edit \`backend/appsettings.Development.json\`:
|
|
455
|
+
|
|
456
|
+
\`\`\`json
|
|
457
|
+
{
|
|
458
|
+
"Bitbybit": {
|
|
459
|
+
"ApiKey": "your-api-key-here",
|
|
460
|
+
"ApiUrl": "https://api.bitbybit.dev"
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
\`\`\``
|
|
464
|
+
: backend.startsWith("hono")
|
|
465
|
+
? `Edit \`backend/.dev.vars\`:
|
|
466
|
+
|
|
467
|
+
\`\`\`
|
|
468
|
+
BITBYBIT_API_KEY=your-api-key-here
|
|
469
|
+
BITBYBIT_API_URL=https://api.bitbybit.dev
|
|
470
|
+
\`\`\``
|
|
471
|
+
: `Edit \`backend/.env\`:
|
|
472
|
+
|
|
473
|
+
\`\`\`
|
|
474
|
+
BITBYBIT_API_KEY=your-api-key-here
|
|
475
|
+
BITBYBIT_API_URL=https://api.bitbybit.dev
|
|
476
|
+
\`\`\``;
|
|
477
|
+
const backendStartCmd = backend === "dotnet-rest"
|
|
478
|
+
? "cd backend\ndotnet run"
|
|
479
|
+
: "cd backend\nnpm install\nnpm run dev";
|
|
480
|
+
return `# ${projectName}
|
|
481
|
+
|
|
482
|
+
A CAD Cloud application powered by [Bitbybit](https://bitbybit.dev) managed CAD servers.
|
|
483
|
+
|
|
484
|
+
## Architecture
|
|
485
|
+
|
|
486
|
+
\`\`\`
|
|
487
|
+
┌─────────────────────────────┐ ┌─────────────────────────────┐
|
|
488
|
+
│ frontend/ │ │ Bitbybit CAD Cloud API │
|
|
489
|
+
│ React 19 + Vite + Three.js │──/api──▶ ${backendName.padEnd(27)} │──▶ api.bitbybit.dev
|
|
490
|
+
│ Port 5173 │ proxy │ Port 3000 │
|
|
491
|
+
└─────────────────────────────┘ └─────────────────────────────┘
|
|
492
|
+
\`\`\`
|
|
493
|
+
|
|
494
|
+
The frontend never calls the Bitbybit API directly — your **API key stays on the server**. Vite's dev proxy forwards \`/api/*\` requests to \`localhost:3000\`.
|
|
495
|
+
|
|
496
|
+
## Prerequisites
|
|
497
|
+
|
|
498
|
+
- **Node.js** ≥ 20
|
|
499
|
+
${backend === "dotnet-rest" ? "- **.NET** ≥ 10\n" : ""}- A **Bitbybit API key** — purchase one at [bitbybit.dev/auth/pick-plan?api-keys=true](https://bitbybit.dev/auth/pick-plan?api-keys=true)
|
|
500
|
+
${backend.startsWith("hono") ? "- **Wrangler** CLI (installed as a dev dependency)\n" : ""}
|
|
501
|
+
## Quick Start
|
|
502
|
+
|
|
503
|
+
### 1. Configure your API key
|
|
504
|
+
|
|
505
|
+
${keyConfigSection}
|
|
506
|
+
|
|
507
|
+
### 2. Start the backend
|
|
508
|
+
|
|
509
|
+
\`\`\`bash
|
|
510
|
+
${backendStartCmd}
|
|
511
|
+
\`\`\`
|
|
512
|
+
|
|
513
|
+
The backend starts on **port 3000**.
|
|
514
|
+
|
|
515
|
+
### 3. Start the frontend (separate terminal)
|
|
516
|
+
|
|
517
|
+
\`\`\`bash
|
|
518
|
+
cd frontend
|
|
519
|
+
npm install
|
|
520
|
+
npm run dev
|
|
521
|
+
\`\`\`
|
|
522
|
+
|
|
523
|
+
### 4. Open the app
|
|
524
|
+
|
|
525
|
+
Navigate to **http://localhost:5173** in your browser.
|
|
526
|
+
|
|
527
|
+
## What This App Demonstrates
|
|
528
|
+
|
|
529
|
+
### Single CAD Operation
|
|
530
|
+
Click **Generate** to create a parametric "dragon cup" model. The backend submits the request to Bitbybit CAD Cloud, polls until complete, and returns a glTF download URL. The frontend loads it into a Three.js scene.
|
|
531
|
+
|
|
532
|
+
### Batch Generation
|
|
533
|
+
Click **Generate Batch** to create 3 model variations in parallel.
|
|
534
|
+
|
|
535
|
+
### Pipelines
|
|
536
|
+
Several pipeline examples are available:
|
|
537
|
+
|
|
538
|
+
| Pipeline | What it does |
|
|
539
|
+
|----------|-------------|
|
|
540
|
+
| **Translate → Union → Fillet** | Creates two boxes, translates one, unions them, fillets edges — demonstrates \`$ref:N\` step references |
|
|
541
|
+
| **Map Cylinders** | Uses a \`map\` step to create cylinders at different positions — demonstrates iteration |
|
|
542
|
+
| **Map Spheres** | Maps over an array to create multiple spheres — demonstrates \`$item\` references |
|
|
543
|
+
| **Choice** | Uses a \`choice\` step to conditionally create a box or cylinder — demonstrates branching |
|
|
544
|
+
| **File Input** | Upload a STEP file, fillet its edges — demonstrates file upload flow |
|
|
545
|
+
|
|
546
|
+
## Project Structure
|
|
547
|
+
|
|
548
|
+
\`\`\`
|
|
549
|
+
${projectName}/
|
|
550
|
+
├── README.md
|
|
551
|
+
├── frontend/
|
|
552
|
+
│ ├── src/
|
|
553
|
+
│ │ ├── App.tsx
|
|
554
|
+
│ │ ├── components/ # Three.js viewer, header, API key warning
|
|
555
|
+
│ │ └── panels/ # Models and Pipelines UI panels
|
|
556
|
+
│ ├── vite.config.ts # Dev proxy: /api → localhost:3000
|
|
557
|
+
│ └── package.json
|
|
558
|
+
└── backend/
|
|
559
|
+
${backend === "dotnet-rest" ? ` ├── Program.cs
|
|
560
|
+
├── BitbybitClient.cs
|
|
561
|
+
├── appsettings.json
|
|
562
|
+
└── dotnet-rest.csproj` : ` ├── src/
|
|
563
|
+
│ ├── index.ts # Routes
|
|
564
|
+
│ └── bitbybit-client.ts # API calls
|
|
565
|
+
└── package.json`}
|
|
566
|
+
\`\`\`
|
|
567
|
+
|
|
568
|
+
## API Routes
|
|
569
|
+
|
|
570
|
+
| Method | Route | Description |
|
|
571
|
+
|--------|-------|-------------|
|
|
572
|
+
| \`POST\` | \`/api/generate\` | Single CAD operation (dragon cup) |
|
|
573
|
+
| \`POST\` | \`/api/generate-batch\` | Parallel batch generation |
|
|
574
|
+
| \`GET\` | \`/api/task/:id\` | Poll / fetch task result |
|
|
575
|
+
| \`POST\` | \`/api/pipeline/translate-union-fillet\` | Pipeline: translate → union → fillet |
|
|
576
|
+
| \`POST\` | \`/api/pipeline/map-cylinders\` | Pipeline: map cylinders |
|
|
577
|
+
| \`POST\` | \`/api/pipeline/map-spheres\` | Pipeline: map spheres |
|
|
578
|
+
| \`POST\` | \`/api/pipeline/choice\` | Pipeline: conditional logic |
|
|
579
|
+
| \`POST\` | \`/api/pipeline/file-input\` | Pipeline: file upload + fillet |
|
|
580
|
+
| \`GET\` | \`/api/proxy-download?url=...\` | Proxy glTF downloads (avoids CORS) |
|
|
581
|
+
|
|
582
|
+
## Getting an API Key
|
|
583
|
+
|
|
584
|
+
1. Create an account on [bitbybit.dev](https://bitbybit.dev)
|
|
585
|
+
2. Go to [bitbybit.dev/auth/pick-plan?api-keys=true](https://bitbybit.dev/auth/pick-plan?api-keys=true)
|
|
586
|
+
3. Purchase a Starter, Professional, or Business API key plan
|
|
587
|
+
4. Manage your keys in [Bitbybit Studio](https://studio.bitbybit.dev/keys/billing)
|
|
588
|
+
|
|
589
|
+
## Learn More
|
|
590
|
+
|
|
591
|
+
- [SDK Documentation](https://learn.bitbybit.dev/api/sdk/typescript/intro)
|
|
592
|
+
- [Pipeline Guide](https://learn.bitbybit.dev/api/sdk/typescript/pipelines)
|
|
593
|
+
- [Bitbybit GitHub](https://github.com/bitbybit-dev/bitbybit)
|
|
594
|
+
- [Discord Community](https://discord.gg/GSe3VMe)
|
|
595
|
+
`;
|
|
596
|
+
}
|
|
597
|
+
async function createCloudProject(options) {
|
|
598
|
+
const { projectName, backend } = options;
|
|
599
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
600
|
+
console.log();
|
|
601
|
+
console.log(chalk.gray("─".repeat(72)));
|
|
602
|
+
console.log();
|
|
603
|
+
console.log(chalk.white.bold(" 📋 Project Configuration:"));
|
|
604
|
+
console.log();
|
|
605
|
+
console.log(` ${chalk.gray("Project:")} ${chalk.white.bold(projectName)}`);
|
|
606
|
+
console.log(` ${chalk.gray("Type:")} ${chalk.hex("#FF6633")("CAD Cloud App")}`);
|
|
607
|
+
console.log(` ${chalk.gray("Backend:")} ${BACKEND_COLORS[backend](BACKEND_DISPLAY_NAMES[backend])}`);
|
|
608
|
+
console.log(` ${chalk.gray("Frontend:")} ${chalk.cyan("React 19 + Vite + Three.js")}`);
|
|
609
|
+
console.log();
|
|
610
|
+
console.log(chalk.gray("─".repeat(72)));
|
|
611
|
+
console.log();
|
|
612
|
+
// Check if directory exists
|
|
613
|
+
if (fs.existsSync(targetDir)) {
|
|
614
|
+
const { overwrite } = await inquirer.prompt([
|
|
615
|
+
{
|
|
616
|
+
type: "confirm",
|
|
617
|
+
name: "overwrite",
|
|
618
|
+
message: chalk.yellow(`⚠️ Directory "${projectName}" already exists. Do you want to overwrite it?`),
|
|
619
|
+
default: false
|
|
620
|
+
}
|
|
621
|
+
]);
|
|
622
|
+
if (!overwrite) {
|
|
623
|
+
console.log(chalk.red("\n ✖ Project creation cancelled.\n"));
|
|
624
|
+
process.exit(0);
|
|
625
|
+
}
|
|
626
|
+
const spinner = ora("Removing existing directory...").start();
|
|
627
|
+
await fs.remove(targetDir);
|
|
628
|
+
spinner.succeed("Existing directory removed");
|
|
629
|
+
}
|
|
630
|
+
const spinner = ora({
|
|
631
|
+
text: "Creating project structure...",
|
|
632
|
+
color: "cyan"
|
|
633
|
+
}).start();
|
|
634
|
+
try {
|
|
635
|
+
const cloudTemplatesDir = path.join(__dirname, "..", "templates", "cloud");
|
|
636
|
+
// Copy frontend
|
|
637
|
+
const frontendTemplateDir = path.join(cloudTemplatesDir, "frontend");
|
|
638
|
+
const frontendTargetDir = path.join(targetDir, "frontend");
|
|
639
|
+
await fs.copy(frontendTemplateDir, frontendTargetDir);
|
|
640
|
+
// Update frontend package.json name
|
|
641
|
+
const frontendPackageJsonPath = path.join(frontendTargetDir, "package.json");
|
|
642
|
+
if (fs.existsSync(frontendPackageJsonPath)) {
|
|
643
|
+
const packageJson = await fs.readJson(frontendPackageJsonPath);
|
|
644
|
+
packageJson.name = `${projectName}-frontend`;
|
|
645
|
+
await fs.writeJson(frontendPackageJsonPath, packageJson, { spaces: 4 });
|
|
646
|
+
}
|
|
647
|
+
// Copy backend
|
|
648
|
+
const backendTemplateDir = path.join(cloudTemplatesDir, "backends", backend);
|
|
649
|
+
const backendTargetDir = path.join(targetDir, "backend");
|
|
650
|
+
await fs.copy(backendTemplateDir, backendTargetDir);
|
|
651
|
+
// Update backend package.json name (if applicable — not dotnet)
|
|
652
|
+
const backendPackageJsonPath = path.join(backendTargetDir, "package.json");
|
|
653
|
+
if (fs.existsSync(backendPackageJsonPath)) {
|
|
654
|
+
const packageJson = await fs.readJson(backendPackageJsonPath);
|
|
655
|
+
packageJson.name = `${projectName}-backend`;
|
|
656
|
+
await fs.writeJson(backendPackageJsonPath, packageJson, { spaces: 4 });
|
|
657
|
+
}
|
|
658
|
+
// For Hono backends, update wrangler.jsonc name
|
|
659
|
+
const wranglerPath = path.join(backendTargetDir, "wrangler.jsonc");
|
|
660
|
+
if (fs.existsSync(wranglerPath)) {
|
|
661
|
+
let wranglerContent = await fs.readFile(wranglerPath, "utf-8");
|
|
662
|
+
wranglerContent = wranglerContent.replace(/"name":\s*"[^"]*"/, `"name": "${projectName}-backend"`);
|
|
663
|
+
await fs.writeFile(wranglerPath, wranglerContent, "utf-8");
|
|
664
|
+
}
|
|
665
|
+
// For nodejs backends, copy .env.example to .env
|
|
666
|
+
const envExamplePath = path.join(backendTargetDir, ".env.example");
|
|
667
|
+
if (fs.existsSync(envExamplePath)) {
|
|
668
|
+
await fs.copy(envExamplePath, path.join(backendTargetDir, ".env"));
|
|
669
|
+
}
|
|
670
|
+
// For Hono backends, create .dev.vars
|
|
671
|
+
if (backend.startsWith("hono")) {
|
|
672
|
+
const devVarsContent = "# Get your API key at https://bitbybit.dev/auth/pick-plan?api-keys=true\nBITBYBIT_API_KEY=\nBITBYBIT_API_URL=https://api.bitbybit.dev\n";
|
|
673
|
+
await fs.writeFile(path.join(backendTargetDir, ".dev.vars"), devVarsContent, "utf-8");
|
|
674
|
+
}
|
|
675
|
+
// For dotnet, create appsettings.Development.json
|
|
676
|
+
if (backend === "dotnet-rest") {
|
|
677
|
+
const devSettings = {
|
|
678
|
+
Bitbybit: {
|
|
679
|
+
ApiKey: "",
|
|
680
|
+
ApiUrl: "https://api.bitbybit.dev"
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
await fs.writeJson(path.join(backendTargetDir, "appsettings.Development.json"), devSettings, { spaces: 2 });
|
|
684
|
+
}
|
|
685
|
+
// Generate README.md
|
|
686
|
+
await fs.writeFile(path.join(targetDir, "README.md"), generateCloudReadme(projectName, backend), "utf-8");
|
|
687
|
+
spinner.succeed("Project structure created");
|
|
688
|
+
// Success message
|
|
689
|
+
console.log();
|
|
690
|
+
console.log(chalk.gray("─".repeat(72)));
|
|
691
|
+
console.log();
|
|
692
|
+
console.log(chalk.gray(" Home: ") + chalk.underline.cyan("https://bitbybit.dev"));
|
|
693
|
+
console.log(chalk.gray(" Learn: ") + chalk.underline.cyan("https://learn.bitbybit.dev"));
|
|
694
|
+
console.log(chalk.gray(" SDK Docs: ") + chalk.underline.cyan("https://learn.bitbybit.dev/api/sdk/typescript/intro"));
|
|
695
|
+
console.log(chalk.gray(" Community: ") + chalk.underline.cyan("https://discord.gg/GSe3VMe"));
|
|
696
|
+
console.log(chalk.gray(" GitHub: ") + chalk.underline.cyan("https://github.com/bitbybit-dev/bitbybit"));
|
|
697
|
+
console.log();
|
|
698
|
+
console.log(chalk.green.bold(" ✔ CAD Cloud project created successfully! 🎉"));
|
|
699
|
+
console.log();
|
|
700
|
+
console.log(chalk.white(" Next steps:"));
|
|
701
|
+
console.log();
|
|
702
|
+
console.log(chalk.gray(" 1. Navigate to your project:"));
|
|
703
|
+
console.log(chalk.cyan(` cd ${projectName}`));
|
|
704
|
+
console.log();
|
|
705
|
+
if (backend === "dotnet-rest") {
|
|
706
|
+
console.log(chalk.gray(" 2. Add your API key to backend/appsettings.Development.json"));
|
|
707
|
+
console.log();
|
|
708
|
+
console.log(chalk.gray(" 3. Start the backend:"));
|
|
709
|
+
console.log(chalk.cyan(" cd backend && dotnet run"));
|
|
710
|
+
console.log();
|
|
711
|
+
}
|
|
712
|
+
else if (backend.startsWith("hono")) {
|
|
713
|
+
console.log(chalk.gray(" 2. Add your API key to backend/.dev.vars"));
|
|
714
|
+
console.log();
|
|
715
|
+
console.log(chalk.gray(" 3. Start the backend:"));
|
|
716
|
+
console.log(chalk.cyan(" cd backend && npm install && npm run dev"));
|
|
717
|
+
console.log();
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
console.log(chalk.gray(" 2. Add your API key to backend/.env"));
|
|
721
|
+
console.log();
|
|
722
|
+
console.log(chalk.gray(" 3. Start the backend:"));
|
|
723
|
+
console.log(chalk.cyan(" cd backend && npm install && npm run dev"));
|
|
724
|
+
console.log();
|
|
725
|
+
}
|
|
726
|
+
console.log(chalk.gray(" 4. Start the frontend (in a separate terminal):"));
|
|
727
|
+
console.log(chalk.cyan(` cd ${projectName}/frontend && npm install && npm run dev`));
|
|
728
|
+
console.log();
|
|
729
|
+
console.log(chalk.gray(" 5. Open ") + chalk.cyan("http://localhost:5173") + chalk.gray(" in your browser"));
|
|
730
|
+
console.log();
|
|
731
|
+
console.log(chalk.gray("─".repeat(72)));
|
|
732
|
+
console.log();
|
|
733
|
+
console.log(chalk.yellow.bold(" 🔑 You need a Bitbybit API key to use CAD Cloud:"));
|
|
734
|
+
console.log(chalk.yellow(" 1. Create an account on https://bitbybit.dev"));
|
|
735
|
+
console.log(chalk.yellow(" 2. Purchase an API key plan at:"));
|
|
736
|
+
console.log(chalk.underline.yellow(" https://bitbybit.dev/auth/pick-plan?api-keys=true"));
|
|
737
|
+
console.log();
|
|
738
|
+
console.log(chalk.gray("─".repeat(72)));
|
|
739
|
+
console.log();
|
|
740
|
+
console.log(chalk.white(" Happy coding! 💻✨"));
|
|
741
|
+
console.log();
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
spinner.fail("Failed to create project");
|
|
745
|
+
console.error(chalk.red("\n ✖ Error creating project:"), error);
|
|
746
|
+
process.exit(1);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
338
749
|
async function main() {
|
|
339
750
|
const program = new Command();
|
|
340
751
|
program
|
|
341
752
|
.name("@bitbybit-dev/create-app")
|
|
342
753
|
.description("Scaffold a new Bit By Bit Developers 3D/CAD project")
|
|
343
|
-
.version("1.0.0
|
|
754
|
+
.version("1.0.0")
|
|
344
755
|
.argument("[project-name]", "Name of the project to create")
|
|
345
756
|
.option("-e, --engine <engine>", "Game engine to use (threejs, babylonjs, playcanvas)")
|
|
346
757
|
.option("-o, --occt-architecture <arch>", "OCCT worker architecture (32, 64, 64-mt). Default: 32")
|
|
758
|
+
.option("-t, --type <type>", "App type (frontend, cloud)")
|
|
759
|
+
.option("-b, --backend <backend>", "Backend for cloud app (hono-sdk, hono-rest, nodejs-sdk, nodejs-rest, dotnet-rest)")
|
|
347
760
|
.action(async (projectName, cmdOptions) => {
|
|
348
761
|
await displayWelcome();
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (cmdOptions.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
console.error(chalk.
|
|
355
|
-
console.error(chalk.gray(` Valid options: ${validEngines.join(", ")}`));
|
|
762
|
+
// Determine app type
|
|
763
|
+
let appType;
|
|
764
|
+
if (cmdOptions.type) {
|
|
765
|
+
if (cmdOptions.type !== "frontend" && cmdOptions.type !== "cloud") {
|
|
766
|
+
console.error(chalk.red(`\n ✖ Invalid app type: ${cmdOptions.type}`));
|
|
767
|
+
console.error(chalk.gray(` Valid options: frontend, cloud`));
|
|
356
768
|
process.exit(1);
|
|
357
769
|
}
|
|
770
|
+
appType = cmdOptions.type;
|
|
358
771
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const validArchitectures = ["32", "64", "64-mt"];
|
|
362
|
-
if (!validArchitectures.includes(cmdOptions.occtArchitecture)) {
|
|
363
|
-
console.error(chalk.red(`\n ✖ Invalid OCCT architecture: ${cmdOptions.occtArchitecture}`));
|
|
364
|
-
console.error(chalk.gray(` Valid options: ${validArchitectures.join(", ")}`));
|
|
365
|
-
process.exit(1);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
// If all options are provided via CLI, skip prompts
|
|
369
|
-
if (projectName && cmdOptions.engine && cmdOptions.occtArchitecture) {
|
|
370
|
-
options = {
|
|
371
|
-
projectName,
|
|
372
|
-
engine: cmdOptions.engine,
|
|
373
|
-
bundler: "vite",
|
|
374
|
-
language: "typescript",
|
|
375
|
-
occtArchitecture: cmdOptions.occtArchitecture
|
|
376
|
-
};
|
|
772
|
+
else {
|
|
773
|
+
appType = await promptAppType();
|
|
377
774
|
}
|
|
378
|
-
|
|
379
|
-
//
|
|
380
|
-
|
|
381
|
-
|
|
775
|
+
if (appType === "cloud") {
|
|
776
|
+
// Validate backend option if provided
|
|
777
|
+
if (cmdOptions.backend) {
|
|
778
|
+
const validBackends = ["hono-sdk", "hono-rest", "nodejs-sdk", "nodejs-rest", "dotnet-rest"];
|
|
779
|
+
if (!validBackends.includes(cmdOptions.backend)) {
|
|
780
|
+
console.error(chalk.red(`\n ✖ Invalid backend: ${cmdOptions.backend}`));
|
|
781
|
+
console.error(chalk.gray(` Valid options: ${validBackends.join(", ")}`));
|
|
782
|
+
process.exit(1);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
let cloudOptions;
|
|
786
|
+
if (projectName && cmdOptions.backend) {
|
|
787
|
+
cloudOptions = { projectName, backend: cmdOptions.backend };
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
cloudOptions = await promptCloudProjectOptions(projectName);
|
|
791
|
+
}
|
|
792
|
+
await createCloudProject(cloudOptions);
|
|
382
793
|
}
|
|
383
794
|
else {
|
|
384
|
-
options
|
|
795
|
+
let options;
|
|
796
|
+
// If engine is provided via CLI, validate it
|
|
797
|
+
if (cmdOptions.engine) {
|
|
798
|
+
const validEngines = ["threejs", "babylonjs", "playcanvas"];
|
|
799
|
+
if (!validEngines.includes(cmdOptions.engine)) {
|
|
800
|
+
console.error(chalk.red(`\n ✖ Invalid engine: ${cmdOptions.engine}`));
|
|
801
|
+
console.error(chalk.gray(` Valid options: ${validEngines.join(", ")}`));
|
|
802
|
+
process.exit(1);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
// If OCCT architecture is provided via CLI, validate it
|
|
806
|
+
if (cmdOptions.occtArchitecture) {
|
|
807
|
+
const validArchitectures = ["32", "64", "64-mt"];
|
|
808
|
+
if (!validArchitectures.includes(cmdOptions.occtArchitecture)) {
|
|
809
|
+
console.error(chalk.red(`\n ✖ Invalid OCCT architecture: ${cmdOptions.occtArchitecture}`));
|
|
810
|
+
console.error(chalk.gray(` Valid options: ${validArchitectures.join(", ")}`));
|
|
811
|
+
process.exit(1);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
// If all options are provided via CLI, skip prompts
|
|
815
|
+
if (projectName && cmdOptions.engine && cmdOptions.occtArchitecture) {
|
|
816
|
+
options = {
|
|
817
|
+
projectName,
|
|
818
|
+
engine: cmdOptions.engine,
|
|
819
|
+
bundler: "vite",
|
|
820
|
+
language: "typescript",
|
|
821
|
+
occtArchitecture: cmdOptions.occtArchitecture
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
else if (projectName && cmdOptions.engine) {
|
|
825
|
+
options = await promptProjectOptions(projectName);
|
|
826
|
+
options.engine = cmdOptions.engine;
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
options = await promptProjectOptions(projectName);
|
|
830
|
+
}
|
|
831
|
+
await createProject(options);
|
|
385
832
|
}
|
|
386
|
-
await createProject(options);
|
|
387
833
|
});
|
|
388
834
|
await program.parseAsync(process.argv);
|
|
389
835
|
}
|