@flare-engine/cli 0.2.1 → 0.3.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.
package/dist/bin.js CHANGED
@@ -1,340 +1,90 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
-
26
- // src/cli.ts
27
- var import_node_child_process = require("child_process");
28
- var import_commander = require("commander");
29
-
30
- // src/pack-atlas.ts
31
- var import_promises = require("fs/promises");
32
- var import_node_path = require("path");
33
- var import_maxrects_packer = require("maxrects-packer");
34
- var import_sharp = __toESM(require("sharp"));
35
- function absPath(p) {
36
- return (0, import_node_path.isAbsolute)(p) ? p : (0, import_node_path.resolve)(process.cwd(), p);
37
- }
38
- async function listPngs(dir) {
39
- const entries = await (0, import_promises.readdir)(dir, { withFileTypes: true });
40
- const result = [];
41
- for (const e of entries) {
42
- if (!e.isFile()) continue;
43
- if ((0, import_node_path.extname)(e.name).toLowerCase() === ".png") result.push((0, import_node_path.join)(dir, e.name));
44
- }
45
- result.sort();
46
- return result;
47
- }
48
- async function readSprite(path) {
49
- const meta = await (0, import_sharp.default)(path).metadata();
50
- if (!meta.width || !meta.height) {
51
- throw new Error(`[pack-atlas] unable to read dimensions for ${path}`);
52
- }
53
- return {
54
- name: (0, import_node_path.basename)(path, (0, import_node_path.extname)(path)),
55
- path,
56
- width: meta.width,
57
- height: meta.height
58
- };
59
- }
60
- async function packAtlas(opts) {
61
- const inputDir = absPath(opts.input);
62
- const outDir = absPath(opts.out ?? opts.input);
63
- const name = opts.name ?? "atlas";
64
- const padding = opts.padding ?? 2;
65
- const maxSize = opts.maxSize ?? 2048;
66
- const format = opts.format ?? "png";
67
- await (0, import_promises.mkdir)(outDir, { recursive: true });
68
- const files = await listPngs(inputDir);
69
- if (files.length === 0) {
70
- throw new Error(`[pack-atlas] no .png files found in ${inputDir}`);
71
- }
72
- const sprites = [];
73
- for (const f of files) sprites.push(await readSprite(f));
74
- const packer = new import_maxrects_packer.MaxRectsPacker(maxSize, maxSize, padding, {
75
- smart: true,
76
- pot: false,
77
- square: false,
78
- allowRotation: false,
79
- tag: false,
80
- border: 0
81
- });
82
- for (const s of sprites) packer.add(s.width, s.height, s);
83
- if (packer.bins.length !== 1) {
84
- throw new Error(
85
- `[pack-atlas] sprites do not fit in a single ${maxSize}x${maxSize} atlas (got ${packer.bins.length} bins)`
86
- );
87
- }
88
- const bin = packer.bins[0];
89
- if (!bin) throw new Error("[pack-atlas] packing produced no bin");
90
- const atlasWidth = bin.width;
91
- const atlasHeight = bin.height;
92
- const frames = [];
93
- const composites = [];
94
- for (const rect of bin.rects) {
95
- const sprite = rect.data;
96
- const buf = await (0, import_promises.readFile)(sprite.path);
97
- composites.push({ input: buf, left: rect.x, top: rect.y });
98
- frames.push({
99
- name: sprite.name,
100
- x: rect.x,
101
- y: rect.y,
102
- w: sprite.width,
103
- h: sprite.height
104
- });
105
- }
106
- frames.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
107
- const imageName = `${name}.${format}`;
108
- const jsonName = `${name}.json`;
109
- const imagePath = (0, import_node_path.join)(outDir, imageName);
110
- const jsonPath = (0, import_node_path.join)(outDir, jsonName);
111
- let pipeline = (0, import_sharp.default)({
112
- create: {
113
- width: atlasWidth,
114
- height: atlasHeight,
115
- channels: 4,
116
- background: { r: 0, g: 0, b: 0, alpha: 0 }
117
- }
118
- }).composite(composites);
119
- pipeline = format === "webp" ? pipeline.webp() : pipeline.png();
120
- await pipeline.toFile(imagePath);
121
- const jsonFrames = {};
122
- for (const f of frames) {
123
- jsonFrames[f.name] = { frame: { x: f.x, y: f.y, w: f.w, h: f.h } };
124
- }
125
- const jsonDoc = {
126
- frames: jsonFrames,
127
- meta: {
128
- app: "@flare-engine/cli",
129
- version: "1.0",
130
- image: imageName,
131
- format: "RGBA8888",
132
- size: { w: atlasWidth, h: atlasHeight },
133
- scale: "1"
134
- }
135
- };
136
- await (0, import_promises.writeFile)(jsonPath, `${JSON.stringify(jsonDoc, null, 2)}
137
- `, "utf8");
138
- return {
139
- jsonPath,
140
- imagePath,
141
- frames,
142
- width: atlasWidth,
143
- height: atlasHeight
144
- };
145
- }
146
-
147
- // src/tiled-to-flare.ts
148
- var import_promises2 = require("fs/promises");
149
- var import_node_path2 = require("path");
150
- function absPath2(p, base) {
151
- return (0, import_node_path2.isAbsolute)(p) ? p : (0, import_node_path2.resolve)(base, p);
152
- }
153
- function propsToRecord(props) {
154
- const out = {};
155
- if (!props) return out;
156
- for (const p of props) out[p.name] = p.value;
157
- return out;
158
- }
159
- async function resolveTileset(ref, mapDir, embed) {
160
- let data = ref;
161
- if (ref.source && embed) {
162
- const srcPath = absPath2(ref.source, mapDir);
163
- const raw = await (0, import_promises2.readFile)(srcPath, "utf8");
164
- const external = JSON.parse(raw);
165
- data = { ...external, firstgid: ref.firstgid };
166
- }
167
- return {
168
- name: data.name ?? "tileset",
169
- firstgid: data.firstgid,
170
- tilewidth: data.tilewidth ?? 0,
171
- tileheight: data.tileheight ?? 0,
172
- columns: data.columns ?? 0,
173
- tilecount: data.tilecount ?? 0,
174
- image: data.image ?? "",
175
- imagewidth: data.imagewidth ?? 0,
176
- imageheight: data.imageheight ?? 0
177
- };
178
- }
179
- function flattenLayers(layers) {
180
- const out = [];
181
- const walk = (ls) => {
182
- for (const l of ls) {
183
- if (l.type === "group") {
184
- const inner = l.layers;
185
- if (inner) walk(inner);
186
- } else {
187
- out.push(l);
188
- }
189
- }
190
- };
191
- walk(layers);
192
- return out;
193
- }
194
- function convertLayer(layer) {
195
- const visible = layer.visible !== false;
196
- const opacity = typeof layer.opacity === "number" ? layer.opacity : 1;
197
- if (layer.type === "tilelayer") {
198
- const tile = {
199
- kind: "tile",
200
- name: layer.name,
201
- width: layer.width ?? 0,
202
- height: layer.height ?? 0,
203
- data: layer.data ?? [],
204
- visible,
205
- opacity
206
- };
207
- return tile;
208
- }
209
- if (layer.type === "objectgroup") {
210
- const objects = (layer.objects ?? []).map((o) => ({
211
- id: o.id,
212
- name: o.name ?? "",
213
- type: o.type ?? o.class ?? "",
214
- x: o.x,
215
- y: o.y,
216
- width: o.width,
217
- height: o.height,
218
- properties: propsToRecord(o.properties)
219
- }));
220
- const obj = {
221
- kind: "object",
222
- name: layer.name,
223
- objects,
224
- visible,
225
- opacity
226
- };
227
- return obj;
228
- }
229
- return null;
230
- }
231
- async function convertTiled(opts) {
232
- const inputPath = absPath2(opts.input, process.cwd());
233
- const outPath = opts.out ? absPath2(opts.out, process.cwd()) : (0, import_node_path2.join)((0, import_node_path2.dirname)(inputPath), `${inputPath.replace(/\.tmj$|\.json$/i, "")}.flare.json`);
234
- const embed = opts.embedTilesets !== false;
235
- const raw = await (0, import_promises2.readFile)(inputPath, "utf8");
236
- const parsed = JSON.parse(raw);
237
- const mapDir = (0, import_node_path2.dirname)(inputPath);
238
- const tilesets = [];
239
- for (const ref of parsed.tilesets ?? []) {
240
- tilesets.push(await resolveTileset(ref, mapDir, embed));
241
- }
242
- const layers = [];
243
- for (const l of flattenLayers(parsed.layers ?? [])) {
244
- const converted = convertLayer(l);
245
- if (converted) layers.push(converted);
246
- }
247
- const map = {
248
- width: parsed.width,
249
- height: parsed.height,
250
- tilewidth: parsed.tilewidth,
251
- tileheight: parsed.tileheight,
252
- tilesets,
253
- layers
254
- };
255
- await (0, import_promises2.writeFile)(outPath, `${JSON.stringify(map, null, 2)}
256
- `, "utf8");
257
- return { outPath, layers, tilesets, map };
258
- }
259
-
260
- // src/cli.ts
2
+ const require_tiled_to_flare = require("./tiled-to-flare-CEdmaHp_.js");
3
+ let node_child_process = require("node:child_process");
4
+ let commander = require("commander");
5
+ //#region package.json
6
+ var version = "0.3.1";
7
+ //#endregion
8
+ //#region src/cli.ts
261
9
  function parseIntArg(value, _prev) {
262
- const n = Number.parseInt(value, 10);
263
- if (!Number.isFinite(n)) throw new Error(`invalid integer: ${value}`);
264
- return n;
10
+ const n = Number.parseInt(value, 10);
11
+ if (!Number.isFinite(n)) throw new Error(`invalid integer: ${value}`);
12
+ return n;
265
13
  }
