@astryxdesign/cli 0.6.6 → 0.6.7
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/CHANGELOG.md +129 -0
- package/README.md +84 -82
- package/api/build/_adapter.d.mts +20 -0
- package/api/build/_adapter.mjs +24 -0
- package/api/build/build.doc.mjs +1 -1
- package/api/build/build.test.mjs +1 -1
- package/api/build/build.type.d.mts +12 -0
- package/api/build/build.type.mjs +3 -0
- package/api/build/help/help.mjs +1 -1
- package/api/build/kit/kit.mjs +13 -1
- package/api/component/_adapter.d.mts +19 -0
- package/api/component/_adapter.mjs +33 -0
- package/api/component/component-replacement.test.mjs +615 -0
- package/api/component/component.doc.mjs +5 -2
- package/api/component/component.mjs +49 -15
- package/api/component/component.test.mjs +32 -0
- package/api/component/component.type.d.mts +33 -3
- package/api/component/component.type.mjs +10 -3
- package/api/component/detail/blocks/blocks.d.mts +2 -1
- package/api/component/detail/blocks/blocks.mjs +5 -2
- package/api/component/detail/detail.mjs +5 -1
- package/api/component/detail/props/props.d.mts +2 -1
- package/api/component/detail/props/props.mjs +3 -2
- package/api/component/detail/showcase/showcase.d.mts +3 -1
- package/api/component/detail/showcase/showcase.mjs +3 -1
- package/api/component/detail/source/source.d.mts +3 -2
- package/api/component/detail/source/source.mjs +7 -3
- package/api/component/list/list.mjs +128 -10
- package/api/docs/_adapter.d.mts +11 -0
- package/api/docs/_adapter.mjs +73 -1
- package/api/docs/compiled-topics.test.mjs +1 -1
- package/api/docs/detail/detail.mjs +19 -3
- package/api/docs/detail/section/section.d.mts +44 -0
- package/api/docs/detail/section/section.mjs +171 -14
- package/api/docs/detail/section/section.test.mjs +4 -4
- package/api/docs/docOverlays.test.mjs +38 -23
- package/api/docs/docs.depth.test.mjs +2 -0
- package/api/docs/docs.doc.mjs +3 -3
- package/api/docs/docs.mjs +13 -16
- package/api/docs/docs.test.mjs +9 -10
- package/api/docs/docs.type.d.mts +43 -3
- package/api/docs/docs.type.mjs +23 -3
- package/api/docs/index/index.mjs +11 -2
- package/api/docs/index/index.test.mjs +7 -2
- package/api/docs/integration-tree.test.mjs +26 -26
- package/api/docs/integrationDocs.test.mjs +8 -7
- package/api/docs/namespace-section.test.mjs +260 -0
- package/api/docs/node/node.mjs +3 -0
- package/api/docs/token-tables.test.mjs +93 -0
- package/api/doctor/_adapter.d.mts +50 -0
- package/api/doctor/_adapter.mjs +190 -0
- package/api/doctor/doctor.d.mts +6 -10
- package/api/doctor/doctor.doc.mjs +1 -3
- package/api/doctor/doctor.mjs +144 -150
- package/api/doctor/doctor.test.mjs +104 -0
- package/api/doctor/theme-checks.d.mts +24 -0
- package/api/doctor/theme-checks.mjs +1231 -0
- package/api/doctor/theme-checks.test.mjs +667 -0
- package/api/gap-report/gap-report.doc.mjs +2 -1
- package/api/gap-report/gap-report.mjs +15 -1
- package/api/hook/_adapter.d.mts +1 -0
- package/api/hook/_adapter.mjs +3 -0
- package/api/hook/detail/detail.mjs +2 -2
- package/api/hook/detail/params/params.mjs +2 -2
- package/api/hook/hook.type.d.mts +12 -0
- package/api/hook/hook.type.mjs +3 -0
- package/api/hook/list/list.mjs +8 -8
- package/api/index.d.mts +1 -1
- package/api/index.mjs +4 -0
- package/api/init/run/run.d.mts +3 -5
- package/api/init/run/run.mjs +11 -11
- package/api/integration/__fixtures__/released-0.6.5-ocean.d.mts +14 -0
- package/api/integration/__fixtures__/released-0.6.5-ocean.mjs +15 -0
- package/api/integration/add-helpers.d.mts +26 -5
- package/api/integration/add-helpers.mjs +50 -5
- package/api/integration/add-theme.mjs +16 -2
- package/api/integration/add-theme.test.mjs +66 -15
- package/api/integration/authoring-checks.mjs +21 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +6 -3
- package/api/integration/pack-check.component-replaces.test.mjs +126 -0
- package/api/integration/pack-check.d.mts +10 -0
- package/api/integration/pack-check.lifecycle-output.test.mjs +21 -2
- package/api/integration/pack-check.mjs +483 -1
- package/api/integration/pack-check.test.mjs +568 -8
- package/api/integration/validate-integration.mjs +20 -4
- package/api/integration/validate-integration.test.mjs +73 -0
- package/api/layout/check/check.d.mts +1 -0
- package/api/layout/check/check.mjs +1 -0
- package/api/layout/expand/expand.d.mts +1 -0
- package/api/layout/expand/expand.mjs +1 -0
- package/api/layout/grammar/grammar.d.mts +1 -0
- package/api/layout/grammar/grammar.mjs +1 -0
- package/api/layout/layoutCheck.doc.mjs +1 -1
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/layout/layoutGrammar.doc.mjs +1 -1
- package/api/search/search.d.mts +47 -3
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.domain-priority.test.mjs +261 -0
- package/api/search/search.mjs +247 -43
- package/api/search/search.test.mjs +5 -1
- package/api/search/search.type.d.mts +3 -3
- package/api/search/search.type.mjs +2 -2
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +23 -0
- package/api/swizzle/copy/copy.d.mts +5 -6
- package/api/swizzle/copy/copy.mjs +29 -10
- package/api/swizzle/list/list.mjs +2 -2
- package/api/swizzle/swizzle.doc.mjs +5 -2
- package/api/swizzle/swizzle.test.mjs +55 -5
- package/api/swizzle/swizzle.type.d.mts +8 -0
- package/api/swizzle/swizzle.type.mjs +2 -0
- package/api/template/copy/copy.mjs +14 -1
- package/api/template/show/show.mjs +2 -0
- package/api/template/skeleton/skeleton.mjs +2 -1
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +1 -1
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +15 -0
- package/api/template/template.type.mjs +6 -0
- package/api/theme/_adapter.d.mts +106 -6
- package/api/theme/_adapter.mjs +687 -18
- package/api/theme/add/add.binary.test.mjs +76 -3
- package/api/theme/add/add.d.mts +5 -9
- package/api/theme/add/add.mjs +87 -64
- package/api/theme/add/add.rollback.test.mjs +9 -9
- package/api/theme/add/add.staging.test.mjs +9 -9
- package/api/theme/add/add.test.mjs +461 -55
- package/api/theme/add/add.types.test.mjs +151 -0
- package/api/theme/build/build.d.mts +96 -2
- package/api/theme/build/build.family.test.mjs +13 -4
- package/api/theme/build/build.mjs +286 -118
- package/api/theme/build/build.test.mjs +30 -0
- package/api/theme/build/font-warning.d.mts +11 -0
- package/api/theme/build/font-warning.mjs +28 -3
- package/api/theme/eject/eject.binary.test.mjs +90 -0
- package/api/theme/eject/eject.d.mts +17 -0
- package/api/theme/eject/eject.mjs +65 -0
- package/api/theme/eject/eject.rollback.test.mjs +158 -0
- package/api/theme/eject/eject.staging.test.mjs +83 -0
- package/api/theme/eject/eject.test.mjs +160 -0
- package/api/theme/integration-themes.test.mjs +30 -6
- package/api/theme/list/list.d.mts +10 -0
- package/api/theme/list/list.mjs +75 -7
- package/api/theme/list/list.test.mjs +155 -4
- package/api/theme/remove/remove.d.mts +12 -0
- package/api/theme/remove/remove.mjs +15 -0
- package/api/theme/remove/remove.test.mjs +94 -0
- package/api/theme/template/template.mjs +3 -4
- package/api/theme/theme.d.mts +5 -2
- package/api/theme/theme.mjs +13 -8
- package/api/theme/theme.type.d.mts +106 -2
- package/api/theme/theme.type.mjs +54 -5
- package/api/theme/themeAdd.doc.d.mts +1 -3
- package/api/theme/themeAdd.doc.mjs +35 -22
- package/api/theme/themeBuild.doc.mjs +1 -1
- package/api/theme/themeEject.doc.d.mts +8 -0
- package/api/theme/themeEject.doc.mjs +89 -0
- package/api/theme/themeListAvailable.doc.mjs +4 -4
- package/api/theme/themeListCopySources.doc.d.mts +8 -0
- package/api/theme/themeListCopySources.doc.mjs +60 -0
- package/api/theme/themeRemove.doc.d.mts +6 -0
- package/api/theme/themeRemove.doc.mjs +50 -0
- package/api/theme/themeTemplate.doc.mjs +4 -3
- package/api/theme/themeUse.doc.d.mts +6 -0
- package/api/theme/themeUse.doc.mjs +47 -0
- package/api/theme/use/use.d.mts +12 -0
- package/api/theme/use/use.mjs +15 -0
- package/api/theme/use/use.test.mjs +98 -0
- package/api/upgrade/_adapter.d.mts +1 -0
- package/api/upgrade/_adapter.mjs +3 -0
- package/api/upgrade/list/list.mjs +9 -3
- package/api/upgrade/upgrade.type.d.mts +4 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- package/assets/codemods/integration-discovery.mjs +1 -1
- package/assets/codemods/integration-discovery.test.mjs +64 -0
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/transforms/v0.6.7/__tests__/migrate-copied-themes-to-descriptors.test.mjs +129 -0
- package/assets/codemods/transforms/v0.6.7/index.mjs +23 -0
- package/assets/codemods/transforms/v0.6.7/migrate-copied-themes-to-descriptors.mjs +54 -0
- package/assets/docs/author-a-theme.doc.mjs +166 -0
- package/assets/docs/getting-started.doc.mjs +61 -17
- package/assets/docs/principles.doc.dense.mjs +4 -4
- package/assets/docs/principles.doc.mjs +6 -6
- package/assets/docs/principles.doc.zh.mjs +4 -4
- package/assets/docs/styling-overview.doc.mjs +211 -0
- package/assets/docs/theme.doc.dense.mjs +10 -198
- package/assets/docs/theme.doc.mjs +13 -771
- package/assets/docs/theme.doc.zh.mjs +31 -12
- package/assets/docs/tree/add-a-theme.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +5 -4
- package/assets/docs/tree/component-migration.doc.mjs +107 -0
- package/assets/docs/tree/css-and-stylex.doc.mjs +150 -0
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +4 -4
- package/assets/docs/tree/font-setup.doc.mjs +122 -0
- package/assets/docs/tree/fonts-and-assets.doc.mjs +25 -20
- package/assets/docs/tree/headers-and-footers.doc.mjs +67 -0
- package/assets/docs/tree/i18n-library-integration.doc.mjs +167 -0
- package/assets/docs/tree/i18n-quick-start.doc.mjs +101 -0
- package/assets/docs/{internationalization.doc.mjs → tree/i18n-rtl-and-testing.doc.mjs} +17 -223
- package/assets/docs/tree/internationalization.doc.mjs +29 -0
- package/assets/docs/tree/layout-spacing.doc.mjs +168 -0
- package/assets/docs/tree/layout.doc.mjs +55 -0
- package/assets/docs/{migration.doc.mjs → tree/migration-setup.doc.mjs} +24 -129
- package/assets/docs/tree/migration-verification.doc.mjs +67 -0
- package/assets/docs/tree/migration.doc.mjs +28 -0
- package/assets/docs/tree/non-css-processing.doc.mjs +112 -0
- package/assets/docs/tree/other-libraries.doc.mjs +218 -0
- package/assets/docs/tree/replace-a-core-component.doc.mjs +21 -4
- package/assets/docs/tree/responsive.doc.mjs +98 -0
- package/assets/docs/tree/scaffold.doc.mjs +140 -0
- package/assets/docs/tree/side-panels.doc.mjs +81 -0
- package/assets/docs/tree/structure.doc.mjs +140 -0
- package/assets/docs/tree/styling-advanced.doc.mjs +159 -0
- package/assets/docs/tree/styling-basics.doc.mjs +181 -0
- package/assets/docs/tree/styling-libraries.doc.mjs +30 -0
- package/assets/docs/tree/styling.doc.mjs +29 -0
- package/assets/docs/tree/tailwind.doc.mjs +65 -0
- package/assets/docs/tree/themes.doc.mjs +2 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +128 -0
- package/assets/docs/tree/tokens-border.doc.mjs +46 -0
- package/assets/docs/tree/tokens-color.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-color.doc.mjs +438 -0
- package/assets/docs/tree/tokens-color.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-data.doc.mjs +323 -0
- package/assets/docs/tree/tokens-duration.doc.mjs +78 -0
- package/assets/docs/tree/tokens-ease.doc.mjs +46 -0
- package/assets/docs/tree/tokens-focus.doc.mjs +57 -0
- package/assets/docs/tree/tokens-font-weight.doc.mjs +58 -0
- package/assets/docs/tree/tokens-radius.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-radius.doc.mjs +70 -0
- package/assets/docs/tree/tokens-radius.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-shadow.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-shadow.doc.mjs +74 -0
- package/assets/docs/tree/tokens-shadow.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-size.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-size.doc.mjs +54 -0
- package/assets/docs/tree/tokens-size.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-spacing.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-spacing.doc.mjs +102 -0
- package/assets/docs/tree/tokens-spacing.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-syntax.doc.mjs +98 -0
- package/assets/docs/tree/tokens-text-size.doc.mjs +90 -0
- package/assets/docs/tree/tokens-type-scale.doc.mjs +210 -0
- package/assets/docs/tree/tokens-typography.doc.mjs +54 -0
- package/assets/docs/tree/tokens-usage.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-usage.doc.mjs +36 -0
- package/assets/docs/tree/tokens-usage.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens.doc.mjs +28 -0
- package/assets/docs/tree/troubleshooting.doc.mjs +4 -0
- package/assets/docs/tree/type-scale.doc.mjs +147 -0
- package/assets/docs/tree/typography-best-practices.doc.mjs +55 -0
- package/assets/docs/tree/typography.doc.mjs +29 -0
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +22 -5
- package/assets/docs/tree/versioning.doc.mjs +4 -1
- package/assets/docs/use-a-theme.doc.mjs +212 -0
- package/assets/templates/pages/incident-console/page.tsx +1 -1
- package/assets/templates/pages/table-collapsible/page.tsx +1474 -0
- package/assets/templates/pages/table-collapsible/template.doc.mjs +12 -0
- package/assets/templates/pages/table-comparison/page.tsx +1449 -0
- package/assets/templates/pages/table-comparison/template.doc.mjs +12 -0
- package/assets/theme.template.ts +4 -3
- package/authoring/doctypes/command/command.doc.mjs +5 -0
- package/authoring/doctypes/command/type.ts +2 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/component/type.ts +8 -4
- package/authoring/doctypes/template/type.ts +1 -0
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/commands/blog.mjs +3 -3
- package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
- package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
- package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
- package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
- package/clients/cli/commands/build-theme.mjs +338 -45
- package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
- package/clients/cli/commands/build.mjs +8 -6
- package/clients/cli/commands/build.text-fields.test.mjs +1 -1
- package/clients/cli/commands/component/index.mjs +91 -12
- package/clients/cli/commands/component-replacement.text.test.mjs +316 -0
- package/clients/cli/commands/component.doc.mjs +9 -2
- package/clients/cli/commands/docs.doc.mjs +2 -1
- package/clients/cli/commands/docs.mjs +63 -23
- package/clients/cli/commands/docs.test.mjs +17 -15
- package/clients/cli/commands/doctor-integration-components.doc.mjs +15 -4
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +59 -52
- package/clients/cli/commands/gap-report.doc.mjs +2 -2
- package/clients/cli/commands/hook/index.mjs +7 -2
- package/clients/cli/commands/import-hint-correctness.test.mjs +28 -5
- package/clients/cli/commands/init.next-steps.test.mjs +18 -23
- package/clients/cli/commands/integration-real-world.test.mjs +61 -12
- package/clients/cli/commands/layout-check.doc.mjs +2 -0
- package/clients/cli/commands/layout-expand.doc.mjs +2 -0
- package/clients/cli/commands/layout-grammar.doc.mjs +2 -0
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
- package/clients/cli/commands/layout.doc.mjs +2 -0
- package/clients/cli/commands/layout.mjs +40 -4
- package/clients/cli/commands/no-prompt-wording.test.mjs +4 -4
- package/clients/cli/commands/search.test.mjs +10 -4
- package/clients/cli/commands/swizzle.doc.mjs +12 -3
- package/clients/cli/commands/swizzle.mjs +2 -1
- package/clients/cli/commands/swizzle.routing.test.mjs +2 -1
- package/clients/cli/commands/template.mjs +56 -5
- package/clients/cli/commands/text-json-parity.test.mjs +40 -0
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +135 -0
- package/clients/cli/commands/theme-add.doc.mjs +19 -19
- package/clients/cli/commands/theme-build.doc.mjs +3 -1
- package/clients/cli/commands/theme-eject.doc.mjs +47 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +5 -2
- package/clients/cli/commands/theme-list.doc.mjs +2 -2
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -2
- package/clients/cli/commands/theme-remove.doc.mjs +22 -0
- package/clients/cli/commands/theme-template.doc.mjs +4 -3
- package/clients/cli/commands/theme-use.doc.mjs +22 -0
- package/clients/cli/commands/theme.doc.mjs +21 -16
- package/clients/cli/commands/upgrade.config-ordering.test.mjs +2 -1
- package/clients/cli/commands/upgrade.mjs +1 -1
- package/clients/cli/index.mjs +5 -2
- package/clients/cli/lib/component-format.mjs +29 -2
- package/clients/cli/lib/component-format.test.mjs +1 -1
- package/clients/cli/lib/define-command.mjs +4 -0
- package/clients/cli/lib/resolve-theme.mjs +80 -78
- package/clients/cli/lib/resolve-theme.test.mjs +523 -27
- package/foundation/agent-docs/agent-docs.mjs +48 -30
- package/foundation/agent-docs/agent-docs.test.mjs +47 -34
- package/foundation/agent-docs/app-theme-workflow.test.mjs +13 -0
- package/foundation/config/project.d.mts +20 -5
- package/foundation/config/project.mjs +43 -6
- package/foundation/config/project.test.mjs +1 -1
- package/foundation/config/theme-private-vars.d.mts +12 -0
- package/foundation/config/theme-private-vars.mjs +107 -0
- package/foundation/config/theme-private-vars.test.mjs +55 -0
- package/foundation/config/theme-state.d.mts +145 -0
- package/foundation/config/theme-state.mjs +417 -0
- package/foundation/config/theme-state.test.mjs +182 -0
- package/foundation/discovery/component-discovery.d.mts +5 -2
- package/foundation/discovery/component-discovery.mjs +12 -6
- package/foundation/discovery/component-replacement.d.mts +91 -0
- package/foundation/discovery/component-replacement.mjs +417 -0
- package/foundation/discovery/component-replacement.test.mjs +480 -0
- package/foundation/discovery/docs-discovery.test.mjs +1 -1
- package/foundation/discovery/docs-output-budget.d.mts +6 -2
- package/foundation/discovery/docs-output-budget.mjs +2 -1
- package/foundation/discovery/docs-section-key.d.mts +4 -2
- package/foundation/discovery/docs-section-key.mjs +1 -1
- package/foundation/discovery/module-exports.d.mts +10 -0
- package/foundation/discovery/module-exports.mjs +146 -0
- package/foundation/discovery/package-exports.d.mts +29 -0
- package/foundation/discovery/package-exports.mjs +200 -0
- package/foundation/discovery/template-needs.d.mts +31 -0
- package/foundation/discovery/template-needs.mjs +156 -0
- package/foundation/discovery/template-needs.test.mjs +203 -0
- package/foundation/discovery/theme-discovery.d.mts +72 -5
- package/foundation/discovery/theme-discovery.mjs +134 -18
- package/foundation/discovery/theme-discovery.test.mjs +9 -3
- package/foundation/discovery/theme-imports.d.mts +15 -0
- package/foundation/discovery/theme-imports.mjs +217 -0
- package/foundation/discovery/theme-imports.test.mjs +173 -0
- package/foundation/doc-compiler/bundle.mjs +52 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +15 -5
- package/foundation/doc-compiler/inputs.mjs +2 -1
- package/foundation/doc-compiler/lenses.d.mts +4 -2
- package/foundation/doc-compiler/lenses.mjs +1 -1
- package/foundation/doc-compiler/split-topic-keywords.test.mjs +73 -0
- package/foundation/doc-compiler/tree.d.mts +10 -0
- package/foundation/doc-compiler/tree.mjs +22 -0
- package/foundation/doc-compiler/tree.test.mjs +3 -2
- package/foundation/env/package-manager.d.mts +31 -8
- package/foundation/env/package-manager.mjs +120 -13
- package/foundation/env/package-manager.test.mjs +174 -1
- package/foundation/fs/module-loader.d.mts +9 -0
- package/foundation/fs/module-loader.mjs +71 -2
- package/foundation/integrations/cli-requirement.d.mts +22 -0
- package/foundation/integrations/cli-requirement.mjs +31 -0
- package/foundation/integrations/cli-requirement.test.mjs +70 -0
- package/foundation/integrations/contribution-inventory.mjs +3 -3
- package/foundation/integrations/validate-contributions.d.mts +16 -0
- package/foundation/integrations/validate-contributions.mjs +56 -8
- package/foundation/response/base.d.ts +9 -3
- package/foundation/response/json.d.mts +7 -4
- package/foundation/response/json.mjs +10 -6
- package/foundation/response/response-types.doc.mjs +41 -26
- package/foundation/response/response.doc.mjs +18 -4
- package/foundation/text/copyright-header.mjs +1 -1
- package/foundation/text/copyright-header.test.mjs +1 -1
- package/package.json +1 -1
- package/assets/docs/layout.doc.dense.mjs +0 -388
- package/assets/docs/layout.doc.mjs +0 -550
- package/assets/docs/styling-libraries.doc.mjs +0 -469
- package/assets/docs/styling.doc.mjs +0 -412
- package/assets/docs/tokens.doc.dense.mjs +0 -15
- package/assets/docs/tokens.doc.mjs +0 -1491
- package/assets/docs/tokens.doc.zh.mjs +0 -15
- package/assets/docs/typography.doc.mjs +0 -286
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import {validatePrivateVars} from './theme-private-vars.mjs';
|
|
5
|
+
|
|
6
|
+
describe('validatePrivateVars', () => {
|
|
7
|
+
it('accepts guaranteed properties that the compiler expands to private variables', () => {
|
|
8
|
+
expect(
|
|
9
|
+
validatePrivateVars({
|
|
10
|
+
name: 'correct',
|
|
11
|
+
tokens: {},
|
|
12
|
+
components: {
|
|
13
|
+
button: {base: {borderRadius: 'var(--radius-full)'}},
|
|
14
|
+
card: {base: {padding: 'var(--spacing-4)'}},
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('reports direct private keys on every authored input surface', () => {
|
|
21
|
+
const errors = validatePrivateVars({
|
|
22
|
+
name: 'private-inputs',
|
|
23
|
+
tokens: {'--_root-token': 'red'},
|
|
24
|
+
localTokens: {'--_root-local': 'blue'},
|
|
25
|
+
components: {button: {base: {'--_root-component': '1px'}}},
|
|
26
|
+
onDark: {
|
|
27
|
+
tokens: {'--_dark-token': 'black'},
|
|
28
|
+
components: {card: {base: {'--_dark-component': '2px'}}},
|
|
29
|
+
},
|
|
30
|
+
adaptations: {
|
|
31
|
+
rules: [
|
|
32
|
+
{
|
|
33
|
+
when: {pointer: 'coarse'},
|
|
34
|
+
value: {
|
|
35
|
+
localTokens: {'--_rule-local': '3px'},
|
|
36
|
+
components: {button: {base: {'--_rule-component': '4px'}}},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
for (const name of [
|
|
44
|
+
'--_root-token',
|
|
45
|
+
'--_root-local',
|
|
46
|
+
'--_root-component',
|
|
47
|
+
'--_dark-token',
|
|
48
|
+
'--_dark-component',
|
|
49
|
+
'--_rule-local',
|
|
50
|
+
'--_rule-component',
|
|
51
|
+
]) {
|
|
52
|
+
expect(errors.join('\n')).toContain(name);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/** @param {string} value */
|
|
5
|
+
export function projectPath(value: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Find the nearest package.json from a working directory.
|
|
8
|
+
* @param {string} cwd
|
|
9
|
+
*/
|
|
10
|
+
export function findThemeProject(cwd: string): {
|
|
11
|
+
projectDir: string;
|
|
12
|
+
packageFile: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Whether an owner value names a project-relative local theme root instead of
|
|
16
|
+
* an installed package.
|
|
17
|
+
* @param {string} owner
|
|
18
|
+
*/
|
|
19
|
+
export function isLocalThemeOwner(owner: string): boolean;
|
|
20
|
+
/** @param {string} projectDir */
|
|
21
|
+
export function projectUsesTypeScript(projectDir: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* All conventional module locations. The preferred new location is first.
|
|
24
|
+
* @param {string} projectDir
|
|
25
|
+
*/
|
|
26
|
+
export function themeModuleCandidates(projectDir: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Parse the generated module's record without executing the module.
|
|
29
|
+
* @param {string} source
|
|
30
|
+
* @param {string} label
|
|
31
|
+
*/
|
|
32
|
+
export function parseThemeModuleRecord(source: string, label?: string): {
|
|
33
|
+
themes: Record<string, string>;
|
|
34
|
+
defaultSlug: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Preserve the one existing generated module. With none, choose the first
|
|
38
|
+
* conventional location. Two generated copies are ambiguous and fail closed.
|
|
39
|
+
* @param {string} projectDir
|
|
40
|
+
* @param {{forWrite?: boolean}} [options]
|
|
41
|
+
*/
|
|
42
|
+
export function resolveThemeModule(projectDir: string, { forWrite }?: {
|
|
43
|
+
forWrite?: boolean;
|
|
44
|
+
}): {
|
|
45
|
+
file: string;
|
|
46
|
+
path: string;
|
|
47
|
+
typescript: boolean;
|
|
48
|
+
expectedOriginal: NonSharedBuffer | undefined;
|
|
49
|
+
exists: boolean;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {object} ThemeState
|
|
53
|
+
* @property {string} projectDir
|
|
54
|
+
* @property {string} packageFile
|
|
55
|
+
* @property {Record<string, string>} themes
|
|
56
|
+
* @property {string|null} defaultSlug
|
|
57
|
+
* @property {string|null} legacyTheme
|
|
58
|
+
* @property {boolean} configured
|
|
59
|
+
* @property {ReturnType<typeof resolveThemeModule>} module
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Read app-theme state from the generated module. Only when no module exists is
|
|
63
|
+
* the released `package.json#astryx.theme` meaning returned as legacy input.
|
|
64
|
+
* @param {string} [cwd]
|
|
65
|
+
* @returns {ThemeState}
|
|
66
|
+
*/
|
|
67
|
+
export function readThemeState(cwd?: string): ThemeState;
|
|
68
|
+
/**
|
|
69
|
+
* @typedef {object} ResolvedAppTheme
|
|
70
|
+
* @property {string} slug
|
|
71
|
+
* @property {string} owner
|
|
72
|
+
* @property {string} exportName
|
|
73
|
+
* @property {string} module
|
|
74
|
+
* @property {string} stylesheet
|
|
75
|
+
* @property {string} [fontStylesheet]
|
|
76
|
+
* @property {string} moduleFile
|
|
77
|
+
* @property {string} stylesheetFile
|
|
78
|
+
* @property {string} [fontStylesheetFile]
|
|
79
|
+
* @property {'bundled'|'package'|'local'} source
|
|
80
|
+
*/
|
|
81
|
+
/**
|
|
82
|
+
* Render one generated module from final resolved state.
|
|
83
|
+
* @param {ResolvedAppTheme[]} themes
|
|
84
|
+
* @param {string} defaultSlug
|
|
85
|
+
* @param {boolean} typescript
|
|
86
|
+
*/
|
|
87
|
+
export function renderThemeModule(themes: ResolvedAppTheme[], defaultSlug: string, typescript: boolean): string;
|
|
88
|
+
/**
|
|
89
|
+
* Resolve a project-relative import from the generated module to a local file.
|
|
90
|
+
* @param {string} moduleFile
|
|
91
|
+
* @param {string} target
|
|
92
|
+
*/
|
|
93
|
+
export function localImportSpecifier(moduleFile: string, target: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Plan the generated-module write. The caller applies it through the shared
|
|
96
|
+
* atomic transaction.
|
|
97
|
+
* @param {ThemeState} state
|
|
98
|
+
* @param {Record<string, string>} themes
|
|
99
|
+
* @param {string} defaultSlug
|
|
100
|
+
* @param {ResolvedAppTheme[]} resolvedThemes
|
|
101
|
+
*/
|
|
102
|
+
export function planThemeAppWrite(state: ThemeState, themes: Record<string, string>, defaultSlug: string, resolvedThemes: ResolvedAppTheme[]): {
|
|
103
|
+
module: {
|
|
104
|
+
file: string;
|
|
105
|
+
path: string;
|
|
106
|
+
typescript: boolean;
|
|
107
|
+
expectedOriginal: NonSharedBuffer | undefined;
|
|
108
|
+
exists: boolean;
|
|
109
|
+
};
|
|
110
|
+
entries: ResolvedAppTheme[];
|
|
111
|
+
plan: {
|
|
112
|
+
expectedOriginal?: NonSharedBuffer | undefined;
|
|
113
|
+
path: string;
|
|
114
|
+
contents: string;
|
|
115
|
+
createOnly: boolean;
|
|
116
|
+
};
|
|
117
|
+
moduleContents: string;
|
|
118
|
+
};
|
|
119
|
+
export const LOCAL_THEME_ROOT: "./src/themes";
|
|
120
|
+
export const THEME_MODULE_BASENAME: "astryx-themes";
|
|
121
|
+
export const THEME_MODULE_MARKER: "@generated by `astryx theme` \u2014 do not edit manually.";
|
|
122
|
+
export const THEME_RECORD_MARKER: "@astryx-theme-record";
|
|
123
|
+
export class ThemeStateError extends Error {
|
|
124
|
+
}
|
|
125
|
+
export type ThemeState = {
|
|
126
|
+
projectDir: string;
|
|
127
|
+
packageFile: string;
|
|
128
|
+
themes: Record<string, string>;
|
|
129
|
+
defaultSlug: string | null;
|
|
130
|
+
legacyTheme: string | null;
|
|
131
|
+
configured: boolean;
|
|
132
|
+
module: ReturnType<typeof resolveThemeModule>;
|
|
133
|
+
};
|
|
134
|
+
export type ResolvedAppTheme = {
|
|
135
|
+
slug: string;
|
|
136
|
+
owner: string;
|
|
137
|
+
exportName: string;
|
|
138
|
+
module: string;
|
|
139
|
+
stylesheet: string;
|
|
140
|
+
fontStylesheet?: string | undefined;
|
|
141
|
+
moduleFile: string;
|
|
142
|
+
stylesheetFile: string;
|
|
143
|
+
fontStylesheetFile?: string | undefined;
|
|
144
|
+
source: "bundled" | "package" | "local";
|
|
145
|
+
};
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file App-theme state stored in the generated theme module.
|
|
5
|
+
*
|
|
6
|
+
* The module is both the app import surface and the only record of added themes.
|
|
7
|
+
* Its generated header records owners and the default without adding another public
|
|
8
|
+
* export. Commands parse that header without running project code, regenerate the
|
|
9
|
+
* whole marked file instead of editing it, and never replace an authored file.
|
|
10
|
+
*
|
|
11
|
+
* @input A project directory and resolved built-theme imports
|
|
12
|
+
* @output Parsed state plus deterministic generated-module write plans
|
|
13
|
+
* @position packages/cli/foundation/config — shared app-theme state
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as path from 'node:path';
|
|
18
|
+
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
19
|
+
|
|
20
|
+
export const LOCAL_THEME_ROOT = './src/themes';
|
|
21
|
+
export const THEME_MODULE_BASENAME = 'astryx-themes';
|
|
22
|
+
export const THEME_MODULE_MARKER =
|
|
23
|
+
'@generated by `astryx theme` — do not edit manually.';
|
|
24
|
+
export const THEME_RECORD_MARKER = '@astryx-theme-record';
|
|
25
|
+
|
|
26
|
+
const THEME_SLUG_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
27
|
+
|
|
28
|
+
export class ThemeStateError extends Error {}
|
|
29
|
+
|
|
30
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
31
|
+
function isRecord(value) {
|
|
32
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @param {string} value */
|
|
36
|
+
export function projectPath(value) {
|
|
37
|
+
return value.split(path.sep).join('/');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Find the nearest package.json from a working directory.
|
|
42
|
+
* @param {string} cwd
|
|
43
|
+
*/
|
|
44
|
+
export function findThemeProject(cwd) {
|
|
45
|
+
let projectDir = path.resolve(cwd);
|
|
46
|
+
for (let depth = 0; depth < 50; depth++) {
|
|
47
|
+
const packageFile = path.join(projectDir, 'package.json');
|
|
48
|
+
if (fs.existsSync(packageFile)) return {projectDir, packageFile};
|
|
49
|
+
const parent = path.dirname(projectDir);
|
|
50
|
+
if (parent === projectDir) break;
|
|
51
|
+
projectDir = parent;
|
|
52
|
+
}
|
|
53
|
+
throw new ThemeStateError(
|
|
54
|
+
'No package.json found. Run this command inside an app project.',
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether an owner value names a project-relative local theme root instead of
|
|
60
|
+
* an installed package.
|
|
61
|
+
* @param {string} owner
|
|
62
|
+
*/
|
|
63
|
+
export function isLocalThemeOwner(owner) {
|
|
64
|
+
return owner.startsWith('./') || owner.startsWith('../') || path.isAbsolute(owner);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {string} projectDir */
|
|
68
|
+
export function projectUsesTypeScript(projectDir) {
|
|
69
|
+
try {
|
|
70
|
+
return fs
|
|
71
|
+
.readdirSync(projectDir, {withFileTypes: true})
|
|
72
|
+
.some(
|
|
73
|
+
entry =>
|
|
74
|
+
entry.isFile() &&
|
|
75
|
+
/^tsconfig(?:\.[^.]+)*\.json$/u.test(entry.name),
|
|
76
|
+
);
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* All conventional module locations. The preferred new location is first.
|
|
84
|
+
* @param {string} projectDir
|
|
85
|
+
*/
|
|
86
|
+
export function themeModuleCandidates(projectDir) {
|
|
87
|
+
const src = path.join(projectDir, 'src');
|
|
88
|
+
const hasSrc = fs.existsSync(src) && fs.statSync(src).isDirectory();
|
|
89
|
+
const typescript = projectUsesTypeScript(projectDir);
|
|
90
|
+
const preferredDir = hasSrc ? src : projectDir;
|
|
91
|
+
const otherDir = hasSrc ? projectDir : src;
|
|
92
|
+
const preferredExtension = typescript ? '.ts' : '.js';
|
|
93
|
+
const otherExtension = typescript ? '.js' : '.ts';
|
|
94
|
+
return [
|
|
95
|
+
path.join(preferredDir, `${THEME_MODULE_BASENAME}${preferredExtension}`),
|
|
96
|
+
path.join(preferredDir, `${THEME_MODULE_BASENAME}${otherExtension}`),
|
|
97
|
+
path.join(otherDir, `${THEME_MODULE_BASENAME}${preferredExtension}`),
|
|
98
|
+
path.join(otherDir, `${THEME_MODULE_BASENAME}${otherExtension}`),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {unknown} value
|
|
104
|
+
* @param {string} label
|
|
105
|
+
*/
|
|
106
|
+
function validThemeRecord(value, label) {
|
|
107
|
+
if (!isRecord(value) || !isRecord(value.themes)) {
|
|
108
|
+
throw new ThemeStateError(
|
|
109
|
+
`${label} must carry a static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug> --import\`.`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const keys = Object.keys(value);
|
|
113
|
+
if (
|
|
114
|
+
keys.length !== 2 ||
|
|
115
|
+
!keys.includes('themes') ||
|
|
116
|
+
!keys.includes('defaultThemeSlug')
|
|
117
|
+
) {
|
|
118
|
+
throw new ThemeStateError(
|
|
119
|
+
`${label} ${THEME_RECORD_MARKER} header must contain only themes and defaultThemeSlug.`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @type {Record<string, string>} */
|
|
124
|
+
const themes = {};
|
|
125
|
+
for (const [slug, owner] of Object.entries(value.themes)) {
|
|
126
|
+
if (
|
|
127
|
+
!THEME_SLUG_RE.test(slug) ||
|
|
128
|
+
typeof owner !== 'string' ||
|
|
129
|
+
owner.trim() === ''
|
|
130
|
+
) {
|
|
131
|
+
throw new ThemeStateError(
|
|
132
|
+
`${label} theme record must map lowercase kebab-case slugs to package names or local theme roots.`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
themes[slug] = owner;
|
|
136
|
+
}
|
|
137
|
+
if (
|
|
138
|
+
typeof value.defaultThemeSlug !== 'string' ||
|
|
139
|
+
!THEME_SLUG_RE.test(value.defaultThemeSlug)
|
|
140
|
+
) {
|
|
141
|
+
throw new ThemeStateError(
|
|
142
|
+
`${label} defaultThemeSlug must be a lowercase kebab-case slug. Regenerate it with \`astryx theme use <slug>\`.`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return {themes, defaultSlug: value.defaultThemeSlug};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Parse the generated module's record without executing the module.
|
|
150
|
+
* @param {string} source
|
|
151
|
+
* @param {string} label
|
|
152
|
+
*/
|
|
153
|
+
export function parseThemeModuleRecord(source, label = 'theme module') {
|
|
154
|
+
if (!source.includes(THEME_MODULE_MARKER)) {
|
|
155
|
+
throw new ThemeStateError(`${label} does not carry the Astryx generated marker.`);
|
|
156
|
+
}
|
|
157
|
+
const recordLines = source
|
|
158
|
+
.split(/\r?\n/u)
|
|
159
|
+
.filter(line => /^\s*\*\s*@astryx-theme-record\s+/u.test(line));
|
|
160
|
+
if (recordLines.length !== 1) {
|
|
161
|
+
throw new ThemeStateError(
|
|
162
|
+
`${label} must carry exactly one static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug> --import\`.`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const payload = recordLines[0].replace(
|
|
166
|
+
/^\s*\*\s*@astryx-theme-record\s+/u,
|
|
167
|
+
'',
|
|
168
|
+
);
|
|
169
|
+
let record;
|
|
170
|
+
try {
|
|
171
|
+
record = JSON.parse(payload);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
throw new ThemeStateError(
|
|
174
|
+
`${label} has an invalid ${THEME_RECORD_MARKER} header: ${error instanceof Error ? error.message : String(error)}`,
|
|
175
|
+
{cause: error},
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return validThemeRecord(record, label);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Preserve the one existing generated module. With none, choose the first
|
|
183
|
+
* conventional location. Two generated copies are ambiguous and fail closed.
|
|
184
|
+
* @param {string} projectDir
|
|
185
|
+
* @param {{forWrite?: boolean}} [options]
|
|
186
|
+
*/
|
|
187
|
+
export function resolveThemeModule(projectDir, {forWrite = false} = {}) {
|
|
188
|
+
const candidates = themeModuleCandidates(projectDir);
|
|
189
|
+
const generated = candidates.filter(file => {
|
|
190
|
+
try {
|
|
191
|
+
return fs.readFileSync(file, 'utf-8').includes(THEME_MODULE_MARKER);
|
|
192
|
+
} catch {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (generated.length > 1) {
|
|
197
|
+
throw new ThemeStateError(
|
|
198
|
+
`More than one generated theme module exists: ${generated
|
|
199
|
+
.map(file => projectPath(path.relative(projectDir, file)))
|
|
200
|
+
.join(', ')}. Keep one and remove the others before running the command again.`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
const file = generated[0] ?? candidates[0];
|
|
204
|
+
if (forWrite) {
|
|
205
|
+
try {
|
|
206
|
+
assertWithin(path.relative(projectDir, file), projectDir, {
|
|
207
|
+
label: 'generated theme module',
|
|
208
|
+
});
|
|
209
|
+
} catch (error) {
|
|
210
|
+
if (error instanceof PathSafetyError) {
|
|
211
|
+
throw new ThemeStateError(error.message, {cause: error});
|
|
212
|
+
}
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
let expectedOriginal;
|
|
217
|
+
if (fs.existsSync(file)) {
|
|
218
|
+
expectedOriginal = fs.readFileSync(file);
|
|
219
|
+
if (!expectedOriginal.toString('utf-8').includes(THEME_MODULE_MARKER)) {
|
|
220
|
+
if (forWrite) {
|
|
221
|
+
throw new ThemeStateError(
|
|
222
|
+
`Refusing to replace ${projectPath(path.relative(projectDir, file))}: it is not an Astryx-generated theme module. Move that file before adding themes.`,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
expectedOriginal = undefined;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
file,
|
|
230
|
+
path: projectPath(path.relative(projectDir, file)),
|
|
231
|
+
typescript: file.endsWith('.ts'),
|
|
232
|
+
expectedOriginal,
|
|
233
|
+
exists: generated.length === 1,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @typedef {object} ThemeState
|
|
239
|
+
* @property {string} projectDir
|
|
240
|
+
* @property {string} packageFile
|
|
241
|
+
* @property {Record<string, string>} themes
|
|
242
|
+
* @property {string|null} defaultSlug
|
|
243
|
+
* @property {string|null} legacyTheme
|
|
244
|
+
* @property {boolean} configured
|
|
245
|
+
* @property {ReturnType<typeof resolveThemeModule>} module
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Read app-theme state from the generated module. Only when no module exists is
|
|
250
|
+
* the released `package.json#astryx.theme` meaning returned as legacy input.
|
|
251
|
+
* @param {string} [cwd]
|
|
252
|
+
* @returns {ThemeState}
|
|
253
|
+
*/
|
|
254
|
+
export function readThemeState(cwd = process.cwd()) {
|
|
255
|
+
const {projectDir, packageFile} = findThemeProject(cwd);
|
|
256
|
+
const module = resolveThemeModule(projectDir);
|
|
257
|
+
if (module.exists && module.expectedOriginal) {
|
|
258
|
+
const record = parseThemeModuleRecord(
|
|
259
|
+
module.expectedOriginal.toString('utf-8'),
|
|
260
|
+
module.path,
|
|
261
|
+
);
|
|
262
|
+
return {
|
|
263
|
+
projectDir,
|
|
264
|
+
packageFile,
|
|
265
|
+
themes: record.themes,
|
|
266
|
+
defaultSlug: record.defaultSlug,
|
|
267
|
+
legacyTheme: null,
|
|
268
|
+
configured: true,
|
|
269
|
+
module,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
let legacyTheme = null;
|
|
274
|
+
try {
|
|
275
|
+
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf-8'));
|
|
276
|
+
if (
|
|
277
|
+
isRecord(pkg) &&
|
|
278
|
+
isRecord(pkg.astryx) &&
|
|
279
|
+
typeof pkg.astryx.theme === 'string'
|
|
280
|
+
) {
|
|
281
|
+
legacyTheme = pkg.astryx.theme;
|
|
282
|
+
}
|
|
283
|
+
} catch {
|
|
284
|
+
// Theme commands surface package problems at their own write boundary. A
|
|
285
|
+
// legacy lookup with no readable package field simply has no configured theme.
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
projectDir,
|
|
289
|
+
packageFile,
|
|
290
|
+
themes: {},
|
|
291
|
+
defaultSlug: null,
|
|
292
|
+
legacyTheme,
|
|
293
|
+
configured: false,
|
|
294
|
+
module,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @typedef {object} ResolvedAppTheme
|
|
300
|
+
* @property {string} slug
|
|
301
|
+
* @property {string} owner
|
|
302
|
+
* @property {string} exportName
|
|
303
|
+
* @property {string} module
|
|
304
|
+
* @property {string} stylesheet
|
|
305
|
+
* @property {string} [fontStylesheet]
|
|
306
|
+
* @property {string} moduleFile
|
|
307
|
+
* @property {string} stylesheetFile
|
|
308
|
+
* @property {string} [fontStylesheetFile]
|
|
309
|
+
* @property {'bundled'|'package'|'local'} source
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Render one generated module from final resolved state.
|
|
314
|
+
* @param {ResolvedAppTheme[]} themes
|
|
315
|
+
* @param {string} defaultSlug
|
|
316
|
+
* @param {boolean} typescript
|
|
317
|
+
*/
|
|
318
|
+
export function renderThemeModule(themes, defaultSlug, typescript) {
|
|
319
|
+
if (!themes.some(theme => theme.slug === defaultSlug)) {
|
|
320
|
+
throw new ThemeStateError(
|
|
321
|
+
`Default theme "${defaultSlug}" is not added. Run \`astryx theme add ${defaultSlug} --import\` first.`,
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
/** @type {string[]} */
|
|
325
|
+
const imports = [];
|
|
326
|
+
/** @type {string[]} */
|
|
327
|
+
const entries = [];
|
|
328
|
+
/** @type {Record<string, string>} */
|
|
329
|
+
const owners = {};
|
|
330
|
+
themes.forEach((theme, index) => {
|
|
331
|
+
const local = `_astryxTheme${index}`;
|
|
332
|
+
imports.push(
|
|
333
|
+
`import {${theme.exportName} as ${local}} from ${JSON.stringify(theme.module)};`,
|
|
334
|
+
`import ${JSON.stringify(theme.stylesheet)};`,
|
|
335
|
+
);
|
|
336
|
+
if (theme.fontStylesheet) {
|
|
337
|
+
imports.push(`import ${JSON.stringify(theme.fontStylesheet)};`);
|
|
338
|
+
}
|
|
339
|
+
entries.push(` ${JSON.stringify(theme.slug)}: ${local},`);
|
|
340
|
+
owners[theme.slug] = theme.owner;
|
|
341
|
+
});
|
|
342
|
+
const record = JSON.stringify({themes: owners, defaultThemeSlug: defaultSlug});
|
|
343
|
+
return `/**\n * ${THEME_MODULE_MARKER}\n * ${THEME_RECORD_MARKER} ${record}\n */\n\n${imports.join(
|
|
344
|
+
'\n',
|
|
345
|
+
)}\n\nexport const themes = {\n${entries.join('\n')}\n}${
|
|
346
|
+
typescript ? ' as const' : ''
|
|
347
|
+
};\n${
|
|
348
|
+
typescript ? 'export type ThemeSlug = keyof typeof themes;\n' : ''
|
|
349
|
+
}\nexport const defaultThemeSlug${
|
|
350
|
+
typescript ? ': keyof typeof themes' : ''
|
|
351
|
+
} = ${JSON.stringify(defaultSlug)};\n`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Resolve a project-relative import from the generated module to a local file.
|
|
356
|
+
* @param {string} moduleFile
|
|
357
|
+
* @param {string} target
|
|
358
|
+
*/
|
|
359
|
+
export function localImportSpecifier(moduleFile, target) {
|
|
360
|
+
let relative = projectPath(path.relative(path.dirname(moduleFile), target));
|
|
361
|
+
if (!relative.startsWith('.')) relative = `./${relative}`;
|
|
362
|
+
return relative;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Plan the generated-module write. The caller applies it through the shared
|
|
367
|
+
* atomic transaction.
|
|
368
|
+
* @param {ThemeState} state
|
|
369
|
+
* @param {Record<string, string>} themes
|
|
370
|
+
* @param {string} defaultSlug
|
|
371
|
+
* @param {ResolvedAppTheme[]} resolvedThemes
|
|
372
|
+
*/
|
|
373
|
+
export function planThemeAppWrite(state, themes, defaultSlug, resolvedThemes) {
|
|
374
|
+
const module = resolveThemeModule(state.projectDir, {forWrite: true});
|
|
375
|
+
const entries = resolvedThemes.map(theme =>
|
|
376
|
+
theme.source === 'local'
|
|
377
|
+
? {
|
|
378
|
+
...theme,
|
|
379
|
+
module: localImportSpecifier(module.file, theme.moduleFile),
|
|
380
|
+
stylesheet: localImportSpecifier(module.file, theme.stylesheetFile),
|
|
381
|
+
...(theme.fontStylesheetFile
|
|
382
|
+
? {
|
|
383
|
+
fontStylesheet: localImportSpecifier(
|
|
384
|
+
module.file,
|
|
385
|
+
theme.fontStylesheetFile,
|
|
386
|
+
),
|
|
387
|
+
}
|
|
388
|
+
: {}),
|
|
389
|
+
}
|
|
390
|
+
: theme,
|
|
391
|
+
);
|
|
392
|
+
for (const theme of entries) {
|
|
393
|
+
if (themes[theme.slug] !== theme.owner) {
|
|
394
|
+
throw new ThemeStateError(
|
|
395
|
+
`Theme record for "${theme.slug}" does not match its resolved owner.`,
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const moduleContents = renderThemeModule(
|
|
400
|
+
entries,
|
|
401
|
+
defaultSlug,
|
|
402
|
+
module.typescript,
|
|
403
|
+
);
|
|
404
|
+
return {
|
|
405
|
+
module,
|
|
406
|
+
entries,
|
|
407
|
+
plan: {
|
|
408
|
+
path: module.file,
|
|
409
|
+
contents: moduleContents,
|
|
410
|
+
createOnly: module.expectedOriginal == null,
|
|
411
|
+
...(module.expectedOriginal != null
|
|
412
|
+
? {expectedOriginal: module.expectedOriginal}
|
|
413
|
+
: {}),
|
|
414
|
+
},
|
|
415
|
+
moduleContents,
|
|
416
|
+
};
|
|
417
|
+
}
|