Ver código fonte

feat: add build script for deployable dist/ target

- npm run build — builds client (Vite) and bundles dist/
- dist/client/ — SPA static files
- dist/data/ — word bank
- STATIC_DIR env var for production path override
- npm start — runs server with tsx
- npm run solve — runs solver

Co-Authored-By: Claude <noreply@anthropic.com>
Oleg Panashchenko 2 semanas atrás
pai
commit
8b473443fc
3 arquivos alterados com 17 adições e 3 exclusões
  1. 5 1
      .claude/settings.local.json
  2. 9 1
      package.json
  3. 3 1
      server/src/index.ts

+ 5 - 1
.claude/settings.local.json

@@ -30,7 +30,11 @@
       "Bash(echo \"solver: $?\")",
       "Bash(fuser -k 3001/tcp)",
       "Bash(curl -s -X POST http://localhost:3001/api/guess -H 'Content-Type: application/json' -d '{\"wordId\":4,\"guess\":\"style\",\"tryNo\":1}')",
-      "Bash(curl -s -X POST http://localhost:3001/api/guess -H 'Content-Type: application/json' -d '{\"wordId\":4,\"guess\":\"crane\",\"tryNo\":6}')"
+      "Bash(curl -s -X POST http://localhost:3001/api/guess -H 'Content-Type: application/json' -d '{\"wordId\":4,\"guess\":\"crane\",\"tryNo\":6}')",
+      "Bash(npm run *)",
+      "Bash(PORT=3001 STATIC_DIR=dist/client npx tsx server/src/index.ts)",
+      "Bash(curl -s http://localhost:3001/)",
+      "Bash(curl -s http://localhost:3001/api/daily)"
     ]
   }
 }

+ 9 - 1
package.json

@@ -1,5 +1,13 @@
 {
   "name": "wordle",
   "private": true,
-  "workspaces": ["client", "server", "shared", "solver"]
+  "workspaces": ["client", "server", "shared", "solver"],
+  "scripts": {
+    "build": "npm run build:client && npm run build:bundle",
+    "build:client": "cd client && npx vite build",
+    "build:bundle": "rm -rf dist && mkdir -p dist/client dist/data && cp -r client/dist/* dist/client/ && cp data/word-bank.json dist/data/",
+    "start": "node --import tsx server/src/index.ts",
+    "dev": "node --import tsx server/src/index.ts",
+    "solve": "cd solver && npm run solve"
+  }
 }

+ 3 - 1
server/src/index.ts

@@ -22,7 +22,9 @@ app.use('/api/guess', createGuessRouter(wordBank));
 app.use('/api/play-again', createPlayAgainRouter(wordBank));
 
 // Serve SPA in production
-const clientDist = resolve(__dirname, '../../client/dist');
+const clientDist = process.env.STATIC_DIR
+  ? resolve(process.env.STATIC_DIR)
+  : resolve(__dirname, '../../client/dist');
 app.use(express.static(clientDist));
 app.get('/{*path}', (_req, res) => {
   res.sendFile(resolve(clientDist, 'index.html'));