266
14
  function parseFormatArg(value) {
267
- if (value !== "png" && value !== "webp") {
268
- throw new Error(`invalid --format: ${value} (expected png|webp)`);
269
- }
270
- return value;
15
+ if (value !== "png" && value !== "webp") throw new Error(`invalid --format: ${value} (expected png|webp)`);
16
+ return value;
271
17
  }
272
18
  function parseTemplateArg(value) {
273
- if (value !== "blank" && value !== "topdown" && value !== "shmup") {
274
- throw new Error(`invalid --template: ${value} (expected blank|topdown|shmup)`);
275
- }
276
- return value;
19
+ if (value !== "blank" && value !== "topdown" && value !== "shmup") throw new Error(`invalid --template: ${value} (expected blank|topdown|shmup)`);
20
+ return value;
277
21
  }
278
22
  function parsePmArg(value) {
279
- if (value !== "bun" && value !== "npm" && value !== "pnpm") {
280
- throw new Error(`invalid --package-manager: ${value} (expected bun|npm|pnpm)`);
281
- }
282
- return value;
283
- }
23
+ if (value !== "bun" && value !== "npm" && value !== "pnpm") throw new Error(`invalid --package-manager: ${value} (expected bun|npm|pnpm)`);
24
+ return value;
25
+ }
26
+ const VALID_APP_NAME = /^[a-z0-9@/_-]+$/i;
27
+ /** Returns the spawn configuration for `npx create-flare-app` on the given platform. */
28
+ function createAppSpawnSpec(platform) {
29
+ return {
30
+ cmd: "npx",
31
+ shell: platform === "win32"
32
+ };
33
+ }
34
+ /** Build the `flare` CLI program. Exposed for tests. */
284
35
  function buildProgram() {
285
- const program = new import_commander.Command();
286
- program.name("flare").description("Flare engine CLI").version("0.0.0");
287
- program.command("pack-atlas <input>").description("Pack a directory of PNG sprites into an atlas JSON + image").option("-o, --out <dir>", "output directory (defaults to <input>)").option("-n, --name <name>", "base filename for the atlas pair", "atlas").option("-p, --padding <n>", "pixel padding between sprites", parseIntArg, 2).option("-m, --max-size <n>", "maximum atlas side length in px", parseIntArg, 2048).option("-f, --format <fmt>", "output image format (png|webp)", parseFormatArg, "png").action(async (input, opts) => {
288
- const result = await packAtlas({
289
- input,
290
- out: opts.out,
291
- name: opts.name,
292
- padding: opts.padding,
293
- maxSize: opts.maxSize,
294
- format: opts.format
295
- });
296
- process.stdout.write(
297
- `[pack-atlas] wrote ${result.frames.length} frames \u2192 ${result.imagePath} (${result.width}x${result.height})
298
- `
299
- );
300
- });
301
- program.command("tiled-to-flare <tmj>").description("Convert a Tiled .tmj file to Flare runtime JSON").option("-o, --out <file>", "output .json path").option("--no-embed-tilesets", "keep external tileset references rather than inlining").action(async (input, opts) => {
302
- const result = await convertTiled({
303
- input,
304
- out: opts.out,
305
- embedTilesets: opts.embedTilesets
306
- });
307
- process.stdout.write(
308
- `[tiled-to-flare] wrote ${result.layers.length} layers \u2192 ${result.outPath}
309
- `
310
- );
311
- });
312
- program.command("new <name>").description("Scaffold a new Flare app (alias for create-flare-app)").option("-t, --template <name>", "template (blank|topdown|shmup)", parseTemplateArg, "blank").option("-p, --package-manager <pm>", "package manager (bun|npm|pnpm)", parsePmArg).action(async (name, opts) => {
313
- const args = [name, "--template", opts.template];
314
- if (opts.packageManager) args.push("--package-manager", opts.packageManager);
315
- const code = await runCreateFlareApp(args);
316
- if (code !== 0) process.exit(code);
317
- });
318
- return program;
36
+ const program = new commander.Command();
37
+ program.name("flare").description("Flare engine CLI").version(version);
38
+ program.command("pack-atlas <input>").description("Pack a directory of PNG sprites into an atlas JSON + image").option("-o, --out <dir>", "output directory (defaults to <input>)").option("-n, --name <name>", "base filename for the atlas pair", "atlas").option("-p, --padding <n>", "pixel padding between sprites", parseIntArg, 2).option("-m, --max-size <n>", "maximum atlas side length in px", parseIntArg, 2048).option("-f, --format <fmt>", "output image format (png|webp)", parseFormatArg, "png").action(async (input, opts) => {
39
+ const result = await require_tiled_to_flare.packAtlas({
40
+ input,
41
+ out: opts.out,
42
+ name: opts.name,
43
+ padding: opts.padding,
44
+ maxSize: opts.maxSize,
45
+ format: opts.format
46
+ });
47
+ process.stdout.write(`[pack-atlas] wrote ${result.frames.length} frames → ${result.imagePath} (${result.width}x${result.height})\n`);
48
+ });
49
+ program.command("tiled-to-flare <tmj>").description("Convert a Tiled .tmj file to Flare runtime JSON").option("-o, --out <file>", "output .json path").option("--no-embed-tilesets", "keep external tileset references rather than inlining").action(async (input, opts) => {
50
+ const result = await require_tiled_to_flare.convertTiled({
51
+ input,
52
+ out: opts.out,
53
+ embedTilesets: opts.embedTilesets
54
+ });
55
+ process.stdout.write(`[tiled-to-flare] wrote ${result.layers.length} layers → ${result.outPath}\n`);
56
+ });
57
+ program.command("new <name>").description("Scaffold a new Flare app (alias for create-flare-app)").option("-t, --template <name>", "template (blank|topdown|shmup)", parseTemplateArg, "blank").option("-p, --package-manager <pm>", "package manager (bun|npm|pnpm)", parsePmArg).action(async (name, opts) => {
58
+ if (!VALID_APP_NAME.test(name)) throw new Error(`invalid app name: ${name}`);
59
+ const args = [
60
+ name,
61
+ "--template",
62
+ opts.template
63
+ ];
64
+ if (opts.packageManager) args.push("--package-manager", opts.packageManager);
65
+ const code = await runCreateFlareApp(args);
66
+ if (code !== 0) process.exit(code);
67
+ });
68
+ return program;
319
69
  }
