create-dreamer-app 1.0.17 → 1.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/README.md CHANGED
@@ -18,16 +18,16 @@ Open the local URL printed by Vite. The development server uses port `3000` by d
18
18
 
19
19
  ## What's included
20
20
 
21
- - **Disco Dreamer** with a starter scene and text component.
21
+ - **Disco Dreamer** (`^1.3.0`) with a starter scene and text component.
22
22
  - **TypeScript and TSX** with strict type checking.
23
23
  - **Vite** for local development and production builds.
24
24
  - **Source aliases** so you can import from `@/` instead of navigating relative paths.
25
25
  - A full-page canvas with basic styles.
26
- - `DISCO_DREAMER_REFERENCE.md`, a practical guide to the Disco Dreamer API.
26
+ - [`DISCO_DREAMER_REFERENCE.md`](template/DISCO_DREAMER_REFERENCE.md), a practical guide to the Disco Dreamer 1.3.0 API, copied into your generated project.
27
27
 
28
28
  ## Make it yours
29
29
 
30
- Start in `src/components/Message/index.tsx` to change the greeting:
30
+ Start in `src/components/Message/index.tsx` to change the default `Howdy` greeting:
31
31
 
32
32
  ```tsx
33
33
  import { Text } from "discodreamer";
@@ -43,6 +43,18 @@ Add components to `src/components/GameScreen/index.tsx` to build out your scene.
43
43
  import { Message } from "@/components/Message";
44
44
  ```
45
45
 
46
+ The template configures the JSX factory automatically, so TSX components only need to import the Disco Dreamer components and hooks they use.
47
+
48
+ ### Coordinate units
49
+
50
+ The starter registers `Main` in `src/main.ts` with `registerRoot(Main)`, which uses CSS-pixel coordinates. To use the scale mode documented in the bundled 1.3.0 reference, replace that call inside the existing load handler:
51
+
52
+ ```ts
53
+ registerRoot(Main, { units: "scale", scaling: 0.01 });
54
+ ```
55
+
56
+ With `scaling: 0.01`, one game unit is 1% of the canvas's shorter CSS dimension. Positions, display sizes, viewport dimensions, and pointer coordinates use those units. Keep a single `registerRoot` call per app.
57
+
46
58
  ## Project structure
47
59
 
