create-surf-app 0.1.0 → 0.1.2

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 (2) hide show
  1. package/dist/index.js +44 -14
  2. package/package.json +7 -3
package/dist/index.js CHANGED
@@ -5,18 +5,18 @@ import fs from "fs";
5
5
  import path from "path";
6
6
  var args = process.argv.slice(2);
7
7
  var projectName = args.find((a) => !a.startsWith("--")) || ".";
8
- var frontendPort = getFlag("--port", "5173");
9
- var backendPort = getFlag("--backend-port", "3001");
10
- function getFlag(name2, fallback) {
8
+ var frontendPort = getFlag("--port") || process.env.VITE_PORT || "5173";
9
+ var backendPort = getFlag("--backend-port") || process.env.VITE_BACKEND_PORT || "3001";
10
+ function getFlag(name2) {
11
11
  const idx = args.indexOf(name2);
12
- return idx >= 0 && args[idx + 1] ? args[idx + 1] : fallback;
12
+ return idx >= 0 && args[idx + 1] ? args[idx + 1] : void 0;
13
13
  }
14
14
  var frontendPkg = {
15
15
  name: "frontend",
16
16
  private: true,
17
17
  type: "module",
18
18
  scripts: {
19
- dev: `vite --port ${frontendPort}`,
19
+ dev: "vite",
20
20
  build: "vite build",
21
21
  preview: "vite preview",
22
22
  lint: "eslint ."
@@ -61,6 +61,7 @@ var frontendPkg = {
61
61
  "next-themes": "0.4.6",
62
62
  "react": "19.2.4",
63
63
  "react-dom": "19.2.4",
64
+ "react-router-dom": "7.6.1",
64
65
  "sonner": "1.7.4",
65
66
  "tailwind-merge": "2.6.1",
66
67
  "vaul": "1.1.2",
@@ -91,7 +92,7 @@ var templates = {
91
92
  private: true,
92
93
  scripts: {
93
94
  start: "node server.js",
94
- dev: "node --watch server.js"
95
+ dev: "node --env-file=.env --watch server.js"
95
96
  },
96
97
  dependencies: {
97
98
  "@surf-ai/sdk": "latest",
@@ -99,7 +100,7 @@ var templates = {
99
100
  }
100
101
  }, null, 2),
101
102
  "backend/server.js": `const { createServer } = require('@surf-ai/sdk/server')
102
- createServer({ port: ${backendPort} }).start()
103
+ createServer().start()
103
104
  `,
104
105
  "backend/routes/.gitkeep": "",
105
106
  "backend/db/schema.js": `// Define your Drizzle ORM tables here.
@@ -110,17 +111,37 @@ createServer({ port: ${backendPort} }).start()
110
111
  // name: text('name').notNull(),
111
112
  // created_at: timestamp('created_at').defaultNow(),
112
113
  // })
114
+ `,
115
+ "backend/.env": `PORT=${backendPort}
113
116
  `,
114
117
  // ── Frontend ─────────────────────────────────────────────────────────────
115
118
  "frontend/package.json": JSON.stringify(frontendPkg, null, 2),
119
+ "frontend/.env": `VITE_PORT=${frontendPort}
120
+ VITE_BACKEND_PORT=${backendPort}
121
+ `,
116
122
  "frontend/vite.config.ts": `import { defineConfig, loadEnv } from 'vite'
117
123
  import react from '@vitejs/plugin-react'
118
124
  import tailwindcss from '@tailwindcss/vite'
119
125
  import path from 'path'
120
126
 
121
127
  const env = loadEnv('', process.cwd(), '')
122
- const FRONTEND_PORT = parseInt(env.VITE_PORT || '${frontendPort}', 10)
123
- const BACKEND_PORT = parseInt(env.VITE_BACKEND_PORT || '${backendPort}', 10)
128
+
129
+ function requiredPort(name: string) {
130
+ const value = env[name]
131
+ if (!value) {
132
+ throw new Error(\`Missing \${name}. Set it in frontend/.env or your shell environment.\`)
133
+ }
134
+
135
+ const port = Number.parseInt(value, 10)
136
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
137
+ throw new Error(\`Invalid \${name}: \${value}\`)
138
+ }
139
+
140
+ return port
141
+ }
142
+
143
+ const FRONTEND_PORT = requiredPort('VITE_PORT')
144
+ const BACKEND_PORT = requiredPort('VITE_BACKEND_PORT')
124
145
 
125
146
  export default defineConfig({
126
147
  plugins: [react(), tailwindcss()],
@@ -280,9 +301,18 @@ exports.users = pgTable('users', {
280
301
  Tables are auto-created on startup and when \`schema.js\` changes (file watcher).
281
302
  The agent can also call \`POST /api/__sync-schema\` explicitly after editing.
282
303
 
304
+ ## Dev Servers
305
+
306
+ - Frontend: \`cd frontend && npm run dev\` (port from \`.env\`, do NOT pass \`--port\`)
307
+ - Backend: \`cd backend && npm run dev\` (port from \`.env\`)
308
+ - After \`npm install\` new packages, do NOT restart servers \u2014 Vite auto-discovers deps, backend uses \`node --watch\`
309
+ - If a server crashes, restart with \`npm run dev\` in that directory
310
+ - NEVER use \`npx vite\` \u2014 always use \`npm run dev\`
311
+
283
312
  ## Do NOT modify
284
313
 
285
314
  - \`vite.config.ts\` \u2014 proxy and build config
315
+ - \`frontend/.env\` \u2014 port configuration (auto-generated)
286
316
  - \`backend/server.js\` \u2014 uses @surf-ai/sdk/server
287
317
  - \`entry-client.tsx\` \u2014 app bootstrap with SSR hydration
288
318
  - \`entry-server.tsx\` \u2014 SSR render for deploy
@@ -294,7 +324,7 @@ The agent can also call \`POST /api/__sync-schema\` explicitly after editing.
294
324
 
295
325
  - Use \`@surf-ai/sdk/react\` hooks in frontend, \`@surf-ai/sdk/server\` dataApi in backend
296
326
  - Use Tailwind CSS classes for styling (Surf Design System theme via \`@surf-ai/theme\`)
297
- - Use shadcn/ui components \u2014 install with \`bunx shadcn@latest add button\`
327
+ - Use shadcn/ui components \u2014 install with \`npx shadcn@latest add button\`
298
328
  - Use \`cn()\` from \`@surf-ai/sdk/react\` to merge Tailwind classes
299
329
  - Frontend packages are pre-installed \u2014 check \`package.json\` before installing
300
330
  - Dark theme is the default (configured in entry-client.tsx)
@@ -333,14 +363,14 @@ console.log(`
333
363
  Done! Next steps:
334
364
 
335
365
  cd ${name}
336
- cd backend && bun install && cd ..
337
- cd frontend && bun install && cd ..
366
+ cd backend && npm install && cd ..
367
+ cd frontend && npm install && cd ..
338
368
 
339
369
  # Start backend
340
- cd backend && bun dev &
370
+ cd backend && npm run dev &
341
371
 
342
372
  # Start frontend
343
- cd frontend && bun dev
373
+ cd frontend && npm run dev
344
374
 
345
375
  Open http://localhost:${frontendPort}
346
376
  `);
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "create-surf-app",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Scaffold a Surf app — Vite + React + Express + @surf-ai/sdk",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "create-surf-app": "./dist/index.js"
8
8
  },
9
- "files": ["dist", "templates"],
9
+ "files": [
10
+ "dist",
11
+ "templates"
12
+ ],
10
13
  "scripts": {
11
14
  "build": "tsup src/index.ts --format esm --clean && rm -rf dist/templates && cp -r templates dist/templates",
12
- "dev": "tsup src/index.ts --format esm --watch"
15
+ "dev": "tsup src/index.ts --format esm --watch",
16
+ "test": "bun test"
13
17
  },
14
18
  "devDependencies": {
15
19
  "tsup": "^8.0.0",