320
70
  function runCreateFlareApp(args) {
321
- return new Promise((resolvePromise) => {
322
- const isWin = process.platform === "win32";
323
- const cmd = isWin ? "npx.cmd" : "npx";
324
- const child = (0, import_node_child_process.spawn)(cmd, ["create-flare-app", ...args], {
325
- stdio: "inherit",
326
- shell: false
327
- });
328
- child.on("exit", (code) => resolvePromise(code ?? 1));
329
- child.on("error", () => resolvePromise(1));
330
- });
331
- }
332
-
333
- // src/bin.ts
71
+ return new Promise((resolvePromise) => {
72
+ const { cmd, shell } = createAppSpawnSpec(process.platform);
73
+ const child = (0, node_child_process.spawn)(cmd, ["create-flare-app", ...args], {
74
+ stdio: "inherit",
75
+ shell
76
+ });
77
+ child.on("exit", (code) => resolvePromise(code ?? 1));
78
+ child.on("error", () => resolvePromise(1));
79
+ });
80
+ }
81
+ //#endregion
82
+ //#region src/bin.ts
334
83
  buildProgram().parseAsync(process.argv).catch((err) => {
335
- const msg = err instanceof Error ? err.message : String(err);
336
- process.stderr.write(`[flare] ${msg}
337
- `);
338
- process.exit(1);
84
+ const msg = err instanceof Error ? err.message : String(err);
85
+ process.stderr.write(`[flare] ${msg}\n`);
86
+ process.exit(1);
339
87
  });
