@pie-element/cli 0.1.4-next.20261006160832 → 0.1.4

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 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/lib/schemas/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,eAAe,EAAE,SAAS,CAAU,CAAC;AAY3E,MAAM,WAAW,GAA+B;IAC9C,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,8FAA8F;AAC9F,+FAA+F;AAC/F,iDAAiD;AACjD,MAAM,WAAW,GAAgC;IAC/C,KAAK,EAAE,IAAI;IACX,aAAa,EAAE,IAAI;IACnB,OAAO,EAAE,KAAK;CACf,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAgB,EAAE,EAAE,CAAC,aAAa,IAAI,cAAc,CAAC;AAErF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAkB,EAAmB,EAAE,CACzE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAoB,CAAC;AAEzF,qEAAqE;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAyB,EAAgB,EAAE,CAC7E,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC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tF,CAAC;IACD,wBAAwB,CAAC,SAAS,CAAC,CAAC;IAEpC,MAAM,SAAS,GAAG,eAAe,CAAC;QAChC,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC;QAC3C,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,UAAU;QACjB,aAAa,EAAE,IAAI;QACnB,oBAAoB,EAAE,IAAI;KAC3B,CAAC,CAAC;IAEH,MAAM,OAAO,GAA4C,EAAE,CAAC;IAC5D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,YAAY,CACjD,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CACtB,CAAC;QAChB,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,GAAG;YACd,OAAO;YACP,GAAG,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;YAC7B,GAAG,IAAI;YACP,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9D,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { createGenerator } from 'ts-json-schema-generator';\n\n/**\n * JSON Schema generation for an element's contract types.\n *\n * An element declares its contract in `src/types.ts` as `<Name>Model`, `<Name>Configuration` and\n * `<Name>Session`, where `<Name>` is the PascalCase package name. Which schemas it publishes is set\n * by its `exports`: each `./schemas/<kind>.schema.json` entry is generated from the matching type.\n */\n\nexport const SCHEMA_KINDS = ['model', 'configuration', 'session'] as const;\n\nexport type SchemaKind = (typeof SCHEMA_KINDS)[number];\n\ntype JsonSchema = Record<string, unknown>;\n\ntype ElementManifest = {\n name: string;\n version: string;\n exports?: Record<string, unknown>;\n};\n\nconst TYPE_SUFFIX: Record<SchemaKind, string> = {\n model: 'Model',\n configuration: 'Configuration',\n session: 'Session',\n};\n\n// The authored model and configuration are closed at the root, as in the legacy schemas, so a\n// misspelled top-level key fails validation. Nested objects and the session, which players and\n// controllers write extra state into, stay open.\nconst CLOSED_ROOT: Record<SchemaKind, boolean> = {\n model: true,\n configuration: true,\n session: false,\n};\n\nexport const schemaExportKey = (kind: SchemaKind) => `./schemas/${kind}.schema.json`;\n\nexport const readElementManifest = (packageDir: string): ElementManifest =>\n JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf-8')) as ElementManifest;\n\n/** The schema kinds a package publishes, in `SCHEMA_KINDS` order. */\nexport const declaredSchemaKinds = (manifest: ElementManifest): SchemaKind[] =>\n SCHEMA_KINDS.filter((kind) => manifest.exports?.[schemaExportKey(kind)] !== undefined);\n\n/** `@pie-element/multiple-choice` → `MultipleChoice`. */\nexport const typeNamePrefix = (packageName: string) =>\n (packageName.split('/').pop() ?? packageName)\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n\nexport const schemaTypeName = (packageName: string, kind: SchemaKind) =>\n `${typeNamePrefix(packageName)}${TYPE_SUFFIX[kind]}`;\n\n/** Where the published schema resolves: the versioned file on jsDelivr. */\nexport const schemaId = (manifest: ElementManifest, kind: SchemaKind) =>\n `https://cdn.jsdelivr.net/npm/${manifest.name}@${manifest.version}/dist/schemas/${kind}.schema.json`;\n\n// `@deprecated reason` arrives as a string; JSON Schema's `deprecated` is a boolean, so the reason\n// moves into the description.\nconst normalizeDeprecated = (node: unknown): void => {\n if (Array.isArray(node)) {\n for (const item of node) normalizeDeprecated(item);\n return;\n }\n if (!node || typeof node !== 'object') return;\n const schema = node as JsonSchema;\n if (typeof schema.deprecated === 'string') {\n const reason = schema.deprecated.trim();\n schema.description = [schema.description, reason && `Deprecated: ${reason}`]\n .filter(Boolean)\n .join('\\n\\n');\n schema.deprecated = true;\n }\n for (const value of Object.values(schema)) normalizeDeprecated(value);\n};\n\n// TypeScript reads `@scope/name` in a JSDoc comment as a tag and drops the description from there\n// on, so a package name in a comment sits in backticks.\nconst assertNoBarePackageNames = (typesPath: string): void => {\n for (const [comment] of readFileSync(typesPath, 'utf-8').matchAll(/\\/\\*\\*[\\s\\S]*?\\*\\//g)) {\n const bare = comment.replace(/`[^`]*`/g, '').match(/(?:^|\\s)(@[\\w-]+\\/[\\w-]+)/);\n if (bare) {\n throw new Error(`${typesPath}: wrap ${bare[1]} in backticks; JSDoc reads it as a tag`);\n }\n }\n};\n\n/** Generates every schema the package at `packageDir` declares, keyed by kind. */\nexport const generateElementSchemas = (\n packageDir: string\n): Partial<Record<SchemaKind, JsonSchema>> => {\n const manifest = readElementManifest(packageDir);\n const kinds = declaredSchemaKinds(manifest);\n if (kinds.length === 0) return {};\n\n const typesPath = join(packageDir, 'src/types.ts');\n if (!existsSync(typesPath)) {\n throw new Error(`${manifest.name} declares schema exports but has no src/types.ts`);\n }\n assertNoBarePackageNames(typesPath);\n\n const generator = createGenerator({\n path: typesPath,\n tsconfig: join(packageDir, 'tsconfig.json'),\n expose: 'export',\n topRef: false,\n jsDoc: 'extended',\n skipTypeCheck: true,\n additionalProperties: true,\n });\n\n const schemas: Partial<Record<SchemaKind, JsonSchema>> = {};\n for (const kind of kinds) {\n const { $schema, ...body } = generator.createSchema(\n schemaTypeName(manifest.name, kind)\n ) as JsonSchema;\n normalizeDeprecated(body);\n schemas[kind] = {\n $schema,\n $id: schemaId(manifest, kind),\n ...body,\n ...(CLOSED_ROOT[kind] ? { additionalProperties: false } : {}),\n };\n }\n return schemas;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/cli",
3
- "version": "0.1.4-next.20261006160832",
3
+ "version": "0.1.4",
4
4
  "description": "CLI tools for managing PIE Elements NG",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,10 +23,11 @@
23
23
  "dependencies": {
24
24
  "@oclif/core": "^5.1.2",
25
25
  "@oclif/plugin-help": "^6.2.0",
26
- "@pie-element/element-bundler": "0.1.4-next.20261006160832",
26
+ "@pie-element/element-bundler": "0.1.3",
27
27
  "es-module-lexer": "^1.7.0",
28
28
  "glob": "^13.0.0",
29
29
  "open": "^10.0.3",
30
+ "ts-json-schema-generator": "^2.9.0",
30
31
  "webpack": "^5.104.1"
31
32
  },
32
33
  "oclif": {