@caperjs/core 0.1.2 → 0.2.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.
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The `caper-runtime` virtual module: the entry the framework injects into
3
+ * index.html so an app needs no hand-written `src/index.ts` that only exists to
4
+ * import it.
5
+ *
6
+ * It installs the `Caper` global, hands the discovered scene/plugin/popup/entity
7
+ * /ui lists over, then boots the application from `virtual:caper-config`. When the
8
+ * preset was given a `pwa` option, the PWA runtime is appended here too — that is
9
+ * what makes `Caper.pwa` real, rather than the never-imported entry it used to
10
+ * live in.
11
+ */
12
+ import { pwaRuntimeSnippet } from './pwa.mjs';
13
+
14
+ export function createCaperRuntimePlugin({ pwa } = {}) {
15
+ const virtualModuleId = 'caper-runtime';
16
+ const resolvedVirtualModuleId = '\0' + virtualModuleId;
17
+
18
+ return {
19
+ name: 'vite-plugin-caper-runtime',
20
+ enforce: 'pre',
21
+ // Auto-inject the runtime entry so apps don't need a hand-written
22
+ // `src/index.ts` that just does `import('caper-runtime')`. Legacy HTML that
23
+ // already references the runtime (or a src/index.(ts|js) entry) is left
24
+ // untouched so existing apps keep working.
25
+ transformIndexHtml: {
26
+ order: 'pre',
27
+ handler(html) {
28
+ const referencesRuntime = html.includes('caper-runtime');
29
+ const referencesLegacyEntry = /<script[^>]*\bsrc=["'][^"']*src\/index\.(ts|js)["']/.test(html);
30
+ if (referencesRuntime || referencesLegacyEntry) {
31
+ return html;
32
+ }
33
+ return {
34
+ html,
35
+ tags: [
36
+ {
37
+ tag: 'script',
38
+ attrs: { type: 'module' },
39
+ children: 'import("caper-runtime");',
40
+ injectTo: 'body',
41
+ },
42
+ ],
43
+ };
44
+ },
45
+ },
46
+ resolveId(id) {
47
+ if (id === virtualModuleId) {
48
+ return resolvedVirtualModuleId;
49
+ }
50
+ },
51
+ load(id) {
52
+ if (id === resolvedVirtualModuleId) {
53
+ return `
54
+ import { pluginsList } from 'virtual:caper-plugins';
55
+ import { sceneList } from 'virtual:caper-scenes';
56
+ import { popupList } from 'virtual:caper-popups';
57
+ import { entityList } from 'virtual:caper-entities';
58
+ import { uiList } from 'virtual:caper-uis';
59
+ import { create, signalCaperReady, installCaperGlobal } from '@caperjs/core';
60
+
61
+ (globalThis).Caper = (globalThis).Caper || {};
62
+
63
+ // Install Caper.apps / Caper.ready() / Caper.automation immediately
64
+ // so automation drivers can await Caper.ready() before boot finishes.
65
+ installCaperGlobal();
66
+
67
+ try {
68
+ (globalThis).Caper.APP_NAME = __CAPER_APP_NAME;
69
+ (globalThis).Caper.APP_VERSION = __CAPER_APP_VERSION;
70
+ } catch (e) {
71
+ console.error('Failed to set app name and version', e);
72
+ }
73
+
74
+ (globalThis).Caper.sceneList = sceneList;
75
+ (globalThis).Caper.pluginsList = pluginsList;
76
+ (globalThis).Caper.popupList = popupList;
77
+ (globalThis).Caper.entityList = entityList;
78
+ (globalThis).Caper.uiList = uiList;
79
+
80
+ (globalThis).Caper.sceneIds = sceneList.map((scene) => scene.id);
81
+ (globalThis).Caper.pluginIds = pluginsList.map((plugin) => plugin.id);
82
+ (globalThis).Caper.popupIds = popupList.map((popup) => popup.id);
83
+ (globalThis).Caper.entityIds = entityList.map((entity) => entity.id);
84
+ (globalThis).Caper.uiIds = uiList.map((ui) => ui.id);
85
+
86
+ (globalThis).Caper.get = function (key) {
87
+ (globalThis).Caper = (globalThis).Caper || {};
88
+ return key ? (globalThis).Caper[key] : (globalThis).Caper;
89
+ };
90
+
91
+ async function bootstrap() {
92
+ const configModule = await import('virtual:caper-config');
93
+ const config = configModule.default;
94
+ (globalThis).Caper.config = config;
95
+ const app = await create(config);
96
+ const mains = import.meta.glob('/src/main.ts', { eager: true });
97
+ const mainPath = Object.keys(mains)[0];
98
+
99
+ if (mainPath) {
100
+ const mainModule = mains[mainPath];
101
+ if (mainModule && typeof mainModule.default === 'function') {
102
+ await mainModule.default(app);
103
+ }
104
+ }
105
+
106
+ signalCaperReady(app);
107
+ }
108
+
109
+ // Pass dev-ness through to the framework. This virtual module is
110
+ // transformed in the CONSUMER app's vite context, so import.meta.env
111
+ // is real here — inside the pre-built framework lib it has already
112
+ // been compiled away, so globals.ts reads Caper.__dev instead.
113
+ (globalThis).Caper.__dev = !!import.meta.env.DEV;
114
+
115
+ // Mark this app as managed by the vite runtime so create() does not
116
+ // double-signal readiness, then guard against a double bootstrap.
117
+ // (ES module caching already prevents re-evaluating this id; this is
118
+ // belt-and-braces.)
119
+ (globalThis).Caper.__runtimeManaged = true;
120
+ if (!(globalThis).__CAPER_BOOTSTRAPPED__) {
121
+ (globalThis).__CAPER_BOOTSTRAPPED__ = true;
122
+ bootstrap();
123
+ }
124
+ ${pwa ? pwaRuntimeSnippet(pwa) : ''}
125
+ `;
126
+ }
127
+ },
128
+ };
129
+ }
package/cli.mjs CHANGED
@@ -10,7 +10,6 @@ import { compress } from './cli/audio/index.mjs';
10
10
  import { create } from './cli/create.mjs';