88
+ //#endregion
89
+
340
90
  //# sourceMappingURL=bin.js.map
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../src/pack-atlas.ts","../src/tiled-to-flare.ts","../src/bin.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { Command } from 'commander';\nimport { packAtlas } from './pack-atlas.js';\nimport { convertTiled } from './tiled-to-flare.js';\n\nfunction parseIntArg(value: string, _prev: number): number {\n const n = Number.parseInt(value, 10);\n if (!Number.isFinite(n)) throw new Error(`invalid integer: ${value}`);\n return n;\n}\n\nfunction parseFormatArg(value: string): 'png' | 'webp' {\n if (value !== 'png' && value !== 'webp') {\n throw new Error(`invalid --format: ${value} (expected png|webp)`);\n }\n return value;\n}\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` CLI program. Exposed for tests. */\nexport function buildProgram(): Command {\n const program = new Command();\n program.name('flare').description('Flare engine CLI').version('0.0.0');\n\n program\n .command('pack-atlas <input>')\n .description('Pack a directory of PNG sprites into an atlas JSON + image')\n .option('-o, --out <dir>', 'output directory (defaults to <input>)')\n .option('-n, --name <name>', 'base filename for the atlas pair', 'atlas')\n .option('-p, --padding <n>', 'pixel padding between sprites', parseIntArg, 2)\n .option('-m, --max-size <n>', 'maximum atlas side length in px', parseIntArg, 2048)\n .option('-f, --format <fmt>', 'output image format (png|webp)', parseFormatArg, 'png')\n .action(async (input: string, opts) => {\n const result = await packAtlas({\n input,\n out: opts.out,\n name: opts.name,\n padding: opts.padding,\n maxSize: opts.maxSize,\n format: opts.format,\n });\n process.stdout.write(\n `[pack-atlas] wrote ${result.frames.length} frames → ${result.imagePath} (${result.width}x${result.height})\\n`,\n );\n });\n\n program\n .command('tiled-to-flare <tmj>')\n .description('Convert a Tiled .tmj file to Flare runtime JSON')\n .option('-o, --out <file>', 'output .json path')\n .option('--no-embed-tilesets', 'keep external tileset references rather than inlining')\n .action(async (input: string, opts) => {\n const result = await convertTiled({\n input,\n out: opts.out,\n embedTilesets: opts.embedTilesets,\n });\n process.stdout.write(\n `[tiled-to-flare] wrote ${result.layers.length} layers → ${result.outPath}\\n`,\n );\n });\n\n program\n .command('new <name>')\n .description('Scaffold a new Flare app (alias for create-flare-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 .action(async (name: string, opts) => {\n const args = [name, '--template', opts.template];\n if (opts.packageManager) args.push('--package-manager', opts.packageManager);\n const code = await runCreateFlareApp(args);\n if (code !== 0) process.exit(code);\n });\n\n return program;\n}\n\nfunction runCreateFlareApp(args: string[]): Promise<number> {\n return new Promise((resolvePromise) => {\n const isWin = process.platform === 'win32';\n const cmd = isWin ? 'npx.cmd' : 'npx';\n const child = spawn(cmd, ['create-flare-app', ...args], {\n stdio: 'inherit',\n shell: false,\n });\n child.on('exit', (code) => resolvePromise(code ?? 1));\n child.on('error', () => resolvePromise(1));\n });\n}\n","import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';\nimport { basename, extname, isAbsolute, join, resolve } from 'node:path';\nimport { MaxRectsPacker } from 'maxrects-packer';\nimport sharp from 'sharp';\nimport type { AtlasFrame, AtlasPackerOptions, AtlasResult } from './types.js';\n\ninterface SpriteInput {\n name: string;\n path: string;\n width: number;\n height: number;\n}\n\nfunction absPath(p: string): string {\n return isAbsolute(p) ? p : resolve(process.cwd(), p);\n}\n\nasync function listPngs(dir: string): Promise<string[]> {\n const entries = await readdir(dir, { withFileTypes: true });\n const result: string[] = [];\n for (const e of entries) {\n if (!e.isFile()) continue;\n if (extname(e.name).toLowerCase() === '.png') result.push(join(dir, e.name));\n }\n result.sort();\n return result;\n}\n\nasync function readSprite(path: string): Promise<SpriteInput> {\n const meta = await sharp(path).metadata();\n if (!meta.width || !meta.height) {\n throw new Error(`[pack-atlas] unable to read dimensions for ${path}`);\n }\n return {\n name: basename(path, extname(path)),\n path,\n width: meta.width,\n height: meta.height,\n };\n}\n\n/**\n * Pack a directory of PNG sprites into a single TexturePacker-compatible\n * atlas (JSON + image) consumable by `@flare-engine/assets`.\n */\nexport async function packAtlas(opts: AtlasPackerOptions): Promise<AtlasResult> {\n const inputDir = absPath(opts.input);\n const outDir = absPath(opts.out ?? opts.input);\n const name = opts.name ?? 'atlas';\n const padding = opts.padding ?? 2;\n const maxSize = opts.maxSize ?? 2048;\n const format = opts.format ?? 'png';\n\n await mkdir(outDir, { recursive: true });\n\n const files = await listPngs(inputDir);\n if (files.length === 0) {\n throw new Error(`[pack-atlas] no .png files found in ${inputDir}`);\n }\n\n const sprites: SpriteInput[] = [];\n for (const f of files) sprites.push(await readSprite(f));\n\n const packer = new MaxRectsPacker(maxSize, maxSize, padding, {\n smart: true,\n pot: false,\n square: false,\n allowRotation: false,\n tag: false,\n border: 0,\n });\n for (const s of sprites) packer.add(s.width, s.height, s);\n\n if (packer.bins.length !== 1) {\n throw new Error(\n `[pack-atlas] sprites do not fit in a single ${maxSize}x${maxSize} atlas (got ${packer.bins.length} bins)`,\n );\n }\n const bin = packer.bins[0];\n if (!bin) throw new Error('[pack-atlas] packing produced no bin');\n\n const atlasWidth = bin.width;\n const atlasHeight = bin.height;\n\n const frames: AtlasFrame[] = [];\n const composites: { input: Buffer; left: number; top: number }[] = [];\n\n for (const rect of bin.rects) {\n const sprite = rect.data as SpriteInput;\n const buf = await readFile(sprite.path);\n composites.push({ input: buf, left: rect.x, top: rect.y });\n frames.push({\n name: sprite.name,\n x: rect.x,\n y: rect.y,\n w: sprite.width,\n h: sprite.height,\n });\n }\n frames.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n\n const imageName = `${name}.${format}`;\n const jsonName = `${name}.json`;\n const imagePath = join(outDir, imageName);\n const jsonPath = join(outDir, jsonName);\n\n let pipeline = sharp({\n create: {\n width: atlasWidth,\n height: atlasHeight,\n channels: 4,\n background: { r: 0, g: 0, b: 0, alpha: 0 },\n },\n }).composite(composites);\n pipeline = format === 'webp' ? pipeline.webp() : pipeline.png();\n await pipeline.toFile(imagePath);\n\n // TexturePacker-compatible JSON (hash format).\n const jsonFrames: Record<string, { frame: { x: number; y: number; w: number; h: number } }> = {};\n for (const f of frames) {\n jsonFrames[f.name] = { frame: { x: f.x, y: f.y, w: f.w, h: f.h } };\n }\n const jsonDoc = {\n frames: jsonFrames,\n meta: {\n app: '@flare-engine/cli',\n version: '1.0',\n image: imageName,\n format: 'RGBA8888',\n size: { w: atlasWidth, h: atlasHeight },\n scale: '1',\n },\n };\n await writeFile(jsonPath, `${JSON.stringify(jsonDoc, null, 2)}\\n`, 'utf8');\n\n return {\n jsonPath,\n imagePath,\n frames,\n width: atlasWidth,\n height: atlasHeight,\n };\n}\n","import { readFile, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport type {\n FlareLayer,\n FlareMap,\n FlareObject,\n FlareObjectLayer,\n FlareTileLayer,\n FlareTileset,\n TiledConvertOptions,\n TiledResult,\n} from './types.js';\n\ninterface TiledProperty {\n name: string;\n type?: string;\n value: string | number | boolean;\n}\n\ninterface TiledObject {\n id: number;\n name?: string;\n type?: string;\n class?: string;\n x: number;\n y: number;\n width: number;\n height: number;\n visible?: boolean;\n properties?: TiledProperty[];\n}\n\ninterface TiledLayer {\n type: 'tilelayer' | 'objectgroup' | 'imagelayer' | 'group';\n name: string;\n visible?: boolean;\n opacity?: number;\n width?: number;\n height?: number;\n data?: number[];\n objects?: TiledObject[];\n}\n\ninterface TiledTilesetRef {\n firstgid: number;\n source?: string;\n name?: string;\n tilewidth?: number;\n tileheight?: number;\n columns?: number;\n tilecount?: number;\n image?: string;\n imagewidth?: number;\n imageheight?: number;\n}\n\ninterface TiledMap {\n width: number;\n height: number;\n tilewidth: number;\n tileheight: number;\n layers: TiledLayer[];\n tilesets: TiledTilesetRef[];\n}\n\nfunction absPath(p: string, base: string): string {\n return isAbsolute(p) ? p : resolve(base, p);\n}\n\nfunction propsToRecord(\n props: TiledProperty[] | undefined,\n): Record<string, string | number | boolean> {\n const out: Record<string, string | number | boolean> = {};\n if (!props) return out;\n for (const p of props) out[p.name] = p.value;\n return out;\n}\n\nasync function resolveTileset(\n ref: TiledTilesetRef,\n mapDir: string,\n embed: boolean,\n): Promise<FlareTileset> {\n let data: TiledTilesetRef = ref;\n if (ref.source && embed) {\n const srcPath = absPath(ref.source, mapDir);\n const raw = await readFile(srcPath, 'utf8');\n const external = JSON.parse(raw) as TiledTilesetRef;\n data = { ...external, firstgid: ref.firstgid };\n }\n return {\n name: data.name ?? 'tileset',\n firstgid: data.firstgid,\n tilewidth: data.tilewidth ?? 0,\n tileheight: data.tileheight ?? 0,\n columns: data.columns ?? 0,\n tilecount: data.tilecount ?? 0,\n image: data.image ?? '',\n imagewidth: data.imagewidth ?? 0,\n imageheight: data.imageheight ?? 0,\n };\n}\n\nfunction flattenLayers(layers: TiledLayer[]): TiledLayer[] {\n const out: TiledLayer[] = [];\n const walk = (ls: TiledLayer[]): void => {\n for (const l of ls) {\n if (l.type === 'group') {\n const inner = (l as unknown as { layers?: TiledLayer[] }).layers;\n if (inner) walk(inner);\n } else {\n out.push(l);\n }\n }\n };\n walk(layers);\n return out;\n}\n\nfunction convertLayer(layer: TiledLayer): FlareLayer | null {\n const visible = layer.visible !== false;\n const opacity = typeof layer.opacity === 'number' ? layer.opacity : 1;\n if (layer.type === 'tilelayer') {\n const tile: FlareTileLayer = {\n kind: 'tile',\n name: layer.name,\n width: layer.width ?? 0,\n height: layer.height ?? 0,\n data: layer.data ?? [],\n visible,\n opacity,\n };\n return tile;\n }\n if (layer.type === 'objectgroup') {\n const objects: FlareObject[] = (layer.objects ?? []).map((o) => ({\n id: o.id,\n name: o.name ?? '',\n type: o.type ?? o.class ?? '',\n x: o.x,\n y: o.y,\n width: o.width,\n height: o.height,\n properties: propsToRecord(o.properties),\n }));\n const obj: FlareObjectLayer = {\n kind: 'object',\n name: layer.name,\n objects,\n visible,\n opacity,\n };\n return obj;\n }\n return null;\n}\n\n/**\n * Convert a Tiled `.tmj` JSON map into Flare's normalized runtime format.\n * Flattens group layers, resolves external tilesets (when `embedTilesets`),\n * and drops image/editor-only layers.\n */\nexport async function convertTiled(opts: TiledConvertOptions): Promise<TiledResult> {\n const inputPath = absPath(opts.input, process.cwd());\n const outPath = opts.out\n ? absPath(opts.out, process.cwd())\n : join(dirname(inputPath), `${inputPath.replace(/\\.tmj$|\\.json$/i, '')}.flare.json`);\n const embed = opts.embedTilesets !== false;\n\n const raw = await readFile(inputPath, 'utf8');\n const parsed = JSON.parse(raw) as TiledMap;\n const mapDir = dirname(inputPath);\n\n const tilesets: FlareTileset[] = [];\n for (const ref of parsed.tilesets ?? []) {\n tilesets.push(await resolveTileset(ref, mapDir, embed));\n }\n\n const layers: FlareLayer[] = [];\n for (const l of flattenLayers(parsed.layers ?? [])) {\n const converted = convertLayer(l);\n if (converted) layers.push(converted);\n }\n\n const map: FlareMap = {\n width: parsed.width,\n height: parsed.height,\n tilewidth: parsed.tilewidth,\n tileheight: parsed.tileheight,\n tilesets,\n layers,\n };\n\n await writeFile(outPath, `${JSON.stringify(map, null, 2)}\\n`, 'utf8');\n return { outPath, layers, tilesets, map };\n}\n","#!/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] ${msg}\\n`);\n process.exit(1);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gCAAsB;AACtB,uBAAwB;;;ACDxB,sBAAoD;AACpD,uBAA6D;AAC7D,6BAA+B;AAC/B,mBAAkB;AAUlB,SAAS,QAAQ,GAAmB;AAClC,aAAO,6BAAW,CAAC,IAAI,QAAI,0BAAQ,QAAQ,IAAI,GAAG,CAAC;AACrD;AAEA,eAAe,SAAS,KAAgC;AACtD,QAAM,UAAU,UAAM,yBAAQ,KAAK,EAAE,eAAe,KAAK,CAAC;AAC1D,QAAM,SAAmB,CAAC;AAC1B,aAAW,KAAK,SAAS;AACvB,QAAI,CAAC,EAAE,OAAO,EAAG;AACjB,YAAI,0BAAQ,EAAE,IAAI,EAAE,YAAY,MAAM,OAAQ,QAAO,SAAK,uBAAK,KAAK,EAAE,IAAI,CAAC;AAAA,EAC7E;AACA,SA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AAK;AAAA,MACV,eAAe,KAAK;AAAA,IACtB,CAAC;AACD,YAAQ,OAAO;AAAA,MACb,0BAA0B,OAAO,OAAO,MAAM,kBAAa,OAAO,OAAO;AAAA;AAAA,IAC3E;AAAA,EACF,CAAC;AAEH,UACG,QAAQ,YAAY,EACpB,YAAY,uDAAuD,EACnE,OAAO,yBAAyB,kCAAkC,kBAAkB,OAAO,EAC3F,OAAO,8BAA8B,kCAAkC,UAAU,EACjF,OAAO,OAAO,MAAc,SAAS;AACpC,UAAM,OAAO,CAAC,MAAM,cAAc,KAAK,QAAQ;AAC/C,QAAI,KAAK,eAAgB,MAAK,KAAK,qBAAqB,KAAK,cAAc;AAC3E,UAAM,OAAO,MAAM,kBAAkB,IAAI;AACzC,QAAI,SAAS,EAAG,SAAQ,KAAK,IAAI;AAAA,EACnC,CAAC;AAEH,SAAO;AACT;AAEA,SAAS,kBAAkB,MAAiC;AAC1D,SAAO,IAAI,QAAQ,CAAC,mBAAmB;AACrC,UAAM,QAAQ,QAAQ,aAAa;AACnC,UAAM,MAAM,QAAQ,YAAY;AAChC,UAAM,YAAQ,iCAAM,KAAK,CAAC,oBAAoB,GAAG,IAAI,GAAG;AAAA,MACtD,OAAO;AAAA,MACP,OAAO;AAAA,IACT,CAAC;AACD,UAAM,GAAG,QAAQ,CAAC,SAAS,eAAe,QAAQ,CAAC,CAAC;AACpD,UAAM,GAAG,SAAS,MAAM,eAAe,CAAC,CAAC;AAAA,EAC3C,CAAC;AACH;;;AGlGA,aAAa,EACV,WAAW,QAAQ,IAAI,EACvB,MAAM,CAAC,QAAiB;AACvB,QAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC3D,UAAQ,OAAO,MAAM,WAAW,GAAG;AAAA,CAAI;AACvC,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["sharp","import_promises","import_node_path","absPath"]}
1
+ {"version":3,"file":"bin.js","names":["Command","packAtlas","convertTiled"],"sources":["../package.json","../src/cli.ts","../src/bin.ts"],"sourcesContent":["","import { spawn } from 'node:child_process';\nimport { Command } from 'commander';\nimport { version } from '../package.json';\nimport { packAtlas } from './pack-atlas.js';\nimport { convertTiled } from './tiled-to-flare.js';\n\nfunction parseIntArg(value: string, _prev: number): number {\n const n = Number.parseInt(value, 10);\n if (!Number.isFinite(n)) throw new Error(`invalid integer: ${value}`);\n return n;\n}\n\nfunction parseFormatArg(value: string): 'png' | 'webp' {\n if (value !== 'png' && value !== 'webp') {\n throw new Error(`invalid --format: ${value} (expected png|webp)`);\n }\n return value;\n}\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\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/** Returns the spawn configuration for `npx create-flare-app` on the given platform. */\nexport function createAppSpawnSpec(platform: NodeJS.Platform): { cmd: string; shell: boolean } {\n return { cmd: 'npx', shell: platform === 'win32' };\n}\n\n/** Build the `flare` CLI program. Exposed for tests. */\nexport function buildProgram(): Command {\n const program = new Command();\n program.name('flare').description('Flare engine CLI').version(version);\n\n program\n .command('pack-atlas <input>')\n .description('Pack a directory of PNG sprites into an atlas JSON + image')\n .option('-o, --out <dir>', 'output directory (defaults to <input>)')\n .option('-n, --name <name>', 'base filename for the atlas pair', 'atlas')\n .option('-p, --padding <n>', 'pixel padding between sprites', parseIntArg, 2)\n .option('-m, --max-size <n>', 'maximum atlas side length in px', parseIntArg, 2048)\n .option('-f, --format <fmt>', 'output image format (png|webp)', parseFormatArg, 'png')\n .action(async (input: string, opts) => {\n const result = await packAtlas({\n input,\n out: opts.out,\n name: opts.name,\n padding: opts.padding,\n maxSize: opts.maxSize,\n format: opts.format,\n });\n process.stdout.write(\n `[pack-atlas] wrote ${result.frames.length} frames → ${result.imagePath} (${result.width}x${result.height})\\n`,\n );\n });\n\n program\n .command('tiled-to-flare <tmj>')\n .description('Convert a Tiled .tmj file to Flare runtime JSON')\n .option('-o, --out <file>', 'output .json path')\n .option('--no-embed-tilesets', 'keep external tileset references rather than inlining')\n .action(async (input: string, opts) => {\n const result = await convertTiled({\n input,\n out: opts.out,\n embedTilesets: opts.embedTilesets,\n });\n process.stdout.write(\n `[tiled-to-flare] wrote ${result.layers.length} layers → ${result.outPath}\\n`,\n );\n });\n\n program\n .command('new <name>')\n .description('Scaffold a new Flare app (alias for create-flare-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 .action(async (name: string, opts) => {\n if (!VALID_APP_NAME.test(name)) throw new Error(`invalid app name: ${name}`);\n const args = [name, '--template', opts.template];\n if (opts.packageManager) args.push('--package-manager', opts.packageManager);\n const code = await runCreateFlareApp(args);\n if (code !== 0) process.exit(code);\n });\n\n return program;\n}\n\nfunction runCreateFlareApp(args: string[]): Promise<number> {\n return new Promise((resolvePromise) => {\n const { cmd, shell } = createAppSpawnSpec(process.platform);\n const child = spawn(cmd, ['create-flare-app', ...args], {\n stdio: 'inherit',\n shell,\n });\n child.on('exit', (code) => resolvePromise(code ?? 1));\n child.on('error', () => resolvePromise(1));\n });\n}\n","#!/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] ${msg}\\n`);\n process.exit(1);\n });\n"],"mappings":";;;;;;;;ACMA,SAAS,YAAY,OAAe,OAAuB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eAAe,CAAC,CAAC;CAC3C,CAAC;AACH;;;AC/GA,aAAa,CAAC,CACX,WAAW,QAAQ,IAAI,CAAC,CACxB,OAAO,QAAiB;CACvB,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;CAC3D,QAAQ,OAAO,MAAM,WAAW,IAAI,GAAG;CACvC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
package/dist/bin.mjs CHANGED
@@ -1,89 +1,91 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- convertTiled,
4
- packAtlas
5
- } from "./chunk-SUMZ7TVL.mjs";
6
-
7
- // src/cli.ts
8
- import { spawn } from "child_process";
2
+ import { n as packAtlas, t as convertTiled } from "./tiled-to-flare-Cc-ofNer.mjs";
3
+ import { spawn } from "node:child_process";
9
4
  import { Command } from "commander";
