@xavatech/create-xara-game 1.0.0 → 1.0.1

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 (3) hide show
  1. package/README.md +3 -3
  2. package/index.mjs +12 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,7 +13,7 @@ npm run dev
13
13
  | `--name` | The game's name, as players see it. Defaults to the folder's name. |
14
14
  | `--description` | One line about the game. |
15
15
  | `--players` | `2`, or a range like `2-4`. Defaults to `2`. |
16
- | `--xara-games <dir>` | For Xara's own games. Also adds the game to that [xara-games](https://github.com/xavatech/xara-games) checkout. |
16
+ | `--xara-games <dir>` | For Xara's own games. Creates the game inside that [xara-games](https://github.com/xavatech/xara-games) checkout instead of the current folder. |
17
17
 
18
18
  The starter is a placeholder game: add 1, 2, or 3, and whoever makes the total 10 wins.
19
19
 
@@ -22,10 +22,10 @@ The starter is a placeholder game: add 1, 2, or 3, and whoever makes the total 1
22
22
  Name the folder `xara-<game>` and pass `--xara-games`:
23
23
 
24
24
  ```bash
25
- npx @xavatech/create-xara-game xara-word-chain --name "Word Chain" --players 2-4 --xara-games ./xara-games
25
+ npx @xavatech/create-xara-game xara-word-chain --name "Word Chain" --players 2-4 --xara-games path/to/xara-games
26
26
  ```
27
27
 
28
- This also adds the game as the submodule `games/word-chain` (pointing at `github.com/xavatech/xara-word-chain`), adds it to `games.json`, and builds it into `site/word-chain/`. With the site served at `GAMES_URL`, run the backend's `Game` seeder to list it. Then push the game's repo.
28
+ Run it from any folder, including inside `xara-games` with `--xara-games .`. The game is created at `games/word-chain` in that checkout and registered there as a submodule whose remote is `github.com/xavatech/xara-word-chain`. Nothing is created in the folder you run it from. It is added to `games.json` and built into `site/word-chain/`. With the site served at `GAMES_URL`, run the backend's `Game` seeder to list it. Then create the GitHub repo and push.
29
29
 
30
30
  ## Change the starter
31
31
 
package/index.mjs CHANGED
@@ -12,7 +12,7 @@ const USAGE = `Start a game for Xara chats.
12
12
  --name <name> The game's name, as players see it. Defaults to the folder's name.
13
13
  --description <description> One line about the game.
14
14
  --players <players> How many play: 2, or a range like 2-4. Defaults to 2.
15
- --xara-games <dir> For Xara's own games: also add it to that xara-games checkout.`;
15
+ --xara-games <dir> For Xara's own games: create it in that xara-games checkout, at games/<game>.`;
16
16
 
17
17
  const fail = (message) => {
18
18
  console.error(`\n${message}\n`);
@@ -34,13 +34,15 @@ if (values.help || !positionals[0]) {
34
34
  process.exit(values.help ? 0 : 1);
35
35
  }
36
36
 
37
- const dir = resolve(positionals[0]);
38
- const folder = basename(dir);
37
+ const folder = basename(positionals[0]);
39
38
  if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(folder)) fail("Name the folder like word-chain: lowercase letters, numbers, and dashes.");
40
- if (existsSync(dir)) fail(`${dir} already exists.`);
41
39
 
42
- // Xara's own repos are named xara-<game>; the game is served at /<game>/.
40
+ // Xara's own repos are named xara-<game>; the game lives in xara-games at games/<game> and is served at /<game>/.
43
41
  const path = folder.replace(/^xara-/, "");
42
+ const gamesDir = values["xara-games"] && resolve(values["xara-games"]);
43
+ const dir = gamesDir ? join(gamesDir, "games", path) : resolve(positionals[0]);
44
+ const repoUrl = `https://github.com/xavatech/${folder}.git`;
45
+ if (existsSync(dir)) fail(`${dir} already exists.`);
44
46
  const name = values.name?.trim() || path.split("-").map((word) => word[0].toUpperCase() + word.slice(1)).join(" ");
45
47
  const description = values.description?.trim() ?? "";
46
48
  const [minPlayers, maxPlayers = minPlayers] = values.players.split("-").map(Number);
@@ -48,7 +50,6 @@ if (![minPlayers, maxPlayers].every(Number.isInteger) || minPlayers < 2 || maxPl
48
50
  fail("--players is from 2 to 8, like 2 or 2-4.");
49
51
  }
50
52
 
51
- const gamesDir = values["xara-games"] && resolve(values["xara-games"]);
52
53
  const listFile = gamesDir && join(gamesDir, "games.json");
53
54
  const list = listFile && (existsSync(listFile) ? JSON.parse(readFileSync(listFile, "utf8")) : fail(`${listFile} was not found.`));
54
55
  if (list?.some((game) => game.path === path || game.name === name)) fail(`${path} or "${name}" is already in games.json.`);
@@ -75,8 +76,9 @@ run("npm install --no-fund --no-audit", dir);
75
76
  run(`git init -q -b main && git add -A && git commit -q -m "${name.replace(/"/g, "")} for Xara chats"`, dir);
76
77
 
77
78
  if (gamesDir) {
78
- run(`git -c protocol.file.allow=always submodule add -q "${dir}" games/${path}`, gamesDir);
79
- run(`git config -f .gitmodules submodule.games/${path}.url https://github.com/xavatech/${folder}.git`, gamesDir);
79
+ // The game is already at games/<game>, so this registers that repo in place instead of cloning it.
80
+ run(`git remote add origin ${repoUrl}`, dir);
81
+ run(`git submodule add -q ${repoUrl} games/${path}`, gamesDir);
80
82
  writeFileSync(listFile, `${JSON.stringify([...list, { path, name, description, minPlayers, maxPlayers }], null, 2)}\n`);
81
83
  run(`node build.mjs ${path}`, gamesDir);
82
84
  run("git add -A", gamesDir);
@@ -85,7 +87,7 @@ if (gamesDir) {
85
87
  console.log(`
86
88
  ${name} is ready.
87
89
 
88
- cd ${positionals[0]}
90
+ cd ${dir}
89
91
  npm run dev Play it in a browser; every player shares the screen.
90
92
 
91
93
  Then describe the real game to your coding assistant in that folder.`);
@@ -96,7 +98,7 @@ It is in xara-games at games/${path}, and built into site/${path}/.
96
98
 
97
99
  List it: bun run avanda.ts app seed -t Game (in xara_backend, with xara-games served at GAMES_URL)
98
100
  Push it: create github.com/xavatech/${folder}, then
99
- cd ${dir} && git remote add origin https://github.com/xavatech/${folder}.git && git push -u origin main
101
+ cd ${dir} && git push -u origin main
100
102
  cd ${gamesDir} && git commit -m "Add ${name}"`);
101
103
  } else {
102
104
  console.log(`To ship it, see README.md.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xavatech/create-xara-game",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Start a game for Xara chats: a working starter with the Xara game SDK and the coding-assistant skill.",
5
5
  "type": "module",
6
6
  "bin": {