48
60
  ```text
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-dreamer-app",
3
- "version": "1.0.17",
3
+ "version": "1.1.0",
4
4
  "description": "The scaffolding application for using Disco Dreamer.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,15 +1,15 @@
1
1
  # Disco Dreamer reference
2
2
 
3
- A practical guide to building browser games with `discodreamer`. Examples use the public API in version 1.2.2 and TypeScript with JSX.
3
+ A practical guide to building browser games with `discodreamer`. Examples use the public API in version 1.4.0 and TypeScript with JSX.
4
4
 
5
5
  ## How a game runs
6
6
 
7
7
  Disco Dreamer draws a tree of game objects onto a 2D canvas. Components are functions that return game objects; hooks provide state, input, animation, and other game behavior.
8
8
 
9
- Your root function runs again on every animation frame. Each frame, the engine builds the tree, solves collisions, manages sound, draws the tree, and cleans up. A state setter updates stored data immediately; it does not schedule a separate render.
9
+ Your root function runs again on every animation frame. Each frame, the engine builds the tree, solves collisions, detects touch-area hits, manages sound, draws the tree, and cleans up. A state setter updates stored data immediately; it does not schedule a separate render.
10
10
 
11
11
  - Coordinates use CSS pixels by default, or scaled game units when configured through `registerRoot`. In both modes, `(0, 0)` is at the canvas's top-left, positive `x` points right, and positive `y` points downward.
12
- - Child positions are relative to their parent `Scene` or `RigidBody2D`.
12
+ - Child positions are relative to their parent `Scene`, `RigidBody2D`, or `TouchArea`.
13
13
  - Siblings draw in ascending `z` order; higher values appear later, on top. This is local to each parent, not a global depth order.
14
14
  - Update times and interpolation durations are in milliseconds. Convert `dt` to seconds for movement expressed in units per second.
15
15
  - Import components and hooks from `discodreamer`.
@@ -147,9 +147,17 @@ The first call initializes the shared slot; later calls do not reset it. Literal
147
147
 
148
148
  State that is no longer used is removed during frame cleanup. This also applies to `$` keys: sharing a slot does not make it permanent. If an entity disappears for a frame and returns later, expect its state to initialize again.
149
149
 
150
- ### `createDynamicId()`
150
+ ### `createDynamicId()` / `createDynamicId(count)`
151
151
 
152
- Returns a fresh string ID. Generate it when spawning an entity, store it with that entity, and reuse it across frames. Calling it on every render would give the entity a new identity every frame.
152
+ Returns a fresh string ID, or an array of fresh IDs when given a count.
153
+
154
+ ```ts
155
+ const id = createDynamicId(); // string
156
+ const ids = createDynamicId(3); // string[]
157
+ const [playerId, enemyId] = createDynamicId(2);
158
+ ```
159
+
160
+ Generate IDs when spawning entities, store them with those entities, and reuse them across frames. Calling this function every frame generates new identities each time. A count of zero or a negative count returns an empty array.
153
161
 
154
162
  ## Drawing components
155
163
 
@@ -322,7 +330,7 @@ A stateful moving body. Put drawing components and one or more `Bounds` inside i
322
330
  | `layer` | Unset | Layer name used by other colliders' filters; body mode only |
323
331
  | `collidesWith` | `[]` | Layers eligible for physical collision |
324
332
  | `hitsWith` | `[]` | Layers to report overlap with, without requiring physical response |
325
- | `ref` | Unset | Key returned by `gameRef` |
333
+ | `ref` | Unset | Complete result of `gameRef`, or its `key` |
326
334
  | `onChange` | Unset | Callback receiving `{ position, velocity }` |
327
335
  | `children` | `[]` | Visuals and bounds attached to the body |
328
336
 
@@ -339,7 +347,7 @@ Keep `x`, `y`, `velocity`, and `mass` props stable to let the simulation evolve.
339
347
 
340
348
  ### `Bounds`
341
349
 
342
- Defines collision geometry owned by its containing body. Choose either rectangle dimensions or a circle radius:
350
+ Defines collision geometry inside a `RigidBody2D`, or press-detection geometry inside a `TouchArea`. Choose either rectangle dimensions or a circle radius:
343
351
 
344
352
  ```tsx
345
353
  // Rectangle:
@@ -402,7 +410,7 @@ function PhysicsExample() {
402
410
 
403
411
  ### `gameRef<RigidBody2DSnapshot>(key)`
404
412
 
405
- Reads and updates a body's live stored state. Pass the returned `key` to the body's `ref`, and check `ready` before calling `snapshot()`:
413
+ Reads and updates a body's live stored state. Pass the complete result to the body's `ref`, or pass its `key`, and check `ready` before calling `snapshot()`:
406
414
 
407
415
  ```tsx
408
416
  function TrackedBody() {
@@ -413,14 +421,14 @@ function TrackedBody() {
413
421
  }
414
422
 
415
423
  return (
416
- <RigidBody2D key="player.body" ref={body.key} gravity={0}>
424
+ <RigidBody2D key="player.body" ref={body} gravity={0}>
417
425
  <Bounds width={32} height={32} outline />
418
426
  </RigidBody2D>
419
427
  );
420
428
  }
421
429
  ```
422
430
 
423
- Import `RigidBody2DSnapshot` with `import type`. The ref normally becomes ready on a later frame after the body attaches. A snapshot contains local `position`, `velocity`, `mass`, and an `update` method:
431
+ Import `RigidBody2DSnapshot` with `import type`. `ref={body.key}` remains supported. Use the public `GameRefResult<RigidBody2DSnapshot>` type when declaring a variable or prop that holds the complete result; `GameRef` is no longer a public named export in 1.3.0. The ref normally becomes ready on a later frame after the body attaches. A snapshot contains local `position`, `velocity`, `mass`, and an `update` method:
424
432
 
425
433
  ```ts
426
434
  update: (handler: (prev: BodyState) => BodyState) => void;
@@ -486,6 +494,8 @@ Reads current input; call it each frame. It invokes the listener immediately for
486
494
  | `touch` | `{ x, y }` | Each frame while the primary pointer is held |
487
495
  | `touchStart` | `{ x, y }` | Primary pointer press on the canvas |
488
496
  | `touchEnd` | `{ x, y }` | Primary pointer release or cancellation |
497
+ | `swipe` | Swipe details described below | A completed gesture qualifies as a swipe |
498
+ | `swipe-left`, `swipe-right`, `swipe-up`, `swipe-down` | Swipe details described below | A completed swipe qualifies for that direction |
489
499
 
490
500
  Key names use `KeyboardEvent.key`, for example `"ArrowLeft"`, `"a"`, or `" "` for space. Despite the `touch` names, pointer input supports mouse, touch, and pen, tracking one active pointer. Positions are relative to the canvas content area in the selected coordinate units. In scale mode, canvas-relative CSS-pixel positions are divided by the current unit size; DPR does not enter this conversion.
491
501
 
@@ -498,6 +508,68 @@ gameEvent("touchStart", ({ x, y }) => {
498
508
  });
499
509
  ```
500
510
 
511
+ Touch and swipe events share the same pointer input and track one active pointer at a time. A press must begin on the canvas; additional pointers are ignored until that interaction ends. Mouse input uses the main button. Pointer capture keeps the interaction tracked when it moves outside the canvas. The engine sets `touch-action: none` on the canvas. Cancellation, lost pointer capture, and window blur end the active touch, discard any pending swipe, and clear pointer tracking. A normal release reports its release position; cancellation uses the last known touch position.
512
+
513
+ All swipe listeners receive the same payload shape:
514
+
515
+ ```ts
516
+ {
517
+ direction: "left" | "right" | "up" | "down" | "unknown";
518
+ start: { x: number; y: number };
519
+ end: { x: number; y: number };
520
+ length: number;
521
+ duration: number;
522
+ }
523
+ ```
524
+
525
+ `start` and `end` are canvas-relative positions in the selected coordinate units. `length` is the straight-line displacement in game units, and `duration` is elapsed wall-clock milliseconds. Recognition uses the start and release points, rather than the full movement path. A swipe must last more than `0` and less than `1000` milliseconds and travel more than `30` game units. These thresholds are fixed internally.
526
+
527
+ Direction tests use a dot-product threshold of `0.65` against each cardinal direction. Their ranges overlap, so a diagonal can trigger two directional listeners as well as the general `swipe` listener. The general event reports a direction only when exactly one direction matches; otherwise it reports `"unknown"`. Each directional event reports its own matched direction.
528
+
529
+ ```ts
530
+ gameEvent("swipe", ({ start, end, length, duration, direction }) => {
531
+ console.log("Swipe", direction, start, end, length, duration);
532
+ });
533
+ gameEvent("swipe-left", () => sendMessage("player.dodge", "left"));
534
+ ```
535
+
536
+ ### `TouchArea`
537
+
538
+ Defines an area that detects pointer presses independently of physics. It accepts only `Bounds` children; supplying another kind of child throws an error. Multiple bounds can describe one area.
539
+
540
+ | Prop | Default | Purpose |
541
+ | --- | --- | --- |
542
+ | `key` | Required | Stable area identity |
543
+ | `label` | Required | Group/filter name used by `gameTouchArea` |
544
+ | `x`, `y`, `z` | `0` | Local position and sibling draw order |
545
+ | `children` | `[]` | Circular or rectangular `Bounds` defining the area |
546
+ | `debug` | `false` | Draws the area's key and label |
547
+ | `debugColor` | `"#ff0000"` | Color of those debug labels |
548
+
549
+ Bounds positions are relative to the area, including accumulated parent offsets. Rectangles use their top-left corner; circles use their center. Positions and sizes use the selected game units. Rectangle edges count as hits; a point exactly on a circle's circumference does not. Use `outline` and `style` on the bounds to display the geometry; `debug` on the area displays its identity labels.
550
+
551
+ Touch areas respond to `touchStart`, so mouse, finger, and pen presses all work. They do not require a `RigidBody2D`, and their bounds do not create physics contacts. Every matching area can report a hit, regardless of visual `z` order; overlapping areas do not block one another. Matching bounds with the same area key and label produce only one event per frame.
552
+
553
+ ### `gameTouchArea(listener, labelArray?)`
554
+
555
+ Reads touch-area hits; call it each frame. The listener runs immediately for each matching buffered event and receives `{ touch: { key, label, position } }`. `position` is the canvas-relative press position in the selected game units. The inner event has the public type `TouchAreaEvent`.
556
+
557
+ ```tsx
558
+ function StartButton() {
559
+ gameTouchArea(({ touch }) => {
560
+ if (touch.key === "start.button") sendMessage("game.start", null);
561
+ }, ["menu"]);
562
+
563
+ return (
564
+ <TouchArea key="start.button" label="menu" x={20} y={20}>
565
+ <Bounds width={120} height={48} outline style={{ fill: "navy" }} />
566
+ </TouchArea>
567
+ );
568
+ }
569
+ ```
570
+
571
+ Omitting `labelArray` accepts every label; an empty array accepts none. Hits are detected after tree construction and become available to hooks on the following frame. Reading does not consume them: each matching hook call can read the same events. The buffer is replaced by the next touch-area pass, so an event is available for one frame. These are press events, not continuous hold or release events. Multiple presses on the same key and label between frames are combined into one event, retaining the first matching press position.
572
+
501
573
  ### `gameViewport()`
502
574
 
503
575
  Returns the canvas's current size as `{ width, height }` in the selected coordinate units. In pixel mode these are CSS dimensions; in scale mode they are CSS dimensions divided by the current unit size. With `scaling: 0.01` and a nonzero canvas size, the shorter dimension is 100 game units. Use this for responsive placement; the engine handles the canvas backing resolution for device pixel ratio.
@@ -664,6 +736,48 @@ If `Sprite` display dimensions are omitted, they default to the source frame dim
664
736
 
665
737
  Use a final `true` condition as a fallback. A non-looping group holds its final frame. Call `animation.onAnimationFinish(handler)` each frame to handle its completion transition; it is not a persistent listener. Keep the source URL unchanged for an animation key, and use a positive frame size that fits the sheet.
666
738
 
739
+ ### `preloadImage(src)`
740
+
741
+ Starts loading an image before it is needed for drawing. Returns `void`. Repeated calls with the same source reuse the cached image.
742
+
743
+ ```ts
744
+ preloadImage("/background.png");
745
+ preloadImage("/player.png");
746
+ ```
747
+
748
+ Preloaded images share the cache used by `Sprite` and `gameAnimation`. Call this during setup to start loading assets early.
749
+
750
+ ### `gameImageStatus(src)`
751
+
752
+ Returns the current status of an image without starting a load:
753
+
754
+ | Status | Meaning |
755
+ | --- | --- |
756
+ | `"unset"` | The source has not been requested. |
757
+ | `"loading"` | Loading has started, but the image is not ready. |
758
+ | `"ready"` | The image is loaded and available for drawing. |
759
+ | `"error"` | The image failed to load. |
760
+
761
+ ```tsx
762
+ // During setup:
763
+ preloadImage("/player.png");
764
+
765
+ // Inside the game component, evaluated each frame:
766
+ const status = gameImageStatus("/player.png");
767
+
768
+ if (status === "error") {
769
+ return <Text value="Could not load the player image." />;
770
+ }
771
+
772
+ if (status !== "ready") {
773
+ return <Text value="Loading..." />;
774
+ }
775
+
776
+ return <Sprite src="/player.png" />;
777
+ ```
778
+
779
+ Failed images remain cached as `"error"`; calling `preloadImage` again does not retry them.
780
+
667
781
  ### `gameImage(src)`
668
782
 
669
783
  Returns a cached `HTMLImageElement` when loaded, otherwise `null`. Useful for checking dimensions or readiness. `Sprite` and `gameAnimation` already use it internally.
@@ -728,8 +842,41 @@ A sound key must be unique across the entire tree. Keeping the same key and sour
728
842
 
729
843
  `onLoad` runs once when the buffer is ready for that playback instance. `onComplete` runs once after natural playback completion, not when the node is removed. Browser audio may wait for a native pointer or keyboard gesture before becoming audible.
730
844
 
845
+ ## Vector and number helpers
846
+
847
+ These helpers are exported directly from `discodreamer`. Vectors use the public `Vector2d` shape, `{ x: number; y: number }`.
848
+
849
+ | Helper | Result |
850
+ | --- | --- |
851
+ | `vectorBetweenPoints(start, end)` | Displacement `{ x: end.x - start.x, y: end.y - start.y }` |
852
+ | `lengthOfVector(vector)` | Euclidean magnitude |
853
+ | `normalizeVector(vector)` | Unit-length vector in the same direction; `{ x: 0, y: 0 }` for a zero vector |
854
+ | `dotProduct(a, b)` | Scalar `a.x * b.x + a.y * b.y` |
855
+ | `angleOfVector(vector)` | Direction in degrees from `-180` to `180`; `0` for a zero vector |
856
+ | `angleBetweenPoints(start, end)` | Direction from start to end, using the same degree convention |
857
+
858
+ Angles use `atan2(y, x)`: right is `0`, down is `90`, and up is `-90` in canvas coordinates. `angleBetweenPoints` gives the direction between positions, rather than the angle between two independent vectors.
859
+
860
+ ```ts
861
+ const displacement = vectorBetweenPoints({ x: 10, y: 20 }, { x: 13, y: 24 });
862
+ lengthOfVector(displacement); // 5
863
+ normalizeVector(displacement); // { x: 0.6, y: 0.8 }
864
+ angleBetweenPoints({ x: 0, y: 0 }, { x: 0, y: 10 }); // 90
865
+ ```
866
+
867
+ ### `wrap(bounds, num)`
868
+
869
+ Wraps a number into a range that includes its minimum and excludes its maximum. Pass a number for `[0, max)`, or a tuple for `[min, max)`. Negative inputs wrap too. The maximum must be greater than the minimum; otherwise the helper throws.
870
+
871
+ ```ts
872
+ wrap(360, 370); // 10
873
+ wrap(360, -10); // 350
874
+ wrap([10, 20], 23); // 13
875
+ wrap([10, 20], 20); // 10
876
+ ```
877
+
731
878
  ## Public API scope
732
879
 
733
- The public components are `Scene`, `Sprite`, `Text`, `Rect`, `Circ`, `RigidBody2D`, `Bounds`, and `Sound`. The hooks described above, `DreamFactory`, `registerRoot`, `createComparator`, `createDynamicId`, `sendMessage`, `addCustomFont`, `getFontStatus`, and `isFontLoaded` are also exported.
880
+ The public components are `Scene`, `Sprite`, `Text`, `Rect`, `Circ`, `RigidBody2D`, `TouchArea`, `Bounds`, and `Sound`. The hooks described above, including `gameTouchArea`, plus `DreamFactory`, `registerRoot`, `createComparator`, `createDynamicId`, `preloadImage`, `sendMessage`, `addCustomFont`, `getFontStatus`, `isFontLoaded`, the vector helpers, and `wrap` are also exported.
734
881
 
735
- Public type exports are `SceneProps`, `GameObject`, `Viewport`, `Vector2d`, `RigidBody2DSnapshot`, `GameRef`, `GameRefResult`, and `EventType`. Other implementation files, including `Img`, `Txt`, and the unfinished global helpers, are not public package exports.
882
+ Public type exports are `SceneProps`, `GameObject`, `Viewport`, `Vector2d`, `RigidBody2DSnapshot`, `GameRefResult`, `EventType`, and `TouchAreaEvent`. `GameRef` is no longer publicly exported. Other implementation files, including `Img`, `Txt`, browser input handlers, touch-area collection helpers, and the unfinished global helpers, are not public package exports.
@@ -5,6 +5,8 @@
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "dev": "vite",
8
+ "dev:tunnel": "npx concurrently -k --raw \"npm run dev -- --strictPort\" \"npm run tunnel\"",
9
+ "tunnel": "npx cloudflared tunnel --url http://localhost:3000 2>&1 | node -e \"const seen = new Set(); require('node:readline').createInterface({ input: process.stdin }).on('line', line => { console.log(line); const url = line.match(/https:\\/\\/[a-z0-9-]+\\.trycloudflare\\.com/); if (url && !seen.has(url[0])) { seen.add(url[0]); require('qrcode-terminal').generate(url[0], { small: true }); } });\"",
8
10
  "typecheck": "tsc --noEmit",
9
11
  "build": "npm run typecheck && vite build",
10
12
  "preview": "vite preview"
@@ -18,10 +20,13 @@
18
20
  "license": "ISC",
19
21
  "devDependencies": {
20
22
  "@types/node": "^26.6.4",
23
+ "cloudflared": "^0.7.3",
24
+ "concurrently": "^10.0.7",
25
+ "qrcode-terminal": "^0.12.0",
21
26
  "typescript": "^7.0.2",
22
27
  "vite": "^8.3.2"
23
28
  },
24
29
  "dependencies": {
25
- "discodreamer": "^1.2.2"
30
+ "discodreamer": "^1.4.0"
26
31
  }
27
- }
32
+ }
@@ -19,6 +19,7 @@ export default defineConfig({
19
19
  },
20
20
  server: {
21
21
  port: 3000,
22
+ allowedHosts: [".trycloudflare.com"]
22
23
  },
23
24
  build: {
24
25
  outDir: "../dist",
package/test/cli.test.js DELETED
@@ -1,106 +0,0 @@
1
- const assert = require("node:assert/strict");
2
- const fs = require("node:fs/promises");
3
- const os = require("node:os");
4
- const path = require("node:path");
5
- const { spawnSync } = require("node:child_process");
6
- const { test } = require("node:test");
7
-
8
- const cli = path.resolve(__dirname, "../index.js");
9
- const reference = "DISCO_DREAMER_REFERENCE.md";
10
-
11
- async function workspace(t) {
12
- const directory = await fs.mkdtemp(path.join(os.tmpdir(), "dreamer-cli-"));
13
- t.after(() => fs.rm(directory, { recursive: true, force: true }));
14
- return directory;
15
- }
16
-
17
- function run(cwd, args) {
18
- const result = spawnSync(process.execPath, [cli, ...args], {
19
- cwd,
20
- encoding: "utf8",
21
- timeout: 10000,
22
- });
23
- assert.ifError(result.error);
24
- return result;
25
- }
26
-
27
- test("default app includes the reference and updates the package name", async (t) => {
28
- const cwd = await workspace(t);
29
- const result = run(cwd, ["my-app", "--skip-install"]);
30
- assert.equal(result.status, 0, result.stderr);
31
- assert.equal(await fs.readFile(path.join(cwd, "my-app", reference), "utf8"),
32
- await fs.readFile(path.resolve(__dirname, "../template", reference), "utf8"));
33
- const manifest = JSON.parse(await fs.readFile(path.join(cwd, "my-app/package.json"), "utf8"));
34
- assert.equal(manifest.name, "my-app");
35
- });
36
-
37
- for (const flag of ["--ref-only", "-ro"]) {
38
- test(`${flag} copies only the reference into the current existing project`, async (t) => {
39
- const cwd = await workspace(t);
40
- await fs.writeFile(path.join(cwd, "package.json"), '{"name":"existing"}\n');
41
- const result = run(cwd, [flag]);
42
- assert.equal(result.status, 0, result.stderr);
43
- assert.deepEqual((await fs.readdir(cwd)).sort(), [reference, "package.json"]);
44
- assert.equal(await fs.readFile(path.join(cwd, "package.json"), "utf8"), '{"name":"existing"}\n');
45
- assert.doesNotMatch(result.stdout, /npm install|npm run dev|Installing dependencies/);
46
- });
47
-
48
- test(`${flag} supports a new nested destination without npm name restrictions`, async (t) => {
49
- const cwd = await workspace(t);
50
- const result = run(cwd, ["docs/Reference Notes", flag]);
51
- assert.equal(result.status, 0, result.stderr);
52
- assert.deepEqual(await fs.readdir(path.join(cwd, "docs/Reference Notes")), [reference]);
53
- });
54
- }
55
-
56
- for (const flag of ["--exclude-reference", "-er"]) {
57
- test(`${flag} excludes the reference while copying the app`, async (t) => {
58
- const cwd = await workspace(t);
59
- const result = run(cwd, [flag, "my-app", "--skip-install"]);
60
- assert.equal(result.status, 0, result.stderr);
61
- await assert.rejects(fs.access(path.join(cwd, "my-app", reference)), { code: "ENOENT" });
62
- await fs.access(path.join(cwd, "my-app/package.json"));
63
- await fs.access(path.join(cwd, "my-app/src/index.tsx"));
64
- });
65
- }
66
-
67
- test("reference-only refuses to overwrite an existing reference", async (t) => {
68
- const cwd = await workspace(t);
69
- await fs.writeFile(path.join(cwd, reference), "custom reference");
70
- const result = run(cwd, ["--ref-only"]);
71
- assert.equal(result.status, 1);
72
- assert.match(result.stderr, /Reference already exists/);
73
- assert.equal(await fs.readFile(path.join(cwd, reference), "utf8"), "custom reference");
74
- });
75
-
76
- test("conflicting modes fail before creating files for all aliases", async (t) => {
77
- const cwd = await workspace(t);
78
- for (const refFlag of ["--ref-only", "-ro"]) {
79
- for (const excludeFlag of ["--exclude-reference", "-er"]) {
80
- const result = run(cwd, ["my-app", refFlag, excludeFlag]);
81
- assert.equal(result.status, 1);
82
- assert.match(result.stderr, /cannot be used together/);
83
- }
84
- }
85
- assert.deepEqual(await fs.readdir(cwd), []);
86
- });
87
-
88
- test("existing app safeguards and argument validation still apply", async (t) => {
89
- const cwd = await workspace(t);
90
- await fs.writeFile(path.join(cwd, "keep.txt"), "keep");
91
- for (const args of [[".", "--skip-install"], [".", "-er", "--skip-install"]]) {
92
- const result = run(cwd, args);
93
- assert.equal(result.status, 1);
94
- assert.match(result.stderr, /not an empty directory/);
95
- }
96
- assert.match(run(cwd, ["--unknown"]).stderr, /Unknown option/);
97
- assert.match(run(cwd, ["a", "b", "-ro"]).stderr, /only one project directory/);
98
- assert.deepEqual(await fs.readdir(cwd), ["keep.txt"]);
99
- });
100
-
101
- test("help documents both reference modes and aliases", async (t) => {
102
- const result = run(await workspace(t), ["--help"]);
103
- assert.equal(result.status, 0, result.stderr);
104
- assert.match(result.stdout, /-ro, --ref-only/);
105
- assert.match(result.stdout, /-er, --exclude-reference/);
106
- });