5
+ //#region package.json
6
+ var version = "0.3.1";
7
+ //#endregion
8
+ //#region src/cli.ts
10
9
  function parseIntArg(value, _prev) {
11
- const n = Number.parseInt(value, 10);
12
- if (!Number.isFinite(n)) throw new Error(`invalid integer: ${value}`);
13
- return n;
10
+ const n = Number.parseInt(value, 10);
11
+ if (!Number.isFinite(n)) throw new Error(`invalid integer: ${value}`);
12
+ return n;
14
13
  }
15
14
  function parseFormatArg(value) {
16
- if (value !== "png" && value !== "webp") {
17
- throw new Error(`invalid --format: ${value} (expected png|webp)`);
18
- }
19
- return value;
15
+ if (value !== "png" && value !== "webp") throw new Error(`invalid --format: ${value} (expected png|webp)`);
16
+ return value;
20
17
  }
21
18
  function parseTemplateArg(value) {
22
- if (value !== "blank" && value !== "topdown" && value !== "shmup") {
23
- throw new Error(`invalid --template: ${value} (expected blank|topdown|shmup)`);
24
- }
25
- return value;
19
+ if (value !== "blank" && value !== "topdown" && value !== "shmup") throw new Error(`invalid --template: ${value} (expected blank|topdown|shmup)`);
20
+ return value;
26
21
  }
