create-ifloom 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +18 -2
- package/bin.js +4 -0
- package/dist/bin.js +391 -0
- package/dist/bin.js.map +1 -0
- package/dist/examples/cafe/index.html +12 -0
- package/dist/examples/cafe/package.json +24 -0
- package/dist/examples/cafe/src/game.ts +41 -0
- package/dist/examples/cafe/src/layout.tsx +49 -0
- package/dist/examples/cafe/src/main.ts +7 -0
- package/dist/examples/cafe/src/rules.ts +38 -0
- package/dist/examples/cafe/src/story/hiring.ts +25 -0
- package/dist/examples/cafe/src/story/opening.ts +19 -0
- package/dist/examples/cafe/src/styles.css +7 -0
- package/dist/examples/cafe/src/world/actions.ts +40 -0
- package/dist/examples/cafe/src/world/menu.ts +14 -0
- package/dist/examples/cafe/src/world/staff.ts +12 -0
- package/dist/examples/cafe/src/world/stats.ts +10 -0
- package/dist/examples/cafe/src/world/triggers.ts +18 -0
- package/dist/examples/cafe/tsconfig.json +9 -0
- package/dist/examples/cafe/vite.config.ts +7 -0
- package/dist/examples/novel/index.html +12 -0
- package/dist/examples/novel/package.json +24 -0
- package/dist/examples/novel/src/game.ts +49 -0
- package/dist/examples/novel/src/layout.tsx +25 -0
- package/dist/examples/novel/src/main.ts +8 -0
- package/dist/examples/novel/src/story/ch1.ts +36 -0
- package/dist/examples/novel/src/story/ch2.ts +42 -0
- package/dist/examples/novel/src/story/ch3.ts +41 -0
- package/dist/examples/novel/src/styles.css +7 -0
- package/dist/examples/novel/src/world/stats.ts +6 -0
- package/dist/examples/novel/tsconfig.json +9 -0
- package/dist/examples/novel/vite.config.ts +7 -0
- package/dist/examples/showcase/.env +4 -0
- package/dist/examples/showcase/index.html +12 -0
- package/dist/examples/showcase/package.json +43 -0
- package/dist/examples/showcase/public/art/character/ava.svg +1 -0
- package/dist/examples/showcase/public/art/character/sam.svg +1 -0
- package/dist/examples/showcase/public/art/photo/ava.svg +1 -0
- package/dist/examples/showcase/public/art/photo/sam.svg +1 -0
- package/dist/examples/showcase/src/game.ts +168 -0
- package/dist/examples/showcase/src/layout.tsx +84 -0
- package/dist/examples/showcase/src/main.tsx +55 -0
- package/dist/examples/showcase/src/place.ts +8 -0
- package/dist/examples/showcase/src/rules.ts +51 -0
- package/dist/examples/showcase/src/story/ava.prose.ts +12 -0
- package/dist/examples/showcase/src/story/ava.ts +199 -0
- package/dist/examples/showcase/src/story/cafe.ts +157 -0
- package/dist/examples/showcase/src/story/flat.ts +90 -0
- package/dist/examples/showcase/src/story/high-street.ts +37 -0
- package/dist/examples/showcase/src/story/moving-day.ts +74 -0
- package/dist/examples/showcase/src/story/office.ts +26 -0
- package/dist/examples/showcase/src/story/park.ts +172 -0
- package/dist/examples/showcase/src/story/sam.ts +27 -0
- package/dist/examples/showcase/src/styles.css +8 -0
- package/dist/examples/showcase/src/ui.ts +44 -0
- package/dist/examples/showcase/src/unlocks/supporter.ts +40 -0
- package/dist/examples/showcase/src/world/achievements.ts +13 -0
- package/dist/examples/showcase/src/world/actions.ts +13 -0
- package/dist/examples/showcase/src/world/cast.ts +46 -0
- package/dist/examples/showcase/src/world/cheats.ts +33 -0
- package/dist/examples/showcase/src/world/phone.ts +88 -0
- package/dist/examples/showcase/src/world/settings.ts +24 -0
- package/dist/examples/showcase/src/world/stats.ts +24 -0
- package/dist/examples/showcase/src/world/strings.ts +7 -0
- package/dist/examples/showcase/src/world/things.ts +59 -0
- package/dist/examples/showcase/tsconfig.json +9 -0
- package/dist/examples/showcase/vite.config.ts +7 -0
- package/dist/templates/next/AGENTS.md +60 -0
- package/dist/templates/next/README.md +33 -0
- package/dist/templates/next/app/Game.tsx +46 -0
- package/dist/templates/next/app/layout.tsx +13 -0
- package/dist/templates/next/app/page.tsx +6 -0
- package/dist/templates/next/gitignore +6 -0
- package/dist/templates/next/next.config.ts +6 -0
- package/dist/templates/next/package.json +32 -0
- package/dist/templates/next/postcss.config.mjs +6 -0
- package/dist/templates/next/src/layout.tsx +73 -0
- package/dist/templates/next/src/styles.css +16 -0
- package/dist/templates/next/tsconfig.json +21 -0
- package/dist/templates/plugin/README.md +81 -0
- package/dist/templates/plugin/gitignore +2 -0
- package/dist/templates/plugin/package.json +64 -0
- package/dist/templates/plugin/src/index.ts +162 -0
- package/dist/templates/plugin/src/react/index.tsx +95 -0
- package/dist/templates/plugin/tests/contracts.test.ts +28 -0
- package/dist/templates/plugin/tests/plugin.test.ts +59 -0
- package/dist/templates/plugin/tests/react.test.tsx +47 -0
- package/dist/templates/plugin/tsconfig.json +21 -0
- package/dist/templates/plugin/tsdown.config.ts +14 -0
- package/dist/templates/react/package.json +28 -0
- package/dist/templates/react/src/layout.tsx +69 -0
- package/dist/templates/react/src/main.ts +11 -0
- package/dist/templates/react/src/styles.css +16 -0
- package/dist/templates/react/vite.config.ts +7 -0
- package/dist/templates/shared/AGENTS.md +58 -0
- package/dist/templates/shared/gitignore +3 -0
- package/dist/templates/shared/index.html +12 -0
- package/dist/templates/shared/src/game.ts +23 -0
- package/dist/templates/shared/src/story/opening.ts +34 -0
- package/dist/templates/shared/src/styles.css +228 -0
- package/dist/templates/shared/src/world/stats.ts +6 -0
- package/dist/templates/shared/tsconfig.json +9 -0
- package/dist/templates/shared/vite.config.ts +5 -0
- package/dist/templates/svelte/package.json +25 -0
- package/dist/templates/svelte/src/App.svelte +11 -0
- package/dist/templates/svelte/src/Beat.svelte +31 -0
- package/dist/templates/svelte/src/InputField.svelte +36 -0
- package/dist/templates/svelte/src/Layout.svelte +84 -0
- package/dist/templates/svelte/src/Line.svelte +26 -0
- package/dist/templates/svelte/src/Minigame.svelte +21 -0
- package/dist/templates/svelte/src/Panel.svelte +27 -0
- package/dist/templates/svelte/src/main.ts +5 -0
- package/dist/templates/svelte/src/runner.ts +29 -0
- package/dist/templates/svelte/vite.config.ts +5 -0
- package/dist/templates/vanilla/package.json +22 -0
- package/dist/templates/vanilla/src/layout.ts +35 -0
- package/dist/templates/vanilla/src/main.ts +253 -0
- package/dist/templates/vue/package.json +25 -0
- package/dist/templates/vue/src/App.vue +12 -0
- package/dist/templates/vue/src/Beat.vue +28 -0
- package/dist/templates/vue/src/InputField.vue +34 -0
- package/dist/templates/vue/src/Layout.vue +84 -0
- package/dist/templates/vue/src/Line.vue +41 -0
- package/dist/templates/vue/src/Minigame.vue +19 -0
- package/dist/templates/vue/src/Panel.vue +30 -0
- package/dist/templates/vue/src/main.ts +5 -0
- package/dist/templates/vue/src/runner.ts +32 -0
- package/dist/templates/vue/vite.config.ts +5 -0
- package/package.json +48 -4
- package/src/bin.ts +18 -0
- package/src/create.ts +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The IFLoom authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-ifloom
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Starts a new IFLoom game in a folder of its own. It installs nothing itself, and prints the next commands for the package manager you ran it with. It is part of [IFLoom](https://ifloom.dev), an interactive fiction engine whose games build to one HTML file that opens from disk.
|
|
4
|
+
|
|
5
|
+
## Use
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm create ifloom@latest my-game
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
With pnpm, yarn or bun, run `pnpm create ifloom my-game`, `yarn create ifloom my-game` or `bun create ifloom my-game`. `--template` picks `react` (the default), `vanilla`, `vue`, `svelte`, `next`, `novel`, `cafe`, `town` or `plugin`, and `--theme` picks the React UI's preset. With npm, put the flags after `--`.
|
|
12
|
+
|
|
13
|
+
## Docs
|
|
14
|
+
|
|
15
|
+
- [Create a game](https://ifloom.dev/docs/how-to/create-a-game) explains the templates and the themes.
|
|
16
|
+
|
|
17
|
+
## Licence
|
|
18
|
+
|
|
19
|
+
MIT. See [LICENSE](./LICENSE).
|
package/bin.js
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region ../cli/dist/new.js
|
|
6
|
+
/**
|
|
7
|
+
* `ifloom new`: a new game from a template, ready to run. The `react`,
|
|
8
|
+
* `vanilla`, `vue`, `svelte` and `next` templates live beside this file; the others are the example games, copied from the
|
|
9
|
+
* checkout so there is only one of each to keep working. The `plugin` template
|
|
10
|
+
* is not a game: it's a plugin package of its own, with a test, to publish on npm.
|
|
11
|
+
*/
|
|
12
|
+
/** The templates `ifloom new` can start a game from. `novel`, `cafe` and `town` copy the examples, and `plugin` makes a plugin package. */
|
|
13
|
+
const TEMPLATES = [
|
|
14
|
+
"react",
|
|
15
|
+
"vanilla",
|
|
16
|
+
"vue",
|
|
17
|
+
"svelte",
|
|
18
|
+
"next",
|
|
19
|
+
"novel",
|
|
20
|
+
"cafe",
|
|
21
|
+
"town",
|
|
22
|
+
"plugin"
|
|
23
|
+
];
|
|
24
|
+
/** The names of the React UI's theme presets, each a stylesheet at `@ifloom/react/themes/<name>.css`. */
|
|
25
|
+
const THEMES = [
|
|
26
|
+
"paper",
|
|
27
|
+
"terminal",
|
|
28
|
+
"studio",
|
|
29
|
+
"storybook"
|
|
30
|
+
];
|
|
31
|
+
const here = (path) => fileURLToPath(new URL(path, import.meta.url));
|
|
32
|
+
/**
|
|
33
|
+
* Where the templates and the example games are. In the CLI's package the
|
|
34
|
+
* templates are `templates/` beside `src/` and `dist/`, and the examples are in
|
|
35
|
+
* the IFLoom checkout. create-ifloom bundles this module into its `dist/`
|
|
36
|
+
* with copies of both beside it, so it looks there first.
|
|
37
|
+
*/
|
|
38
|
+
const TEMPLATE_DIR = [here("./templates"), here("../templates")].find((dir) => existsSync(dir)) ?? here("../templates");
|
|
39
|
+
const EXAMPLE_DIR = [here("./examples"), here("../../../examples")].find((dir) => existsSync(dir));
|
|
40
|
+
/** The IFLoom checkout this module is in, if it is: the root with `tsconfig.base.json`, which a game inside it extends. */
|
|
41
|
+
const CHECKOUT = [here("../../../")].find((dir) => existsSync(join(dir, "tsconfig.base.json")) && existsSync(join(dir, "packages/cli/package.json")));
|
|
42
|
+
/**
|
|
43
|
+
* The checkout's `tsconfig.base.json` without its `ifloom-source` condition: what a
|
|
44
|
+
* game outside the checkout gets in its `tsconfig.json` in place of `extends`.
|
|
45
|
+
* A test holds it to the file.
|
|
46
|
+
*/
|
|
47
|
+
const BASE_COMPILER_OPTIONS = {
|
|
48
|
+
target: "es2023",
|
|
49
|
+
lib: ["ES2023"],
|
|
50
|
+
module: "esnext",
|
|
51
|
+
moduleResolution: "bundler",
|
|
52
|
+
allowImportingTsExtensions: true,
|
|
53
|
+
verbatimModuleSyntax: true,
|
|
54
|
+
moduleDetection: "force",
|
|
55
|
+
erasableSyntaxOnly: true,
|
|
56
|
+
noEmit: true,
|
|
57
|
+
strict: true,
|
|
58
|
+
skipLibCheck: true,
|
|
59
|
+
noUnusedLocals: true,
|
|
60
|
+
noUnusedParameters: true,
|
|
61
|
+
noFallthroughCasesInSwitch: true
|
|
62
|
+
};
|
|
63
|
+
/** The files every template of our own takes from `templates/shared/`. */
|
|
64
|
+
const BASE = [
|
|
65
|
+
"AGENTS.md",
|
|
66
|
+
"gitignore",
|
|
67
|
+
"tsconfig.json",
|
|
68
|
+
"index.html"
|
|
69
|
+
];
|
|
70
|
+
/** The game itself, the same in every template: `game.ts` assembles the content in `world/` and `story/`. */
|
|
71
|
+
const GAME = [
|
|
72
|
+
"src/game.ts",
|
|
73
|
+
"src/world/stats.ts",
|
|
74
|
+
"src/story/opening.ts"
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* What the templates without React share: the game and the plain stylesheet. The clock for timers and minigames, and
|
|
78
|
+
* the keys, come from `@ifloom/browser`.
|
|
79
|
+
*/
|
|
80
|
+
const PLAIN = [
|
|
81
|
+
...BASE,
|
|
82
|
+
...GAME,
|
|
83
|
+
"src/styles.css"
|
|
84
|
+
];
|
|
85
|
+
/**
|
|
86
|
+
* Where each template's files come from, under the templates' folder or the examples'. Ours add the shared files; the
|
|
87
|
+
* examples bring their own.
|
|
88
|
+
*/
|
|
89
|
+
const SOURCES = {
|
|
90
|
+
react: {
|
|
91
|
+
dir: "react",
|
|
92
|
+
shared: [...BASE, ...GAME]
|
|
93
|
+
},
|
|
94
|
+
vanilla: {
|
|
95
|
+
dir: "vanilla",
|
|
96
|
+
shared: [...PLAIN, "vite.config.ts"]
|
|
97
|
+
},
|
|
98
|
+
vue: {
|
|
99
|
+
dir: "vue",
|
|
100
|
+
shared: PLAIN
|
|
101
|
+
},
|
|
102
|
+
svelte: {
|
|
103
|
+
dir: "svelte",
|
|
104
|
+
shared: PLAIN
|
|
105
|
+
},
|
|
106
|
+
next: {
|
|
107
|
+
dir: "next",
|
|
108
|
+
shared: GAME
|
|
109
|
+
},
|
|
110
|
+
novel: {
|
|
111
|
+
dir: "novel",
|
|
112
|
+
example: true,
|
|
113
|
+
shared: ["AGENTS.md", "gitignore"]
|
|
114
|
+
},
|
|
115
|
+
cafe: {
|
|
116
|
+
dir: "cafe",
|
|
117
|
+
example: true,
|
|
118
|
+
shared: ["AGENTS.md", "gitignore"]
|
|
119
|
+
},
|
|
120
|
+
town: {
|
|
121
|
+
dir: "showcase",
|
|
122
|
+
example: true,
|
|
123
|
+
shared: ["AGENTS.md", "gitignore"]
|
|
124
|
+
},
|
|
125
|
+
plugin: {
|
|
126
|
+
dir: "plugin",
|
|
127
|
+
shared: []
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/** What an example has that a new game should not: its build, its tests, its recorded runs. */
|
|
131
|
+
const LEFT_OUT = /* @__PURE__ */ new Set([
|
|
132
|
+
"node_modules",
|
|
133
|
+
"dist",
|
|
134
|
+
"dist-one",
|
|
135
|
+
"tests",
|
|
136
|
+
"snapshots",
|
|
137
|
+
"playtest",
|
|
138
|
+
"mods"
|
|
139
|
+
]);
|
|
140
|
+
/** What any template may have lying around that is never copied. */
|
|
141
|
+
const BUILT = /* @__PURE__ */ new Set(["node_modules", "dist"]);
|
|
142
|
+
/** The templates that draw the game without the React UI, and so take no theme. */
|
|
143
|
+
const NO_REACT = /* @__PURE__ */ new Set([
|
|
144
|
+
"vanilla",
|
|
145
|
+
"vue",
|
|
146
|
+
"svelte",
|
|
147
|
+
"plugin"
|
|
148
|
+
]);
|
|
149
|
+
const VALID_NAME = /^[a-z0-9][a-z0-9._~-]*$/;
|
|
150
|
+
/** `my-story` as a title: `My Story`. */
|
|
151
|
+
function titleOf(name) {
|
|
152
|
+
return name.split(/[-._~]+/).filter(Boolean).map((word) => word[0].toUpperCase() + word.slice(1)).join(" ");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The plugin template's names, from its package name: the plugin's id
|
|
156
|
+
* (`weather`), and that id as code names (`weather`, `Weather`, `WEATHER`) and
|
|
157
|
+
* a title. Its code holds `__id__`, `__camel__`, `__Pascal__` and
|
|
158
|
+
* `__CONSTANT__`, which TypeScript reads as names, so the template still parses.
|
|
159
|
+
*/
|
|
160
|
+
function pluginNames(name) {
|
|
161
|
+
const id = name.replace(/^(?:ifloom-)?plugin-/, "");
|
|
162
|
+
if (!/^[a-z][a-z0-9-]*$/.test(id)) throw new Error(`"${id}" can't be a plugin's id: start with a letter and use lower-case letters, digits and dashes, like ifloom-plugin-weather.`);
|
|
163
|
+
const words = id.split("-").filter(Boolean);
|
|
164
|
+
const camel = words[0] + words.slice(1).map((word) => word[0].toUpperCase() + word.slice(1)).join("");
|
|
165
|
+
return {
|
|
166
|
+
id,
|
|
167
|
+
camel,
|
|
168
|
+
Pascal: camel[0].toUpperCase() + camel.slice(1),
|
|
169
|
+
CONSTANT: words.join("_").toUpperCase(),
|
|
170
|
+
title: titleOf(id)
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** Every file under a folder, as paths relative to it. */
|
|
174
|
+
function filesUnder(dir, base = dir) {
|
|
175
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? filesUnder(join(dir, entry.name), base) : [relative(base, join(dir, entry.name))]);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* An example in the checkout leans on the workspace for React, its types and
|
|
179
|
+
* TypeScript. As a game of its own it lists them as the `react` template does,
|
|
180
|
+
* with the same versions, and gets the template's `typecheck` script.
|
|
181
|
+
*/
|
|
182
|
+
function withReactTemplate(pkg) {
|
|
183
|
+
const react = JSON.parse(readFileSync(join(TEMPLATE_DIR, "react/package.json"), "utf8"));
|
|
184
|
+
const sorted = (deps) => Object.fromEntries(Object.entries(deps).sort(([a], [b]) => a < b ? -1 : 1));
|
|
185
|
+
const missing = (field) => Object.fromEntries(Object.entries(react[field] ?? {}).filter(([dep]) => !dep.startsWith("@ifloom/") && !pkg[field]?.[dep]));
|
|
186
|
+
pkg.scripts = {
|
|
187
|
+
...pkg.scripts,
|
|
188
|
+
typecheck: pkg.scripts?.typecheck ?? react.scripts.typecheck
|
|
189
|
+
};
|
|
190
|
+
pkg.dependencies = sorted({
|
|
191
|
+
...pkg.dependencies,
|
|
192
|
+
...missing("dependencies")
|
|
193
|
+
});
|
|
194
|
+
pkg.devDependencies = sorted({
|
|
195
|
+
...pkg.devDependencies,
|
|
196
|
+
...missing("devDependencies")
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A template's tsconfig extends the checkout's `tsconfig.base.json`. Inside
|
|
201
|
+
* the checkout it keeps that, by the right path from the game's folder; anywhere
|
|
202
|
+
* else the settings are written out in full, without the checkout's condition.
|
|
203
|
+
*/
|
|
204
|
+
/** Whether a folder is inside the IFLoom checkout this module is in. */
|
|
205
|
+
function inCheckout(dir) {
|
|
206
|
+
return CHECKOUT !== void 0 && (resolve(dir) + sep).startsWith(resolve(CHECKOUT) + sep);
|
|
207
|
+
}
|
|
208
|
+
function standaloneTsconfig(dir) {
|
|
209
|
+
const path = join(dir, "tsconfig.json");
|
|
210
|
+
if (!existsSync(path)) return;
|
|
211
|
+
const tsconfig = JSON.parse(readFileSync(path, "utf8"));
|
|
212
|
+
if (tsconfig.extends !== "../../tsconfig.base.json") return;
|
|
213
|
+
if (CHECKOUT && inCheckout(dir)) tsconfig.extends = relative(dir, join(CHECKOUT, "tsconfig.base.json")).split(sep).join("/");
|
|
214
|
+
else {
|
|
215
|
+
delete tsconfig.extends;
|
|
216
|
+
tsconfig.compilerOptions = {
|
|
217
|
+
...BASE_COMPILER_OPTIONS,
|
|
218
|
+
...tsconfig.compilerOptions
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
writeFileSync(path, `${JSON.stringify(tsconfig, null, 2)}\n`);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Makes a new game from a template, and returns its folder, the files written there and the theme it chose. It installs
|
|
225
|
+
* nothing.
|
|
226
|
+
*
|
|
227
|
+
* It throws when the name can't be a package name, the template or theme doesn't exist, or the folder isn't empty.
|
|
228
|
+
*/
|
|
229
|
+
function newGame(options) {
|
|
230
|
+
const { name, template = "react" } = options;
|
|
231
|
+
if (!VALID_NAME.test(name) || name.length > 214) throw new Error(`"${name}" can't be a package name: use lower-case letters, digits and dashes, like my-story.`);
|
|
232
|
+
const source = SOURCES[template];
|
|
233
|
+
if (!source) throw new Error(`There is no template "${template}". Pick one of: ${TEMPLATES.join(", ")}.`);
|
|
234
|
+
if (options.theme && options.theme !== "none" && !THEMES.includes(options.theme)) throw new Error(`There is no theme "${options.theme}". Pick one of: ${THEMES.join(", ")}, or none.`);
|
|
235
|
+
const dir = resolve(options.into ?? (CHECKOUT ? join(CHECKOUT, "games", name) : name));
|
|
236
|
+
if (existsSync(dir) && readdirSync(dir).length > 0) throw new Error(`${dir} already exists and isn't empty.`);
|
|
237
|
+
const plugin = template === "plugin" ? pluginNames(name) : null;
|
|
238
|
+
const example = source.example === true;
|
|
239
|
+
if (example && !EXAMPLE_DIR) throw new Error(`The ${template} template copies an example from the IFLoom repository. Use npm create ifloom to start from it.`);
|
|
240
|
+
const from = join(example ? EXAMPLE_DIR : TEMPLATE_DIR, source.dir);
|
|
241
|
+
cpSync(from, dir, {
|
|
242
|
+
recursive: true,
|
|
243
|
+
filter: (path) => !(example ? LEFT_OUT : BUILT).has(relative(from, path).split(/[\\/]/)[0])
|
|
244
|
+
});
|
|
245
|
+
for (const file of source.shared) {
|
|
246
|
+
mkdirSync(dirname(join(dir, file)), { recursive: true });
|
|
247
|
+
cpSync(join(TEMPLATE_DIR, "shared", file), join(dir, file === "gitignore" ? ".gitignore" : file));
|
|
248
|
+
}
|
|
249
|
+
if (existsSync(join(dir, "gitignore"))) renameSync(join(dir, "gitignore"), join(dir, ".gitignore"));
|
|
250
|
+
if (plugin) renameSync(join(dir, "tests/plugin.test.ts"), join(dir, `tests/${plugin.id}.test.ts`));
|
|
251
|
+
const title = plugin?.title ?? titleOf(name);
|
|
252
|
+
const files = filesUnder(dir);
|
|
253
|
+
for (const file of files.filter((path) => /\.(ts|tsx|json|html|md|css)$/.test(path))) {
|
|
254
|
+
const path = join(dir, file);
|
|
255
|
+
const text = readFileSync(path, "utf8");
|
|
256
|
+
let filled = text.replaceAll("{{name}}", name).replaceAll("{{title}}", title);
|
|
257
|
+
if (plugin) filled = filled.replaceAll("__id__", plugin.id).replaceAll("__camel__", plugin.camel).replaceAll("__Pascal__", plugin.Pascal).replaceAll("__CONSTANT__", plugin.CONSTANT);
|
|
258
|
+
if (filled !== text) writeFileSync(path, filled);
|
|
259
|
+
}
|
|
260
|
+
const pkgPath = join(dir, "package.json");
|
|
261
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
262
|
+
pkg.name = name;
|
|
263
|
+
if (example) {
|
|
264
|
+
delete pkg.description;
|
|
265
|
+
delete pkg.license;
|
|
266
|
+
withReactTemplate(pkg);
|
|
267
|
+
}
|
|
268
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
269
|
+
standaloneTsconfig(dir);
|
|
270
|
+
const styles = join(dir, "src/styles.css");
|
|
271
|
+
let theme = null;
|
|
272
|
+
if (!NO_REACT.has(template) && existsSync(styles)) {
|
|
273
|
+
const css = readFileSync(styles, "utf8");
|
|
274
|
+
const chosen = options.theme ?? (template === "react" || template === "next" ? THEMES[Math.floor(Math.random() * THEMES.length)] : void 0);
|
|
275
|
+
if (chosen === "none") writeFileSync(styles, css.replace(/@import "@ifloom\/react\/themes\/[\w-]+\.css";\n?/, ""));
|
|
276
|
+
else if (chosen) {
|
|
277
|
+
const line = `@import "@ifloom/react/themes/${chosen}.css";`;
|
|
278
|
+
const withTheme = /@import "@ifloom\/react\/themes\/[\w-]+\.css";/.test(css) ? css.replace(/@import "@ifloom\/react\/themes\/[\w-]+\.css";/, line) : css.replace("@import \"@ifloom/react/styles.css\";", `@import "@ifloom/react/styles.css";\n${line}`);
|
|
279
|
+
writeFileSync(styles, withTheme);
|
|
280
|
+
theme = chosen;
|
|
281
|
+
} else theme = css.match(/@ifloom\/react\/themes\/([\w-]+)\.css/)?.[1] ?? null;
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
dir,
|
|
285
|
+
files,
|
|
286
|
+
theme
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/create.ts
|
|
291
|
+
/**
|
|
292
|
+
* create-ifloom: what `npm create ifloom@latest my-game` runs. It makes a new
|
|
293
|
+
* game in the folder `my-game` with the CLI's `newGame`, the same as `ifloom
|
|
294
|
+
* new`, with the same `--template` and `--theme`, and says what to run next
|
|
295
|
+
* with the package manager that ran it. It installs nothing.
|
|
296
|
+
*/
|
|
297
|
+
const USAGE = `npm create ifloom@latest <name> -- [--template ${TEMPLATES.join("|")}] [--theme ${THEMES.join("|")}|none]`;
|
|
298
|
+
/** The arguments after the command: a name, and `--template` and `--theme` with a value each, as `--template vue` or `--template=vue`. */
|
|
299
|
+
function parseArgs(argv) {
|
|
300
|
+
const args = { help: false };
|
|
301
|
+
for (let at = 0; at < argv.length; at++) {
|
|
302
|
+
const arg = argv[at];
|
|
303
|
+
if (arg === "--help" || arg === "-h") args.help = true;
|
|
304
|
+
else if (arg.startsWith("--")) {
|
|
305
|
+
const [flag, inline] = arg.slice(2).split(/=(.*)/s);
|
|
306
|
+
if (flag !== "template" && flag !== "theme") return { error: `There is no option --${flag}. ${USAGE}` };
|
|
307
|
+
const value = inline ?? argv[++at];
|
|
308
|
+
if (!value || value.startsWith("--")) return { error: `--${flag} needs a value. ${USAGE}` };
|
|
309
|
+
args[flag] = value;
|
|
310
|
+
} else if (args.name === void 0) args.name = arg;
|
|
311
|
+
else return { error: `One name only: "${args.name}" or "${arg}". ${USAGE}` };
|
|
312
|
+
}
|
|
313
|
+
return args;
|
|
314
|
+
}
|
|
315
|
+
/** The package manager that ran the command, from the `npm_config_user_agent` each of them sets, such as `pnpm/10.4.1 npm/? node/v24.1.0 linux x64`. npm if it's none of them. */
|
|
316
|
+
function packageManager(userAgent) {
|
|
317
|
+
const [name, version = ""] = (userAgent ?? "").split(" ")[0].split("/");
|
|
318
|
+
const major = Number.parseInt(version, 10) || 0;
|
|
319
|
+
return name === "pnpm" || name === "yarn" || name === "bun" ? {
|
|
320
|
+
name,
|
|
321
|
+
major
|
|
322
|
+
} : {
|
|
323
|
+
name: "npm",
|
|
324
|
+
major
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
/** What to type next: into the folder, install, then play the game (or test the plugin). */
|
|
328
|
+
function nextSteps(pm, folder, template) {
|
|
329
|
+
const run = (script) => pm === "npm" ? `npm run ${script}` : pm === "pnpm" ? `pnpm ${script}` : `${pm} run ${script}`;
|
|
330
|
+
return [
|
|
331
|
+
...folder === "." ? [] : [`cd ${folder}`],
|
|
332
|
+
`${pm} install`,
|
|
333
|
+
template === "plugin" ? pm === "npm" ? "npm test" : run("test") : run("dev")
|
|
334
|
+
];
|
|
335
|
+
}
|
|
336
|
+
/** Make the game, and print what was made and what to type next. Returns the exit code. */
|
|
337
|
+
function create(argv, io) {
|
|
338
|
+
const args = parseArgs(argv);
|
|
339
|
+
if ("error" in args) {
|
|
340
|
+
io.error(args.error);
|
|
341
|
+
return 1;
|
|
342
|
+
}
|
|
343
|
+
if (args.help) {
|
|
344
|
+
io.log(USAGE);
|
|
345
|
+
return 0;
|
|
346
|
+
}
|
|
347
|
+
if (!args.name) {
|
|
348
|
+
io.error(`Give the new game a name: ${USAGE}`);
|
|
349
|
+
return 1;
|
|
350
|
+
}
|
|
351
|
+
const pm = packageManager(io.userAgent);
|
|
352
|
+
const template = args.template ?? "react";
|
|
353
|
+
try {
|
|
354
|
+
const made = newGame({
|
|
355
|
+
name: args.name,
|
|
356
|
+
template,
|
|
357
|
+
theme: args.theme,
|
|
358
|
+
into: resolve(io.cwd, args.name)
|
|
359
|
+
});
|
|
360
|
+
if (pm.name === "yarn" && pm.major >= 2) writeFileSync(join(made.dir, ".yarnrc.yml"), "nodeLinker: node-modules\n");
|
|
361
|
+
const look = made.theme ? `, with the ${made.theme} theme` : args.theme === "none" ? ", with no theme preset" : "";
|
|
362
|
+
io.log(`Made ${args.name} from the ${template} template${look}. Next:\n`);
|
|
363
|
+
for (const line of nextSteps(pm.name, relative(io.cwd, made.dir) || ".", template)) io.log(` ${line}`);
|
|
364
|
+
io.log(template === "plugin" ? "\nWriting a plugin: https://ifloom.dev/docs/how-to/write-a-plugin" : "\nYour first story: https://ifloom.dev/docs/tutorial/story/start-a-story");
|
|
365
|
+
return 0;
|
|
366
|
+
} catch (error) {
|
|
367
|
+
io.error(error.message);
|
|
368
|
+
return 1;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/bin.ts
|
|
373
|
+
/**
|
|
374
|
+
* create-ifloom — a new IFLoom game, for `npm create ifloom`:
|
|
375
|
+
*
|
|
376
|
+
* npm create ifloom@latest my-game
|
|
377
|
+
* npm create ifloom@latest my-game -- --template vue
|
|
378
|
+
* pnpm create ifloom my-game --theme paper
|
|
379
|
+
*
|
|
380
|
+
* Makes the game in ./my-game and prints what to run next. See create.ts.
|
|
381
|
+
*/
|
|
382
|
+
process.exitCode = create(process.argv.slice(2), {
|
|
383
|
+
cwd: process.cwd(),
|
|
384
|
+
userAgent: process.env.npm_config_user_agent,
|
|
385
|
+
log: (line) => console.log(line),
|
|
386
|
+
error: (line) => console.error(line)
|
|
387
|
+
});
|
|
388
|
+
//#endregion
|
|
389
|
+
export {};
|
|
390
|
+
|
|
391
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../../cli/dist/new.js","../src/create.ts","../src/bin.ts"],"sourcesContent":["import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, resolve, sep } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n//#region src/new.ts\n/**\n* `ifloom new`: a new game from a template, ready to run. The `react`,\n* `vanilla`, `vue`, `svelte` and `next` templates live beside this file; the others are the example games, copied from the\n* checkout so there is only one of each to keep working. The `plugin` template\n* is not a game: it's a plugin package of its own, with a test, to publish on npm.\n*/\n/** The templates `ifloom new` can start a game from. `novel`, `cafe` and `town` copy the examples, and `plugin` makes a plugin package. */\nconst TEMPLATES = [\n\t\"react\",\n\t\"vanilla\",\n\t\"vue\",\n\t\"svelte\",\n\t\"next\",\n\t\"novel\",\n\t\"cafe\",\n\t\"town\",\n\t\"plugin\"\n];\n/** The names of the React UI's theme presets, each a stylesheet at `@ifloom/react/themes/<name>.css`. */\nconst THEMES = [\n\t\"paper\",\n\t\"terminal\",\n\t\"studio\",\n\t\"storybook\"\n];\nconst here = (path) => fileURLToPath(new URL(path, import.meta.url));\n/**\n* Where the templates and the example games are. In the CLI's package the\n* templates are `templates/` beside `src/` and `dist/`, and the examples are in\n* the IFLoom checkout. create-ifloom bundles this module into its `dist/`\n* with copies of both beside it, so it looks there first.\n*/\nconst TEMPLATE_DIR = [here(\"./templates\"), here(\"../templates\")].find((dir) => existsSync(dir)) ?? here(\"../templates\");\nconst EXAMPLE_DIR = [here(\"./examples\"), here(\"../../../examples\")].find((dir) => existsSync(dir));\n/** The IFLoom checkout this module is in, if it is: the root with `tsconfig.base.json`, which a game inside it extends. */\nconst CHECKOUT = [here(\"../../../\")].find((dir) => existsSync(join(dir, \"tsconfig.base.json\")) && existsSync(join(dir, \"packages/cli/package.json\")));\n/**\n* The checkout's `tsconfig.base.json` without its `ifloom-source` condition: what a\n* game outside the checkout gets in its `tsconfig.json` in place of `extends`.\n* A test holds it to the file.\n*/\nconst BASE_COMPILER_OPTIONS = {\n\ttarget: \"es2023\",\n\tlib: [\"ES2023\"],\n\tmodule: \"esnext\",\n\tmoduleResolution: \"bundler\",\n\tallowImportingTsExtensions: true,\n\tverbatimModuleSyntax: true,\n\tmoduleDetection: \"force\",\n\terasableSyntaxOnly: true,\n\tnoEmit: true,\n\tstrict: true,\n\tskipLibCheck: true,\n\tnoUnusedLocals: true,\n\tnoUnusedParameters: true,\n\tnoFallthroughCasesInSwitch: true\n};\n/** The files every template of our own takes from `templates/shared/`. */\nconst BASE = [\n\t\"AGENTS.md\",\n\t\"gitignore\",\n\t\"tsconfig.json\",\n\t\"index.html\"\n];\n/** The game itself, the same in every template: `game.ts` assembles the content in `world/` and `story/`. */\nconst GAME = [\n\t\"src/game.ts\",\n\t\"src/world/stats.ts\",\n\t\"src/story/opening.ts\"\n];\n/**\n* What the templates without React share: the game and the plain stylesheet. The clock for timers and minigames, and\n* the keys, come from `@ifloom/browser`.\n*/\nconst PLAIN = [\n\t...BASE,\n\t...GAME,\n\t\"src/styles.css\"\n];\n/**\n* Where each template's files come from, under the templates' folder or the examples'. Ours add the shared files; the\n* examples bring their own.\n*/\nconst SOURCES = {\n\treact: {\n\t\tdir: \"react\",\n\t\tshared: [...BASE, ...GAME]\n\t},\n\tvanilla: {\n\t\tdir: \"vanilla\",\n\t\tshared: [...PLAIN, \"vite.config.ts\"]\n\t},\n\tvue: {\n\t\tdir: \"vue\",\n\t\tshared: PLAIN\n\t},\n\tsvelte: {\n\t\tdir: \"svelte\",\n\t\tshared: PLAIN\n\t},\n\tnext: {\n\t\tdir: \"next\",\n\t\tshared: GAME\n\t},\n\tnovel: {\n\t\tdir: \"novel\",\n\t\texample: true,\n\t\tshared: [\"AGENTS.md\", \"gitignore\"]\n\t},\n\tcafe: {\n\t\tdir: \"cafe\",\n\t\texample: true,\n\t\tshared: [\"AGENTS.md\", \"gitignore\"]\n\t},\n\ttown: {\n\t\tdir: \"showcase\",\n\t\texample: true,\n\t\tshared: [\"AGENTS.md\", \"gitignore\"]\n\t},\n\tplugin: {\n\t\tdir: \"plugin\",\n\t\tshared: []\n\t}\n};\n/** What an example has that a new game should not: its build, its tests, its recorded runs. */\nconst LEFT_OUT = /* @__PURE__ */ new Set([\n\t\"node_modules\",\n\t\"dist\",\n\t\"dist-one\",\n\t\"tests\",\n\t\"snapshots\",\n\t\"playtest\",\n\t\"mods\"\n]);\n/** What any template may have lying around that is never copied. */\nconst BUILT = /* @__PURE__ */ new Set([\"node_modules\", \"dist\"]);\n/** The templates that draw the game without the React UI, and so take no theme. */\nconst NO_REACT = /* @__PURE__ */ new Set([\n\t\"vanilla\",\n\t\"vue\",\n\t\"svelte\",\n\t\"plugin\"\n]);\nconst VALID_NAME = /^[a-z0-9][a-z0-9._~-]*$/;\n/** `my-story` as a title: `My Story`. */\nfunction titleOf(name) {\n\treturn name.split(/[-._~]+/).filter(Boolean).map((word) => word[0].toUpperCase() + word.slice(1)).join(\" \");\n}\n/**\n* The plugin template's names, from its package name: the plugin's id\n* (`weather`), and that id as code names (`weather`, `Weather`, `WEATHER`) and\n* a title. Its code holds `__id__`, `__camel__`, `__Pascal__` and\n* `__CONSTANT__`, which TypeScript reads as names, so the template still parses.\n*/\nfunction pluginNames(name) {\n\tconst id = name.replace(/^(?:ifloom-)?plugin-/, \"\");\n\tif (!/^[a-z][a-z0-9-]*$/.test(id)) throw new Error(`\"${id}\" can't be a plugin's id: start with a letter and use lower-case letters, digits and dashes, like ifloom-plugin-weather.`);\n\tconst words = id.split(\"-\").filter(Boolean);\n\tconst camel = words[0] + words.slice(1).map((word) => word[0].toUpperCase() + word.slice(1)).join(\"\");\n\treturn {\n\t\tid,\n\t\tcamel,\n\t\tPascal: camel[0].toUpperCase() + camel.slice(1),\n\t\tCONSTANT: words.join(\"_\").toUpperCase(),\n\t\ttitle: titleOf(id)\n\t};\n}\n/** Every file under a folder, as paths relative to it. */\nfunction filesUnder(dir, base = dir) {\n\treturn readdirSync(dir, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? filesUnder(join(dir, entry.name), base) : [relative(base, join(dir, entry.name))]);\n}\n/**\n* An example in the checkout leans on the workspace for React, its types and\n* TypeScript. As a game of its own it lists them as the `react` template does,\n* with the same versions, and gets the template's `typecheck` script.\n*/\nfunction withReactTemplate(pkg) {\n\tconst react = JSON.parse(readFileSync(join(TEMPLATE_DIR, \"react/package.json\"), \"utf8\"));\n\tconst sorted = (deps) => Object.fromEntries(Object.entries(deps).sort(([a], [b]) => a < b ? -1 : 1));\n\tconst missing = (field) => Object.fromEntries(Object.entries(react[field] ?? {}).filter(([dep]) => !dep.startsWith(\"@ifloom/\") && !pkg[field]?.[dep]));\n\tpkg.scripts = {\n\t\t...pkg.scripts,\n\t\ttypecheck: pkg.scripts?.typecheck ?? react.scripts.typecheck\n\t};\n\tpkg.dependencies = sorted({\n\t\t...pkg.dependencies,\n\t\t...missing(\"dependencies\")\n\t});\n\tpkg.devDependencies = sorted({\n\t\t...pkg.devDependencies,\n\t\t...missing(\"devDependencies\")\n\t});\n}\n/**\n* A template's tsconfig extends the checkout's `tsconfig.base.json`. Inside\n* the checkout it keeps that, by the right path from the game's folder; anywhere\n* else the settings are written out in full, without the checkout's condition.\n*/\n/** Whether a folder is inside the IFLoom checkout this module is in. */\nfunction inCheckout(dir) {\n\treturn CHECKOUT !== void 0 && (resolve(dir) + sep).startsWith(resolve(CHECKOUT) + sep);\n}\nfunction standaloneTsconfig(dir) {\n\tconst path = join(dir, \"tsconfig.json\");\n\tif (!existsSync(path)) return;\n\tconst tsconfig = JSON.parse(readFileSync(path, \"utf8\"));\n\tif (tsconfig.extends !== \"../../tsconfig.base.json\") return;\n\tif (CHECKOUT && inCheckout(dir)) tsconfig.extends = relative(dir, join(CHECKOUT, \"tsconfig.base.json\")).split(sep).join(\"/\");\n\telse {\n\t\tdelete tsconfig.extends;\n\t\ttsconfig.compilerOptions = {\n\t\t\t...BASE_COMPILER_OPTIONS,\n\t\t\t...tsconfig.compilerOptions\n\t\t};\n\t}\n\twriteFileSync(path, `${JSON.stringify(tsconfig, null, 2)}\\n`);\n}\n/**\n* Makes a new game from a template, and returns its folder, the files written there and the theme it chose. It installs\n* nothing.\n*\n* It throws when the name can't be a package name, the template or theme doesn't exist, or the folder isn't empty.\n*/\nfunction newGame(options) {\n\tconst { name, template = \"react\" } = options;\n\tif (!VALID_NAME.test(name) || name.length > 214) throw new Error(`\"${name}\" can't be a package name: use lower-case letters, digits and dashes, like my-story.`);\n\tconst source = SOURCES[template];\n\tif (!source) throw new Error(`There is no template \"${template}\". Pick one of: ${TEMPLATES.join(\", \")}.`);\n\tif (options.theme && options.theme !== \"none\" && !THEMES.includes(options.theme)) throw new Error(`There is no theme \"${options.theme}\". Pick one of: ${THEMES.join(\", \")}, or none.`);\n\tconst dir = resolve(options.into ?? (CHECKOUT ? join(CHECKOUT, \"games\", name) : name));\n\tif (existsSync(dir) && readdirSync(dir).length > 0) throw new Error(`${dir} already exists and isn't empty.`);\n\tconst plugin = template === \"plugin\" ? pluginNames(name) : null;\n\tconst example = source.example === true;\n\tif (example && !EXAMPLE_DIR) throw new Error(`The ${template} template copies an example from the IFLoom repository. Use npm create ifloom to start from it.`);\n\tconst from = join(example ? EXAMPLE_DIR : TEMPLATE_DIR, source.dir);\n\tcpSync(from, dir, {\n\t\trecursive: true,\n\t\tfilter: (path) => !(example ? LEFT_OUT : BUILT).has(relative(from, path).split(/[\\\\/]/)[0])\n\t});\n\tfor (const file of source.shared) {\n\t\tmkdirSync(dirname(join(dir, file)), { recursive: true });\n\t\tcpSync(join(TEMPLATE_DIR, \"shared\", file), join(dir, file === \"gitignore\" ? \".gitignore\" : file));\n\t}\n\tif (existsSync(join(dir, \"gitignore\"))) renameSync(join(dir, \"gitignore\"), join(dir, \".gitignore\"));\n\tif (plugin) renameSync(join(dir, \"tests/plugin.test.ts\"), join(dir, `tests/${plugin.id}.test.ts`));\n\tconst title = plugin?.title ?? titleOf(name);\n\tconst files = filesUnder(dir);\n\tfor (const file of files.filter((path) => /\\.(ts|tsx|json|html|md|css)$/.test(path))) {\n\t\tconst path = join(dir, file);\n\t\tconst text = readFileSync(path, \"utf8\");\n\t\tlet filled = text.replaceAll(\"{{name}}\", name).replaceAll(\"{{title}}\", title);\n\t\tif (plugin) filled = filled.replaceAll(\"__id__\", plugin.id).replaceAll(\"__camel__\", plugin.camel).replaceAll(\"__Pascal__\", plugin.Pascal).replaceAll(\"__CONSTANT__\", plugin.CONSTANT);\n\t\tif (filled !== text) writeFileSync(path, filled);\n\t}\n\tconst pkgPath = join(dir, \"package.json\");\n\tconst pkg = JSON.parse(readFileSync(pkgPath, \"utf8\"));\n\tpkg.name = name;\n\tif (example) {\n\t\tdelete pkg.description;\n\t\tdelete pkg.license;\n\t\twithReactTemplate(pkg);\n\t}\n\twriteFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`);\n\tstandaloneTsconfig(dir);\n\tconst styles = join(dir, \"src/styles.css\");\n\tlet theme = null;\n\tif (!NO_REACT.has(template) && existsSync(styles)) {\n\t\tconst css = readFileSync(styles, \"utf8\");\n\t\tconst chosen = options.theme ?? (template === \"react\" || template === \"next\" ? THEMES[Math.floor(Math.random() * THEMES.length)] : void 0);\n\t\tif (chosen === \"none\") writeFileSync(styles, css.replace(/@import \"@ifloom\\/react\\/themes\\/[\\w-]+\\.css\";\\n?/, \"\"));\n\t\telse if (chosen) {\n\t\t\tconst line = `@import \"@ifloom/react/themes/${chosen}.css\";`;\n\t\t\tconst withTheme = /@import \"@ifloom\\/react\\/themes\\/[\\w-]+\\.css\";/.test(css) ? css.replace(/@import \"@ifloom\\/react\\/themes\\/[\\w-]+\\.css\";/, line) : css.replace(\"@import \\\"@ifloom/react/styles.css\\\";\", `@import \"@ifloom/react/styles.css\";\\n${line}`);\n\t\t\twriteFileSync(styles, withTheme);\n\t\t\ttheme = chosen;\n\t\t} else theme = css.match(/@ifloom\\/react\\/themes\\/([\\w-]+)\\.css/)?.[1] ?? null;\n\t}\n\treturn {\n\t\tdir,\n\t\tfiles,\n\t\ttheme\n\t};\n}\n//#endregion\nexport { BASE_COMPILER_OPTIONS, TEMPLATES, THEMES, inCheckout, newGame, pluginNames };\n\n//# sourceMappingURL=new.js.map","/**\n * create-ifloom: what `npm create ifloom@latest my-game` runs. It makes a new\n * game in the folder `my-game` with the CLI's `newGame`, the same as `ifloom\n * new`, with the same `--template` and `--theme`, and says what to run next\n * with the package manager that ran it. It installs nothing.\n */\nimport { writeFileSync } from 'node:fs'\nimport { join, relative, resolve } from 'node:path'\nimport { TEMPLATES, THEMES, newGame, type TemplateName, type ThemeName } from '@ifloom/cli'\n\nexport const USAGE = `npm create ifloom@latest <name> -- [--template ${TEMPLATES.join('|')}] [--theme ${THEMES.join('|')}|none]`\n\nexport type Args = { name?: string; template?: string; theme?: string; help: boolean }\n\n/** The arguments after the command: a name, and `--template` and `--theme` with a value each, as `--template vue` or `--template=vue`. */\nexport function parseArgs(argv: string[]): Args | { error: string } {\n const args: Args = { help: false }\n for (let at = 0; at < argv.length; at++) {\n const arg = argv[at]\n if (arg === '--help' || arg === '-h') {\n args.help = true\n } else if (arg.startsWith('--')) {\n const [flag, inline] = arg.slice(2).split(/=(.*)/s)\n if (flag !== 'template' && flag !== 'theme') return { error: `There is no option --${flag}. ${USAGE}` }\n const value = inline ?? argv[++at]\n if (!value || value.startsWith('--')) return { error: `--${flag} needs a value. ${USAGE}` }\n args[flag] = value\n } else if (args.name === undefined) {\n args.name = arg\n } else {\n return { error: `One name only: \"${args.name}\" or \"${arg}\". ${USAGE}` }\n }\n }\n return args\n}\n\nexport type PackageManager = { name: 'npm' | 'pnpm' | 'yarn' | 'bun'; major: number }\n\n/** The package manager that ran the command, from the `npm_config_user_agent` each of them sets, such as `pnpm/10.4.1 npm/? node/v24.1.0 linux x64`. npm if it's none of them. */\nexport function packageManager(userAgent: string | undefined): PackageManager {\n const [name, version = ''] = (userAgent ?? '').split(' ')[0].split('/')\n const major = Number.parseInt(version, 10) || 0\n return name === 'pnpm' || name === 'yarn' || name === 'bun' ? { name, major } : { name: 'npm', major }\n}\n\n/** What to type next: into the folder, install, then play the game (or test the plugin). */\nexport function nextSteps(pm: PackageManager['name'], folder: string, template: TemplateName): string[] {\n // `yarn check` and `bun test` are those tools' own commands, so a script always goes through `run` there.\n const run = (script: string) => (pm === 'npm' ? `npm run ${script}` : pm === 'pnpm' ? `pnpm ${script}` : `${pm} run ${script}`)\n return [...(folder === '.' ? [] : [`cd ${folder}`]), `${pm} install`, template === 'plugin' ? (pm === 'npm' ? 'npm test' : run('test')) : run('dev')]\n}\n\nexport type Io = { cwd: string; userAgent: string | undefined; log: (line: string) => void; error: (line: string) => void }\n\n/** Make the game, and print what was made and what to type next. Returns the exit code. */\nexport function create(argv: string[], io: Io): number {\n const args = parseArgs(argv)\n if ('error' in args) {\n io.error(args.error)\n return 1\n }\n if (args.help) {\n io.log(USAGE)\n return 0\n }\n if (!args.name) {\n io.error(`Give the new game a name: ${USAGE}`)\n return 1\n }\n const pm = packageManager(io.userAgent)\n const template = (args.template ?? 'react') as TemplateName\n try {\n const made = newGame({ name: args.name, template, theme: args.theme as ThemeName | 'none' | undefined, into: resolve(io.cwd, args.name) })\n // Yarn 2 and later install with Plug'n'Play unless told otherwise, and Vite needs a node_modules folder.\n if (pm.name === 'yarn' && pm.major >= 2) writeFileSync(join(made.dir, '.yarnrc.yml'), 'nodeLinker: node-modules\\n')\n const look = made.theme ? `, with the ${made.theme} theme` : args.theme === 'none' ? ', with no theme preset' : ''\n io.log(`Made ${args.name} from the ${template} template${look}. Next:\\n`)\n for (const line of nextSteps(pm.name, relative(io.cwd, made.dir) || '.', template)) io.log(` ${line}`)\n io.log(\n template === 'plugin'\n ? '\\nWriting a plugin: https://ifloom.dev/docs/how-to/write-a-plugin'\n : '\\nYour first story: https://ifloom.dev/docs/tutorial/story/start-a-story',\n )\n return 0\n } catch (error) {\n io.error((error as Error).message)\n return 1\n }\n}\n","#!/usr/bin/env node\n/**\n * create-ifloom — a new IFLoom game, for `npm create ifloom`:\n *\n * npm create ifloom@latest my-game\n * npm create ifloom@latest my-game -- --template vue\n * pnpm create ifloom my-game --theme paper\n *\n * Makes the game in ./my-game and prints what to run next. See create.ts.\n */\nimport { create } from './create.ts'\n\nprocess.exitCode = create(process.argv.slice(2), {\n cwd: process.cwd(),\n userAgent: process.env.npm_config_user_agent,\n log: (line) => console.log(line),\n error: (line) => console.error(line),\n})\n"],"mappings":";;;;;;;;;;;;AAWA,MAAM,YAAY;CACjB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAEA,MAAM,SAAS;CACd;CACA;CACA;CACA;AACD;AACA,MAAM,QAAQ,SAAS,cAAc,IAAI,IAAI,MAAM,YAAY,GAAG,CAAC;;;;;;;AAOnE,MAAM,eAAe,CAAC,KAAK,aAAa,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC,MAAM,QAAQ,WAAW,GAAG,CAAC,KAAK,KAAK,cAAc;AACtH,MAAM,cAAc,CAAC,KAAK,YAAY,GAAG,KAAK,mBAAmB,CAAC,CAAC,CAAC,MAAM,QAAQ,WAAW,GAAG,CAAC;;AAEjG,MAAM,WAAW,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,QAAQ,WAAW,KAAK,KAAK,oBAAoB,CAAC,KAAK,WAAW,KAAK,KAAK,2BAA2B,CAAC,CAAC;;;;;;AAMpJ,MAAM,wBAAwB;CAC7B,QAAQ;CACR,KAAK,CAAC,QAAQ;CACd,QAAQ;CACR,kBAAkB;CAClB,4BAA4B;CAC5B,sBAAsB;CACtB,iBAAiB;CACjB,oBAAoB;CACpB,QAAQ;CACR,QAAQ;CACR,cAAc;CACd,gBAAgB;CAChB,oBAAoB;CACpB,4BAA4B;AAC7B;;AAEA,MAAM,OAAO;CACZ;CACA;CACA;CACA;AACD;;AAEA,MAAM,OAAO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
6
|
+
<title>The Corner Café</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="./src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ifloom/example-cafe",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "A small management game on IFLoom: a café run a week at a time, with staff and dishes that each keep their own numbers.",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "ifloom dev",
|
|
10
|
+
"build": "ifloom build",
|
|
11
|
+
"check": "ifloom check",
|
|
12
|
+
"playtest": "ifloom playtest --turns 8 --out playtest/season.txt"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@ifloom/engine": "^0.1.0",
|
|
16
|
+
"@ifloom/react": "^0.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@ifloom/cli": "^0.1.0",
|
|
20
|
+
"@tailwindcss/vite": "4.3.3",
|
|
21
|
+
"@vitejs/plugin-react": "6.1.1",
|
|
22
|
+
"tailwindcss": "4.3.3"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Corner Café: a management game, a week at a time.
|
|
3
|
+
*
|
|
4
|
+
* The shape this shows is the one a management game needs: things the game
|
|
5
|
+
* keeps several of (staff, dishes), each with numbers of its own; people
|
|
6
|
+
* hired and leaving in play; upkeep that runs over all of them each week; and
|
|
7
|
+
* triggers that watch counts. A turn is a week, ended by a button. No places,
|
|
8
|
+
* no characters, no clock: the café is the whole world.
|
|
9
|
+
*
|
|
10
|
+
* A game like this is mostly data, so most of it is in `world/`, a file per
|
|
11
|
+
* kind (stats, staff, the menu, actions, triggers), with its two scenes in
|
|
12
|
+
* `story/` and its sums in `rules.ts`. This file only puts it together.
|
|
13
|
+
*/
|
|
14
|
+
import { loadGame, type Content, type Loaded } from '@ifloom/engine'
|
|
15
|
+
import { defineGame, probe } from '@ifloom/cli/game'
|
|
16
|
+
import { rules } from './rules.ts'
|
|
17
|
+
import { stats } from './world/stats.ts'
|
|
18
|
+
import { staff } from './world/staff.ts'
|
|
19
|
+
import { menu } from './world/menu.ts'
|
|
20
|
+
import { actions } from './world/actions.ts'
|
|
21
|
+
import { triggers } from './world/triggers.ts'
|
|
22
|
+
import { opening } from './story/opening.ts'
|
|
23
|
+
import { hiring } from './story/hiring.ts'
|
|
24
|
+
|
|
25
|
+
/** The game's content: the world, by kind, then the story. */
|
|
26
|
+
export const content: Content[] = [stats, staff, menu, actions, triggers, opening, hiring]
|
|
27
|
+
|
|
28
|
+
/** The game: its content, with a base that has its own sums. */
|
|
29
|
+
export function cornerCafe(): Loaded {
|
|
30
|
+
return loadGame(content, {
|
|
31
|
+
id: 'corner-cafe',
|
|
32
|
+
title: 'The Corner Café',
|
|
33
|
+
rules,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** What the command line reads: the game, and where `ifloom playtest` and `ifloom snapshot` start, the opening scene closed and the doors open. */
|
|
38
|
+
export default defineGame({
|
|
39
|
+
build: cornerCafe,
|
|
40
|
+
start: (game) => probe('open', game, [{ scene: null }]).state,
|
|
41
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Clock,
|
|
3
|
+
EntityTable,
|
|
4
|
+
Game,
|
|
5
|
+
GameMenu,
|
|
6
|
+
InputFields,
|
|
7
|
+
Notices,
|
|
8
|
+
Overlay,
|
|
9
|
+
PanelHost,
|
|
10
|
+
RoomActions,
|
|
11
|
+
Scene,
|
|
12
|
+
Section,
|
|
13
|
+
Sidebar,
|
|
14
|
+
StatList,
|
|
15
|
+
Story,
|
|
16
|
+
Title,
|
|
17
|
+
useWords,
|
|
18
|
+
} from '@ifloom/react'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The café's layout: the books in the story, where the eye goes. The staff
|
|
22
|
+
* and the menu (`EntityTable`) sit over the week's buttons; the side column
|
|
23
|
+
* keeps the title, the week, the menu and the takings.
|
|
24
|
+
*/
|
|
25
|
+
export function Layout() {
|
|
26
|
+
const words = useWords()
|
|
27
|
+
return (
|
|
28
|
+
<Game>
|
|
29
|
+
<Sidebar>
|
|
30
|
+
<Title />
|
|
31
|
+
<Clock />
|
|
32
|
+
<GameMenu />
|
|
33
|
+
<Section id="stats" title={words('stats')} collapsible open>
|
|
34
|
+
<StatList />
|
|
35
|
+
</Section>
|
|
36
|
+
</Sidebar>
|
|
37
|
+
<Story>
|
|
38
|
+
<Scene />
|
|
39
|
+
<EntityTable />
|
|
40
|
+
<RoomActions />
|
|
41
|
+
<InputFields />
|
|
42
|
+
</Story>
|
|
43
|
+
<PanelHost />
|
|
44
|
+
<Overlay>
|
|
45
|
+
<Notices />
|
|
46
|
+
</Overlay>
|
|
47
|
+
</Game>
|
|
48
|
+
)
|
|
49
|
+
}
|