@flare-engine/create 0.4.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.
Files changed (55) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +43 -0
  4. package/dist/bin.js +10 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/bin.mjs +12 -0
  7. package/dist/bin.mjs.map +1 -0
  8. package/dist/cli-BGXZ73ie.mjs +189 -0
  9. package/dist/cli-BGXZ73ie.mjs.map +1 -0
  10. package/dist/cli-JzwtwZhm.js +230 -0
  11. package/dist/cli-JzwtwZhm.js.map +1 -0
  12. package/dist/index.d.mts +101 -0
  13. package/dist/index.d.mts.map +1 -0
  14. package/dist/index.d.ts +101 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +9 -0
  17. package/dist/index.mjs +2 -0
  18. package/package.json +61 -0
  19. package/templates/blank/README.md +59 -0
  20. package/templates/blank/app.json +10 -0
  21. package/templates/blank/babel.config.js +7 -0
  22. package/templates/blank/gitignore +8 -0
  23. package/templates/blank/index.ts +4 -0
  24. package/templates/blank/index.web.ts +17 -0
  25. package/templates/blank/metro.config.js +3 -0
  26. package/templates/blank/package.json +36 -0
  27. package/templates/blank/scripts/copy-canvaskit.mjs +15 -0
  28. package/templates/blank/src/App.tsx +45 -0
  29. package/templates/blank/tsconfig.json +15 -0
  30. package/templates/shmup/README.md +59 -0
  31. package/templates/shmup/app.json +10 -0
  32. package/templates/shmup/babel.config.js +7 -0
  33. package/templates/shmup/gitignore +8 -0
  34. package/templates/shmup/index.ts +4 -0
  35. package/templates/shmup/index.web.ts +17 -0
  36. package/templates/shmup/metro.config.js +3 -0
  37. package/templates/shmup/package.json +39 -0
  38. package/templates/shmup/scripts/copy-canvaskit.mjs +15 -0
  39. package/templates/shmup/src/App.tsx +171 -0
  40. package/templates/shmup/src/logic.ts +356 -0
  41. package/templates/shmup/tests/logic.test.ts +235 -0
  42. package/templates/shmup/tsconfig.json +15 -0
  43. package/templates/topdown/README.md +79 -0
  44. package/templates/topdown/app.json +10 -0
  45. package/templates/topdown/babel.config.js +7 -0
  46. package/templates/topdown/gitignore +8 -0
  47. package/templates/topdown/index.ts +4 -0
  48. package/templates/topdown/index.web.ts +17 -0
  49. package/templates/topdown/metro.config.js +3 -0
  50. package/templates/topdown/package.json +39 -0
  51. package/templates/topdown/scripts/copy-canvaskit.mjs +15 -0
  52. package/templates/topdown/src/App.tsx +138 -0
  53. package/templates/topdown/src/map.ts +126 -0
  54. package/templates/topdown/tests/tilemap.test.ts +201 -0
  55. package/templates/topdown/tsconfig.json +15 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Grzegorz Otto
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Flare Engine
2
+ Copyright 2026 Grzegorz Otto
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @flare-engine/create
2
+
3
+ One-shot project scaffolder. Produces a runnable Expo + Flare app with a minimal scene + HUD in under 5 minutes on a clean machine. Three templates: `blank` (single centered sprite — smallest starting point), `topdown` (analog movement + tilemap collision + camera follow), `shmup` (auto-fire + spawner + HUD).
4
+
5
+ ## Install
6
+
7
+ Run via your package manager's `create` shortcut — no install needed. npm, pnpm and yarn map a bare `@flare-engine` to this package:
8
+
9
+ ```sh
10
+ npm create @flare-engine my-game -- --template shmup
11
+ # or
12
+ pnpm create @flare-engine my-game --template shmup
13
+ # or (bun create only resolves unscoped names)
14
+ bunx @flare-engine/create my-game --template shmup
15
+ ```
16
+
17
+ `npm create flare-app` is **not** this package: `create-flare-app` on npm belongs to an unrelated project.
18
+
19
+ ## Usage
20
+
21
+ ```sh
22
+ flare-create my-game [--template blank|topdown|shmup] \
23
+ [--package-manager bun|npm|pnpm] \
24
+ [--skip-install]
25
+ ```
26
+
27
+ `flare new` in [`@flare-engine/cli`](https://github.com/grzott/flare-engine/tree/main/packages/cli) runs the same scaffolder.
28
+
29
+ Programmatic API:
30
+
31
+ ```ts
32
+ import { scaffoldApp } from '@flare-engine/create';
33
+
34
+ await scaffoldApp({ name: 'my-game', template: 'shmup', packageManager: 'bun' });
35
+ ```
36
+
37
+ For full-scope showcases built on Flare, see [flareengine.dev](https://flareengine.dev).
38
+
39
+ See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md#flare-enginecreate--35kb-raw-node-only).
40
+
41
+ ## License
42
+
43
+ Apache-2.0
package/dist/bin.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ //#region src/bin.ts
3
+ require("./cli-JzwtwZhm.js").buildProgram().parseAsync(process.argv).catch((err) => {
4
+ const msg = err instanceof Error ? err.message : String(err);
5
+ process.stderr.write(`[flare-create] ${msg}\n`);
6
+ process.exit(1);
7
+ });
8
+ //#endregion
9
+
10
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","names":["buildProgram"],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { buildProgram } from './cli.js';\n\nbuildProgram()\n .parseAsync(process.argv)\n .catch((err: unknown) => {\n const msg = err instanceof Error ? err.message : String(err);\n process.stderr.write(`[flare-create] ${msg}\\n`);\n process.exit(1);\n });\n"],"mappings":";;2BAGAA,CAAAA,CAAAA,aAAa,CAAC,CACX,WAAW,QAAQ,IAAI,CAAC,CACxB,OAAO,QAAiB;CACvB,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;CAC3D,QAAQ,OAAO,MAAM,kBAAkB,IAAI,GAAG;CAC9C,QAAQ,KAAK,CAAC;AAChB,CAAC"}
package/dist/bin.mjs ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { t as buildProgram } from "./cli-BGXZ73ie.mjs";
3
+ //#region src/bin.ts
4
+ buildProgram().parseAsync(process.argv).catch((err) => {
5
+ const msg = err instanceof Error ? err.message : String(err);
6
+ process.stderr.write(`[flare-create] ${msg}\n`);
7
+ process.exit(1);
8
+ });
9
+ //#endregion
10
+ export {};
11
+
12
+ //# sourceMappingURL=bin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.mjs","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { buildProgram } from './cli.js';\n\nbuildProgram()\n .parseAsync(process.argv)\n .catch((err: unknown) => {\n const msg = err instanceof Error ? err.message : String(err);\n process.stderr.write(`[flare-create] ${msg}\\n`);\n process.exit(1);\n });\n"],"mappings":";;;AAGA,aAAa,CAAC,CACX,WAAW,QAAQ,IAAI,CAAC,CACxB,OAAO,QAAiB;CACvB,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;CAC3D,QAAQ,OAAO,MAAM,kBAAkB,IAAI,GAAG;CAC9C,QAAQ,KAAK,CAAC;AAChB,CAAC"}
@@ -0,0 +1,189 @@
1
+ import { Command } from "commander";
2
+ import { spawn } from "node:child_process";
3
+ import { cp, mkdir, readFile, readdir, rename, stat, writeFile } from "node:fs/promises";
4
+ import { dirname, isAbsolute, join, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ //#region package.json
7
+ var version = "0.4.0";
8
+ //#endregion
9
+ //#region src/manifest.ts
10
+ /** Built-in templates shipped inside `@flare-engine/create`. */
11
+ const TEMPLATES = {
12
+ blank: {
13
+ id: "blank",
14
+ displayName: "Blank",
15
+ description: "Empty scene with a single sprite — smallest starting point.",
16
+ engines: { node: ">=20" },
17
+ postInstall: "bun run start"
18
+ },
19
+ topdown: {
20
+ id: "topdown",
21
+ displayName: "Top-down",
22
+ description: "Analog player movement with tilemap collision + camera follow.",
23
+ engines: { node: ">=20" },
24
+ postInstall: "bun run start"
25
+ },
26
+ shmup: {
27
+ id: "shmup",
28
+ displayName: "Shoot-em-up",
29
+ description: "Auto-fire player, enemy spawner, HUD score — mirrors a minimum vertical-slice shmup.",
30
+ engines: { node: ">=20" },
31
+ postInstall: "bun run start"
32
+ }
33
+ };
34
+ function isTemplateId(value) {
35
+ return Object.hasOwn(TEMPLATES, value);
36
+ }
37
+ //#endregion
38
+ //#region src/scaffold.ts
39
+ const DEFAULT_TEMPLATES_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "..", "templates");
40
+ const VALID_APP_NAME = /^[a-z0-9@/_-]+$/i;
41
+ /** Returns true when the name is safe to use as an app name and shell argument. */
42
+ function isValidAppName(name) {
43
+ return VALID_APP_NAME.test(name);
44
+ }
45
+ /** Detect the package manager from `--package-manager` > `npm_config_user_agent` > `bun`. */
46
+ function detectPackageManager(explicit) {
47
+ if (explicit === "bun" || explicit === "npm" || explicit === "pnpm") return explicit;
48
+ const agent = process.env.npm_config_user_agent ?? "";
49
+ if (agent.startsWith("bun")) return "bun";
50
+ if (agent.startsWith("pnpm")) return "pnpm";
51
+ if (agent.startsWith("npm") || agent.startsWith("yarn")) return "npm";
52
+ return "bun";
53
+ }
54
+ async function pathExists(p) {
55
+ try {
56
+ await stat(p);
57
+ return true;
58
+ } catch {
59
+ return false;
60
+ }
61
+ }
62
+ const TOKEN_FILE_EXTS = /* @__PURE__ */ new Set([
63
+ ".ts",
64
+ ".tsx",
65
+ ".js",
66
+ ".jsx",
67
+ ".json",
68
+ ".md",
69
+ ".txt",
70
+ ".html",
71
+ ".css"
72
+ ]);
73
+ function shouldApplyTokens(path) {
74
+ const dot = path.lastIndexOf(".");
75
+ if (dot < 0) return false;
76
+ return TOKEN_FILE_EXTS.has(path.slice(dot).toLowerCase());
77
+ }
78
+ function replaceTokens(content, tokens) {
79
+ let out = content;
80
+ for (const [k, v] of Object.entries(tokens)) out = out.split(k).join(v);
81
+ return out;
82
+ }
83
+ async function walkFiles(dir, base, out) {
84
+ const entries = await readdir(dir, { withFileTypes: true });
85
+ for (const e of entries) {
86
+ const full = join(dir, e.name);
87
+ const rel = full.slice(base.length + 1);
88
+ if (e.isDirectory()) await walkFiles(full, base, out);
89
+ else if (e.isFile()) out.push(rel);
90
+ }
91
+ }
92
+ /** Returns the spawn configuration for the given package manager on the given platform. */
93
+ function installSpawnSpec(pm, platform) {
94
+ return {
95
+ cmd: pm,
96
+ shell: platform === "win32"
97
+ };
98
+ }
99
+ function runInstall(pm, cwd) {
100
+ return new Promise((resolvePromise) => {
101
+ const { cmd, shell } = installSpawnSpec(pm, process.platform);
102
+ const child = spawn(cmd, ["install"], {
103
+ cwd,
104
+ stdio: "inherit",
105
+ shell
106
+ });
107
+ child.on("exit", (code) => resolvePromise(code ?? 1));
108
+ child.on("error", () => resolvePromise(1));
109
+ });
110
+ }
111
+ /**
112
+ * Copy the chosen template into `targetDir`, apply token replacements, and
113
+ * optionally run the package manager's install. Fails if the target exists
114
+ * and is non-empty.
115
+ */
116
+ async function scaffoldApp(opts) {
117
+ if (!isValidAppName(opts.name)) throw new Error(`[flare-create] invalid app name: ${opts.name}`);
118
+ const templateId = opts.template ?? "blank";
119
+ if (!isTemplateId(templateId)) throw new Error(`[flare-create] unknown template: ${templateId}`);
120
+ if (!TEMPLATES[templateId]) throw new Error(`[flare-create] missing manifest for ${templateId}`);
121
+ const cwd = process.cwd();
122
+ const target = opts.targetDir ? isAbsolute(opts.targetDir) ? opts.targetDir : resolve(cwd, opts.targetDir) : resolve(cwd, opts.name);
123
+ if (await pathExists(target)) {
124
+ if ((await readdir(target)).length > 0) throw new Error(`[flare-create] target ${target} already exists and is not empty`);
125
+ } else await mkdir(target, { recursive: true });
126
+ const src = join(opts.templatesDir ?? DEFAULT_TEMPLATES_DIR, templateId);
127
+ if (!await pathExists(src)) throw new Error(`[flare-create] template directory not found: ${src}`);
128
+ await cp(src, target, { recursive: true });
129
+ const gi = join(target, "gitignore");
130
+ if (await pathExists(gi)) await rename(gi, join(target, ".gitignore"));
131
+ const tokens = {
132
+ "{{APP_NAME}}": opts.name,
133
+ "{{FLARE_VERSION}}": opts.flareVersion ?? `^${version}`,
134
+ "{{TEMPLATE_ID}}": templateId
135
+ };
136
+ const files = [];
137
+ await walkFiles(target, target, files);
138
+ for (const rel of files) {
139
+ if (!shouldApplyTokens(rel)) continue;
140
+ const p = join(target, rel);
141
+ const content = await readFile(p, "utf8");
142
+ const next = replaceTokens(content, tokens);
143
+ if (next !== content) await writeFile(p, next, "utf8");
144
+ }
145
+ const pm = detectPackageManager(opts.packageManager);
146
+ let installed = false;
147
+ if (!opts.skipInstall) {
148
+ const code = await runInstall(pm, target);
149
+ if (code !== 0) throw new Error(`[flare-create] ${pm} install exited with code ${code}`);
150
+ installed = true;
151
+ }
152
+ return {
153
+ targetDir: target,
154
+ template: templateId,
155
+ packageManager: pm,
156
+ installed
157
+ };
158
+ }
159
+ //#endregion
160
+ //#region src/cli.ts
161
+ function parseTemplateArg(value) {
162
+ if (value !== "blank" && value !== "topdown" && value !== "shmup") throw new Error(`invalid --template: ${value} (expected blank|topdown|shmup)`);
163
+ return value;
164
+ }
165
+ function parsePmArg(value) {
166
+ if (value !== "bun" && value !== "npm" && value !== "pnpm") throw new Error(`invalid --package-manager: ${value} (expected bun|npm|pnpm)`);
167
+ return value;
168
+ }
169
+ /** Build the `flare-create` CLI program. Exposed for tests. */
170
+ function buildProgram() {
171
+ const program = new Command();
172
+ program.name("flare-create").description("Scaffold a new Flare engine app").version(version).argument("<name>", "directory name / package name for the new app").option("-t, --template <name>", "template (blank|topdown|shmup)", parseTemplateArg, "blank").option("-p, --package-manager <pm>", "package manager (bun|npm|pnpm)", parsePmArg).option("--skip-install", "skip running install after scaffolding", false).action(async (name, opts) => {
173
+ const result = await scaffoldApp({
174
+ name,
175
+ template: opts.template,
176
+ packageManager: opts.packageManager,
177
+ skipInstall: opts.skipInstall === true
178
+ });
179
+ const manifest = TEMPLATES[result.template];
180
+ process.stdout.write(`[flare-create] scaffolded ${manifest?.displayName ?? result.template} at ${result.targetDir}\n`);
181
+ if (!result.installed) process.stdout.write(`[flare-create] skipped install — run \`cd ${name} && ${result.packageManager} install\` when ready\n`);
182
+ else if (manifest?.postInstall) process.stdout.write(`[flare-create] next: cd ${name} && ${manifest.postInstall}\n`);
183
+ });
184
+ return program;
185
+ }
186
+ //#endregion
187
+ export { scaffoldApp as a, isValidAppName as i, detectPackageManager as n, TEMPLATES as o, installSpawnSpec as r, isTemplateId as s, buildProgram as t };
188
+
189
+ //# sourceMappingURL=cli-BGXZ73ie.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-BGXZ73ie.mjs","names":[],"sources":["../package.json","../src/manifest.ts","../src/scaffold.ts","../src/cli.ts"],"sourcesContent":["","/** Declared metadata for a `@flare-engine/create` template. */\nexport interface TemplateManifest {\n /** Template directory name (`blank`, `topdown`, `shmup`, ...). */\n id: string;\n /** Human-readable name shown in logs. */\n displayName: string;\n /** One-line description of what the template produces. */\n description: string;\n /** Engines required — mirrors Node/npm engines field in scaffolded package.json. */\n engines: { node: string };\n /** Optional post-install instructions printed after scaffold completes. */\n postInstall?: string;\n}\n\n/** Built-in templates shipped inside `@flare-engine/create`. */\nexport const TEMPLATES = {\n blank: {\n id: 'blank',\n displayName: 'Blank',\n description: 'Empty scene with a single sprite — smallest starting point.',\n engines: { node: '>=20' },\n postInstall: 'bun run start',\n },\n topdown: {\n id: 'topdown',\n displayName: 'Top-down',\n description: 'Analog player movement with tilemap collision + camera follow.',\n engines: { node: '>=20' },\n postInstall: 'bun run start',\n },\n shmup: {\n id: 'shmup',\n displayName: 'Shoot-em-up',\n description:\n 'Auto-fire player, enemy spawner, HUD score — mirrors a minimum vertical-slice shmup.',\n engines: { node: '>=20' },\n postInstall: 'bun run start',\n },\n} satisfies Record<string, TemplateManifest>;\n\nexport type TemplateId = keyof typeof TEMPLATES;\n\nexport function isTemplateId(value: string): value is TemplateId {\n return Object.hasOwn(TEMPLATES, value);\n}\n","import { spawn } from 'node:child_process';\nimport { cp, mkdir, readdir, readFile, rename, stat, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { version } from '../package.json';\nimport { isTemplateId, TEMPLATES, type TemplateId } from './manifest.js';\n\n/** Options for `scaffoldApp`. */\nexport interface ScaffoldOptions {\n /** App name — also used as the target directory and `name` in package.json. */\n name: string;\n /** Template id (default: `blank`). */\n template?: string;\n /** Destination directory (default: `<cwd>/<name>`). */\n targetDir?: string;\n /** Package manager used for `engines` + post-install command. */\n packageManager?: 'bun' | 'npm' | 'pnpm';\n /** Skip `install` after copying (default: false). */\n skipInstall?: boolean;\n /** Pinned Flare version for template {{FLARE_VERSION}} token (default: current package version prefixed with ^). */\n flareVersion?: string;\n /** Override templates root — used by tests. */\n templatesDir?: string;\n}\n\n/** Result returned by `scaffoldApp`. */\nexport interface ScaffoldResult {\n /** Absolute path of the scaffolded app. */\n targetDir: string;\n /** Resolved template id. */\n template: TemplateId;\n /** Package manager used. */\n packageManager: 'bun' | 'npm' | 'pnpm';\n /** Whether install was run. */\n installed: boolean;\n}\n\nconst FILENAME = fileURLToPath(import.meta.url);\nconst DEFAULT_TEMPLATES_DIR = resolve(dirname(FILENAME), '..', 'templates');\n\nconst VALID_APP_NAME = /^[a-z0-9@/_-]+$/i;\n\n/** Returns true when the name is safe to use as an app name and shell argument. */\nexport function isValidAppName(name: string): boolean {\n return VALID_APP_NAME.test(name);\n}\n\n/** Detect the package manager from `--package-manager` > `npm_config_user_agent` > `bun`. */\nexport function detectPackageManager(explicit: string | undefined): 'bun' | 'npm' | 'pnpm' {\n if (explicit === 'bun' || explicit === 'npm' || explicit === 'pnpm') return explicit;\n const agent = process.env.npm_config_user_agent ?? '';\n if (agent.startsWith('bun')) return 'bun';\n if (agent.startsWith('pnpm')) return 'pnpm';\n if (agent.startsWith('npm') || agent.startsWith('yarn')) return 'npm';\n return 'bun';\n}\n\nasync function pathExists(p: string): Promise<boolean> {\n try {\n await stat(p);\n return true;\n } catch {\n return false;\n }\n}\n\nconst TOKEN_FILE_EXTS = new Set([\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.json',\n '.md',\n '.txt',\n '.html',\n '.css',\n]);\n\nfunction shouldApplyTokens(path: string): boolean {\n const dot = path.lastIndexOf('.');\n if (dot < 0) return false;\n return TOKEN_FILE_EXTS.has(path.slice(dot).toLowerCase());\n}\n\nfunction replaceTokens(content: string, tokens: Record<string, string>): string {\n let out = content;\n for (const [k, v] of Object.entries(tokens)) out = out.split(k).join(v);\n return out;\n}\n\nasync function walkFiles(dir: string, base: string, out: string[]): Promise<void> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const e of entries) {\n const full = join(dir, e.name);\n const rel = full.slice(base.length + 1);\n if (e.isDirectory()) {\n await walkFiles(full, base, out);\n } else if (e.isFile()) {\n out.push(rel);\n }\n }\n}\n\n/** Returns the spawn configuration for the given package manager on the given platform. */\nexport function installSpawnSpec(\n pm: 'bun' | 'npm' | 'pnpm',\n platform: NodeJS.Platform,\n): { cmd: string; shell: boolean } {\n return { cmd: pm, shell: platform === 'win32' };\n}\n\nfunction runInstall(pm: 'bun' | 'npm' | 'pnpm', cwd: string): Promise<number> {\n return new Promise((resolvePromise) => {\n const { cmd, shell } = installSpawnSpec(pm, process.platform);\n const child = spawn(cmd, ['install'], {\n cwd,\n stdio: 'inherit',\n shell,\n });\n child.on('exit', (code) => resolvePromise(code ?? 1));\n child.on('error', () => resolvePromise(1));\n });\n}\n\n/**\n * Copy the chosen template into `targetDir`, apply token replacements, and\n * optionally run the package manager's install. Fails if the target exists\n * and is non-empty.\n */\nexport async function scaffoldApp(opts: ScaffoldOptions): Promise<ScaffoldResult> {\n if (!isValidAppName(opts.name)) {\n throw new Error(`[flare-create] invalid app name: ${opts.name}`);\n }\n const templateId = opts.template ?? 'blank';\n if (!isTemplateId(templateId)) {\n throw new Error(`[flare-create] unknown template: ${templateId}`);\n }\n const manifest = TEMPLATES[templateId];\n if (!manifest) throw new Error(`[flare-create] missing manifest for ${templateId}`);\n\n const cwd = process.cwd();\n const target = opts.targetDir\n ? isAbsolute(opts.targetDir)\n ? opts.targetDir\n : resolve(cwd, opts.targetDir)\n : resolve(cwd, opts.name);\n\n if (await pathExists(target)) {\n const entries = await readdir(target);\n if (entries.length > 0) {\n throw new Error(`[flare-create] target ${target} already exists and is not empty`);\n }\n } else {\n await mkdir(target, { recursive: true });\n }\n\n const templatesRoot = opts.templatesDir ?? DEFAULT_TEMPLATES_DIR;\n const src = join(templatesRoot, templateId);\n if (!(await pathExists(src))) {\n throw new Error(`[flare-create] template directory not found: ${src}`);\n }\n\n await cp(src, target, { recursive: true });\n\n const gi = join(target, 'gitignore');\n if (await pathExists(gi)) {\n await rename(gi, join(target, '.gitignore'));\n }\n\n const tokens: Record<string, string> = {\n '{{APP_NAME}}': opts.name,\n '{{FLARE_VERSION}}': opts.flareVersion ?? `^${version}`,\n '{{TEMPLATE_ID}}': templateId,\n };\n\n const files: string[] = [];\n await walkFiles(target, target, files);\n for (const rel of files) {\n if (!shouldApplyTokens(rel)) continue;\n const p = join(target, rel);\n const content = await readFile(p, 'utf8');\n const next = replaceTokens(content, tokens);\n if (next !== content) await writeFile(p, next, 'utf8');\n }\n\n const pm = detectPackageManager(opts.packageManager);\n let installed = false;\n if (!opts.skipInstall) {\n const code = await runInstall(pm, target);\n if (code !== 0) {\n throw new Error(`[flare-create] ${pm} install exited with code ${code}`);\n }\n installed = true;\n }\n\n return {\n targetDir: target,\n template: templateId,\n packageManager: pm,\n installed,\n };\n}\n","import { Command } from 'commander';\nimport { version } from '../package.json';\nimport { TEMPLATES } from './manifest.js';\nimport { scaffoldApp } from './scaffold.js';\n\nfunction parseTemplateArg(value: string): 'blank' | 'topdown' | 'shmup' {\n if (value !== 'blank' && value !== 'topdown' && value !== 'shmup') {\n throw new Error(`invalid --template: ${value} (expected blank|topdown|shmup)`);\n }\n return value;\n}\n\nfunction parsePmArg(value: string): 'bun' | 'npm' | 'pnpm' {\n if (value !== 'bun' && value !== 'npm' && value !== 'pnpm') {\n throw new Error(`invalid --package-manager: ${value} (expected bun|npm|pnpm)`);\n }\n return value;\n}\n\n/** Build the `flare-create` CLI program. Exposed for tests. */\nexport function buildProgram(): Command {\n const program = new Command();\n program\n .name('flare-create')\n .description('Scaffold a new Flare engine app')\n .version(version)\n .argument('<name>', 'directory name / package name for the new app')\n .option('-t, --template <name>', 'template (blank|topdown|shmup)', parseTemplateArg, 'blank')\n .option('-p, --package-manager <pm>', 'package manager (bun|npm|pnpm)', parsePmArg)\n .option('--skip-install', 'skip running install after scaffolding', false)\n .action(async (name: string, opts) => {\n const result = await scaffoldApp({\n name,\n template: opts.template,\n packageManager: opts.packageManager,\n skipInstall: opts.skipInstall === true,\n });\n const manifest = TEMPLATES[result.template];\n process.stdout.write(\n `[flare-create] scaffolded ${\n manifest?.displayName ?? result.template\n } at ${result.targetDir}\\n`,\n );\n if (!result.installed) {\n process.stdout.write(\n `[flare-create] skipped install — run \\`cd ${name} && ${result.packageManager} install\\` when ready\\n`,\n );\n } else if (manifest?.postInstall) {\n process.stdout.write(`[flare-create] next: cd ${name} && ${manifest.postInstall}\\n`);\n }\n });\n return program;\n}\n"],"mappings":";;;;;;;;;;ACeA,MAAa,YAAY;CACvB,OAAO;EACL,IAAI;EACJ,aAAa;EACb,aAAa;EACb,SAAS,EAAE,MAAM,OAAO;EACxB,aAAa;CACf;CACA,SAAS;EACP,IAAI;EACJ,aAAa;EACb,aAAa;EACb,SAAS,EAAE,MAAM,OAAO;EACxB,aAAa;CACf;CACA,OAAO;EACL,IAAI;EACJ,aAAa;EACb,aACE;EACF,SAAS,EAAE,MAAM,OAAO;EACxB,aAAa;CACf;AACF;AAIA,SAAgB,aAAa,OAAoC;CAC/D,OAAO,OAAO,OAAO,WAAW,KAAK;AACvC;;;ACNA,MAAM,wBAAwB,QAAQ,QADrB,cAAc,OAAO,KAAK,GACU,CAAC,GAAG,MAAM,WAAW;AAE1E,MAAM,iBAAiB;;AAGvB,SAAgB,eAAe,MAAuB;CACpD,OAAO,eAAe,KAAK,IAAI;AACjC;;AAGA,SAAgB,qBAAqB,UAAsD;CACzF,IAAI,aAAa,SAAS,aA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