27
22
  function parsePmArg(value) {
28
- if (value !== "bun" && value !== "npm" && value !== "pnpm") {
29
- throw new Error(`invalid --package-manager: ${value} (expected bun|npm|pnpm)`);
30
- }
31
- return value;
23
+ if (value !== "bun" && value !== "npm" && value !== "pnpm") throw new Error(`invalid --package-manager: ${value} (expected bun|npm|pnpm)`);
24
+ return value;
25
+ }
26
+ const VALID_APP_NAME = /^[a-z0-9@/_-]+$/i;
27
+ /** Returns the spawn configuration for `npx create-flare-app` on the given platform. */
28
+ function createAppSpawnSpec(platform) {
29
+ return {
30
+ cmd: "npx",
31
+ shell: platform === "win32"
32
+ };
32
33
  }
34
+ /** Build the `flare` CLI program. Exposed for tests. */
33
35
  function buildProgram() {
34
- const program = new Command();
35
- program.name("flare").description("Flare engine CLI").version("0.0.0");
36
- program.command("pack-atlas <input>").description("Pack a directory of PNG sprites into an atlas JSON + image").option("-o, --out <dir>", "output directory (defaults to <input>)").option("-n, --name <name>", "base filename for the atlas pair", "atlas").option("-p, --padding <n>", "pixel padding between sprites", parseIntArg, 2).option("-m, --max-size <n>", "maximum atlas side length in px", parseIntArg, 2048).option("-f, --format <fmt>", "output image format (png|webp)", parseFormatArg, "png").action(async (input, opts) => {
37
- const result = await packAtlas({
38
- input,
39
- out: opts.out,
40
- name: opts.name,
41
- padding: opts.padding,
42
- maxSize: opts.maxSize,
43
- format: opts.format
44
- });
45
- process.stdout.write(
46
- `[pack-atlas] wrote ${result.frames.length} frames \u2192 ${result.imagePath} (${result.width}x${result.height})
47
- `
48
- );
49
- });
50
- program.command("tiled-to-flare <tmj>").description("Convert a Tiled .tmj file to Flare runtime JSON").option("-o, --out <file>", "output .json path").option("--no-embed-tilesets", "keep external tileset references rather than inlining").action(async (input, opts) => {
51
- const result = await convertTiled({
52
- input,
53
- out: opts.out,
54
- embedTilesets: opts.embedTilesets
55
- });
56
- process.stdout.write(
57
- `[tiled-to-flare] wrote ${result.layers.length} layers \u2192 ${result.outPath}
58
- `
59
- );
60
- });
61
- program.command("new <name>").description("Scaffold a new Flare app (alias for create-flare-app)").option("-t, --template <name>", "template (blank|topdown|shmup)", parseTemplateArg, "blank").option("-p, --package-manager <pm>", "package manager (bun|npm|pnpm)", parsePmArg).action(async (name, opts) => {
62
- const args = [name, "--template", opts.template];
63
- if (opts.packageManager) args.push("--package-manager", opts.packageManager);
64
- const code = await runCreateFlareApp(args);
65
- if (code !== 0) process.exit(code);
66
- });
67
- return program;
36
+ const program = new Command();
37
+ program.name("flare").description("Flare engine CLI").version(version);
38
+ program.command("pack-atlas <input>").description("Pack a directory of PNG sprites into an atlas JSON + image").option("-o, --out <dir>", "output directory (defaults to <input>)").option("-n, --name <name>", "base filename for the atlas pair", "atlas").option("-p, --padding <n>", "pixel padding between sprites", parseIntArg, 2).option("-m, --max-size <n>", "maximum atlas side length in px", parseIntArg, 2048).option("-f, --format <fmt>", "output image format (png|webp)", parseFormatArg, "png").action(async (input, opts) => {
39
+ const result = await packAtlas({
40
+ input,
41
+ out: opts.out,
42
+ name: opts.name,
43
+ padding: opts.padding,
44
+ maxSize: opts.maxSize,
45
+ format: opts.format
46
+ });
47
+ process.stdout.write(`[pack-atlas] wrote ${result.frames.length} frames → ${result.imagePath} (${result.width}x${result.height})\n`);
48
+ });
49
+ program.command("tiled-to-flare <tmj>").description("Convert a Tiled .tmj file to Flare runtime JSON").option("-o, --out <file>", "output .json path").option("--no-embed-tilesets", "keep external tileset references rather than inlining").action(async (input, opts) => {
50
+ const result = await convertTiled({
51
+ input,
52
+ out: opts.out,
53
+ embedTilesets: opts.embedTilesets
54
+ });
55
+ process.stdout.write(`[tiled-to-flare] wrote ${result.layers.length} layers → ${result.outPath}\n`);
56
+ });
57
+ program.command("new <name>").description("Scaffold a new Flare app (alias for create-flare-app)").option("-t, --template <name>", "template (blank|topdown|shmup)", parseTemplateArg, "blank").option("-p, --package-manager <pm>", "package manager (bun|npm|pnpm)", parsePmArg).action(async (name, opts) => {
58
+ if (!VALID_APP_NAME.test(name)) throw new Error(`invalid app name: ${name}`);
59
+ const args = [
60
+ name,
61
+ "--template",
62
+ opts.template
63
+ ];
64
+ if (opts.packageManager) args.push("--package-manager", opts.packageManager);
65
+ const code = await runCreateFlareApp(args);
66
+ if (code !== 0) process.exit(code);
67
+ });
68
+ return program;
68
69
  }
