@gtkx/cli 1.3.0 → 1.5.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 +5 -4
- package/dist/builder.d.ts +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +6 -6
- package/dist/builder.js.map +1 -1
- package/dist/codegen/run-codegen.d.ts +3 -2
- package/dist/codegen/run-codegen.d.ts.map +1 -1
- package/dist/codegen/run-codegen.js +41 -12
- package/dist/codegen/run-codegen.js.map +1 -1
- package/dist/commands/build.d.ts +0 -4
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +0 -5
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/codegen.d.ts.map +1 -1
- package/dist/commands/codegen.js +2 -4
- package/dist/commands/codegen.js.map +1 -1
- package/dist/deploy/depends.d.ts +2 -2
- package/dist/deploy/depends.d.ts.map +1 -1
- package/dist/deploy/depends.js +30 -15
- package/dist/deploy/depends.js.map +1 -1
- package/dist/deploy/freedesktop/localize.d.ts +6 -0
- package/dist/deploy/freedesktop/localize.d.ts.map +1 -0
- package/dist/deploy/freedesktop/localize.js +107 -0
- package/dist/deploy/freedesktop/localize.js.map +1 -0
- package/dist/deploy/install-hints.d.ts.map +1 -1
- package/dist/deploy/install-hints.js +5 -0
- package/dist/deploy/install-hints.js.map +1 -1
- package/dist/deploy/nfpm/config.js +1 -1
- package/dist/deploy/nfpm/config.js.map +1 -1
- package/dist/deploy/node-runtime/elf.d.ts +1 -1
- package/dist/deploy/node-runtime/elf.d.ts.map +1 -1
- package/dist/deploy/node-runtime/elf.js +2 -2
- package/dist/deploy/node-runtime/elf.js.map +1 -1
- package/dist/deploy/node-runtime/index.js +2 -2
- package/dist/deploy/node-runtime/index.js.map +1 -1
- package/dist/deploy/notices/collect.d.ts +3 -1
- package/dist/deploy/notices/collect.d.ts.map +1 -1
- package/dist/deploy/notices/collect.js +2 -2
- package/dist/deploy/notices/collect.js.map +1 -1
- package/dist/deploy/notices/packages.d.ts +2 -1
- package/dist/deploy/notices/packages.d.ts.map +1 -1
- package/dist/deploy/notices/packages.js +4 -27
- package/dist/deploy/notices/packages.js.map +1 -1
- package/dist/deploy/payload/icons.d.ts +7 -3
- package/dist/deploy/payload/icons.d.ts.map +1 -1
- package/dist/deploy/payload/icons.js +46 -28
- package/dist/deploy/payload/icons.js.map +1 -1
- package/dist/deploy/payload/launcher.d.ts.map +1 -1
- package/dist/deploy/payload/launcher.js +2 -0
- package/dist/deploy/payload/launcher.js.map +1 -1
- package/dist/deploy/payload/stage.d.ts +1 -1
- package/dist/deploy/payload/stage.d.ts.map +1 -1
- package/dist/deploy/payload/stage.js +23 -13
- package/dist/deploy/payload/stage.js.map +1 -1
- package/dist/deploy/run-deploy.d.ts.map +1 -1
- package/dist/deploy/run-deploy.js +149 -25
- package/dist/deploy/run-deploy.js.map +1 -1
- package/dist/deploy/settings/build-manifest.d.ts +9 -0
- package/dist/deploy/settings/build-manifest.d.ts.map +1 -0
- package/dist/deploy/settings/build-manifest.js +80 -0
- package/dist/deploy/settings/build-manifest.js.map +1 -0
- package/dist/deploy/settings/index.d.ts.map +1 -1
- package/dist/deploy/settings/index.js +9 -3
- package/dist/deploy/settings/index.js.map +1 -1
- package/dist/deploy/settings/libraries.d.ts +8 -0
- package/dist/deploy/settings/libraries.d.ts.map +1 -0
- package/dist/deploy/settings/libraries.js +39 -0
- package/dist/deploy/settings/libraries.js.map +1 -0
- package/dist/deploy/settings/paths.d.ts +3 -0
- package/dist/deploy/settings/paths.d.ts.map +1 -1
- package/dist/deploy/settings/paths.js +6 -32
- package/dist/deploy/settings/paths.js.map +1 -1
- package/dist/deploy/targets/appimage.d.ts.map +1 -1
- package/dist/deploy/targets/appimage.js +19 -13
- package/dist/deploy/targets/appimage.js.map +1 -1
- package/dist/deploy/targets/flatpak-manifest.d.ts +2 -1
- package/dist/deploy/targets/flatpak-manifest.d.ts.map +1 -1
- package/dist/deploy/targets/flatpak-manifest.js +5 -1
- package/dist/deploy/targets/flatpak-manifest.js.map +1 -1
- package/dist/deploy/targets/flatpak-source.d.ts.map +1 -1
- package/dist/deploy/targets/flatpak-source.js +30 -16
- package/dist/deploy/targets/flatpak-source.js.map +1 -1
- package/dist/deploy/tools.d.ts +6 -1
- package/dist/deploy/tools.d.ts.map +1 -1
- package/dist/deploy/tools.js +26 -1
- package/dist/deploy/tools.js.map +1 -1
- package/dist/deploy/types.d.ts +4 -4
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/deploy/types.js.map +1 -1
- package/dist/dev/icon-dir.d.ts +1 -1
- package/dist/dev/icon-dir.d.ts.map +1 -1
- package/dist/dev/icon-dir.js +20 -7
- package/dist/dev/icon-dir.js.map +1 -1
- package/dist/dev/locale-dir.d.ts +3 -0
- package/dist/dev/locale-dir.d.ts.map +1 -0
- package/dist/dev/locale-dir.js +17 -0
- package/dist/dev/locale-dir.js.map +1 -0
- package/dist/dev/runner-deps.d.ts.map +1 -1
- package/dist/dev/runner-deps.js +5 -1
- package/dist/dev/runner-deps.js.map +1 -1
- package/dist/dev/runner-main.d.ts.map +1 -1
- package/dist/dev/runner-main.js +6 -4
- package/dist/dev/runner-main.js.map +1 -1
- package/dist/dev/runner.d.ts +1 -1
- package/dist/dev/runner.d.ts.map +1 -1
- package/dist/dev/runner.js +7 -1
- package/dist/dev/runner.js.map +1 -1
- package/dist/dev/schema-dir.d.ts +1 -1
- package/dist/dev/schema-dir.d.ts.map +1 -1
- package/dist/dev/schema-dir.js +3 -1
- package/dist/dev/schema-dir.js.map +1 -1
- package/dist/dev/vite-dev-server.d.ts +1 -0
- package/dist/dev/vite-dev-server.d.ts.map +1 -1
- package/dist/dev/vite-dev-server.js.map +1 -1
- package/dist/i18n/binding-extractor.d.ts +30 -0
- package/dist/i18n/binding-extractor.d.ts.map +1 -0
- package/dist/i18n/binding-extractor.js +1324 -0
- package/dist/i18n/binding-extractor.js.map +1 -0
- package/dist/i18n/catalog-template.d.ts +3 -0
- package/dist/i18n/catalog-template.d.ts.map +1 -0
- package/dist/i18n/catalog-template.js +18 -0
- package/dist/i18n/catalog-template.js.map +1 -0
- package/dist/i18n/catalogs.d.ts +21 -0
- package/dist/i18n/catalogs.d.ts.map +1 -0
- package/dist/i18n/catalogs.js +139 -0
- package/dist/i18n/catalogs.js.map +1 -0
- package/dist/i18n/extractor-plugin.d.ts +8 -0
- package/dist/i18n/extractor-plugin.d.ts.map +1 -0
- package/dist/i18n/extractor-plugin.js +247 -0
- package/dist/i18n/extractor-plugin.js.map +1 -0
- package/dist/i18n/metadata-templates.d.ts +11 -0
- package/dist/i18n/metadata-templates.d.ts.map +1 -0
- package/dist/i18n/metadata-templates.js +11 -0
- package/dist/i18n/metadata-templates.js.map +1 -0
- package/dist/i18n/source-messages.d.ts +23 -0
- package/dist/i18n/source-messages.d.ts.map +1 -0
- package/dist/i18n/source-messages.js +403 -0
- package/dist/i18n/source-messages.js.map +1 -0
- package/dist/i18n/types.d.ts +10 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +108 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/internal/build-manifest.d.ts +20 -0
- package/dist/internal/build-manifest.d.ts.map +1 -0
- package/dist/internal/build-manifest.js +6 -0
- package/dist/internal/build-manifest.js.map +1 -0
- package/dist/internal/icon-path.d.ts +13 -0
- package/dist/internal/icon-path.d.ts.map +1 -0
- package/dist/internal/icon-path.js +86 -0
- package/dist/internal/icon-path.js.map +1 -0
- package/dist/internal/source-imports.d.ts +12 -0
- package/dist/internal/source-imports.d.ts.map +1 -0
- package/dist/internal/source-imports.js +123 -0
- package/dist/internal/source-imports.js.map +1 -0
- package/dist/mcp/client.d.ts +0 -1
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +11 -39
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/handlers.d.ts +2 -1
- package/dist/mcp/handlers.d.ts.map +1 -1
- package/dist/mcp/handlers.js.map +1 -1
- package/dist/mcp/widget-properties.d.ts.map +1 -1
- package/dist/mcp/widget-properties.js +3 -12
- package/dist/mcp/widget-properties.js.map +1 -1
- package/dist/settings/render.d.ts +10 -1
- package/dist/settings/render.d.ts.map +1 -1
- package/dist/settings/render.js +78 -20
- package/dist/settings/render.js.map +1 -1
- package/dist/settings/schema.d.ts +4 -3
- package/dist/settings/schema.d.ts.map +1 -1
- package/dist/settings/schema.js +124 -15
- package/dist/settings/schema.js.map +1 -1
- package/dist/vite-plugins/asset-emitter.d.ts +1 -1
- package/dist/vite-plugins/asset-emitter.d.ts.map +1 -1
- package/dist/vite-plugins/asset-emitter.js.map +1 -1
- package/dist/vite-plugins/asset-extensions.d.ts.map +1 -1
- package/dist/vite-plugins/asset-extensions.js +1 -0
- package/dist/vite-plugins/asset-extensions.js.map +1 -1
- package/dist/vite-plugins/asset-imports.d.ts +2 -1
- package/dist/vite-plugins/asset-imports.d.ts.map +1 -1
- package/dist/vite-plugins/asset-imports.js +39 -28
- package/dist/vite-plugins/asset-imports.js.map +1 -1
- package/dist/vite-plugins/asset-specifier.d.ts +13 -1
- package/dist/vite-plugins/asset-specifier.d.ts.map +1 -1
- package/dist/vite-plugins/asset-specifier.js +39 -1
- package/dist/vite-plugins/asset-specifier.js.map +1 -1
- package/dist/vite-plugins/build-manifest.d.ts +5 -0
- package/dist/vite-plugins/build-manifest.d.ts.map +1 -0
- package/dist/vite-plugins/{bundled-packages.js → build-manifest.js} +20 -14
- package/dist/vite-plugins/build-manifest.js.map +1 -0
- package/dist/vite-plugins/built-url.d.ts +1 -1
- package/dist/vite-plugins/built-url.d.ts.map +1 -1
- package/dist/vite-plugins/built-url.js +37 -24
- package/dist/vite-plugins/built-url.js.map +1 -1
- package/dist/vite-plugins/i18n.d.ts +5 -0
- package/dist/vite-plugins/i18n.d.ts.map +1 -0
- package/dist/vite-plugins/i18n.js +88 -0
- package/dist/vite-plugins/i18n.js.map +1 -0
- package/dist/vite-plugins/icons.d.ts +2 -1
- package/dist/vite-plugins/icons.d.ts.map +1 -1
- package/dist/vite-plugins/icons.js +25 -12
- package/dist/vite-plugins/icons.js.map +1 -1
- package/dist/vite-plugins/index.d.ts +2 -1
- package/dist/vite-plugins/index.d.ts.map +1 -1
- package/dist/vite-plugins/index.js +9 -5
- package/dist/vite-plugins/index.js.map +1 -1
- package/dist/vite-plugins/native.d.ts.map +1 -1
- package/dist/vite-plugins/native.js +23 -4
- package/dist/vite-plugins/native.js.map +1 -1
- package/dist/vite-plugins/resource-init-module.d.ts +7 -3
- package/dist/vite-plugins/resource-init-module.d.ts.map +1 -1
- package/dist/vite-plugins/resource-init-module.js +39 -14
- package/dist/vite-plugins/resource-init-module.js.map +1 -1
- package/dist/vite-plugins/resource-shared.d.ts +3 -1
- package/dist/vite-plugins/resource-shared.d.ts.map +1 -1
- package/dist/vite-plugins/resource-shared.js +3 -1
- package/dist/vite-plugins/resource-shared.js.map +1 -1
- package/dist/vite-plugins/resources.d.ts +1 -1
- package/dist/vite-plugins/resources.d.ts.map +1 -1
- package/dist/vite-plugins/resources.js +877 -86
- package/dist/vite-plugins/resources.js.map +1 -1
- package/dist/vite-plugins/self-contained.d.ts.map +1 -1
- package/dist/vite-plugins/self-contained.js +128 -135
- package/dist/vite-plugins/self-contained.js.map +1 -1
- package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -1
- package/dist/vite-plugins/settings-worker-env.js +6 -3
- package/dist/vite-plugins/settings-worker-env.js.map +1 -1
- package/dist/vite-plugins/settings.d.ts +3 -1
- package/dist/vite-plugins/settings.d.ts.map +1 -1
- package/dist/vite-plugins/settings.js +63 -23
- package/dist/vite-plugins/settings.js.map +1 -1
- package/env.d.ts +11 -192
- package/package.json +11 -10
- package/src/builder.ts +7 -7
- package/src/codegen/run-codegen.ts +64 -15
- package/src/commands/build.ts +0 -5
- package/src/commands/codegen.ts +2 -4
- package/src/deploy/depends.ts +47 -18
- package/src/deploy/freedesktop/localize.ts +144 -0
- package/src/deploy/install-hints.ts +5 -0
- package/src/deploy/nfpm/config.ts +1 -1
- package/src/deploy/node-runtime/elf.ts +3 -3
- package/src/deploy/node-runtime/index.ts +2 -2
- package/src/deploy/notices/collect.ts +4 -2
- package/src/deploy/notices/packages.ts +5 -43
- package/src/deploy/payload/icons.ts +64 -34
- package/src/deploy/payload/launcher.ts +2 -0
- package/src/deploy/payload/stage.ts +40 -12
- package/src/deploy/run-deploy.ts +214 -24
- package/src/deploy/settings/build-manifest.ts +122 -0
- package/src/deploy/settings/index.ts +9 -4
- package/src/deploy/settings/libraries.ts +57 -0
- package/src/deploy/settings/paths.ts +10 -47
- package/src/deploy/targets/appimage.ts +32 -15
- package/src/deploy/targets/flatpak-manifest.ts +7 -1
- package/src/deploy/targets/flatpak-source.ts +42 -20
- package/src/deploy/tools.ts +35 -0
- package/src/deploy/types.ts +4 -4
- package/src/dev/icon-dir.ts +31 -7
- package/src/dev/locale-dir.ts +22 -0
- package/src/dev/runner-deps.ts +5 -1
- package/src/dev/runner-main.ts +6 -4
- package/src/dev/runner.ts +10 -2
- package/src/dev/schema-dir.ts +3 -1
- package/src/dev/vite-dev-server.ts +1 -0
- package/src/i18n/binding-extractor.ts +1969 -0
- package/src/i18n/catalog-template.ts +24 -0
- package/src/i18n/catalogs.ts +216 -0
- package/src/i18n/extractor-plugin.ts +413 -0
- package/src/i18n/metadata-templates.ts +29 -0
- package/src/i18n/source-messages.ts +608 -0
- package/src/i18n/types.ts +154 -0
- package/src/internal/build-manifest.ts +32 -0
- package/src/internal/icon-path.ts +127 -0
- package/src/internal/source-imports.ts +171 -0
- package/src/mcp/client.ts +17 -44
- package/src/mcp/handlers.ts +7 -6
- package/src/mcp/widget-properties.ts +3 -14
- package/src/settings/render.ts +113 -21
- package/src/settings/schema.ts +192 -17
- package/src/vite-plugins/asset-emitter.ts +1 -1
- package/src/vite-plugins/asset-extensions.ts +1 -0
- package/src/vite-plugins/asset-imports.ts +62 -33
- package/src/vite-plugins/asset-specifier.ts +73 -1
- package/src/vite-plugins/{bundled-packages.ts → build-manifest.ts} +30 -19
- package/src/vite-plugins/built-url.ts +49 -28
- package/src/vite-plugins/i18n.ts +146 -0
- package/src/vite-plugins/icons.ts +33 -14
- package/src/vite-plugins/index.ts +15 -5
- package/src/vite-plugins/native.ts +31 -4
- package/src/vite-plugins/resource-init-module.ts +44 -15
- package/src/vite-plugins/resource-shared.ts +4 -0
- package/src/vite-plugins/resources.ts +1397 -100
- package/src/vite-plugins/self-contained.ts +150 -169
- package/src/vite-plugins/settings-worker-env.ts +7 -3
- package/src/vite-plugins/settings.ts +89 -21
- package/dist/vite-plugins/bundled-packages.d.ts +0 -5
- package/dist/vite-plugins/bundled-packages.d.ts.map +0 -1
- package/dist/vite-plugins/bundled-packages.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as GObject from "@gtkx/gi/gobject";
|
|
2
2
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
3
|
import { propertyNotFoundError } from "@gtkx/mcp/internal";
|
|
4
|
-
import { getHandle, getInstanceType, TYPE_ENUM, TYPE_FLAGS, typeIsA, typeName, } from "@gtkx/runtime";
|
|
4
|
+
import { getHandle, getInstanceType, isReadableProperty, TYPE_ENUM, TYPE_FLAGS, typeIsA, typeName, } from "@gtkx/runtime";
|
|
5
5
|
import { fromValue, getValueType } from "@gtkx/runtime/internal";
|
|
6
|
-
import {
|
|
6
|
+
import { errorMessage, kebabCase } from "@gtkx/utils";
|
|
7
7
|
const SCALAR_TYPES = new Set(["string", "number", "boolean"]);
|
|
8
8
|
const canonicalName = (name) => kebabCase(name).replaceAll("_", "-");
|
|
9
9
|
const widgetTypeName = (widget) => typeName(getInstanceType(widget)) ?? widget.constructor.name;
|
|
@@ -18,15 +18,6 @@ function prototypesFor(widget) {
|
|
|
18
18
|
}
|
|
19
19
|
return prototypes;
|
|
20
20
|
}
|
|
21
|
-
function getAccessor(widget, member) {
|
|
22
|
-
for (const prototype of prototypesFor(widget)) {
|
|
23
|
-
const descriptor = Object.getOwnPropertyDescriptor(prototype, member);
|
|
24
|
-
if (descriptor !== undefined) {
|
|
25
|
-
return descriptor;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
21
|
function getReadableNames(prototype) {
|
|
31
22
|
const descriptors = Object.entries(Object.getOwnPropertyDescriptors(prototype));
|
|
32
23
|
return descriptors.filter(([, descriptor]) => descriptor.get !== undefined).map(([member]) => kebabCase(member));
|
|
@@ -36,7 +27,7 @@ function readablePropertyNames(widget) {
|
|
|
36
27
|
return [...new Set(names)].toSorted(byName);
|
|
37
28
|
}
|
|
38
29
|
const requireReadableProperty = (widget, property) => {
|
|
39
|
-
if (
|
|
30
|
+
if (isReadableProperty(getInstanceType(widget), property)) {
|
|
40
31
|
return;
|
|
41
32
|
}
|
|
42
33
|
throw propertyNotFoundError(widgetTypeName(widget), property, readablePropertyNames(widget));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-properties.js","sourceRoot":"","sources":["../../src/mcp/widget-properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAA2B,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAEH,SAAS,EACT,eAAe,EAEf,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMjE,MAAM,YAAY,GAAgB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3E,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GA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EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { propertyNotFoundError, type SerializedProperty } from \"@gtkx/mcp/internal\";\nimport {\n type ExternalObject,\n getHandle,\n getInstanceType,\n type Handle,\n TYPE_ENUM,\n TYPE_FLAGS,\n typeIsA,\n typeName,\n} from \"@gtkx/runtime\";\nimport { fromValue, getValueType } from \"@gtkx/runtime/internal\";\nimport { camelCase, errorMessage, kebabCase } from \"@gtkx/utils\";\nimport type { WidgetRegistry } from \"./widget-registry.js\";\n\ntype PropertyRepresentation = Omit<SerializedProperty, \"type\">;\ntype NativeProperty = { type: bigint; handle: ExternalObject<Handle> };\n\nconst SCALAR_TYPES: Set<string> = new Set([\"string\", \"number\", \"boolean\"]);\n\nconst canonicalName = (name: string): string => kebabCase(name).replaceAll(\"_\", \"-\");\nconst widgetTypeName = (widget: Gtk.Widget): string => typeName(getInstanceType(widget)) ?? widget.constructor.name;\nconst byName = (left: string, right: string): number => left.localeCompare(right);\n\nconst isScalar = (value: unknown): value is string | number | boolean | null =>\n value === null || SCALAR_TYPES.has(typeof value);\n\nfunction prototypesFor(widget: Gtk.Widget): object[] {\n const prototypes: object[] = [];\n let prototype = Object.getPrototypeOf(widget) as object | null;\n\n while (prototype !== null && prototype !== Object.prototype) {\n prototypes.push(prototype);\n prototype = Object.getPrototypeOf(prototype) as object | null;\n }\n\n return prototypes;\n}\n\nfunction getAccessor(widget: Gtk.Widget, member: string): PropertyDescriptor | undefined {\n for (const prototype of prototypesFor(widget)) {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, member);\n\n if (descriptor !== undefined) {\n return descriptor;\n }\n }\n\n return undefined;\n}\n\nfunction getReadableNames(prototype: object): string[] {\n const descriptors = Object.entries(Object.getOwnPropertyDescriptors(prototype));\n\n return descriptors.filter(([, descriptor]) => descriptor.get !== undefined).map(([member]) => kebabCase(member));\n}\n\nfunction readablePropertyNames(widget: Gtk.Widget): string[] {\n const names = prototypesFor(widget).flatMap((prototype) => getReadableNames(prototype));\n\n return [...new Set(names)].toSorted(byName);\n}\n\nconst requireReadableProperty = (widget: Gtk.Widget, property: string): void => {\n if (getAccessor(widget, camelCase(property))?.get !== undefined) {\n return;\n }\n\n throw propertyNotFoundError(widgetTypeName(widget), property, readablePropertyNames(widget));\n};\n\nfunction readNativeProperty(widget: Gtk.Widget, property: string): NativeProperty {\n const value = new GObject.Value();\n widget.getProperty(property, value);\n const handle = getHandle(value);\n\n return { type: getValueType(handle), handle };\n}\n\nfunction describeObjectValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (typeof value !== \"object\" || value === null) {\n return { value: String(value) };\n }\n\n const name = typeName(getInstanceType(value)) ?? value.constructor.name;\n\n if (!(value instanceof Gtk.Widget)) {\n return { value: name };\n }\n\n registry.register(value);\n\n return { value: name, widgetId: registry.getOrCreateId(value) };\n}\n\nfunction representValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (isScalar(value)) {\n return { value };\n }\n\n if (typeof value === \"bigint\") {\n return { value: value.toString() };\n }\n\n if (Array.isArray(value)) {\n return { value: value.map(String) };\n }\n\n return describeObjectValue(value, registry);\n}\n\nfunction representNativeProperty(native: NativeProperty, registry: WidgetRegistry): PropertyRepresentation {\n if (typeIsA(native.type, TYPE_ENUM)) {\n return { value: GObject.enumToString(native.type, Number(fromValue(native.handle))) };\n }\n\n if (typeIsA(native.type, TYPE_FLAGS)) {\n return { value: GObject.flagsToString(native.type, Number(fromValue(native.handle))) };\n }\n\n return representValue(fromValue(native.handle), registry);\n}\n\nfunction serializeProperty(widget: Gtk.Widget, property: string, registry: WidgetRegistry): SerializedProperty {\n const native = readNativeProperty(widget, property);\n const type = typeName(native.type) ?? String(native.type);\n\n try {\n return { type, ...representNativeProperty(native, registry) };\n } catch (error) {\n return { type, value: null, note: `cannot be represented over MCP: ${errorMessage(error)}` };\n }\n}\n\nfunction readWidgetProperties(\n widget: Gtk.Widget,\n properties: string[],\n registry: WidgetRegistry,\n): Record<string, SerializedProperty> {\n const values: Record<string, SerializedProperty> = {};\n\n for (const name of properties) {\n const property = canonicalName(name);\n requireReadableProperty(widget, property);\n values[property] = serializeProperty(widget, property, registry);\n }\n\n return values;\n}\n\nexport { readWidgetProperties };\n"]}
|
|
1
|
+
{"version":3,"file":"widget-properties.js","sourceRoot":"","sources":["../../src/mcp/widget-properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAA2B,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAEH,SAAS,EACT,eAAe,EAEf,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMtD,MAAM,YAAY,GAAgB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3E,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrF,MAAM,cAAc,GAAG,CAAC,MAAkB,EAAU,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;AACpH,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAElF,MA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D,IAAI,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,GAAG,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;IAClE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,mCAAmC,YAAY,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;IACjG,CAAC;AACL,CAAC;AAED,SAAS,oBAAoB,CACzB,MAAkB,EAClB,UAAoB,EACpB,QAAwB;IAExB,MAAM,MAAM,GAAuC,EAAE,CAAC;IAEtD,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QACrC,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC1C,MAAM,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { propertyNotFoundError, type SerializedProperty } from \"@gtkx/mcp/internal\";\nimport {\n type ExternalObject,\n getHandle,\n getInstanceType,\n type Handle,\n isReadableProperty,\n TYPE_ENUM,\n TYPE_FLAGS,\n typeIsA,\n typeName,\n} from \"@gtkx/runtime\";\nimport { fromValue, getValueType } from \"@gtkx/runtime/internal\";\nimport { errorMessage, kebabCase } from \"@gtkx/utils\";\nimport type { WidgetRegistry } from \"./widget-registry.js\";\n\ntype PropertyRepresentation = Omit<SerializedProperty, \"type\">;\ntype NativeProperty = { type: bigint; handle: ExternalObject<Handle> };\n\nconst SCALAR_TYPES: Set<string> = new Set([\"string\", \"number\", \"boolean\"]);\n\nconst canonicalName = (name: string): string => kebabCase(name).replaceAll(\"_\", \"-\");\nconst widgetTypeName = (widget: Gtk.Widget): string => typeName(getInstanceType(widget)) ?? widget.constructor.name;\nconst byName = (left: string, right: string): number => left.localeCompare(right);\n\nconst isScalar = (value: unknown): value is string | number | boolean | null =>\n value === null || SCALAR_TYPES.has(typeof value);\n\nfunction prototypesFor(widget: Gtk.Widget): object[] {\n const prototypes: object[] = [];\n let prototype = Object.getPrototypeOf(widget) as object | null;\n\n while (prototype !== null && prototype !== Object.prototype) {\n prototypes.push(prototype);\n prototype = Object.getPrototypeOf(prototype) as object | null;\n }\n\n return prototypes;\n}\n\nfunction getReadableNames(prototype: object): string[] {\n const descriptors = Object.entries(Object.getOwnPropertyDescriptors(prototype));\n\n return descriptors.filter(([, descriptor]) => descriptor.get !== undefined).map(([member]) => kebabCase(member));\n}\n\nfunction readablePropertyNames(widget: Gtk.Widget): string[] {\n const names = prototypesFor(widget).flatMap((prototype) => getReadableNames(prototype));\n\n return [...new Set(names)].toSorted(byName);\n}\n\nconst requireReadableProperty = (widget: Gtk.Widget, property: string): void => {\n if (isReadableProperty(getInstanceType(widget), property)) {\n return;\n }\n\n throw propertyNotFoundError(widgetTypeName(widget), property, readablePropertyNames(widget));\n};\n\nfunction readNativeProperty(widget: Gtk.Widget, property: string): NativeProperty {\n const value = new GObject.Value();\n widget.getProperty(property, value);\n const handle = getHandle(value);\n\n return { type: getValueType(handle), handle };\n}\n\nfunction describeObjectValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (typeof value !== \"object\" || value === null) {\n return { value: String(value) };\n }\n\n const name = typeName(getInstanceType(value)) ?? value.constructor.name;\n\n if (!(value instanceof Gtk.Widget)) {\n return { value: name };\n }\n\n registry.register(value);\n\n return { value: name, widgetId: registry.getOrCreateId(value) };\n}\n\nfunction representValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (isScalar(value)) {\n return { value };\n }\n\n if (typeof value === \"bigint\") {\n return { value: value.toString() };\n }\n\n if (Array.isArray(value)) {\n return { value: value.map(String) };\n }\n\n return describeObjectValue(value, registry);\n}\n\nfunction representNativeProperty(native: NativeProperty, registry: WidgetRegistry): PropertyRepresentation {\n if (typeIsA(native.type, TYPE_ENUM)) {\n return { value: GObject.enumToString(native.type, Number(fromValue(native.handle))) };\n }\n\n if (typeIsA(native.type, TYPE_FLAGS)) {\n return { value: GObject.flagsToString(native.type, Number(fromValue(native.handle))) };\n }\n\n return representValue(fromValue(native.handle), registry);\n}\n\nfunction serializeProperty(widget: Gtk.Widget, property: string, registry: WidgetRegistry): SerializedProperty {\n const native = readNativeProperty(widget, property);\n const type = typeName(native.type) ?? String(native.type);\n\n try {\n return { type, ...representNativeProperty(native, registry) };\n } catch (error) {\n return { type, value: null, note: `cannot be represented over MCP: ${errorMessage(error)}` };\n }\n}\n\nfunction readWidgetProperties(\n widget: Gtk.Widget,\n properties: string[],\n registry: WidgetRegistry,\n): Record<string, SerializedProperty> {\n const values: Record<string, SerializedProperty> = {};\n\n for (const name of properties) {\n const property = canonicalName(name);\n requireReadableProperty(widget, property);\n values[property] = serializeProperty(widget, property, registry);\n }\n\n return values;\n}\n\nexport { readWidgetProperties };\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { ParsedSchemaFile } from "./parser.js";
|
|
2
|
+
type EnvAssetDeclarations = {
|
|
3
|
+
blocked: string[];
|
|
4
|
+
icons: string[];
|
|
5
|
+
legacy: string[];
|
|
6
|
+
resources: string[];
|
|
7
|
+
};
|
|
8
|
+
type EnvModuleOptions = {
|
|
9
|
+
references?: string[];
|
|
10
|
+
};
|
|
2
11
|
declare const renderRuntimeModule: (file: ParsedSchemaFile) => string;
|
|
3
|
-
declare const renderEnvModule: (files: ParsedSchemaFile[]) => string;
|
|
12
|
+
declare const renderEnvModule: (files: ParsedSchemaFile[], assetDeclarations?: EnvAssetDeclarations, options?: EnvModuleOptions) => string;
|
|
4
13
|
export { renderRuntimeModule, renderEnvModule };
|
|
5
14
|
//# sourceMappingURL=render.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2B,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2B,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAO7E,KAAK,oBAAoB,GAAG;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AA6DF,QAAA,MAAM,mBAAmB,GAAI,MAAM,gBAAgB,KAAG,MA0BrD,CAAC;AA6HF,QAAA,MAAM,eAAe,GACjB,OAAO,gBAAgB,EAAE,EACzB,oBAAoB,oBAAoB,EACxC,UAAS,gBAAqB,KAC/B,MAuBF,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/settings/render.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import { upperFirst } from "@gtkx/utils";
|
|
1
|
+
import { camelCase, sanitizeIdentifier, upperFirst } from "@gtkx/utils";
|
|
2
2
|
const GTKX_ENV_MODULE_HEADER = `/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* \`gtkx build\`; do not edit.
|
|
3
|
+
* Project import declarations generated by GTKX. Regenerated by
|
|
4
|
+
* \`gtkx codegen\`, \`gtkx dev\`, and \`gtkx build\`; do not edit.
|
|
6
5
|
*/`;
|
|
7
6
|
const ENUM_KIND = "enum";
|
|
8
7
|
const FLAGS_KIND = "flags";
|
|
8
|
+
const ID_SEPARATOR = /[._]/;
|
|
9
|
+
const NAME_SEPARATOR = "_";
|
|
9
10
|
const toJsStringLiteral = (value) => JSON.stringify(value).replaceAll("\u{2028}", String.raw `\u2028`).replaceAll("\u{2029}", String.raw `\u2029`);
|
|
10
|
-
const getExportName = (schemaId) => schemaId.
|
|
11
|
+
const getExportName = (schemaId) => sanitizeIdentifier(schemaId.split(ID_SEPARATOR).map((part) => camelCase(part)).join(NAME_SEPARATOR));
|
|
12
|
+
const collisionError = (file, taken, schemaId, name) => new Error(`${file.fileName} declares ${taken} and ${schemaId}, which both export \`${name}\`. ` +
|
|
13
|
+
"Rename one of the schema ids so that every schema in the file gets an export of its own.");
|
|
14
|
+
const getNamedSchemas = (file) => {
|
|
15
|
+
const owners = new Map();
|
|
16
|
+
return file.schemas.map((schema) => {
|
|
17
|
+
const exportName = getExportName(schema.id);
|
|
18
|
+
const taken = owners.get(exportName);
|
|
19
|
+
if (taken !== undefined) {
|
|
20
|
+
throw collisionError(file, taken, schema.id, exportName);
|
|
21
|
+
}
|
|
22
|
+
owners.set(exportName, schema.id);
|
|
23
|
+
return { schema, exportName };
|
|
24
|
+
});
|
|
25
|
+
};
|
|
11
26
|
const runtimeKindForKey = (key) => {
|
|
12
27
|
if (key.enumId !== null) {
|
|
13
28
|
return ENUM_KIND;
|
|
@@ -23,21 +38,22 @@ const getRuntimeKeys = (schema) => {
|
|
|
23
38
|
};
|
|
24
39
|
const renderRuntimeModule = (file) => {
|
|
25
40
|
const lines = [];
|
|
26
|
-
|
|
41
|
+
const named = getNamedSchemas(file);
|
|
42
|
+
for (const [index, { schema, exportName }] of named.entries()) {
|
|
27
43
|
const keysName = `keys_${String(index)}`;
|
|
28
44
|
const id = toJsStringLiteral(schema.id);
|
|
29
45
|
lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);
|
|
30
46
|
if (schema.path === null) {
|
|
31
|
-
lines.push(`export const ${
|
|
47
|
+
lines.push(`export const ${exportName} = { id: ${id}, keys: ${keysName}, ` +
|
|
32
48
|
`at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`);
|
|
33
49
|
}
|
|
34
50
|
else {
|
|
35
|
-
lines.push(`export const ${
|
|
51
|
+
lines.push(`export const ${exportName} = { id: ${id}, path: null, keys: ${keysName} };`);
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
|
-
const first =
|
|
54
|
+
const first = named[0];
|
|
39
55
|
if (first !== undefined) {
|
|
40
|
-
lines.push(`export default ${
|
|
56
|
+
lines.push(`export default ${first.exportName};`);
|
|
41
57
|
}
|
|
42
58
|
return lines.join("\n");
|
|
43
59
|
};
|
|
@@ -73,8 +89,7 @@ const boundRefTypeLines = (interfaceName, indent) => [
|
|
|
73
89
|
`${indent}path: string | null;`,
|
|
74
90
|
`${indent}keys: ${interfaceName};`,
|
|
75
91
|
];
|
|
76
|
-
const renderSchemaConst = (schema, interfaceName) => {
|
|
77
|
-
const exportName = getExportName(schema.id);
|
|
92
|
+
const renderSchemaConst = ({ schema, exportName }, interfaceName) => {
|
|
78
93
|
if (schema.path !== null) {
|
|
79
94
|
return [
|
|
80
95
|
` const ${exportName}: {`,
|
|
@@ -94,15 +109,15 @@ const renderSchemaConst = (schema, interfaceName) => {
|
|
|
94
109
|
];
|
|
95
110
|
};
|
|
96
111
|
const renderFileModule = (file, usedNames) => {
|
|
97
|
-
const lines = [`declare module
|
|
112
|
+
const lines = [`declare module ${toJsStringLiteral(file.fileName)} {`];
|
|
98
113
|
const exportNames = [];
|
|
99
|
-
for (const [index,
|
|
114
|
+
for (const [index, named] of getNamedSchemas(file).entries()) {
|
|
100
115
|
if (index > 0) {
|
|
101
116
|
lines.push("");
|
|
102
117
|
}
|
|
103
|
-
const interfaceName = allocateInterfaceName(schema.id, usedNames);
|
|
104
|
-
lines.push(...renderKeysType(interfaceName, schema), "", ...renderSchemaConst(
|
|
105
|
-
exportNames.push(
|
|
118
|
+
const interfaceName = allocateInterfaceName(named.schema.id, usedNames);
|
|
119
|
+
lines.push(...renderKeysType(interfaceName, named.schema), "", ...renderSchemaConst(named, interfaceName));
|
|
120
|
+
exportNames.push(named.exportName);
|
|
106
121
|
}
|
|
107
122
|
const [firstExport] = exportNames;
|
|
108
123
|
if (firstExport !== undefined) {
|
|
@@ -111,12 +126,55 @@ const renderFileModule = (file, usedNames) => {
|
|
|
111
126
|
lines.push("}");
|
|
112
127
|
return lines;
|
|
113
128
|
};
|
|
114
|
-
const
|
|
129
|
+
const renderResourceModule = (specifier) => [
|
|
130
|
+
`declare module ${toJsStringLiteral(specifier)} {`,
|
|
131
|
+
" const path: string;",
|
|
132
|
+
" export { path };",
|
|
133
|
+
" export default path;",
|
|
134
|
+
"}",
|
|
135
|
+
].join("\n");
|
|
136
|
+
const renderIconModule = (specifier) => [
|
|
137
|
+
`declare module ${toJsStringLiteral(specifier)} {`,
|
|
138
|
+
" const iconName: string;",
|
|
139
|
+
" export default iconName;",
|
|
140
|
+
"}",
|
|
141
|
+
].join("\n");
|
|
142
|
+
const renderLegacyAssetModule = (specifier) => [
|
|
143
|
+
`declare module ${toJsStringLiteral(specifier)} {`,
|
|
144
|
+
" const resourceUri: string;",
|
|
145
|
+
" const path: string;",
|
|
146
|
+
" export { path };",
|
|
147
|
+
" export default resourceUri;",
|
|
148
|
+
"}",
|
|
149
|
+
].join("\n");
|
|
150
|
+
const renderBlockedAssetModule = (specifier) => [
|
|
151
|
+
`declare module ${toJsStringLiteral(specifier)} {`,
|
|
152
|
+
" const assetImportRequiresResourceOrUrlQuery: {",
|
|
153
|
+
" readonly __gtkxAssetImportRequiresResourceOrUrlQuery: unique symbol;",
|
|
154
|
+
" };",
|
|
155
|
+
" export default assetImportRequiresResourceOrUrlQuery;",
|
|
156
|
+
"}",
|
|
157
|
+
].join("\n");
|
|
158
|
+
const renderEnvModule = (files, assetDeclarations, options = {}) => {
|
|
159
|
+
const assets = assetDeclarations ?? { blocked: [], icons: [], legacy: [], resources: [] };
|
|
115
160
|
const usedNames = new Set();
|
|
116
|
-
const
|
|
161
|
+
const schemas = files
|
|
117
162
|
.filter((file) => file.schemas.length > 0)
|
|
118
163
|
.map((file) => renderFileModule(file, usedNames).join("\n"));
|
|
119
|
-
|
|
164
|
+
const blocked = assets.blocked.map((specifier) => renderBlockedAssetModule(specifier));
|
|
165
|
+
const icons = assets.icons.map((specifier) => renderIconModule(specifier));
|
|
166
|
+
const legacy = assets.legacy.map((specifier) => renderLegacyAssetModule(specifier));
|
|
167
|
+
const resources = assets.resources.map((specifier) => renderResourceModule(specifier));
|
|
168
|
+
const references = (options.references ?? []).map((path) => `/// <reference path=${JSON.stringify(path)} />`);
|
|
169
|
+
return `${[
|
|
170
|
+
GTKX_ENV_MODULE_HEADER,
|
|
171
|
+
...references,
|
|
172
|
+
...blocked,
|
|
173
|
+
...icons,
|
|
174
|
+
...legacy,
|
|
175
|
+
...resources,
|
|
176
|
+
...schemas,
|
|
177
|
+
].join("\n\n")}\n`;
|
|
120
178
|
};
|
|
121
179
|
export { renderRuntimeModule, renderEnvModule };
|
|
122
180
|
//# sourceMappingURL=render.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,sBAAsB,GAAG;;;;IAI3B,CAAC;AAEL,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,MAAM,UAAU,GAAG,OAAO,CAAC;AAE3B,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAU,EAAE,CAChD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,CAAA,QAAQ,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,CAAA,QAAQ,CAAC,CAAC;AAEhH,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAU,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,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sB,WAAW,GAAG,CAAC,CAAC;IACtG,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,KAAyB,EAAU,EAAE;IAC1D,MAAM,SAAS,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEzC,MAAM,MAAM,GAAG,KAAK;SACf,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;SACzC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjE,OAAO,GAAG,CAAC,sBAAsB,EAAE,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;AACnE,CAAC,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { upperFirst } from \"@gtkx/utils\";\nimport type { ParsedKey, ParsedSchema, ParsedSchemaFile } from \"./parser.js\";\n\nconst GTKX_ENV_MODULE_HEADER = `/**\n * GSettings schema modules generated by GTKX from the project's\n * \\`.gschema.xml\\` files. Regenerated by \\`gtkx codegen\\`, \\`gtkx dev\\`, and\n * \\`gtkx build\\`; do not edit.\n */`;\n\nconst ENUM_KIND = \"enum\";\nconst FLAGS_KIND = \"flags\";\n\nconst toJsStringLiteral = (value: string): string =>\n JSON.stringify(value).replaceAll(\"\\u{2028}\", String.raw`\\u2028`).replaceAll(\"\\u{2029}\", String.raw`\\u2029`);\n\nconst getExportName = (schemaId: string): string => schemaId.replaceAll(\".\", \"_\");\n\nconst runtimeKindForKey = (key: ParsedKey): string => {\n if (key.enumId !== null) {\n return ENUM_KIND;\n }\n\n if (key.flagsId !== null) {\n return FLAGS_KIND;\n }\n\n return key.variantType ?? \"\";\n};\n\nconst getRuntimeKeys = (schema: ParsedSchema): string => {\n const entries = schema.keys.map(\n (key) => `${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))}`,\n );\n\n return `{ ${entries.join(\", \")} }`;\n};\n\nconst renderRuntimeModule = (file: ParsedSchemaFile): string => {\n const lines: string[] = [];\n\n for (const [index, schema] of file.schemas.entries()) {\n const keysName = `keys_${String(index)}`;\n const id = toJsStringLiteral(schema.id);\n lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);\n\n if (schema.path === null) {\n lines.push(\n `export const ${getExportName(schema.id)} = { id: ${id}, keys: ${keysName}, ` +\n `at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`,\n );\n } else {\n lines.push(`export const ${getExportName(schema.id)} = { id: ${id}, path: null, keys: ${keysName} };`);\n }\n }\n\n const first = file.schemas[0];\n\n if (first !== undefined) {\n lines.push(`export default ${getExportName(first.id)};`);\n }\n\n return lines.join(\"\\n\");\n};\n\nconst sanitizeSummary = (summary: string): string => summary.replaceAll(\"*/\", String.raw`*\\/`);\n\nconst allocateInterfaceName = (schemaId: string, usedNames: Set<string>): string => {\n const base = `${schemaId\n .split(/[^a-zA-Z0-9]+/)\n .filter((part) => part.length > 0)\n .map((part) => upperFirst(part))\n .join(\"\")}Keys`;\n\n let name = base;\n let suffix = 2;\n\n while (usedNames.has(name)) {\n name = `${base}${String(suffix)}`;\n suffix += 1;\n }\n\n usedNames.add(name);\n\n return name;\n};\n\nconst renderKeysType = (name: string, schema: ParsedSchema): string[] => {\n const lines = [` type ${name} = {`];\n\n for (const key of schema.keys) {\n if (key.summary !== null) {\n lines.push(` /** ${sanitizeSummary(key.summary)} */`);\n }\n\n lines.push(` ${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))};`);\n }\n\n lines.push(\" };\");\n\n return lines;\n};\n\nconst boundRefTypeLines = (interfaceName: string, indent: string): string[] => [\n `${indent}id: string;`,\n `${indent}path: string | null;`,\n `${indent}keys: ${interfaceName};`,\n];\n\nconst renderSchemaConst = (schema: ParsedSchema, interfaceName: string): string[] => {\n const exportName = getExportName(schema.id);\n\n if (schema.path !== null) {\n return [\n ` const ${exportName}: {`,\n ` id: ${toJsStringLiteral(schema.id)};`,\n ...boundRefTypeLines(interfaceName, \" \".repeat(8)).slice(1),\n \" };\",\n ];\n }\n\n return [\n ` const ${exportName}: {`,\n ` id: ${JSON.stringify(schema.id)};`,\n ` keys: ${interfaceName};`,\n \" at(path: string): {\",\n ...boundRefTypeLines(interfaceName, \" \".repeat(12)),\n \" };\",\n \" };\",\n ];\n};\n\nconst renderFileModule = (file: ParsedSchemaFile, usedNames: Set<string>): string[] => {\n const lines = [`declare module \"${file.fileName}\" {`];\n const exportNames: string[] = [];\n\n for (const [index, schema] of file.schemas.entries()) {\n if (index > 0) {\n lines.push(\"\");\n }\n\n const interfaceName = allocateInterfaceName(schema.id, usedNames);\n lines.push(...renderKeysType(interfaceName, schema), \"\", ...renderSchemaConst(schema, interfaceName));\n exportNames.push(getExportName(schema.id));\n }\n\n const [firstExport] = exportNames;\n\n if (firstExport !== undefined) {\n lines.push(\"\", ` export { ${exportNames.join(\", \")} };`, ` export default ${firstExport};`);\n }\n\n lines.push(\"}\");\n\n return lines;\n};\n\nconst renderEnvModule = (files: ParsedSchemaFile[]): string => {\n const usedNames: Set<string> = new Set();\n\n const blocks = files\n .filter((file) => file.schemas.length > 0)\n .map((file) => renderFileModule(file, usedNames).join(\"\\n\"));\n\n return `${[GTKX_ENV_MODULE_HEADER, ...blocks].join(\"\\n\\n\")}\\n`;\n};\n\nexport { renderRuntimeModule, renderEnvModule };\n"]}
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAmBxE,MAAM,sBAAsB,GAAG;;;IAG3B,CAAC;AAEL,MAAM,SAA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AAC,MAAM,CAAC,IAAI,CAAC;AACvB,CAAC,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { camelCase, sanitizeIdentifier, upperFirst } from \"@gtkx/utils\";\nimport type { ParsedKey, ParsedSchema, ParsedSchemaFile } from \"./parser.js\";\n\ntype NamedSchema = {\n schema: ParsedSchema;\n exportName: string;\n};\n\ntype EnvAssetDeclarations = {\n blocked: string[];\n icons: string[];\n legacy: string[];\n resources: string[];\n};\n\ntype EnvModuleOptions = {\n references?: string[];\n};\n\nconst GTKX_ENV_MODULE_HEADER = `/**\n * Project import declarations generated by GTKX. Regenerated by\n * \\`gtkx codegen\\`, \\`gtkx dev\\`, and \\`gtkx build\\`; do not edit.\n */`;\n\nconst ENUM_KIND = \"enum\";\nconst FLAGS_KIND = \"flags\";\nconst ID_SEPARATOR = /[._]/;\nconst NAME_SEPARATOR = \"_\";\n\nconst toJsStringLiteral = (value: string): string =>\n JSON.stringify(value).replaceAll(\"\\u{2028}\", String.raw`\\u2028`).replaceAll(\"\\u{2029}\", String.raw`\\u2029`);\n\nconst getExportName = (schemaId: string): string =>\n sanitizeIdentifier(schemaId.split(ID_SEPARATOR).map((part) => camelCase(part)).join(NAME_SEPARATOR));\n\nconst collisionError = (file: ParsedSchemaFile, taken: string, schemaId: string, name: string): Error =>\n new Error(\n `${file.fileName} declares ${taken} and ${schemaId}, which both export \\`${name}\\`. ` +\n \"Rename one of the schema ids so that every schema in the file gets an export of its own.\",\n );\n\nconst getNamedSchemas = (file: ParsedSchemaFile): NamedSchema[] => {\n const owners: Map<string, string> = new Map();\n\n return file.schemas.map((schema) => {\n const exportName = getExportName(schema.id);\n const taken = owners.get(exportName);\n\n if (taken !== undefined) {\n throw collisionError(file, taken, schema.id, exportName);\n }\n\n owners.set(exportName, schema.id);\n\n return { schema, exportName };\n });\n};\n\nconst runtimeKindForKey = (key: ParsedKey): string => {\n if (key.enumId !== null) {\n return ENUM_KIND;\n }\n\n if (key.flagsId !== null) {\n return FLAGS_KIND;\n }\n\n return key.variantType ?? \"\";\n};\n\nconst getRuntimeKeys = (schema: ParsedSchema): string => {\n const entries = schema.keys.map(\n (key) => `${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))}`,\n );\n\n return `{ ${entries.join(\", \")} }`;\n};\n\nconst renderRuntimeModule = (file: ParsedSchemaFile): string => {\n const lines: string[] = [];\n const named = getNamedSchemas(file);\n\n for (const [index, { schema, exportName }] of named.entries()) {\n const keysName = `keys_${String(index)}`;\n const id = toJsStringLiteral(schema.id);\n lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);\n\n if (schema.path === null) {\n lines.push(\n `export const ${exportName} = { id: ${id}, keys: ${keysName}, ` +\n `at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`,\n );\n } else {\n lines.push(`export const ${exportName} = { id: ${id}, path: null, keys: ${keysName} };`);\n }\n }\n\n const first = named[0];\n\n if (first !== undefined) {\n lines.push(`export default ${first.exportName};`);\n }\n\n return lines.join(\"\\n\");\n};\n\nconst sanitizeSummary = (summary: string): string => summary.replaceAll(\"*/\", String.raw`*\\/`);\n\nconst allocateInterfaceName = (schemaId: string, usedNames: Set<string>): string => {\n const base = `${schemaId\n .split(/[^a-zA-Z0-9]+/)\n .filter((part) => part.length > 0)\n .map((part) => upperFirst(part))\n .join(\"\")}Keys`;\n\n let name = base;\n let suffix = 2;\n\n while (usedNames.has(name)) {\n name = `${base}${String(suffix)}`;\n suffix += 1;\n }\n\n usedNames.add(name);\n\n return name;\n};\n\nconst renderKeysType = (name: string, schema: ParsedSchema): string[] => {\n const lines = [` type ${name} = {`];\n\n for (const key of schema.keys) {\n if (key.summary !== null) {\n lines.push(` /** ${sanitizeSummary(key.summary)} */`);\n }\n\n lines.push(` ${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))};`);\n }\n\n lines.push(\" };\");\n\n return lines;\n};\n\nconst boundRefTypeLines = (interfaceName: string, indent: string): string[] => [\n `${indent}id: string;`,\n `${indent}path: string | null;`,\n `${indent}keys: ${interfaceName};`,\n];\n\nconst renderSchemaConst = ({ schema, exportName }: NamedSchema, interfaceName: string): string[] => {\n if (schema.path !== null) {\n return [\n ` const ${exportName}: {`,\n ` id: ${toJsStringLiteral(schema.id)};`,\n ...boundRefTypeLines(interfaceName, \" \".repeat(8)).slice(1),\n \" };\",\n ];\n }\n\n return [\n ` const ${exportName}: {`,\n ` id: ${JSON.stringify(schema.id)};`,\n ` keys: ${interfaceName};`,\n \" at(path: string): {\",\n ...boundRefTypeLines(interfaceName, \" \".repeat(12)),\n \" };\",\n \" };\",\n ];\n};\n\nconst renderFileModule = (file: ParsedSchemaFile, usedNames: Set<string>): string[] => {\n const lines = [`declare module ${toJsStringLiteral(file.fileName)} {`];\n const exportNames: string[] = [];\n\n for (const [index, named] of getNamedSchemas(file).entries()) {\n if (index > 0) {\n lines.push(\"\");\n }\n\n const interfaceName = allocateInterfaceName(named.schema.id, usedNames);\n lines.push(...renderKeysType(interfaceName, named.schema), \"\", ...renderSchemaConst(named, interfaceName));\n exportNames.push(named.exportName);\n }\n\n const [firstExport] = exportNames;\n\n if (firstExport !== undefined) {\n lines.push(\"\", ` export { ${exportNames.join(\", \")} };`, ` export default ${firstExport};`);\n }\n\n lines.push(\"}\");\n\n return lines;\n};\n\nconst renderResourceModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const path: string;\",\n \" export { path };\",\n \" export default path;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderIconModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const iconName: string;\",\n \" export default iconName;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderLegacyAssetModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const resourceUri: string;\",\n \" const path: string;\",\n \" export { path };\",\n \" export default resourceUri;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderBlockedAssetModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const assetImportRequiresResourceOrUrlQuery: {\",\n \" readonly __gtkxAssetImportRequiresResourceOrUrlQuery: unique symbol;\",\n \" };\",\n \" export default assetImportRequiresResourceOrUrlQuery;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderEnvModule = (\n files: ParsedSchemaFile[],\n assetDeclarations?: EnvAssetDeclarations,\n options: EnvModuleOptions = {},\n): string => {\n const assets = assetDeclarations ?? { blocked: [], icons: [], legacy: [], resources: [] };\n const usedNames: Set<string> = new Set();\n\n const schemas = files\n .filter((file) => file.schemas.length > 0)\n .map((file) => renderFileModule(file, usedNames).join(\"\\n\"));\n\n const blocked = assets.blocked.map((specifier) => renderBlockedAssetModule(specifier));\n const icons = assets.icons.map((specifier) => renderIconModule(specifier));\n const legacy = assets.legacy.map((specifier) => renderLegacyAssetModule(specifier));\n const resources = assets.resources.map((specifier) => renderResourceModule(specifier));\n const references = (options.references ?? []).map((path) => `/// <reference path=${JSON.stringify(path)} />`);\n\n return `${[\n GTKX_ENV_MODULE_HEADER,\n ...references,\n ...blocked,\n ...icons,\n ...legacy,\n ...resources,\n ...schemas,\n ].join(\"\\n\\n\")}\\n`;\n};\n\nexport { renderRuntimeModule, renderEnvModule };\n"]}
|
|
@@ -5,8 +5,9 @@ type SchemaEnvResult = {
|
|
|
5
5
|
declare const SCHEMA_SUFFIX = ".gschema.xml";
|
|
6
6
|
declare const prependSchemaDir: (dir: string, existing: string | undefined) => string;
|
|
7
7
|
declare const stageSchema: (dir: string, filePath: string) => void;
|
|
8
|
-
declare const
|
|
8
|
+
declare const projectRelativeSchemaPath: (root: string, filePath: string) => string | null;
|
|
9
|
+
declare const assertUniqueSchemaBasenames: (schemaFiles: string[]) => void;
|
|
9
10
|
declare const stageAndCompileProjectSchemas: (root: string, dataDir: string | null) => string | null;
|
|
10
|
-
declare const emitSchemaEnv: (rootDir: string, dataDir: string | null) => SchemaEnvResult;
|
|
11
|
-
export { SCHEMA_SUFFIX, prependSchemaDir, stageSchema,
|
|
11
|
+
declare const emitSchemaEnv: (rootDir: string, dataDir: string | null, isV2ResourceImports?: boolean) => SchemaEnvResult;
|
|
12
|
+
export { SCHEMA_SUFFIX, prependSchemaDir, stageSchema, assertUniqueSchemaBasenames, projectRelativeSchemaPath, stageAndCompileProjectSchemas, emitSchemaEnv, };
|
|
12
13
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/settings/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/settings/schema.ts"],"names":[],"mappings":"AA6BA,KAAK,eAAe,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,QAAA,MAAM,aAAa,iBAAiB,CAAC;AAMrC,QAAA,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,GAAG,SAAS,KAAG,MAUrE,CAAC;AAKF,QAAA,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,KAAG,IAEpD,CAAC;AAIF,QAAA,MAAM,yBAAyB,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,KAAG,MAAM,GAAG,IAc5E,CAAC;AA+GF,QAAA,MAAM,2BAA2B,GAAI,aAAa,MAAM,EAAE,KAAG,IAiB5D,CAAC;AA+BF,QAAA,MAAM,6BAA6B,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAwBtF,CAAC;AAmDF,QAAA,MAAM,aAAa,GACf,SAAS,MAAM,EACf,SAAS,MAAM,GAAG,IAAI,EACtB,6BAA2B,KAC5B,eAmBF,CAAC;AAEF,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,2BAA2B,EAC3B,yBAAyB,EACzB,6BAA6B,EAC7B,aAAa,GAChB,CAAC"}
|
package/dist/settings/schema.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { sortStrings, warn } from "@gtkx/utils";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
import { copyFileSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, writeFileSync, } from "node:fs";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
|
-
import { dirname, join, relative } from "node:path";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { I18N_TYPES_FILENAME, i18nTypesPath } from "../i18n/types.js";
|
|
6
7
|
import { DATA_IMPORT_PREFIX } from "../internal/data-dir.js";
|
|
8
|
+
import { discoverSourceImports } from "../internal/source-imports.js";
|
|
7
9
|
import { removeTempDir } from "../internal/staging-dir.js";
|
|
10
|
+
import { isBareRelativeAsset, isDataAsset, parseIconSpecifier, parseResourceSpecifier, } from "../vite-plugins/asset-specifier.js";
|
|
8
11
|
import { compileSchemas } from "./compile.js";
|
|
9
12
|
import { parseSchemaXml, SchemaParseError } from "./parser.js";
|
|
10
13
|
import { renderEnvModule } from "./render.js";
|
|
11
14
|
const SCHEMA_SUFFIX = ".gschema.xml";
|
|
12
15
|
const STAGED_NAME_LENGTH = 16;
|
|
16
|
+
const SOURCE_DIR = "src";
|
|
17
|
+
const RESOURCE_QUERY = "?resource=";
|
|
18
|
+
const ICON_QUERY = "?icon=";
|
|
13
19
|
const prependSchemaDir = (dir, existing) => {
|
|
14
20
|
if (existing === undefined || existing.length === 0) {
|
|
15
21
|
return dir;
|
|
@@ -24,7 +30,102 @@ const stageSchema = (dir, filePath) => {
|
|
|
24
30
|
copyFileSync(filePath, join(dir, stagedSchemaName(filePath)));
|
|
25
31
|
};
|
|
26
32
|
const toForwardSlashes = (value) => value.replaceAll(/[/\\]/g, "/");
|
|
33
|
+
const projectRelativeSchemaPath = (root, filePath) => {
|
|
34
|
+
let rel;
|
|
35
|
+
try {
|
|
36
|
+
rel = relative(realpathSync(root), realpathSync(filePath));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return toForwardSlashes(rel);
|
|
45
|
+
};
|
|
27
46
|
const getModuleSpecifier = (dataDirAbs, filePath) => `${DATA_IMPORT_PREFIX}/${toForwardSlashes(relative(dataDirAbs, filePath))}`;
|
|
47
|
+
const getRelativeModuleSpecifier = (filePath) => `*/${basename(filePath)}`;
|
|
48
|
+
const sourceDirFor = (root) => {
|
|
49
|
+
const sourceDir = join(root, SOURCE_DIR);
|
|
50
|
+
return existsSync(sourceDir) ? sourceDir : root;
|
|
51
|
+
};
|
|
52
|
+
const isRelativeImport = (source) => source.startsWith("./") || source.startsWith("../");
|
|
53
|
+
const schemaFileFor = ({ importer, source }) => isRelativeImport(source) && source.endsWith(SCHEMA_SUFFIX) ? resolve(dirname(importer), source) : null;
|
|
54
|
+
const findImportedSchemaFiles = (imports) => {
|
|
55
|
+
const files = imports
|
|
56
|
+
.map((entry) => schemaFileFor(entry))
|
|
57
|
+
.filter((path) => path !== null);
|
|
58
|
+
return sortStrings(new Set(files));
|
|
59
|
+
};
|
|
60
|
+
const legacyAssetSpecifier = (source) => isDataAsset(source) ? source : null;
|
|
61
|
+
const blockedAssetSpecifier = (source) => {
|
|
62
|
+
if (!isBareRelativeAsset(source)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const separator = source.lastIndexOf("/");
|
|
66
|
+
const name = source.slice(separator + 1);
|
|
67
|
+
if (name.includes("*")) {
|
|
68
|
+
throw new Error(`Cannot generate an asset declaration for ${JSON.stringify(source)}: filenames cannot contain *`);
|
|
69
|
+
}
|
|
70
|
+
return `*/${name}`;
|
|
71
|
+
};
|
|
72
|
+
const resourceModuleSpecifier = (source) => {
|
|
73
|
+
const parsed = parseResourceSpecifier(source);
|
|
74
|
+
const queryIndex = source.indexOf(RESOURCE_QUERY);
|
|
75
|
+
if (queryIndex === -1 || typeof parsed?.resourcePath !== "string") {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const query = source.slice(queryIndex);
|
|
79
|
+
if (query.includes("*")) {
|
|
80
|
+
throw new Error(`Cannot generate an asset declaration for ${JSON.stringify(source)}: resource paths cannot contain *`);
|
|
81
|
+
}
|
|
82
|
+
return `*${query}`;
|
|
83
|
+
};
|
|
84
|
+
const iconModuleSpecifier = (source) => {
|
|
85
|
+
const parsed = parseIconSpecifier(source);
|
|
86
|
+
const queryIndex = source.indexOf(ICON_QUERY);
|
|
87
|
+
if (queryIndex === -1 || typeof parsed?.iconName !== "string") {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const query = source.slice(queryIndex);
|
|
91
|
+
if (query.includes("*")) {
|
|
92
|
+
throw new Error(`Cannot generate an asset declaration for ${JSON.stringify(source)}: icon names cannot contain *`);
|
|
93
|
+
}
|
|
94
|
+
return `*${query}`;
|
|
95
|
+
};
|
|
96
|
+
const findAssetModuleSpecifiers = (imports, isV2ResourceImports) => {
|
|
97
|
+
const collect = (getSpecifier) => sortStrings(new Set(imports.map((entry) => getSpecifier(entry.source)).filter((value) => value !== null)));
|
|
98
|
+
if (isV2ResourceImports) {
|
|
99
|
+
return {
|
|
100
|
+
blocked: collect(blockedAssetSpecifier),
|
|
101
|
+
icons: collect(iconModuleSpecifier),
|
|
102
|
+
legacy: [],
|
|
103
|
+
resources: collect(resourceModuleSpecifier),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return { blocked: [], icons: [], legacy: collect(legacyAssetSpecifier), resources: [] };
|
|
107
|
+
};
|
|
108
|
+
const canonicalPath = (path) => {
|
|
109
|
+
try {
|
|
110
|
+
return realpathSync(path);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return resolve(path);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const assertUniqueSchemaBasenames = (schemaFiles) => {
|
|
117
|
+
const owners = new Map();
|
|
118
|
+
const canonicalFiles = sortStrings(new Set(schemaFiles.map((path) => canonicalPath(path))));
|
|
119
|
+
for (const filePath of canonicalFiles) {
|
|
120
|
+
const name = basename(filePath);
|
|
121
|
+
const owner = owners.get(name);
|
|
122
|
+
if (owner !== undefined && owner !== filePath) {
|
|
123
|
+
throw new Error(`Cannot generate types for both ${owner} and ${filePath}: relative GSettings schema imports are ` +
|
|
124
|
+
`typed by basename, and both files are named ${name}. Rename one of them.`);
|
|
125
|
+
}
|
|
126
|
+
owners.set(name, filePath);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
28
129
|
const readVisibleEntries = (dir) => {
|
|
29
130
|
try {
|
|
30
131
|
return readdirSync(dir, { withFileTypes: true }).filter((entry) => !entry.name.startsWith("."));
|
|
@@ -51,10 +152,11 @@ const findSchemaFiles = (dataDir) => {
|
|
|
51
152
|
return sortStrings(found);
|
|
52
153
|
};
|
|
53
154
|
const stageAndCompileProjectSchemas = (root, dataDir) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
155
|
+
const imports = discoverSourceImports(sourceDirFor(root));
|
|
156
|
+
const imported = findImportedSchemaFiles(imports);
|
|
157
|
+
assertUniqueSchemaBasenames(imported);
|
|
158
|
+
const legacy = dataDir === null ? [] : findSchemaFiles(join(root, dataDir));
|
|
159
|
+
const schemaFiles = sortStrings(new Set([...legacy, ...imported]));
|
|
58
160
|
if (schemaFiles.length === 0) {
|
|
59
161
|
return null;
|
|
60
162
|
}
|
|
@@ -69,8 +171,7 @@ const stageAndCompileProjectSchemas = (root, dataDir) => {
|
|
|
69
171
|
return dir;
|
|
70
172
|
};
|
|
71
173
|
const schemaEnvPath = (rootDir) => join(rootDir, "node_modules", ".gtkx", "env.d.ts");
|
|
72
|
-
const parseSchemaFileOrWarn = (filePath,
|
|
73
|
-
const specifier = getModuleSpecifier(dataDirAbs, filePath);
|
|
174
|
+
const parseSchemaFileOrWarn = (filePath, specifier) => {
|
|
74
175
|
try {
|
|
75
176
|
return parseSchemaXml(readFileSync(filePath, "utf8"), specifier);
|
|
76
177
|
}
|
|
@@ -82,10 +183,10 @@ const parseSchemaFileOrWarn = (filePath, dataDirAbs) => {
|
|
|
82
183
|
return null;
|
|
83
184
|
}
|
|
84
185
|
};
|
|
85
|
-
const parseProjectSchemas = (schemaFiles,
|
|
186
|
+
const parseProjectSchemas = (schemaFiles, specifierFor) => {
|
|
86
187
|
const parsed = [];
|
|
87
188
|
for (const filePath of schemaFiles) {
|
|
88
|
-
const result = parseSchemaFileOrWarn(filePath,
|
|
189
|
+
const result = parseSchemaFileOrWarn(filePath, specifierFor(filePath));
|
|
89
190
|
if (result !== null) {
|
|
90
191
|
parsed.push(result);
|
|
91
192
|
}
|
|
@@ -108,14 +209,22 @@ const didWriteChanges = (path, content) => {
|
|
|
108
209
|
writeFileSync(path, content);
|
|
109
210
|
return true;
|
|
110
211
|
};
|
|
111
|
-
const emitSchemaEnv = (rootDir, dataDir) => {
|
|
212
|
+
const emitSchemaEnv = (rootDir, dataDir, isV2ResourceImports = false) => {
|
|
112
213
|
const dataDirAbs = dataDir === null ? null : join(rootDir, dataDir);
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
214
|
+
const legacyFiles = dataDirAbs === null ? [] : findSchemaFiles(dataDirAbs);
|
|
215
|
+
const imports = discoverSourceImports(sourceDirFor(rootDir));
|
|
216
|
+
const legacy = dataDirAbs === null
|
|
217
|
+
? []
|
|
218
|
+
: parseProjectSchemas(legacyFiles, (filePath) => getModuleSpecifier(dataDirAbs, filePath));
|
|
219
|
+
const importedFiles = findImportedSchemaFiles(imports);
|
|
220
|
+
assertUniqueSchemaBasenames(importedFiles);
|
|
221
|
+
const imported = parseProjectSchemas(importedFiles, getRelativeModuleSpecifier);
|
|
222
|
+
const assets = findAssetModuleSpecifiers(imports, isV2ResourceImports);
|
|
223
|
+
const references = existsSync(i18nTypesPath(rootDir)) ? [`./${I18N_TYPES_FILENAME}`] : [];
|
|
224
|
+
const content = renderEnvModule([...legacy, ...imported], assets, { references });
|
|
116
225
|
const path = schemaEnvPath(rootDir);
|
|
117
226
|
const isWritten = didWriteChanges(path, content);
|
|
118
227
|
return { path, isWritten };
|
|
119
228
|
};
|
|
120
|
-
export { SCHEMA_SUFFIX, prependSchemaDir, stageSchema,
|
|
229
|
+
export { SCHEMA_SUFFIX, prependSchemaDir, stageSchema, assertUniqueSchemaBasenames, projectRelativeSchemaPath, stageAndCompileProjectSchemas, emitSchemaEnv, };
|
|
121
230
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/settings/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAe,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtH,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAyB,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa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BAAmB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACvF,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEjD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC/B,CAAC,CAAC;AAEF,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,6BAA6B,EAC7B,aAAa,GAChB,CAAC","sourcesContent":["import { sortStrings, warn } from \"@gtkx/utils\";\nimport { createHash } from \"node:crypto\";\nimport { copyFileSync, type Dirent, mkdirSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join, relative } from \"node:path\";\nimport { DATA_IMPORT_PREFIX } from \"../internal/data-dir.js\";\nimport { removeTempDir } from \"../internal/staging-dir.js\";\nimport { compileSchemas } from \"./compile.js\";\nimport { type ParsedSchemaFile, parseSchemaXml, SchemaParseError } from \"./parser.js\";\nimport { renderEnvModule } from \"./render.js\";\n\ntype SchemaEnvResult = {\n path: string;\n isWritten: boolean;\n};\n\nconst SCHEMA_SUFFIX = \".gschema.xml\";\nconst STAGED_NAME_LENGTH = 16;\n\nconst prependSchemaDir = (dir: string, existing: string | undefined): string => {\n if (existing === undefined || existing.length === 0) {\n return dir;\n }\n\n if (existing.split(\":\").includes(dir)) {\n return existing;\n }\n\n return `${dir}:${existing}`;\n};\n\nconst stagedSchemaName = (filePath: string): string =>\n `${createHash(\"sha1\").update(filePath).digest(\"hex\").slice(0, STAGED_NAME_LENGTH)}${SCHEMA_SUFFIX}`;\n\nconst stageSchema = (dir: string, filePath: string): void => {\n copyFileSync(filePath, join(dir, stagedSchemaName(filePath)));\n};\n\nconst toForwardSlashes = (value: string): string => value.replaceAll(/[/\\\\]/g, \"/\");\n\nconst getModuleSpecifier = (dataDirAbs: string, filePath: string): string =>\n `${DATA_IMPORT_PREFIX}/${toForwardSlashes(relative(dataDirAbs, filePath))}`;\n\nconst readVisibleEntries = (dir: string): Dirent[] => {\n try {\n return readdirSync(dir, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(\".\"));\n } catch {\n return [];\n }\n};\n\nconst isSchemaFile = (entry: Dirent): boolean => entry.isFile() && entry.name.endsWith(SCHEMA_SUFFIX);\n\nconst collectSchemaFiles = (dir: string, found: string[]): void => {\n for (const entry of readVisibleEntries(dir)) {\n const full = join(dir, entry.name);\n\n if (entry.isDirectory()) {\n collectSchemaFiles(full, found);\n } else if (isSchemaFile(entry)) {\n found.push(full);\n }\n }\n};\n\nconst findSchemaFiles = (dataDir: string): string[] => {\n const found: string[] = [];\n collectSchemaFiles(dataDir, found);\n\n return sortStrings(found);\n};\n\nconst stageAndCompileProjectSchemas = (root: string, dataDir: string | null): string | null => {\n if (dataDir === null) {\n return null;\n }\n\n const schemaFiles = findSchemaFiles(join(root, dataDir));\n\n if (schemaFiles.length === 0) {\n return null;\n }\n\n const dir = mkdtempSync(join(tmpdir(), \"gtkx-schemas-\"));\n\n for (const filePath of schemaFiles) {\n stageSchema(dir, filePath);\n }\n\n compileSchemas(dir);\n\n process.once(\"exit\", () => {\n removeTempDir(dir);\n });\n\n return dir;\n};\n\nconst schemaEnvPath = (rootDir: string): string => join(rootDir, \"node_modules\", \".gtkx\", \"env.d.ts\");\n\nconst parseSchemaFileOrWarn = (filePath: string, dataDirAbs: string): ParsedSchemaFile | null => {\n const specifier = getModuleSpecifier(dataDirAbs, filePath);\n\n try {\n return parseSchemaXml(readFileSync(filePath, \"utf8\"), specifier);\n } catch (error) {\n if (!(error instanceof SchemaParseError)) {\n throw error;\n }\n\n warn(`Skipping ${filePath} in schema type generation: ${error.message}`);\n\n return null;\n }\n};\n\nconst parseProjectSchemas = (schemaFiles: string[], dataDirAbs: string): ParsedSchemaFile[] => {\n const parsed: ParsedSchemaFile[] = [];\n\n for (const filePath of schemaFiles) {\n const result = parseSchemaFileOrWarn(filePath, dataDirAbs);\n\n if (result !== null) {\n parsed.push(result);\n }\n }\n\n return parsed;\n};\n\nconst readFileOrNull = (path: string): string | null => {\n try {\n return readFileSync(path, \"utf8\");\n } catch {\n return null;\n }\n};\n\nconst didWriteChanges = (path: string, content: string): boolean => {\n if (readFileOrNull(path) === content) {\n return false;\n }\n\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, content);\n\n return true;\n};\n\nconst emitSchemaEnv = (rootDir: string, dataDir: string | null): SchemaEnvResult => {\n const dataDirAbs = dataDir === null ? null : join(rootDir, dataDir);\n const schemaFiles = dataDirAbs === null ? [] : findSchemaFiles(dataDirAbs);\n const parsed = dataDirAbs === null ? [] : parseProjectSchemas(schemaFiles, dataDirAbs);\n const content = renderEnvModule(parsed);\n const path = schemaEnvPath(rootDir);\n const isWritten = didWriteChanges(path, content);\n\n return { path, isWritten };\n};\n\nexport {\n SCHEMA_SUFFIX,\n prependSchemaDir,\n stageSchema,\n findSchemaFiles,\n stageAndCompileProjectSchemas,\n emitSchemaEnv,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/settings/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACH,YAAY,EAEZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAA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,CAAC,aAAa,EAAE,0BAA0B,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,yBAAyB,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,mBAAmB,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1F,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAClF,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEjD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC/B,CAAC,CAAC;AAEF,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,2BAA2B,EAC3B,yBAAyB,EACzB,6BAA6B,EAC7B,aAAa,GAChB,CAAC","sourcesContent":["import { sortStrings, warn } from \"@gtkx/utils\";\nimport { createHash } from \"node:crypto\";\nimport {\n copyFileSync,\n type Dirent,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n realpathSync,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { I18N_TYPES_FILENAME, i18nTypesPath } from \"../i18n/types.js\";\nimport { DATA_IMPORT_PREFIX } from \"../internal/data-dir.js\";\nimport { discoverSourceImports, type SourceImport } from \"../internal/source-imports.js\";\nimport { removeTempDir } from \"../internal/staging-dir.js\";\nimport {\n isBareRelativeAsset,\n isDataAsset,\n parseIconSpecifier,\n parseResourceSpecifier,\n} from \"../vite-plugins/asset-specifier.js\";\nimport { compileSchemas } from \"./compile.js\";\nimport { type ParsedSchemaFile, parseSchemaXml, SchemaParseError } from \"./parser.js\";\nimport { renderEnvModule } from \"./render.js\";\n\ntype SchemaEnvResult = {\n path: string;\n isWritten: boolean;\n};\n\nconst SCHEMA_SUFFIX = \".gschema.xml\";\nconst STAGED_NAME_LENGTH = 16;\nconst SOURCE_DIR = \"src\";\nconst RESOURCE_QUERY = \"?resource=\";\nconst ICON_QUERY = \"?icon=\";\n\nconst prependSchemaDir = (dir: string, existing: string | undefined): string => {\n if (existing === undefined || existing.length === 0) {\n return dir;\n }\n\n if (existing.split(\":\").includes(dir)) {\n return existing;\n }\n\n return `${dir}:${existing}`;\n};\n\nconst stagedSchemaName = (filePath: string): string =>\n `${createHash(\"sha1\").update(filePath).digest(\"hex\").slice(0, STAGED_NAME_LENGTH)}${SCHEMA_SUFFIX}`;\n\nconst stageSchema = (dir: string, filePath: string): void => {\n copyFileSync(filePath, join(dir, stagedSchemaName(filePath)));\n};\n\nconst toForwardSlashes = (value: string): string => value.replaceAll(/[/\\\\]/g, \"/\");\n\nconst projectRelativeSchemaPath = (root: string, filePath: string): string | null => {\n let rel: string;\n\n try {\n rel = relative(realpathSync(root), realpathSync(filePath));\n } catch {\n return null;\n }\n\n if (rel === \"\" || rel === \"..\" || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {\n return null;\n }\n\n return toForwardSlashes(rel);\n};\n\nconst getModuleSpecifier = (dataDirAbs: string, filePath: string): string =>\n `${DATA_IMPORT_PREFIX}/${toForwardSlashes(relative(dataDirAbs, filePath))}`;\n\nconst getRelativeModuleSpecifier = (filePath: string): string => `*/${basename(filePath)}`;\n\nconst sourceDirFor = (root: string): string => {\n const sourceDir = join(root, SOURCE_DIR);\n\n return existsSync(sourceDir) ? sourceDir : root;\n};\n\nconst isRelativeImport = (source: string): boolean => source.startsWith(\"./\") || source.startsWith(\"../\");\n\nconst schemaFileFor = ({ importer, source }: SourceImport): string | null =>\n isRelativeImport(source) && source.endsWith(SCHEMA_SUFFIX) ? resolve(dirname(importer), source) : null;\n\nconst findImportedSchemaFiles = (imports: SourceImport[]): string[] => {\n const files = imports\n .map((entry) => schemaFileFor(entry))\n .filter((path): path is string => path !== null);\n\n return sortStrings(new Set(files));\n};\n\nconst legacyAssetSpecifier = (source: string): string | null =>\n isDataAsset(source) ? source : null;\n\nconst blockedAssetSpecifier = (source: string): string | null => {\n if (!isBareRelativeAsset(source)) {\n return null;\n }\n\n const separator = source.lastIndexOf(\"/\");\n const name = source.slice(separator + 1);\n\n if (name.includes(\"*\")) {\n throw new Error(\n `Cannot generate an asset declaration for ${JSON.stringify(source)}: filenames cannot contain *`,\n );\n }\n\n return `*/${name}`;\n};\n\nconst resourceModuleSpecifier = (source: string): string | null => {\n const parsed = parseResourceSpecifier(source);\n const queryIndex = source.indexOf(RESOURCE_QUERY);\n\n if (queryIndex === -1 || typeof parsed?.resourcePath !== \"string\") {\n return null;\n }\n\n const query = source.slice(queryIndex);\n\n if (query.includes(\"*\")) {\n throw new Error(\n `Cannot generate an asset declaration for ${JSON.stringify(source)}: resource paths cannot contain *`,\n );\n }\n\n return `*${query}`;\n};\n\nconst iconModuleSpecifier = (source: string): string | null => {\n const parsed = parseIconSpecifier(source);\n const queryIndex = source.indexOf(ICON_QUERY);\n\n if (queryIndex === -1 || typeof parsed?.iconName !== \"string\") {\n return null;\n }\n\n const query = source.slice(queryIndex);\n\n if (query.includes(\"*\")) {\n throw new Error(\n `Cannot generate an asset declaration for ${JSON.stringify(source)}: icon names cannot contain *`,\n );\n }\n\n return `*${query}`;\n};\n\nconst findAssetModuleSpecifiers = (\n imports: SourceImport[],\n isV2ResourceImports: boolean,\n): { blocked: string[]; icons: string[]; legacy: string[]; resources: string[] } => {\n const collect = (getSpecifier: (source: string) => string | null): string[] =>\n sortStrings(new Set(imports.map((entry) => getSpecifier(entry.source)).filter((value) => value !== null)));\n\n if (isV2ResourceImports) {\n return {\n blocked: collect(blockedAssetSpecifier),\n icons: collect(iconModuleSpecifier),\n legacy: [],\n resources: collect(resourceModuleSpecifier),\n };\n }\n\n return { blocked: [], icons: [], legacy: collect(legacyAssetSpecifier), resources: [] };\n};\n\nconst canonicalPath = (path: string): string => {\n try {\n return realpathSync(path);\n } catch {\n return resolve(path);\n }\n};\n\nconst assertUniqueSchemaBasenames = (schemaFiles: string[]): void => {\n const owners: Map<string, string> = new Map();\n const canonicalFiles = sortStrings(new Set(schemaFiles.map((path) => canonicalPath(path))));\n\n for (const filePath of canonicalFiles) {\n const name = basename(filePath);\n const owner = owners.get(name);\n\n if (owner !== undefined && owner !== filePath) {\n throw new Error(\n `Cannot generate types for both ${owner} and ${filePath}: relative GSettings schema imports are ` +\n `typed by basename, and both files are named ${name}. Rename one of them.`,\n );\n }\n\n owners.set(name, filePath);\n }\n};\n\nconst readVisibleEntries = (dir: string): Dirent[] => {\n try {\n return readdirSync(dir, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(\".\"));\n } catch {\n return [];\n }\n};\n\nconst isSchemaFile = (entry: Dirent): boolean => entry.isFile() && entry.name.endsWith(SCHEMA_SUFFIX);\n\nconst collectSchemaFiles = (dir: string, found: string[]): void => {\n for (const entry of readVisibleEntries(dir)) {\n const full = join(dir, entry.name);\n\n if (entry.isDirectory()) {\n collectSchemaFiles(full, found);\n } else if (isSchemaFile(entry)) {\n found.push(full);\n }\n }\n};\n\nconst findSchemaFiles = (dataDir: string): string[] => {\n const found: string[] = [];\n collectSchemaFiles(dataDir, found);\n\n return sortStrings(found);\n};\n\nconst stageAndCompileProjectSchemas = (root: string, dataDir: string | null): string | null => {\n const imports = discoverSourceImports(sourceDirFor(root));\n const imported = findImportedSchemaFiles(imports);\n assertUniqueSchemaBasenames(imported);\n const legacy = dataDir === null ? [] : findSchemaFiles(join(root, dataDir));\n const schemaFiles = sortStrings(new Set([...legacy, ...imported]));\n\n if (schemaFiles.length === 0) {\n return null;\n }\n\n const dir = mkdtempSync(join(tmpdir(), \"gtkx-schemas-\"));\n\n for (const filePath of schemaFiles) {\n stageSchema(dir, filePath);\n }\n\n compileSchemas(dir);\n\n process.once(\"exit\", () => {\n removeTempDir(dir);\n });\n\n return dir;\n};\n\nconst schemaEnvPath = (rootDir: string): string => join(rootDir, \"node_modules\", \".gtkx\", \"env.d.ts\");\n\nconst parseSchemaFileOrWarn = (filePath: string, specifier: string): ParsedSchemaFile | null => {\n try {\n return parseSchemaXml(readFileSync(filePath, \"utf8\"), specifier);\n } catch (error) {\n if (!(error instanceof SchemaParseError)) {\n throw error;\n }\n\n warn(`Skipping ${filePath} in schema type generation: ${error.message}`);\n\n return null;\n }\n};\n\nconst parseProjectSchemas = (schemaFiles: string[], specifierFor: (filePath: string) => string): ParsedSchemaFile[] => {\n const parsed: ParsedSchemaFile[] = [];\n\n for (const filePath of schemaFiles) {\n const result = parseSchemaFileOrWarn(filePath, specifierFor(filePath));\n\n if (result !== null) {\n parsed.push(result);\n }\n }\n\n return parsed;\n};\n\nconst readFileOrNull = (path: string): string | null => {\n try {\n return readFileSync(path, \"utf8\");\n } catch {\n return null;\n }\n};\n\nconst didWriteChanges = (path: string, content: string): boolean => {\n if (readFileOrNull(path) === content) {\n return false;\n }\n\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, content);\n\n return true;\n};\n\nconst emitSchemaEnv = (\n rootDir: string,\n dataDir: string | null,\n isV2ResourceImports = false,\n): SchemaEnvResult => {\n const dataDirAbs = dataDir === null ? null : join(rootDir, dataDir);\n const legacyFiles = dataDirAbs === null ? [] : findSchemaFiles(dataDirAbs);\n const imports = discoverSourceImports(sourceDirFor(rootDir));\n\n const legacy = dataDirAbs === null\n ? []\n : parseProjectSchemas(legacyFiles, (filePath) => getModuleSpecifier(dataDirAbs, filePath));\n\n const importedFiles = findImportedSchemaFiles(imports);\n assertUniqueSchemaBasenames(importedFiles);\n const imported = parseProjectSchemas(importedFiles, getRelativeModuleSpecifier);\n const assets = findAssetModuleSpecifiers(imports, isV2ResourceImports);\n const references = existsSync(i18nTypesPath(rootDir)) ? [`./${I18N_TYPES_FILENAME}`] : [];\n const content = renderEnvModule([...legacy, ...imported], assets, { references });\n const path = schemaEnvPath(rootDir);\n const isWritten = didWriteChanges(path, content);\n\n return { path, isWritten };\n};\n\nexport {\n SCHEMA_SUFFIX,\n prependSchemaDir,\n stageSchema,\n assertUniqueSchemaBasenames,\n projectRelativeSchemaPath,\n stageAndCompileProjectSchemas,\n emitSchemaEnv,\n};\n"]}
|