@astryxdesign/cli 0.6.6 → 0.6.7-canary.13feb39
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 +52 -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 +485 -3
- package/api/integration/pack-check.test.mjs +578 -10
- 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 +11 -197
- package/assets/docs/theme.doc.mjs +16 -764
- 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 +6 -5
- 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/replace-a-core-template.doc.mjs +1 -1
- 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/template-doc-overview.doc.mjs +1 -1
- 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 +7 -3
- 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 +6 -3
- 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 +28 -11
- 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/template.doc.mjs +2 -2
- package/authoring/doctypes/template/type.ts +5 -3
- 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 +43 -10
- package/foundation/integrations/cli-requirement.mjs +56 -13
- package/foundation/integrations/cli-requirement.test.mjs +160 -23
- 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 +9 -9
- 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
package/api/theme/_adapter.mjs
CHANGED
|
@@ -1,24 +1,57 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file Shared data
|
|
4
|
+
* @file Shared data and write adapter for app-theme commands.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Keeps the historical synchronous bundled-theme helper, resolves project-aware
|
|
7
|
+
* source themes, loads recorded built artifacts through the shared runtime
|
|
8
|
+
* loader, reads static generated-module state, and applies each add/remove/use
|
|
9
|
+
* regeneration through the shared atomic write transaction.
|
|
9
10
|
*/
|
|
10
11
|
|
|
12
|
+
import * as fs from 'node:fs';
|
|
13
|
+
import * as path from 'node:path';
|
|
11
14
|
import {Project} from '../../foundation/config/project.mjs';
|
|
12
15
|
import {
|
|
13
16
|
BUNDLED_THEME_PACKAGE,
|
|
14
17
|
THEMES_DIR,
|
|
15
18
|
discoverBundledThemes,
|
|
19
|
+
discoverIntegrationThemes,
|
|
20
|
+
discoverUnmigratedThemeCopies,
|
|
21
|
+
themeImportPackage,
|
|
16
22
|
} from '../../foundation/discovery/theme-discovery.mjs';
|
|
23
|
+
import {
|
|
24
|
+
ThemeImportError,
|
|
25
|
+
resolveThemeImports,
|
|
26
|
+
} from '../../foundation/discovery/theme-imports.mjs';
|
|
27
|
+
import {
|
|
28
|
+
findThemeProject,
|
|
29
|
+
isLocalThemeOwner,
|
|
30
|
+
ThemeStateError,
|
|
31
|
+
planThemeAppWrite,
|
|
32
|
+
readThemeState,
|
|
33
|
+
} from '../../foundation/config/theme-state.mjs';
|
|
17
34
|
import {AstryxError} from '../error.mjs';
|
|
18
35
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
36
|
+
import {
|
|
37
|
+
assertWithin,
|
|
38
|
+
PathSafetyError,
|
|
39
|
+
} from '../../foundation/fs/path-safety.mjs';
|
|
40
|
+
import {stripCopyrightHeader} from '../../foundation/text/copyright-header.mjs';
|
|
41
|
+
import {loadIntegrations} from '../../foundation/integrations/integrations.mjs';
|
|
42
|
+
import {importThemeArtifact} from '../../foundation/fs/module-loader.mjs';
|
|
43
|
+
import {applyWrites} from '../integration/add-helpers.mjs';
|
|
19
44
|
|
|
20
45
|
export {BUNDLED_THEME_PACKAGE, THEMES_DIR};
|
|
21
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Package written to the generated app record for one discovered theme.
|
|
49
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
|
|
50
|
+
*/
|
|
51
|
+
export function themeRecordOwner(theme) {
|
|
52
|
+
return themeImportPackage(theme);
|
|
53
|
+
}
|
|
54
|
+
|
|
22
55
|
/**
|
|
23
56
|
* A bundled theme entry kept for the historical public `listThemes()` helper.
|
|
24
57
|
* @typedef {Pick<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme, 'slug' | 'displayName' | 'description' | 'maintained' | 'entry' | 'exportName' | 'files'>} BundledTheme
|
|
@@ -56,40 +89,387 @@ function availableBundledThemes() {
|
|
|
56
89
|
* discovering them. The issue set lets a package-scoped lookup distinguish an
|
|
57
90
|
* absent theme from an installed package whose theme descriptors are broken.
|
|
58
91
|
* @param {string} cwd
|
|
92
|
+
* @param {{includeLocal?: boolean}} [options]
|
|
59
93
|
* @returns {Promise<{themes: import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[], issues: Array<import('../../foundation/integrations/issue').AstryxIntegrationIssue & {package: string}>}>}
|
|
60
94
|
*/
|
|
61
|
-
async function availableThemeState(cwd) {
|
|
95
|
+
async function availableThemeState(cwd, {includeLocal = true} = {}) {
|
|
96
|
+
let project;
|
|
62
97
|
try {
|
|
63
|
-
|
|
64
|
-
const themes = await project.themes();
|
|
65
|
-
return {themes, issues: await project.issues()};
|
|
98
|
+
project = await Project.load(cwd);
|
|
66
99
|
} catch {
|
|
67
100
|
return {themes: availableBundledThemes(), issues: []};
|
|
68
101
|
}
|
|
102
|
+
try {
|
|
103
|
+
const themes = await project.themes({includeLocal});
|
|
104
|
+
return {themes, issues: await project.issues()};
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw asThemeError(error);
|
|
107
|
+
}
|
|
69
108
|
}
|
|
70
109
|
|
|
71
110
|
/**
|
|
72
|
-
* Bundled themes plus
|
|
73
|
-
*
|
|
74
|
-
* command's historical usefulness outside a configured project.
|
|
111
|
+
* Bundled themes plus local and installed integration themes available to the
|
|
112
|
+
* project.
|
|
75
113
|
* @param {string} [cwd]
|
|
114
|
+
* @param {{includeLocal?: boolean}} [options]
|
|
76
115
|
* @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]>}
|
|
77
116
|
*/
|
|
78
|
-
export async function listAvailableThemes(cwd = process.cwd()) {
|
|
79
|
-
return (await availableThemeState(cwd)).themes;
|
|
117
|
+
export async function listAvailableThemes(cwd = process.cwd(), options = {}) {
|
|
118
|
+
return (await availableThemeState(cwd, options)).themes;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @param {unknown} error */
|
|
122
|
+
function isMissingThemeArtifact(error) {
|
|
123
|
+
return (
|
|
124
|
+
error != null &&
|
|
125
|
+
typeof error === 'object' &&
|
|
126
|
+
'code' in error &&
|
|
127
|
+
error.code === 'ERR_THEME_ARTIFACT_NOT_FOUND'
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** @param {unknown} error */
|
|
132
|
+
function isMalformedThemeArtifact(error) {
|
|
133
|
+
return (
|
|
134
|
+
error instanceof Error &&
|
|
135
|
+
(error.name === 'ParseError' ||
|
|
136
|
+
error.name === 'SyntaxError' ||
|
|
137
|
+
error.message.startsWith('ParseError:') ||
|
|
138
|
+
error.message.startsWith('SyntaxError:'))
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @param {string} specifier @param {string} cwd */
|
|
143
|
+
async function tryRecordedThemeArtifact(specifier, cwd) {
|
|
144
|
+
try {
|
|
145
|
+
return {
|
|
146
|
+
module: await importThemeArtifact(specifier, cwd),
|
|
147
|
+
missing: false,
|
|
148
|
+
problem: null,
|
|
149
|
+
};
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (isMissingThemeArtifact(error)) {
|
|
152
|
+
return {module: null, missing: true, problem: null};
|
|
153
|
+
}
|
|
154
|
+
if (!isMalformedThemeArtifact(error)) throw error;
|
|
155
|
+
const malformed = /** @type {Error} */ (error);
|
|
156
|
+
const detail =
|
|
157
|
+
malformed.message.split('\n', 1)[0]?.trim() || malformed.name;
|
|
158
|
+
return {
|
|
159
|
+
module: null,
|
|
160
|
+
missing: false,
|
|
161
|
+
problem: `could not load the recorded theme artifact "${specifier}": ${detail}`,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Load one built theme named by the generated app record. Callers choose how to
|
|
168
|
+
* present missing, ambiguous, or malformed results; unrelated loader failures
|
|
169
|
+
* propagate. A missing generated module is reported as `configured: false` so
|
|
170
|
+
* the released package-field path can remain separate.
|
|
171
|
+
*
|
|
172
|
+
* @param {string} cwd
|
|
173
|
+
* @param {string} [requestedSlug] defaults to the record's default
|
|
174
|
+
* @returns {Promise<{configured: boolean, slug: string|null, owner: string|null, module: Record<string, unknown>|null, specifier: string, missing?: boolean, problem: string|null}>}
|
|
175
|
+
*/
|
|
176
|
+
export async function resolveRecordedTheme(cwd, requestedSlug) {
|
|
177
|
+
let state;
|
|
178
|
+
try {
|
|
179
|
+
state = readThemeState(cwd);
|
|
180
|
+
} catch {
|
|
181
|
+
return {
|
|
182
|
+
configured: false,
|
|
183
|
+
slug: null,
|
|
184
|
+
owner: null,
|
|
185
|
+
module: null,
|
|
186
|
+
specifier: 'generated theme record',
|
|
187
|
+
problem: null,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (!state.configured) {
|
|
191
|
+
return {
|
|
192
|
+
configured: false,
|
|
193
|
+
slug: null,
|
|
194
|
+
owner: null,
|
|
195
|
+
module: null,
|
|
196
|
+
specifier: 'generated theme record',
|
|
197
|
+
problem: null,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const slug = requestedSlug ?? state.defaultSlug;
|
|
202
|
+
if (slug == null) {
|
|
203
|
+
return {
|
|
204
|
+
configured: true,
|
|
205
|
+
slug: null,
|
|
206
|
+
owner: null,
|
|
207
|
+
module: null,
|
|
208
|
+
specifier: 'generated theme record',
|
|
209
|
+
problem: 'the generated theme record has no default theme',
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const owner = state.themes[slug];
|
|
213
|
+
if (typeof owner !== 'string') {
|
|
214
|
+
return {
|
|
215
|
+
configured: true,
|
|
216
|
+
slug,
|
|
217
|
+
owner: null,
|
|
218
|
+
module: null,
|
|
219
|
+
specifier: `generated theme record (${slug})`,
|
|
220
|
+
problem: `theme "${slug}" is not present in the generated theme record`,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (isLocalThemeOwner(owner)) {
|
|
225
|
+
const specifier = path.join(state.projectDir, owner, slug, `${slug}.js`);
|
|
226
|
+
const loaded = await tryRecordedThemeArtifact(specifier, state.projectDir);
|
|
227
|
+
return {configured: true, slug, owner, ...loaded, specifier};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const perThemeSpecifier = `${owner}/themes/${slug}`;
|
|
231
|
+
const perTheme = await tryRecordedThemeArtifact(
|
|
232
|
+
perThemeSpecifier,
|
|
233
|
+
state.projectDir,
|
|
234
|
+
);
|
|
235
|
+
if (perTheme.module || perTheme.problem) {
|
|
236
|
+
return {
|
|
237
|
+
configured: true,
|
|
238
|
+
slug,
|
|
239
|
+
owner,
|
|
240
|
+
...perTheme,
|
|
241
|
+
specifier: perThemeSpecifier,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let ownerThemeCount = null;
|
|
246
|
+
try {
|
|
247
|
+
const integrations = await loadIntegrations([owner], {
|
|
248
|
+
cwd: state.projectDir,
|
|
249
|
+
resolveProviders: false,
|
|
250
|
+
});
|
|
251
|
+
const integration = integrations.find(
|
|
252
|
+
candidate => candidate.name === owner,
|
|
253
|
+
);
|
|
254
|
+
if (integration && !integration.__loadError) {
|
|
255
|
+
ownerThemeCount = (await discoverIntegrationThemes(integration)).length;
|
|
256
|
+
}
|
|
257
|
+
} catch {
|
|
258
|
+
// Bundled standalone theme packages have no integration manifest.
|
|
259
|
+
}
|
|
260
|
+
if (ownerThemeCount == null) {
|
|
261
|
+
try {
|
|
262
|
+
const available = await listAvailableThemes(state.projectDir);
|
|
263
|
+
ownerThemeCount = available.filter(
|
|
264
|
+
theme => themeImportPackage(theme) === owner,
|
|
265
|
+
).length;
|
|
266
|
+
} catch {
|
|
267
|
+
// An unavailable package cannot safely use the ambiguous shorthand.
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (ownerThemeCount != null && ownerThemeCount > 1) {
|
|
271
|
+
return {
|
|
272
|
+
configured: true,
|
|
273
|
+
slug,
|
|
274
|
+
owner,
|
|
275
|
+
module: null,
|
|
276
|
+
specifier: perThemeSpecifier,
|
|
277
|
+
problem: `theme "${slug}" is recorded from multi-theme package ${owner}, but ${perThemeSpecifier} does not resolve. Refusing to load ${owner}/built or the package root because either could be a different theme`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (ownerThemeCount === 1) {
|
|
281
|
+
for (const specifier of [`${owner}/built`, owner]) {
|
|
282
|
+
const loaded = await tryRecordedThemeArtifact(
|
|
283
|
+
specifier,
|
|
284
|
+
state.projectDir,
|
|
285
|
+
);
|
|
286
|
+
if (loaded.module || loaded.problem) {
|
|
287
|
+
return {configured: true, slug, owner, ...loaded, specifier};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
configured: true,
|
|
293
|
+
slug,
|
|
294
|
+
owner,
|
|
295
|
+
module: null,
|
|
296
|
+
specifier: perThemeSpecifier,
|
|
297
|
+
problem: null,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Source copies made by the released `theme add` before local descriptors.
|
|
303
|
+
* @param {string} cwd
|
|
304
|
+
*/
|
|
305
|
+
export function listUnmigratedThemeCopies(cwd) {
|
|
306
|
+
return discoverUnmigratedThemeCopies(cwd);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** @param {string} slug */
|
|
310
|
+
function defaultEjectTarget(slug) {
|
|
311
|
+
return path.join('src', 'themes', slug);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Strip repository boilerplate from UTF-8 text while preserving binary bytes.
|
|
316
|
+
* @param {Buffer} bytes
|
|
317
|
+
* @returns {Buffer|string}
|
|
318
|
+
*/
|
|
319
|
+
function scaffoldContents(bytes) {
|
|
320
|
+
const text = bytes.toString('utf-8');
|
|
321
|
+
return Buffer.from(text, 'utf-8').equals(bytes)
|
|
322
|
+
? stripCopyrightHeader(text)
|
|
323
|
+
: bytes;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Describe an ejected theme as a new, unmaintained local fork.
|
|
328
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
|
|
329
|
+
*/
|
|
330
|
+
function localThemeDescriptor(theme) {
|
|
331
|
+
return `/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */
|
|
332
|
+
export default {
|
|
333
|
+
type: 'theme',
|
|
334
|
+
name: ${JSON.stringify(theme.slug)},
|
|
335
|
+
displayName: ${JSON.stringify(theme.displayName)},
|
|
336
|
+
description: ${JSON.stringify(theme.description)},
|
|
337
|
+
maintained: false,
|
|
338
|
+
};
|
|
339
|
+
`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Publish one theme's complete source inventory as an atomic local fork.
|
|
344
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
|
|
345
|
+
* @param {{cwd: string, targetPath?: string, overwrite?: boolean}} options
|
|
346
|
+
* @returns {string} project-relative output directory
|
|
347
|
+
*/
|
|
348
|
+
export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
|
|
349
|
+
let resolvedDir;
|
|
350
|
+
try {
|
|
351
|
+
resolvedDir = assertWithin(
|
|
352
|
+
targetPath || defaultEjectTarget(theme.slug),
|
|
353
|
+
cwd,
|
|
354
|
+
{label: 'theme target path'},
|
|
355
|
+
);
|
|
356
|
+
} catch (error) {
|
|
357
|
+
if (error instanceof PathSafetyError) {
|
|
358
|
+
throw new AstryxError(
|
|
359
|
+
error.message,
|
|
360
|
+
undefined,
|
|
361
|
+
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
let writes;
|
|
368
|
+
try {
|
|
369
|
+
writes = theme.files.map(name => ({
|
|
370
|
+
name,
|
|
371
|
+
src: path.join(theme.sourceDir, name),
|
|
372
|
+
dest: assertWithin(name, resolvedDir, {
|
|
373
|
+
label: `theme destination for ${name}`,
|
|
374
|
+
}),
|
|
375
|
+
}));
|
|
376
|
+
} catch (error) {
|
|
377
|
+
if (error instanceof PathSafetyError) {
|
|
378
|
+
throw new AstryxError(
|
|
379
|
+
error.message,
|
|
380
|
+
undefined,
|
|
381
|
+
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
for (const write of writes) {
|
|
388
|
+
if (!fs.existsSync(write.src)) {
|
|
389
|
+
throw new AstryxError(
|
|
390
|
+
`Theme "${theme.slug}" is missing bundled file "${write.name}". ` +
|
|
391
|
+
'Re-run `node scripts/generate-cli-themes.mjs` to rebuild the bundle.',
|
|
392
|
+
undefined,
|
|
393
|
+
ERROR_CODES.ERR_NO_SOURCE,
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (!overwrite) {
|
|
399
|
+
const existing = writes.find(write => fs.existsSync(write.dest));
|
|
400
|
+
if (existing) {
|
|
401
|
+
const rel = path.relative(cwd, existing.dest) || existing.dest;
|
|
402
|
+
throw new AstryxError(
|
|
403
|
+
`Refusing to overwrite existing file ${rel}. ` +
|
|
404
|
+
'Re-run with --overwrite (or -f) to replace it.',
|
|
405
|
+
undefined,
|
|
406
|
+
ERROR_CODES.ERR_FILE_EXISTS,
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
try {
|
|
412
|
+
fs.mkdirSync(resolvedDir, {recursive: true});
|
|
413
|
+
const plans = writes.map(write => {
|
|
414
|
+
fs.mkdirSync(path.dirname(write.dest), {recursive: true});
|
|
415
|
+
const dest = assertWithin(write.name, resolvedDir, {
|
|
416
|
+
label: `theme destination for ${write.name}`,
|
|
417
|
+
});
|
|
418
|
+
return {
|
|
419
|
+
path: dest,
|
|
420
|
+
contents:
|
|
421
|
+
path.resolve(write.src) === path.resolve(theme.docPath)
|
|
422
|
+
? localThemeDescriptor(theme)
|
|
423
|
+
: scaffoldContents(fs.readFileSync(write.src)),
|
|
424
|
+
createOnly: !overwrite,
|
|
425
|
+
};
|
|
426
|
+
});
|
|
427
|
+
applyWrites(plans);
|
|
428
|
+
} catch (error) {
|
|
429
|
+
if (error instanceof AstryxError) throw error;
|
|
430
|
+
if (error instanceof PathSafetyError) {
|
|
431
|
+
throw new AstryxError(
|
|
432
|
+
error.message,
|
|
433
|
+
undefined,
|
|
434
|
+
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
438
|
+
throw new AstryxError(
|
|
439
|
+
`Failed to write theme files: ${message}`,
|
|
440
|
+
undefined,
|
|
441
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return path.relative(cwd, resolvedDir) || '.';
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** @param {unknown} error */
|
|
449
|
+
function asThemeError(error) {
|
|
450
|
+
if (error instanceof AstryxError) return error;
|
|
451
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
452
|
+
const code =
|
|
453
|
+
error instanceof ThemeStateError &&
|
|
454
|
+
message.startsWith('Refusing to replace')
|
|
455
|
+
? ERROR_CODES.ERR_FILE_EXISTS
|
|
456
|
+
: ERROR_CODES.ERR_THEME_INVALID;
|
|
457
|
+
return new AstryxError(message, undefined, code);
|
|
80
458
|
}
|
|
81
459
|
|
|
82
460
|
/**
|
|
83
461
|
* Resolve an available theme by case-insensitive slug and optional owner package.
|
|
84
|
-
*
|
|
462
|
+
* Without an explicit package, a local theme shadows package themes that share
|
|
463
|
+
* its slug. Other duplicate slugs fail closed until the caller selects an owner.
|
|
85
464
|
* @param {string} [slug]
|
|
86
|
-
* @param {{cwd?: string, package?: string}} [options]
|
|
465
|
+
* @param {{cwd?: string, package?: string, includeLocal?: boolean}} [options]
|
|
87
466
|
* @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined>}
|
|
88
467
|
*/
|
|
89
468
|
export async function findTheme(slug, options = {}) {
|
|
90
469
|
if (!slug) return undefined;
|
|
91
470
|
const {themes, issues} = await availableThemeState(
|
|
92
471
|
options.cwd ?? process.cwd(),
|
|
472
|
+
{includeLocal: options.includeLocal},
|
|
93
473
|
);
|
|
94
474
|
const normalized = String(slug).toLowerCase();
|
|
95
475
|
const matches = themes.filter(
|
|
@@ -109,17 +489,306 @@ export async function findTheme(slug, options = {}) {
|
|
|
109
489
|
);
|
|
110
490
|
}
|
|
111
491
|
}
|
|
492
|
+
if (matches.length > 1 && options.package == null) {
|
|
493
|
+
const local = matches.find(theme => theme.source === 'local');
|
|
494
|
+
if (local) return local;
|
|
495
|
+
}
|
|
112
496
|
if (matches.length > 1) {
|
|
113
497
|
throw new AstryxError(
|
|
114
498
|
`Theme "${slug}" is provided by more than one package. Select one with --package.`,
|
|
115
499
|
matches.map(theme => ({
|
|
116
500
|
name: `${theme.slug} --package ${theme.package}`,
|
|
117
|
-
reason:
|
|
118
|
-
|
|
119
|
-
|
|
501
|
+
reason:
|
|
502
|
+
theme.source === 'bundled'
|
|
503
|
+
? 'bundled theme'
|
|
504
|
+
: theme.source === 'local'
|
|
505
|
+
? 'local theme'
|
|
506
|
+
: `provided by ${theme.package}`,
|
|
120
507
|
})),
|
|
121
508
|
ERROR_CODES.ERR_AMBIGUOUS_THEME,
|
|
122
509
|
);
|
|
123
510
|
}
|
|
124
511
|
return matches[0];
|
|
125
512
|
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Read the generated module's app-theme record with stable CLI errors.
|
|
516
|
+
* @param {string} [cwd]
|
|
517
|
+
*/
|
|
518
|
+
export function readAppThemeState(cwd = process.cwd()) {
|
|
519
|
+
try {
|
|
520
|
+
return readThemeState(cwd);
|
|
521
|
+
} catch (error) {
|
|
522
|
+
throw asThemeError(error);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Read the app state needed by a list operation. Outside a package project,
|
|
528
|
+
* bundled themes remain listable and there is no generated app state.
|
|
529
|
+
* @param {string} [cwd]
|
|
530
|
+
* @returns {Pick<ReturnType<typeof readThemeState>, 'projectDir' | 'themes' | 'defaultSlug'>}
|
|
531
|
+
*/
|
|
532
|
+
export function readThemeListState(cwd = process.cwd()) {
|
|
533
|
+
let projectDir;
|
|
534
|
+
try {
|
|
535
|
+
({projectDir} = findThemeProject(cwd));
|
|
536
|
+
} catch (error) {
|
|
537
|
+
if (error instanceof ThemeStateError) {
|
|
538
|
+
return {
|
|
539
|
+
projectDir: path.resolve(cwd),
|
|
540
|
+
themes: {},
|
|
541
|
+
defaultSlug: null,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
throw asThemeError(error);
|
|
545
|
+
}
|
|
546
|
+
return readAppThemeState(projectDir);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Resolve every recorded owner to built import metadata, in record order.
|
|
551
|
+
* @param {ReturnType<typeof readThemeState>} state
|
|
552
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} available
|
|
553
|
+
*/
|
|
554
|
+
export function resolveRecordedThemes(state, available) {
|
|
555
|
+
/** @type {Map<string, number>} */
|
|
556
|
+
const ownerCounts = new Map();
|
|
557
|
+
for (const theme of available) {
|
|
558
|
+
const owner = themeImportPackage(theme);
|
|
559
|
+
ownerCounts.set(owner, (ownerCounts.get(owner) ?? 0) + 1);
|
|
560
|
+
}
|
|
561
|
+
return Object.entries(state.themes).map(([slug, owner]) => {
|
|
562
|
+
const theme = available.find(
|
|
563
|
+
candidate =>
|
|
564
|
+
candidate.slug === slug && themeImportPackage(candidate) === owner,
|
|
565
|
+
);
|
|
566
|
+
if (!theme) {
|
|
567
|
+
throw new AstryxError(
|
|
568
|
+
`Added theme "${slug}" from ${owner} is unavailable. Reinstall the package or restore the local theme, then run \`astryx theme add ${slug} --import --package ${owner}\`.`,
|
|
569
|
+
undefined,
|
|
570
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
try {
|
|
574
|
+
return resolveThemeImports(theme, {
|
|
575
|
+
cwd: state.projectDir,
|
|
576
|
+
ownerThemeCount: ownerCounts.get(owner) ?? 1,
|
|
577
|
+
});
|
|
578
|
+
} catch (error) {
|
|
579
|
+
if (error instanceof ThemeImportError) throw asThemeError(error);
|
|
580
|
+
throw error;
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Resolve the current generated-module state without changing it.
|
|
587
|
+
* @param {string} [cwd]
|
|
588
|
+
*/
|
|
589
|
+
export async function resolveThemeApp(cwd = process.cwd()) {
|
|
590
|
+
const state = readAppThemeState(cwd);
|
|
591
|
+
const available = await listAvailableThemes(state.projectDir);
|
|
592
|
+
const entries = state.configured
|
|
593
|
+
? resolveRecordedThemes(state, available)
|
|
594
|
+
: [];
|
|
595
|
+
return {state, available, entries};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* @param {ReturnType<typeof readThemeState>} state
|
|
600
|
+
* @param {Record<string, string>} themes
|
|
601
|
+
* @param {string} defaultSlug
|
|
602
|
+
* @param {'add'|'remove'|'use'} action
|
|
603
|
+
* @param {string} slug
|
|
604
|
+
* @param {boolean} changed
|
|
605
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} available
|
|
606
|
+
* @returns {Promise<import('./theme.type.mjs').ThemeAppResponse>}
|
|
607
|
+
*/
|
|
608
|
+
async function writeThemeApp(
|
|
609
|
+
state,
|
|
610
|
+
themes,
|
|
611
|
+
defaultSlug,
|
|
612
|
+
action,
|
|
613
|
+
slug,
|
|
614
|
+
changed,
|
|
615
|
+
available,
|
|
616
|
+
) {
|
|
617
|
+
const finalState = {...state, themes, defaultSlug, configured: true};
|
|
618
|
+
const resolved = resolveRecordedThemes(finalState, available);
|
|
619
|
+
let prepared;
|
|
620
|
+
try {
|
|
621
|
+
prepared = planThemeAppWrite(finalState, themes, defaultSlug, resolved);
|
|
622
|
+
} catch (error) {
|
|
623
|
+
throw asThemeError(error);
|
|
624
|
+
}
|
|
625
|
+
try {
|
|
626
|
+
applyWrites([prepared.plan]);
|
|
627
|
+
} catch (error) {
|
|
628
|
+
if (error instanceof AstryxError) throw error;
|
|
629
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
630
|
+
throw new AstryxError(
|
|
631
|
+
`Failed to write the generated theme module: ${message}`,
|
|
632
|
+
undefined,
|
|
633
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
// A result about the one theme `theme add` just added names the npm package
|
|
637
|
+
// that owns it (cli-surface INV28). A local theme has no package to name, and
|
|
638
|
+
// remove and use report the whole record rather than one added theme.
|
|
639
|
+
const added =
|
|
640
|
+
action === 'add'
|
|
641
|
+
? prepared.entries.find(theme => theme.slug === slug)
|
|
642
|
+
: undefined;
|
|
643
|
+
return {
|
|
644
|
+
type: 'theme.app',
|
|
645
|
+
...(added && added.source !== 'local' ? {package: added.owner} : {}),
|
|
646
|
+
data: {
|
|
647
|
+
themes: prepared.entries.map(theme => ({
|
|
648
|
+
slug: theme.slug,
|
|
649
|
+
owner: theme.owner,
|
|
650
|
+
module: theme.module,
|
|
651
|
+
stylesheet: theme.stylesheet,
|
|
652
|
+
...(theme.fontStylesheet ? {fontStylesheet: theme.fontStylesheet} : {}),
|
|
653
|
+
source: theme.source,
|
|
654
|
+
})),
|
|
655
|
+
default: defaultSlug,
|
|
656
|
+
modulePath: prepared.module.path,
|
|
657
|
+
change: {
|
|
658
|
+
action,
|
|
659
|
+
slug,
|
|
660
|
+
changed,
|
|
661
|
+
firstAdd: action === 'add' && !state.configured,
|
|
662
|
+
},
|
|
663
|
+
},
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Add one available built theme to the app record.
|
|
669
|
+
* @param {string} slug
|
|
670
|
+
* @param {{cwd?: string, package?: string}} [options]
|
|
671
|
+
* @returns {Promise<import('./theme.type.mjs').ThemeAppResponse>}
|
|
672
|
+
*/
|
|
673
|
+
export async function addThemeToApp(slug, options = {}) {
|
|
674
|
+
const cwd = options.cwd ?? process.cwd();
|
|
675
|
+
const match = await findTheme(slug, {cwd, package: options.package});
|
|
676
|
+
if (!match) {
|
|
677
|
+
const available = await listAvailableThemes(cwd);
|
|
678
|
+
throw new AstryxError(
|
|
679
|
+
`Unknown theme "${slug}"${options.package ? ` in package "${options.package}"` : ''}.`,
|
|
680
|
+
available.map(theme => ({
|
|
681
|
+
name: `${theme.slug} --package ${theme.package}`,
|
|
682
|
+
reason:
|
|
683
|
+
theme.source === 'bundled'
|
|
684
|
+
? 'bundled theme'
|
|
685
|
+
: theme.source === 'local'
|
|
686
|
+
? 'local theme'
|
|
687
|
+
: `provided by ${theme.package}`,
|
|
688
|
+
})),
|
|
689
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
const state = readAppThemeState(cwd);
|
|
693
|
+
const available = await listAvailableThemes(state.projectDir);
|
|
694
|
+
const owner = themeImportPackage(match);
|
|
695
|
+
const themes = {...state.themes, [match.slug]: owner};
|
|
696
|
+
const changed = state.themes[match.slug] !== owner;
|
|
697
|
+
const defaultSlug =
|
|
698
|
+
state.configured && state.defaultSlug != null
|
|
699
|
+
? state.defaultSlug
|
|
700
|
+
: match.slug;
|
|
701
|
+
return writeThemeApp(
|
|
702
|
+
state,
|
|
703
|
+
themes,
|
|
704
|
+
defaultSlug,
|
|
705
|
+
'add',
|
|
706
|
+
match.slug,
|
|
707
|
+
changed,
|
|
708
|
+
available,
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Canonical recorded slug for a case-insensitive command lookup.
|
|
714
|
+
* @param {ReturnType<typeof readThemeState>} state
|
|
715
|
+
* @param {string} slug
|
|
716
|
+
*/
|
|
717
|
+
function recordedThemeSlug(state, slug) {
|
|
718
|
+
const needle = slug.toLowerCase();
|
|
719
|
+
return Object.keys(state.themes).find(
|
|
720
|
+
candidate => candidate.toLowerCase() === needle,
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Remove one non-default theme from the app record.
|
|
726
|
+
* @param {string} slug
|
|
727
|
+
* @param {{cwd?: string}} [options]
|
|
728
|
+
* @returns {Promise<import('./theme.type.mjs').ThemeAppResponse>}
|
|
729
|
+
*/
|
|
730
|
+
export async function removeThemeFromApp(slug, options = {}) {
|
|
731
|
+
const state = readAppThemeState(options.cwd ?? process.cwd());
|
|
732
|
+
const recordedSlug = recordedThemeSlug(state, slug);
|
|
733
|
+
if (!state.configured || recordedSlug == null) {
|
|
734
|
+
throw new AstryxError(
|
|
735
|
+
`Theme "${slug}" is not added. Run \`astryx theme add ${slug} --import\` first.`,
|
|
736
|
+
undefined,
|
|
737
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
if (state.defaultSlug === recordedSlug) {
|
|
741
|
+
throw new AstryxError(
|
|
742
|
+
`Theme "${recordedSlug}" is the default. Run \`astryx theme use <other-slug>\` before removing it.`,
|
|
743
|
+
undefined,
|
|
744
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
const themes = {...state.themes};
|
|
748
|
+
delete themes[recordedSlug];
|
|
749
|
+
if (state.defaultSlug == null) {
|
|
750
|
+
throw new AstryxError(
|
|
751
|
+
'The generated theme module has no default theme. Run `astryx theme use <slug>` first.',
|
|
752
|
+
undefined,
|
|
753
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
const available = await listAvailableThemes(state.projectDir);
|
|
757
|
+
return writeThemeApp(
|
|
758
|
+
state,
|
|
759
|
+
themes,
|
|
760
|
+
state.defaultSlug,
|
|
761
|
+
'remove',
|
|
762
|
+
recordedSlug,
|
|
763
|
+
true,
|
|
764
|
+
available,
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Select one added theme as the app default.
|
|
770
|
+
* @param {string} slug
|
|
771
|
+
* @param {{cwd?: string}} [options]
|
|
772
|
+
* @returns {Promise<import('./theme.type.mjs').ThemeAppResponse>}
|
|
773
|
+
*/
|
|
774
|
+
export async function useThemeInApp(slug, options = {}) {
|
|
775
|
+
const state = readAppThemeState(options.cwd ?? process.cwd());
|
|
776
|
+
const recordedSlug = recordedThemeSlug(state, slug);
|
|
777
|
+
if (!state.configured || recordedSlug == null) {
|
|
778
|
+
throw new AstryxError(
|
|
779
|
+
`Theme "${slug}" is not added. Run \`astryx theme add ${slug} --import\` first.`,
|
|
780
|
+
undefined,
|
|
781
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
const available = await listAvailableThemes(state.projectDir);
|
|
785
|
+
return writeThemeApp(
|
|
786
|
+
state,
|
|
787
|
+
state.themes,
|
|
788
|
+
recordedSlug,
|
|
789
|
+
'use',
|
|
790
|
+
recordedSlug,
|
|
791
|
+
state.defaultSlug !== recordedSlug,
|
|
792
|
+
available,
|
|
793
|
+
);
|
|
794
|
+
}
|