69
70
  function runCreateFlareApp(args) {
70
- return new Promise((resolvePromise) => {
71
- const isWin = process.platform === "win32";
72
- const cmd = isWin ? "npx.cmd" : "npx";
73
- const child = spawn(cmd, ["create-flare-app", ...args], {
74
- stdio: "inherit",
75
- shell: false
76
- });
77
- child.on("exit", (code) => resolvePromise(code ?? 1));
78
- child.on("error", () => resolvePromise(1));
79
- });
71
+ return new Promise((resolvePromise) => {
72
+ const { cmd, shell } = createAppSpawnSpec(process.platform);
73
+ const child = spawn(cmd, ["create-flare-app", ...args], {
74
+ stdio: "inherit",
75
+ shell
76
+ });
77
+ child.on("exit", (code) => resolvePromise(code ?? 1));
78
+ child.on("error", () => resolvePromise(1));
79
+ });
80
80
  }
81
-
82
- // src/bin.ts
81
+ //#endregion
82
+ //#region src/bin.ts
83
83
  buildProgram().parseAsync(process.argv).catch((err) => {
84
- const msg = err instanceof Error ? err.message : String(err);
85
- process.stderr.write(`[flare] ${msg}
86
- `);
87
- process.exit(1);
84
+ const msg = err instanceof Error ? err.message : String(err);
85
+ process.stderr.write(`[flare] ${msg}\n`);
86
+ process.exit(1);
88
87
  });
88
+ //#endregion
89
+ export {};
90
+
89
91
  //# sourceMappingURL=bin.mjs.map