@boardgamebuddy/game-pack-cli 0.0.7 → 0.0.9
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 +84 -0
- package/cli.js +21 -4
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @boardgamebuddy/game-pack-cli
|
|
2
|
+
|
|
3
|
+
Developer CLI for creating and testing [BoardGameBuddy](https://github.com/BoardGameBuddy) game packs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @boardgamebuddy/game-pack-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
### `bgb new <game-id>`
|
|
14
|
+
|
|
15
|
+
Scaffold a new game pack from the upstream template.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bgb new ticket-to-ride
|
|
19
|
+
bgb new ticket-to-ride --name "Ticket to Ride"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Arguments**
|
|
23
|
+
|
|
24
|
+
| Argument | Description |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `game-id` | Unique identifier for the game. Lowercase alphanumeric and hyphens only (e.g. `ticket-to-ride`). |
|
|
27
|
+
|
|
28
|
+
**Options**
|
|
29
|
+
|
|
30
|
+
| Option | Description |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `-n, --name <displayName>` | Display name shown in the app. Defaults to the title-cased `game-id`. |
|
|
33
|
+
|
|
34
|
+
This command downloads the template from [`BoardGameBuddy/game-packs`](https://github.com/BoardGameBuddy/game-packs) and creates the pack under `<game-id>/` in the current directory:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
ticket-to-ride/
|
|
38
|
+
game.json ← patched with your game-id and display name
|
|
39
|
+
scorer.ts ← implement your scoring logic here
|
|
40
|
+
scorer.js ← compiled output (generated)
|
|
41
|
+
embeddings.json ← card embeddings
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `bgb serve [pack-dir]`
|
|
45
|
+
|
|
46
|
+
Start a local dev server for a game pack with live reload whenever `scorer.ts` changes.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# from inside the pack directory
|
|
50
|
+
cd games/ticket-to-ride
|
|
51
|
+
bgb serve
|
|
52
|
+
|
|
53
|
+
# or pass the path explicitly
|
|
54
|
+
bgb serve games/ticket-to-ride
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The server starts on port `3000` (override with the `PORT` environment variable) and prints a QR code you can scan in the BoardGameBuddy app to load the pack directly.
|
|
58
|
+
|
|
59
|
+
When `scorer.ts` changes, the CLI automatically recompiles it with `tsc` and pushes a reload event to the app via Server-Sent Events.
|
|
60
|
+
|
|
61
|
+
## Developing a game pack
|
|
62
|
+
|
|
63
|
+
1. **Scaffold** the pack:
|
|
64
|
+
```bash
|
|
65
|
+
bgb new my-game
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
2. **Implement scoring** in `my-game/scorer.ts`. The `score` function receives all players and their detected cards and must return a score result for each player:
|
|
69
|
+
```ts
|
|
70
|
+
export function score(players: PlayerInput[]): PlayerScoreResult[] {
|
|
71
|
+
// your logic here
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
3. **Start the dev server**:
|
|
76
|
+
```bash
|
|
77
|
+
bgb serve my-game
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
4. **Open the app**, navigate to Pack Store, and scan the QR code to load your pack. The app reloads automatically whenever you save `scorer.ts`.
|
|
81
|
+
|
|
82
|
+
## Requirements
|
|
83
|
+
|
|
84
|
+
- Node.js >= 18
|
package/cli.js
CHANGED
|
@@ -93,7 +93,7 @@ program
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
const displayName = opts.name || toTitleCase(gameId);
|
|
96
|
-
const targetDir = path.join(process.cwd(),
|
|
96
|
+
const targetDir = path.join(process.cwd(), gameId);
|
|
97
97
|
|
|
98
98
|
if (fs.existsSync(targetDir)) {
|
|
99
99
|
console.error(`Error: directory already exists: ${targetDir}`);
|
|
@@ -123,10 +123,27 @@ program
|
|
|
123
123
|
fs.writeFileSync(embeddingsPath, embeddings);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
// Patch package.json name
|
|
127
|
+
const packJsonPath = path.join(targetDir, 'package.json');
|
|
128
|
+
if (fs.existsSync(packJsonPath)) {
|
|
129
|
+
let packJson = fs.readFileSync(packJsonPath, 'utf8');
|
|
130
|
+
packJson = packJson.replace(/"mygame"/, `"${gameId}"`);
|
|
131
|
+
fs.writeFileSync(packJsonPath, packJson);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
console.log(`\nCreated game pack: ${gameId}/`);
|
|
127
135
|
console.log(` Display name: ${displayName}`);
|
|
136
|
+
console.log(`\nInstalling dependencies...`);
|
|
137
|
+
|
|
138
|
+
await new Promise((resolve, reject) => {
|
|
139
|
+
const proc = spawn('npm', ['install'], { cwd: targetDir, shell: true, stdio: 'inherit' });
|
|
140
|
+
proc.on('close', (code) => code === 0 ? resolve() : reject(new Error(`npm install failed with code ${code}`)));
|
|
141
|
+
}).catch((err) => {
|
|
142
|
+
console.error(`Warning: ${err.message}`);
|
|
143
|
+
});
|
|
144
|
+
|
|
128
145
|
console.log(`\nNext steps:`);
|
|
129
|
-
console.log(` cd
|
|
146
|
+
console.log(` cd ${gameId}`);
|
|
130
147
|
console.log(` # Edit scorer.ts to implement your scoring logic`);
|
|
131
148
|
console.log(` bgb serve . # Start dev server with live reload`);
|
|
132
149
|
console.log('');
|
|
@@ -235,7 +252,7 @@ program
|
|
|
235
252
|
console.log('scorer.ts changed — recompiling...');
|
|
236
253
|
const proc = spawn(
|
|
237
254
|
'npx',
|
|
238
|
-
['
|
|
255
|
+
['esbuild', 'scorer.ts', '--bundle', '--platform=node', '--target=es2017', '--outfile=scorer.js'],
|
|
239
256
|
{ cwd: packDir, shell: true }
|
|
240
257
|
);
|
|
241
258
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boardgamebuddy/game-pack-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Developer CLI for BoardGameBuddy game packs",
|
|
5
5
|
"bin": {
|
|
6
|
-
"bgb": "
|
|
6
|
+
"bgb": "cli.js"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
|
-
"url": "https://github.com/BoardGameBuddy/game-pack-cli"
|
|
9
|
+
"url": "git+https://github.com/BoardGameBuddy/game-pack-cli.git"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"cli.js"
|