@drincs/pixi-vn-json 1.13.14 → 1.13.16

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,90 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Generates the JSON Schemas used by `entranceTransitionKeySchemas`
4
+ * (src/actions/entrance-transitions.ts) from `@drincs/pixi-vn`'s own transition prop types —
5
+ * `ShowWithDissolveTransitionProps`, `ShowWithFadeTransitionProps`, `MoveInOutProps`,
6
+ * `ZoomInOutProps`, `PushInOutProps` — via this package's own generic
7
+ * TypeScript-interface-to-JSON-Schema generator (`schema-generator.mjs`).
8
+ *
9
+ * These 5 types are read straight off `@drincs/pixi-vn`'s own `.d.ts` (they're not declared
10
+ * anywhere in this package), so no `interfaceDir` is passed — every one of them is generated via
11
+ * the depth-capped "external" path, at the default `maxDepth: 1` ("branching" = 1): each prop
12
+ * type's own direct properties (duration, delay, ease, direction, ...) are typed correctly, but
13
+ * any property that is itself an object (e.g. a `position: { x, y }` some future transition prop
14
+ * might add) collapses to an opaque `{ type: "object" }` rather than being expanded.
15
+ *
16
+ * Run via `npm run generate-entrance-transition-schemas`; re-run whenever `@drincs/pixi-vn`'s
17
+ * transition prop types change.
18
+ */
19
+
20
+ import { writeFileSync } from "node:fs";
21
+ import { dirname, join, resolve } from "node:path";
22
+ import { fileURLToPath } from "node:url";
23
+ import { generateJsonSchema } from "./schema-generator.mjs";
24
+
25
+ const __dirname = dirname(fileURLToPath(import.meta.url));
26
+ const rootDir = resolve(__dirname, "..");
27
+
28
+ const canvasDts = join(rootDir, "node_modules", "@drincs", "pixi-vn", "dist", "canvas.d.ts");
29
+
30
+ const ROOT_TYPE_NAMES = [
31
+ "ShowWithDissolveTransitionProps",
32
+ "ShowWithFadeTransitionProps",
33
+ "MoveInOutProps",
34
+ "ZoomInOutProps",
35
+ "PushInOutProps",
36
+ ];
37
+
38
+ const { schemas, definitions } = generateJsonSchema({
39
+ rootFiles: [canvasDts],
40
+ rootTypeNames: ROOT_TYPE_NAMES,
41
+ compilerOptions: { types: [] },
42
+ });
43
+
44
+ /** Each entry must be self-contained (it's used standalone as one JSON Schema by any validator). */
45
+ function toStandaloneSchema(rootSchema) {
46
+ if (rootSchema.$ref) {
47
+ const key = rootSchema.$ref.replace("#/definitions/", "");
48
+ const { [key]: own, ...rest } = definitions;
49
+ const usedRefs = JSON.stringify(own).match(/#\/definitions\/[A-Za-z0-9_]+/g) ?? [];
50
+ if (usedRefs.length === 0) return own;
51
+ const neededDefinitions = Object.fromEntries(
52
+ usedRefs
53
+ .map((ref) => ref.replace("#/definitions/", ""))
54
+ .filter((k) => k in rest)
55
+ .map((k) => [k, rest[k]]),
56
+ );
57
+ return Object.keys(neededDefinitions).length > 0
58
+ ? { ...own, definitions: neededDefinitions }
59
+ : own;
60
+ }
61
+ return rootSchema;
62
+ }
63
+
64
+ const entranceTransitionKeySchemas = {
65
+ dissolve: toStandaloneSchema(schemas.ShowWithDissolveTransitionProps),
66
+ fade: toStandaloneSchema(schemas.ShowWithFadeTransitionProps),
67
+ movein: toStandaloneSchema(schemas.MoveInOutProps),
68
+ zoomin: toStandaloneSchema(schemas.ZoomInOutProps),
69
+ pushin: toStandaloneSchema(schemas.PushInOutProps),
70
+ };
71
+
72
+ const outPath = join(rootDir, "src", "actions", "entrance-transition-schemas.generated.ts");
73
+ const banner = `/**
74
+ * GENERATED FILE — do not edit by hand.
75
+ * Produced by \`scripts/generate-entrance-transition-schemas.mjs\` from
76
+ * \`@drincs/pixi-vn\`'s own transition prop types. Re-run that script (see its header comment) to
77
+ * refresh this file after those types change.
78
+ */
79
+
80
+ /**
81
+ * JSON Schemas (usable as \`@drincs/pixi-vn-ink\`'s \`HashtagHandlerOptions.keySchemas\` values, or
82
+ * with any other JSON Schema validator) for each entrance transition's own props, keyed by
83
+ * transition name.
84
+ */
85
+ export const entranceTransitionKeySchemas: Record<string, object> = `;
86
+
87
+ writeFileSync(outPath, `${banner}${JSON.stringify(entranceTransitionKeySchemas, null, 4)};\n`);
88
+
89
+ console.log(`Generated: ${outPath}`);
90
+ console.log(`Transitions: ${Object.keys(entranceTransitionKeySchemas).join(", ")}`);
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Generates a JSON Schema from the PixiVNJson TypeScript interface.
4
+ * Schema is saved to schemas/<version>/schema.json
5
+ *
6
+ * Thin wrapper around `generateJsonSchema` (schema-generator.mjs) — see that file for the actual
7
+ * AST-traversal/type-checker engine. `PixiVNJson` and everything under `src/schema` is treated as
8
+ * "local" (expanded fully, no depth cap); external types (from `@drincs/pixi-vn`, `pixi.js`, ...)
9
+ * are capped at `maxDepth: 3`, which reproduces this generator's historical depth exactly (its
10
+ * root call used to start at depth 0 with a cap of 2 — three total object levels before
11
+ * collapsing; `generateJsonSchema` starts the root call at depth 1, so the equivalent cap is 3).
12
+ */
13
+
14
+ import { mkdirSync, readFileSync, writeFileSync } from "fs";
15
+ import { dirname, join, resolve } from "path";
16
+ import { fileURLToPath } from "url";
17
+ import { generateJsonSchema } from "./schema-generator.mjs";
18
+
19
+ const __dirname = dirname(fileURLToPath(import.meta.url));
20
+ const rootDir = resolve(__dirname, "..");
21
+
22
+ const pkg = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"));
23
+ const version = pkg.version;
24
+
25
+ const interfaceDir = join(rootDir, "src", "schema");
26
+ const tsconfigPath = join(rootDir, "tsconfig.schema.json");
27
+
28
+ const { schemas, definitions } = generateJsonSchema({
29
+ rootFiles: [],
30
+ tsconfigPath,
31
+ interfaceDir,
32
+ rootTypeNames: ["PixiVNJson"],
33
+ maxDepth: 3,
34
+ includeAllLocalDeclarations: true,
35
+ // `StorageElementType`/`StorageObjectType` come from `@drincs/pixi-vn`, so they're external
36
+ // references with no local declaration to inspect — they'd otherwise fall through to the
37
+ // generic "external type" resolution. That's a problem specifically when they appear inside a
38
+ // union (e.g. `leftValue: StorageElementType | PixiVNJsonValueGet | ...`): `mergeUnion` filters
39
+ // out any branch with zero keys, so an empty-schema branch would silently vanish and the field
40
+ // would end up looking object-only instead of "primitive or object". Giving them real keys
41
+ // here keeps them in the union, same as the historical special-case.
42
+ typeNameOverrides: {
43
+ StorageElementType: { type: ["string", "number", "boolean", "null", "array", "object"] },
44
+ StorageObjectType: { type: "object" },
45
+ },
46
+ });
47
+
48
+ const rootSchema = definitions[schemas.PixiVNJson.$ref.replace("#/definitions/", "")];
49
+
50
+ // ─── Output ───────────────────────────────────────────────────────────────────
51
+
52
+ const schema = {
53
+ $schema: "http://json-schema.org/draft-07/schema#",
54
+ ...rootSchema,
55
+ definitions,
56
+ };
57
+
58
+ const outDir = join(rootDir, "schemas", version);
59
+ mkdirSync(outDir, { recursive: true });
60
+ const outPath = join(outDir, "schema.json");
61
+ writeFileSync(outPath, JSON.stringify(schema, null, 2) + "\n");
62
+
63
+ console.log(`Schema generated: ${outPath}`);
64
+ console.log(`Definitions: ${Object.keys(definitions).length}`);