11
11
  import { installPeerDeps } from './cli/install-peerdeps.mjs';
12
12
  import { update } from './cli/update.mjs';
13
- import { runBuild, runPreview, startDevServer } from './cli/vite.mjs';
14
13
  import { generateVoiceoverCSV } from './cli/voiceover/index.mjs';
15
14
 
16
15
  const currentVersion = process.versions.node;
@@ -48,15 +47,19 @@ switch (args[0]) {
48
47
  break;
49
48
  case 'version':
50
49
  break;
50
+ // `dev` / `build` / `preview` / `start` were removed in 0.2.0: a project runs
51
+ // vite directly now, with `caper()` in its own vite.config. Named here so the
52
+ // error says what to do rather than just "unknown subcommand".
51
53
  case 'dev':
52
54
  case 'start':
53
- await startDevServer();
54
- break;
55
55
  case 'build':
56
- await runBuild();
57
- break;
58
56
  case 'preview':
59
- await runPreview();
57
+ console.error(
58
+ bold(bgRed(white(`Caper - "${args[0]}" was removed in 0.2.0.`))),
59
+ red(`Run vite directly: \`vite\` to develop, \`vite build\` to build.`),
60
+ );
61
+ console.error(red(`Your vite.config should contain: plugins: [caper()] — from '@caperjs/core/vite'.`));
62
+ process.exit(1);
60
63
  break;
61
64
  case 'add':
62
65
  await add(args.slice(1));
package/extras/llms.txt CHANGED
@@ -163,10 +163,10 @@ test`) catches a lot, but UI/scene/asset behavior only shows up live.
163
163
  After any non-trivial change:
164
164
 
165
165
  1. Type-check the app (`pnpm types` or `tsc`).
166
- 2. Build cleanly (`caper build` or the app's `build` script).
167
- 3. **Ask the human to run `caper dev`** and eyeball the affected scene/feature.
166
+ 2. Build cleanly (`vite build`, or the app's `build` script).
167
+ 3. **Ask the human to run `vite`** (the app's `dev` script) and eyeball the affected scene/feature.
168
168
 
169
- Do **not** start `caper dev` yourself — it runs forever and will block. Ask the
169
+ Do **not** start the dev server yourself — it runs forever and will block. Ask the
170
170
  user to verify visually and report back.
171
171
 
172
172
  ---
@@ -210,9 +210,9 @@ subcommands run from the app root.
210
210
  | --- | --- |
211
211
  | `caper create [path] [--use-pnpm\|--use-yarn]` | Interactive scaffolder for a new Caper app. Also exposed as `create-caper`. |
212
212
  | `caper add scene \| plugin \| popup \| entity <Name> [--dir path]` | **Primary scaffolding entry.** Emits `src/<kind>s/<Name>.ts` with `defineX` wrapper + default class + the correct import shape. |
213
- | `caper dev` (alias `caper start`) | Start Vite dev server with Caper plugin pre-wired. |
214
- | `caper build` | Production build. |
215
- | `caper preview` | Build then preview locally. |
213
+ | `vite` | Start the dev server. Caper is wired in through `caper()` in the app's own `vite.config.ts`. |
214
+ | `vite build` | Production build. |
215
+ | `vite build && vite preview` | Build then preview locally. |
216
216
  | `caper update` | Update Caper to latest. |
217
217
  | `caper install` | Install peer deps (rarely needed; normally automatic). |
218
218
  | `caper vo generate [inputDir] [outputDir]` | Voiceover CSV generation from locales. Defaults: `./src/locales` → `./src/assets/audio/vo/csv`. |
@@ -230,9 +230,9 @@ required (plugins are the one exception — see §1.1).
230
230
 
231
231
  ```jsonc
232
232
  {
233
- "dev": "pnpm clean && caper dev",
234
- "build": "pnpm clean && caper build",
235
- "preview": "pnpm clean && caper preview",
233
+ "dev": "pnpm clean && vite",
234
+ "build": "pnpm clean && vite build",
235
+ "preview": "pnpm clean && vite build && vite preview",
236
236
  "types": "tsc",
237
237
  "clean": "rimraf dist .assetpack .cache",
238
238
  "lint": "eslint \"src/**/*.ts\""
@@ -915,7 +915,7 @@ export default class MyPlugin extends Plugin<MyPluginOptions> {
915
915
  - Listed dep IDs must exist in `caper.config.ts plugins: []` (see §1.1). Bootstrap
916
916
  throws with an actionable error if not.
917
917
  - Cycles fail bootstrap with the cycle path printed.
918
- - Build-time validation also warns at `caper dev`/`build` time.
918
+ - Build-time validation also warns at dev/build time.
919
919
 
920
920
  ### 9.5 Exposing API
921
921
 
@@ -1077,9 +1077,15 @@ compression, spritesheets, webfonts, audio, Spine, Rive, and the custom
1077
1077
  **`fontWeights`** pipe that runs before the webfont pipe to convert
1078
1078
  `{weight=X}` to `weights: [X]` for PixiJS.
1079
1079
 
1080
- ### 11.4 Per-app override: `.assetpack.mjs`
1080
+ ### 11.4 Per-app override: `caper({ assets })`
1081
1081
 
1082
- If `.assetpack.mjs` exists at the app root, Caper's framework config loads it
1082
+ Pass `assets` to the preset in `vite.config.ts`. It is deep-merged over caper's
1083
+ defaults, so overriding one knob keeps its siblings; `resolutions` replaces
1084
+ outright because it is a whole set of tiers. `assets: false` turns the pipeline
1085
+ off, and `assets: { pngFallback: true }` keeps the png twins that a production
1086
+ build otherwise prunes.
1087
+
1088
+ Removed in 0.2.0: `.assetpack.mjs`. If one exists at the app root, Caper
1083
1089
  via `import()` and merges it in. Only needed when injecting custom pipes.
1084
1090
 
1085
1091
  ### 11.5 Loading from code
@@ -1218,7 +1224,7 @@ plugins: [
1218
1224
 
1219
1225
  ## 14. Generated types & virtual modules
1220
1226
 
1221
- The Vite plugin ([config/vite.mjs](../config/vite.mjs)) generates types on every
1227
+ The Vite plugin ([build/](../build)) generates types on every
1222
1228
  dev reload. **Do not hand-edit them** — delete stale copies after renames and let
1223
1229
  the next build regen.
1224
1230
 
@@ -1278,9 +1284,9 @@ implementation of the auto-wiring. Know they exist for debugging.
1278
1284
 
1279
1285
  Types regen on dev-server restart. After renaming a scene / plugin / popup /
1280
1286
  entity: delete the stale `caper-app.d.ts` / `caper-assets.d.ts`, then
1281
- `caper dev` — they're re-emitted from scratch.
1287
+ the dev server — they're re-emitted from scratch.
1282
1288
 
1283
- **Source references:** [config/vite.mjs](../config/vite.mjs).
1289
+ **Source references:** [build/plugins/assetTypes.mjs](../build/plugins/assetTypes.mjs).
1284
1290
 
1285
1291
  ---
1286
1292
 
@@ -1491,8 +1497,8 @@ Type-check and build don't catch UI/scene/asset regressions. After changes:
1491
1497
 
1492
1498
  ```bash
1493
1499
  pnpm types # or tsc — compiles clean
1494
- pnpm build # or caper build — builds clean
1495
- # then ask the human to run `pnpm dev` (or `caper dev`) and report visually
1500
+ pnpm build # or vite build — builds clean
1501
+ # then ask the human to run `pnpm dev` and report visually
1496
1502
  ```
1497
1503
 
1498
1504
  Do not start the dev server yourself — it runs forever and blocks.
package/lib/caper.mjs CHANGED
@@ -202,7 +202,7 @@ function B(e, t) {
202
202
  }
203
203
  //#endregion
204
204
  //#region src/version.ts
205
- var V = "0.1.2", H = "8.19.0", kn = " ........ ..... ............ ............. ........... \n ............. ....... ................ ............. .............. \n .............. ......... ............... ............. .............. \n ..... ........... .............. ............ .............. \n ..... ...... ...... .............. ............. ............. \n .............. ...... ..... ............ ............. ..... ...... \n ................... ..... ..... ............. ..... ....... \n ................ .......... ............. ..... ..... ";
205
+ var V = "0.2.1", H = "8.19.0", kn = " ........ ..... ............ ............. ........... \n ............. ....... ................ ............. .............. \n .............. ......... ............... ............. .............. \n ..... ........... .............. ............ .............. \n ..... ...... ...... .............. ............. ............. \n .............. ...... ..... ............ ............. ..... ...... \n ................... ..... ..... ............. ..... ....... \n ................ .......... ............. ..... ..... ";
206
206
  function U() {
207
207
  let e = `\n${kn}\n\n v${V} | %cPixi.js v${H} %c| %chttps://github.com/anthonysapp/caper\n\n`;
208
208
  console.log(e, "color: #E91E63; font-weight: 600;", "color: inherit;", "color: #00BCD4; text-decoration: underline;");