@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -86
- package/api/build/_adapter.d.mts +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +4 -2
- package/api/build/kit/rank.mjs +125 -24
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +340 -43
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +28 -2
- package/api/docs/_adapter.mjs +249 -10
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/authoring-checks.mjs +6 -6
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +5 -0
- package/api/search/_lexical.mjs +8 -2
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +132 -1
- package/api/theme/build/build.mjs +482 -157
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +44 -5
- package/api/theme/build/font-warning.mjs +118 -10
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +115 -4
- package/api/theme-edit/_adapter.mjs +997 -83
- package/api/theme-edit/_catalog.d.mts +20 -2
- package/api/theme-edit/_catalog.mjs +50 -10
- package/api/theme-edit/_check.d.mts +75 -24
- package/api/theme-edit/_check.mjs +2672 -422
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +54 -1
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +133 -15
- package/api/theme-edit/_context.d.mts +14 -3
- package/api/theme-edit/_context.mjs +225 -65
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +54 -4
- package/api/theme-edit/_edit.mjs +2966 -286
- package/api/theme-edit/_how-commands.d.mts +72 -1
- package/api/theme-edit/_how-commands.mjs +770 -9
- package/api/theme-edit/_how-question.d.mts +82 -5
- package/api/theme-edit/_how-question.mjs +6983 -701
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +237 -41
- package/api/theme-edit/_importers.d.mts +38 -0
- package/api/theme-edit/_importers.mjs +188 -0
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +303 -0
- package/api/theme-edit/_normal.mjs +1517 -0
- package/api/theme-edit/_palette.d.mts +12 -0
- package/api/theme-edit/_palette.mjs +37 -4
- package/api/theme-edit/_part-words.d.mts +31 -0
- package/api/theme-edit/_part-words.mjs +126 -0
- package/api/theme-edit/_parts.d.mts +28 -2
- package/api/theme-edit/_parts.mjs +267 -31
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +814 -406
- package/api/theme-edit/_preview.d.mts +116 -16
- package/api/theme-edit/_preview.mjs +649 -152
- package/api/theme-edit/_project.d.mts +22 -1
- package/api/theme-edit/_project.mjs +83 -3
- package/api/theme-edit/_settings.d.mts +467 -42
- package/api/theme-edit/_settings.mjs +3527 -468
- package/api/theme-edit/_tables.d.mts +21 -0
- package/api/theme-edit/_tables.mjs +97 -3
- package/api/theme-edit/_vet.d.mts +31 -0
- package/api/theme-edit/_vet.mjs +114 -8
- package/api/theme-edit/theme-edit.type.d.mts +16 -2
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- package/assets/docs/tree/share-a-page.doc.mjs +157 -0
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +573 -119
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +718 -438
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +132 -24
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/core-component-docs.d.mts +29 -0
- package/foundation/discovery/core-component-docs.mjs +83 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +53 -1
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +31 -4
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.d.mts +6 -5
- package/foundation/discovery/theming-targets.mjs +31 -47
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +38 -0
- package/foundation/fonts/font-stylesheet.mjs +141 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +62 -4
- package/foundation/fs/gather-cache.mjs +517 -91
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +9 -0
- package/foundation/fs/read-record.mjs +19 -11
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +185 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +34 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +641 -96
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +2 -2
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/css-escape.d.mts +18 -0
- package/foundation/text/css-escape.mjs +35 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
|
|
32
32
|
import * as fs from 'node:fs';
|
|
33
33
|
import * as path from 'node:path';
|
|
34
|
+
import {
|
|
35
|
+
fontKey,
|
|
36
|
+
stylesheetFontFamilies,
|
|
37
|
+
} from '../../../foundation/fonts/font-stylesheet.mjs';
|
|
34
38
|
import {fileURLToPath} from 'node:url';
|
|
35
39
|
import {spawn} from 'node:child_process';
|
|
36
40
|
import {
|
|
@@ -85,6 +89,7 @@ import {
|
|
|
85
89
|
themeSourceFiles,
|
|
86
90
|
themeSourceGuesses,
|
|
87
91
|
buildSuggestion,
|
|
92
|
+
generatedSourceCommand,
|
|
88
93
|
writeDeferredBuildOutputs,
|
|
89
94
|
} from '../../../api/theme/build/build.mjs';
|
|
90
95
|
import {defineCommand} from '../lib/define-command.mjs';
|
|
@@ -119,13 +124,46 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
|
|
|
119
124
|
* @property {string} build - The build subcommand's name: `build` or `compile`.
|
|
120
125
|
* @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => import('../../../api/error.mjs').AstryxError | null} [explain] - A clearer refusal for this group, or null.
|
|
121
126
|
* @property {(files: string[], options: {cwd: string, check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}) => Promise<import('../../../api/error.mjs').AstryxError | null>} [preflight] - A refusal before a build starts, or null.
|
|
122
|
-
* @property {(
|
|
127
|
+
* @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => Promise<import('../../../api/error.mjs').AstryxError>} [follow] - The refusal with its first suggested build checked and repaired as the build would check it.
|
|
128
|
+
* @property {(file: string, cwd: string) => import('../../../api/theme/build/build.mjs').FontHelp | null} [fontHelp] - How a group says to load a theme's fonts when it loads them itself (the editor's app copy).
|
|
129
|
+
* @property {(file: string, cwd: string) => string | null} [install] - How the app takes a theme a group wires another way than importing the build's outputs (the editor's app copy), for the full report.
|
|
130
|
+
* @property {(file: string, cwd: string) => string | null} [sourcePath] - The path a source builds under, when not the typed one; null to keep it.
|
|
131
|
+
* @property {(files: string[], cwd: string) => Promise<Record<string, Record<string, unknown>>>} [afterBuild] - Writes a group makes once a build's outputs are written (the editor's app copy), with what each did, by file, for its result.
|
|
132
|
+
* @property {(files: string[], options: {cwd: string, check?: boolean, out?: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
|
|
133
|
+
* @property {(file: string, cwd: string, opts: {check: boolean, upToDate?: boolean, out?: string, iconsSpecifier?: string}) => Record<string, unknown> | null | Promise<Record<string, unknown> | null>} [extraData] - Fields a group adds to a build's result data (the editor's `appCopyStale`); in a check, `upToDate: false` fails it.
|
|
134
|
+
* @property {(file: string, cwd: string) => (['light'] | ['dark'] | null)} [colorModes] - The one color mode a theme file has that the file itself cannot say, for the build to write into the built module.
|
|
135
|
+
* @property {(file: string, cwd: string) => ((family: string) => boolean) | null | Promise<((family: string) => boolean) | null>} [loadedFonts] - Font families the app loads for a theme file that the file itself cannot say, so the build does not name them as unloaded.
|
|
123
136
|
* @property {(file: string, cwd: string) => {name: string, reason: string} | null} [missingSource] - For a source file that is not there, this group's way to write it again, or null.
|
|
124
137
|
* @property {(options: {targetPath?: string, overwrite?: boolean, cwd?: string}) => import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} [template] - This group's template write, in place of `themeTemplate`.
|
|
125
138
|
*/
|
|
126
139
|
|
|
127
140
|
/** @type {ThemeCommandWords} */
|
|
128
|
-
const THEME_WORDS = {
|
|
141
|
+
const THEME_WORDS = {
|
|
142
|
+
group: 'theme',
|
|
143
|
+
build: 'build',
|
|
144
|
+
loadedFonts: fontsLoadedBeside,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The font families a local theme's font stylesheet loads: the
|
|
149
|
+
* `<slug>.fonts.css` beside its source, where the theme's folder is named
|
|
150
|
+
* for its slug (the one font stylesheet `theme add` imports for it), read
|
|
151
|
+
* with its imports (an @fontsource package by its name, a stylesheet by its
|
|
152
|
+
* @font-face rules or the `family=` it requests). A build of that source
|
|
153
|
+
* does not name those families as unloaded. Another stylesheet in the
|
|
154
|
+
* folder loads nothing for the app, so it counts for nothing. Null when the
|
|
155
|
+
* theme has no font stylesheet.
|
|
156
|
+
* @param {string} file the theme source, as given
|
|
157
|
+
* @param {string} cwd
|
|
158
|
+
* @returns {((family: string) => boolean) | null}
|
|
159
|
+
*/
|
|
160
|
+
function fontsLoadedBeside(file, cwd) {
|
|
161
|
+
const dir = path.dirname(path.resolve(cwd, file));
|
|
162
|
+
const sheet = path.join(dir, `${path.basename(dir)}.fonts.css`);
|
|
163
|
+
if (!fs.existsSync(sheet)) return null;
|
|
164
|
+
const loaded = stylesheetFontFamilies(sheet);
|
|
165
|
+
return loaded.size ? family => loaded.has(fontKey(family)) : null;
|
|
166
|
+
}
|
|
129
167
|
|
|
130
168
|
/**
|
|
131
169
|
* Text as the group that ran the command words it: under `experimental
|
|
@@ -193,13 +231,16 @@ function inGroupNotes(result, words) {
|
|
|
193
231
|
* group that works whatever went wrong.
|
|
194
232
|
* @param {import('../../../api/error.mjs').AstryxError} err
|
|
195
233
|
* @param {ThemeCommandWords} [words]
|
|
196
|
-
* @param {Array<{name: string, reason
|
|
234
|
+
* @param {Array<{name: string, reason?: string}>} [fallback]
|
|
197
235
|
*/
|
|
198
236
|
function themeError(err, words = THEME_WORDS, fallback = []) {
|
|
199
237
|
err = words.explain?.(err, process.cwd()) ?? err;
|
|
200
238
|
/** @param {string} text */
|
|
201
239
|
const local = text => inGroupWords(text, words);
|
|
202
240
|
const given = err.suggestions || [];
|
|
241
|
+
// Suggested commands stay bare (`astryx …`): the JSON envelope carries
|
|
242
|
+
// them so, and the text output starts them the way this project runs the
|
|
243
|
+
// CLI.
|
|
203
244
|
return cliError(local(err.message), {
|
|
204
245
|
suggestions: (given.length > 0 ? given : fallback).map(x => ({
|
|
205
246
|
...x,
|
|
@@ -210,6 +251,46 @@ function themeError(err, words = THEME_WORDS, fallback = []) {
|
|
|
210
251
|
});
|
|
211
252
|
}
|
|
212
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Add a group's fields to a build's result data. Its warnings and notices
|
|
256
|
+
* join the build's own, and are printed as the build's are (`--json`
|
|
257
|
+
* prints none).
|
|
258
|
+
* @param {Record<string, any>} data
|
|
259
|
+
* @param {Record<string, unknown>} extra
|
|
260
|
+
*/
|
|
261
|
+
function mergeResultData(data, extra) {
|
|
262
|
+
const {warnings, notices, ...rest} = /** @type {any} */ (extra);
|
|
263
|
+
Object.assign(data, rest);
|
|
264
|
+
if (Array.isArray(warnings) && warnings.length > 0) {
|
|
265
|
+
data.warnings = [...(data.warnings ?? []), ...warnings];
|
|
266
|
+
for (const w of warnings) logger.warn(`Warning: ${w}`);
|
|
267
|
+
}
|
|
268
|
+
if (Array.isArray(notices) && notices.length > 0) {
|
|
269
|
+
data.notices = [...(data.notices ?? []), ...notices];
|
|
270
|
+
for (const n of notices) logger.log(`[note] ${n}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Marks a suggested build with what it builds, for the group's checks. */
|
|
275
|
+
const BUILD_RUN = Symbol('build run');
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* A suggested build, marked with the files and mode it builds so the
|
|
279
|
+
* group's own checks can vet it before it is shown (the mark is not part of
|
|
280
|
+
* what is printed).
|
|
281
|
+
* @template {{name: string, reason: string}} S
|
|
282
|
+
* @param {S} suggestion
|
|
283
|
+
* @param {string[]} files
|
|
284
|
+
* @param {{check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}} mode
|
|
285
|
+
* @returns {S}
|
|
286
|
+
*/
|
|
287
|
+
function buildRun(suggestion, files, mode) {
|
|
288
|
+
return Object.defineProperty(suggestion, BUILD_RUN, {
|
|
289
|
+
value: {files, mode},
|
|
290
|
+
enumerable: false,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
213
294
|
/**
|
|
214
295
|
* A command of this CLI as this project runs it, each argument quoted for the
|
|
215
296
|
* shell.
|
|
@@ -629,6 +710,7 @@ function printThemeApp(result) {
|
|
|
629
710
|
'stylesheet',
|
|
630
711
|
'fontStylesheet',
|
|
631
712
|
'source',
|
|
713
|
+
'mode',
|
|
632
714
|
],
|
|
633
715
|
layout: 'stacked',
|
|
634
716
|
}),
|
|
@@ -641,6 +723,7 @@ function printThemeApp(result) {
|
|
|
641
723
|
slug: change.slug,
|
|
642
724
|
changed: change.changed,
|
|
643
725
|
firstAdd: change.firstAdd,
|
|
726
|
+
...(change.wireModes ? {wireModes: true} : {}),
|
|
644
727
|
},
|
|
645
728
|
],
|
|
646
729
|
{
|
|
@@ -651,20 +734,40 @@ function printThemeApp(result) {
|
|
|
651
734
|
'slug',
|
|
652
735
|
'changed',
|
|
653
736
|
'firstAdd',
|
|
737
|
+
'wireModes',
|
|
654
738
|
],
|
|
655
739
|
layout: 'stacked',
|
|
656
740
|
},
|
|
657
741
|
),
|
|
658
742
|
);
|
|
659
743
|
for (const note of result.data.notes ?? []) emit(text(`[note] ${note}`));
|
|
660
|
-
if (!change.firstAdd) return;
|
|
661
744
|
const stem = path.basename(modulePath, path.extname(modulePath));
|
|
745
|
+
if (!change.firstAdd) {
|
|
746
|
+
// The module now lists one-mode themes' modes: the app's wiring, made
|
|
747
|
+
// without them, passes the selected theme's mode from now on.
|
|
748
|
+
if (change.wireModes)
|
|
749
|
+
emit(
|
|
750
|
+
text(
|
|
751
|
+
"The theme module now exports themeModes. Pass the selected theme's mode to Theme in the app root:",
|
|
752
|
+
),
|
|
753
|
+
code(
|
|
754
|
+
"import {Theme} from '@astryxdesign/core/theme';\n" +
|
|
755
|
+
`import {themes, defaultThemeSlug, themeModes} from './${stem}';\n\n` +
|
|
756
|
+
"<Theme theme={themes[defaultThemeSlug]} mode={themeModes[defaultThemeSlug] ?? 'system'}>\n <App />\n</Theme>",
|
|
757
|
+
),
|
|
758
|
+
);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
// With a theme of one color mode added, the generated module lists each
|
|
762
|
+
// such theme's mode in `themeModes`, and the wiring passes the selected
|
|
763
|
+
// theme's (none for a two-mode theme, which follows the system).
|
|
764
|
+
const modes = result.data.themes.some(t => t.mode);
|
|
662
765
|
emit(
|
|
663
766
|
text('Wire the generated module once in the app root:'),
|
|
664
767
|
code(
|
|
665
768
|
"import {Theme} from '@astryxdesign/core/theme';\n" +
|
|
666
|
-
`import {themes, defaultThemeSlug} from './${stem}';\n\n` +
|
|
667
|
-
|
|
769
|
+
`import {themes, defaultThemeSlug${modes ? ', themeModes' : ''}} from './${stem}';\n\n` +
|
|
770
|
+
`<Theme theme={themes[defaultThemeSlug]}${modes ? " mode={themeModes[defaultThemeSlug] ?? 'system'}" : ''}>\n <App />\n</Theme>`,
|
|
668
771
|
),
|
|
669
772
|
);
|
|
670
773
|
}
|
|
@@ -964,90 +1067,171 @@ function registerPaletteCommands(
|
|
|
964
1067
|
* @param {ThemeCommandWords} words
|
|
965
1068
|
*/
|
|
966
1069
|
function registerThemeCommands(theme, program, docs, words) {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1070
|
+
/** The locks the group holds for one build run (see words.hold below). */
|
|
1071
|
+
/** @type {(() => Promise<void>) | undefined} */
|
|
1072
|
+
let release;
|
|
1073
|
+
const buildAction = async (
|
|
1074
|
+
/** @type {string[]} */ typedFiles,
|
|
1075
|
+
/** @type {{out?: string, watch?: boolean, check?: boolean, iconsSpecifier?: string, family?: boolean, familyKey?: string}} */ options,
|
|
1076
|
+
) => {
|
|
1077
|
+
// A group may name the path a source builds under (an editor theme
|
|
1078
|
+
// reached through a link builds under its own path, which its
|
|
1079
|
+
// outputs' headers name).
|
|
1080
|
+
const files = typedFiles.map(
|
|
1081
|
+
file => words.sourcePath?.(file, process.cwd()) ?? file,
|
|
1082
|
+
);
|
|
1083
|
+
// Every suggested build passes the group's own checks before it is
|
|
1084
|
+
// shown (from a subfolder an editor theme compiles from the app
|
|
1085
|
+
// root): a suggestion the group refuses gives way to the group's own
|
|
1086
|
+
// suggestion, which does.
|
|
1087
|
+
/** @param {Array<{name: string, reason?: string}> | undefined} list */
|
|
1088
|
+
const vet = async list => {
|
|
1089
|
+
/** @type {Array<{name: string, reason?: string}>} */
|
|
1090
|
+
const out = [];
|
|
1091
|
+
for (const s of list ?? []) {
|
|
1092
|
+
const run = /** @type {any} */ (s)[BUILD_RUN];
|
|
1093
|
+
const refused = run
|
|
1094
|
+
? await words.preflight?.(run.files, {
|
|
1095
|
+
cwd: process.cwd(),
|
|
1096
|
+
...run.mode,
|
|
1097
|
+
})
|
|
1098
|
+
: null;
|
|
1099
|
+
out.push(...(refused ? (refused.suggestions ?? []) : [s]));
|
|
1100
|
+
}
|
|
1101
|
+
return out;
|
|
1102
|
+
};
|
|
1103
|
+
/** @param {string} message @param {Parameters<typeof cliError>[1]} [opts] */
|
|
1104
|
+
const refuse = async (message, opts = {}) =>
|
|
1105
|
+
cliError(message, {
|
|
1106
|
+
...opts,
|
|
1107
|
+
suggestions: await vet(opts.suggestions),
|
|
1108
|
+
});
|
|
1109
|
+
/**
|
|
1110
|
+
* @param {import('../../../api/error.mjs').AstryxError} err
|
|
1111
|
+
* @param {ThemeCommandWords} [w]
|
|
1112
|
+
* @param {Array<{name: string, reason?: string}>} [fallback]
|
|
1113
|
+
*/
|
|
1114
|
+
const refuseTheme = async (err, w = words, fallback = []) => {
|
|
1115
|
+
err.suggestions = await vet(err.suggestions);
|
|
1116
|
+
return themeError(err, w, await vet(fallback));
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
const json = program.opts().json || false;
|
|
1120
|
+
// The report is one line per theme unless the user asks for
|
|
1121
|
+
// `--detail full`, which prints the install example and the font
|
|
1122
|
+
// guidance: once for one theme, as it always has, and once for the whole
|
|
1123
|
+
// batch rather than per theme.
|
|
1124
|
+
const detailChosen = program.getOptionValueSource('detail') !== 'default';
|
|
1125
|
+
const detail = detailChosen ? program.opts().detail : undefined;
|
|
1126
|
+
const compact = detail !== 'full';
|
|
1127
|
+
const entries = files.map(file => ({
|
|
1128
|
+
file,
|
|
1129
|
+
filePath: path.resolve(process.cwd(), file),
|
|
1130
|
+
}));
|
|
1131
|
+
|
|
1132
|
+
for (const entry of entries) {
|
|
1133
|
+
if (fs.existsSync(entry.filePath)) continue;
|
|
1134
|
+
// A quoted glob reaches us unexpanded: say so rather than reporting a
|
|
1135
|
+
// literal `themes/*.ts` as a missing file.
|
|
1136
|
+
const looksGlobby = /[*?[\]{}]/.test(entry.file);
|
|
1137
|
+
const guesses = looksGlobby
|
|
1138
|
+
? []
|
|
1139
|
+
: themeSourceGuesses(entry.file, process.cwd());
|
|
1140
|
+
// An editor theme's own source, deleted by hand: the editor writes
|
|
1141
|
+
// it again.
|
|
1142
|
+
const rewrite = looksGlobby
|
|
1143
|
+
? null
|
|
1144
|
+
: (words.missingSource?.(entry.file, process.cwd()) ?? null);
|
|
1145
|
+
// A file another command generates, gone from a folder whose other
|
|
1146
|
+
// files carry that command's mark: that command writes it again; a
|
|
1147
|
+
// blank theme template is no way back.
|
|
1148
|
+
const by =
|
|
1149
|
+
rewrite || looksGlobby ? null : generatedSourceCommand(entry.filePath);
|
|
1150
|
+
if (by)
|
|
1151
|
+
return await refuse(
|
|
1152
|
+
`File not found: ${entry.filePath}. It is a generated file: the files beside it are written by ${by}, so rebuild it with the command that made it.`,
|
|
1153
|
+
{
|
|
1154
|
+
code: ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
1155
|
+
suggestions: /^astryx(\s|$)/.test(by)
|
|
1004
1156
|
? [
|
|
1005
1157
|
{
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
// run stays one.
|
|
1009
|
-
name: buildSuggestion(
|
|
1010
|
-
entry.file,
|
|
1011
|
-
options,
|
|
1012
|
-
process.cwd(),
|
|
1013
|
-
words,
|
|
1014
|
-
{
|
|
1015
|
-
glob: true,
|
|
1016
|
-
family: Boolean(options.family),
|
|
1017
|
-
...(options.family && options.familyKey
|
|
1018
|
-
? {familyKey: String(options.familyKey)}
|
|
1019
|
-
: {}),
|
|
1020
|
-
},
|
|
1021
|
-
),
|
|
1022
|
-
reason:
|
|
1023
|
-
'globs are expanded by your shell; pass the pattern unquoted, or list the files',
|
|
1158
|
+
name: `${getCliInvocation(process.cwd())} ${by.replace(/^astryx\s*/, '')}`.trim(),
|
|
1159
|
+
reason: 'the command that writes these files',
|
|
1024
1160
|
},
|
|
1025
1161
|
]
|
|
1026
|
-
:
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1162
|
+
: [],
|
|
1163
|
+
},
|
|
1164
|
+
);
|
|
1165
|
+
return await refuse(`File not found: ${entry.filePath}`, {
|
|
1166
|
+
code: ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
1167
|
+
suggestions: rewrite
|
|
1168
|
+
? [rewrite]
|
|
1169
|
+
: looksGlobby
|
|
1170
|
+
? [
|
|
1171
|
+
{
|
|
1172
|
+
// The pattern stays unquoted: the shell expands it.
|
|
1173
|
+
// The caller's mode follows it, quoted, and a family
|
|
1174
|
+
// run stays one.
|
|
1175
|
+
name: buildSuggestion(
|
|
1176
|
+
entry.file,
|
|
1177
|
+
options,
|
|
1178
|
+
process.cwd(),
|
|
1179
|
+
words,
|
|
1180
|
+
{
|
|
1181
|
+
glob: true,
|
|
1182
|
+
family: Boolean(options.family),
|
|
1183
|
+
...(options.family && options.familyKey
|
|
1184
|
+
? {familyKey: String(options.familyKey)}
|
|
1185
|
+
: {}),
|
|
1186
|
+
},
|
|
1187
|
+
),
|
|
1188
|
+
reason:
|
|
1189
|
+
'globs are expanded by your shell; pass the pattern unquoted, or list the files',
|
|
1190
|
+
},
|
|
1191
|
+
]
|
|
1192
|
+
: guesses.length > 0
|
|
1193
|
+
? guesses.map(guess =>
|
|
1194
|
+
buildRun(
|
|
1195
|
+
{
|
|
1196
|
+
// The same build of that source: a --check stays a
|
|
1197
|
+
// check.
|
|
1198
|
+
name: buildSuggestion(
|
|
1199
|
+
guess,
|
|
1200
|
+
options,
|
|
1201
|
+
process.cwd(),
|
|
1202
|
+
words,
|
|
1203
|
+
),
|
|
1204
|
+
reason: 'a theme source that exists',
|
|
1205
|
+
},
|
|
1206
|
+
[guess],
|
|
1207
|
+
{
|
|
1208
|
+
check: Boolean(options.check),
|
|
1209
|
+
family: Boolean(options.family),
|
|
1210
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1211
|
+
out: options.out,
|
|
1212
|
+
},
|
|
1213
|
+
),
|
|
1214
|
+
)
|
|
1215
|
+
: [
|
|
1216
|
+
themeCommand(
|
|
1217
|
+
words,
|
|
1218
|
+
'template',
|
|
1219
|
+
['theme.template.ts'],
|
|
1220
|
+
'start a theme source from the annotated template',
|
|
1221
|
+
),
|
|
1222
|
+
],
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1042
1225
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1226
|
+
/**
|
|
1227
|
+
* This build again without some of its options, as the way out of a
|
|
1228
|
+
* refusal about how they combine.
|
|
1229
|
+
* @param {Array<'out' | 'watch' | 'check' | 'family'>} drop
|
|
1230
|
+
* @param {string} reason
|
|
1231
|
+
* @param {string[]} [only] the files to build, when not all of them
|
|
1232
|
+
*/
|
|
1233
|
+
const buildWithout = (drop, reason, only = files) =>
|
|
1234
|
+
buildRun(
|
|
1051
1235
|
themeCommand(
|
|
1052
1236
|
words,
|
|
1053
1237
|
words.build,
|
|
@@ -1065,407 +1249,503 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1065
1249
|
: []),
|
|
1066
1250
|
],
|
|
1067
1251
|
reason,
|
|
1068
|
-
)
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
words,
|
|
1078
|
-
'template',
|
|
1079
|
-
['theme.template.ts'],
|
|
1080
|
-
'an annotated theme source that builds, to compare with',
|
|
1081
|
-
),
|
|
1082
|
-
];
|
|
1083
|
-
|
|
1084
|
-
// One file passed twice would build twice and report two themes.
|
|
1085
|
-
const seenFiles = new Set();
|
|
1086
|
-
for (const entry of entries) {
|
|
1087
|
-
const key = fs.realpathSync(entry.filePath);
|
|
1088
|
-
if (seenFiles.has(key)) {
|
|
1089
|
-
const once = entries
|
|
1090
|
-
.filter(
|
|
1091
|
-
(other, index) =>
|
|
1092
|
-
entries.findIndex(
|
|
1093
|
-
first =>
|
|
1094
|
-
fs.realpathSync(first.filePath) ===
|
|
1095
|
-
fs.realpathSync(other.filePath),
|
|
1096
|
-
) === index,
|
|
1097
|
-
)
|
|
1098
|
-
.map(other => other.file);
|
|
1099
|
-
return cliError(
|
|
1100
|
-
`${entry.file} is given more than once. Select each theme file once.`,
|
|
1101
|
-
{
|
|
1102
|
-
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1103
|
-
suggestions: [buildWithout([], 'each file once', once)],
|
|
1104
|
-
},
|
|
1105
|
-
);
|
|
1106
|
-
}
|
|
1107
|
-
seenFiles.add(key);
|
|
1108
|
-
}
|
|
1252
|
+
),
|
|
1253
|
+
only,
|
|
1254
|
+
{
|
|
1255
|
+
check: Boolean(options.check) && !drop.includes('check'),
|
|
1256
|
+
family: Boolean(options.family) && !drop.includes('family'),
|
|
1257
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1258
|
+
out: drop.includes('out') ? undefined : options.out,
|
|
1259
|
+
},
|
|
1260
|
+
);
|
|
1109
1261
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1262
|
+
// A refusal from the build that names no command: without --out the
|
|
1263
|
+
// outputs go beside the source; otherwise the annotated template shows
|
|
1264
|
+
// a theme source that builds.
|
|
1265
|
+
const buildFallback = options.out
|
|
1266
|
+
? [buildWithout(['out'], 'write the outputs beside the source')]
|
|
1267
|
+
: [
|
|
1268
|
+
themeCommand(
|
|
1269
|
+
words,
|
|
1270
|
+
'template',
|
|
1271
|
+
['theme.template.ts'],
|
|
1272
|
+
'an annotated theme source that builds, to compare with',
|
|
1273
|
+
),
|
|
1274
|
+
];
|
|
1275
|
+
|
|
1276
|
+
// One file passed twice would build twice and report two themes.
|
|
1277
|
+
const seenFiles = new Set();
|
|
1278
|
+
for (const entry of entries) {
|
|
1279
|
+
const key = fs.realpathSync(entry.filePath);
|
|
1280
|
+
if (seenFiles.has(key)) {
|
|
1281
|
+
const once = entries
|
|
1282
|
+
.filter(
|
|
1283
|
+
(other, index) =>
|
|
1284
|
+
entries.findIndex(
|
|
1285
|
+
first =>
|
|
1286
|
+
fs.realpathSync(first.filePath) ===
|
|
1287
|
+
fs.realpathSync(other.filePath),
|
|
1288
|
+
) === index,
|
|
1289
|
+
)
|
|
1290
|
+
.map(other => other.file);
|
|
1291
|
+
return await refuse(
|
|
1292
|
+
`${entry.file} is given more than once. Select each theme file once.`,
|
|
1118
1293
|
{
|
|
1119
1294
|
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1120
|
-
suggestions: [
|
|
1121
|
-
{
|
|
1122
|
-
...themeCommand(
|
|
1123
|
-
words,
|
|
1124
|
-
words.build,
|
|
1125
|
-
[
|
|
1126
|
-
...files,
|
|
1127
|
-
// --out names one output, so it goes with one file only.
|
|
1128
|
-
...(options.out && files.length === 1
|
|
1129
|
-
? ['--out', options.out]
|
|
1130
|
-
: []),
|
|
1131
|
-
...(options.iconsSpecifier
|
|
1132
|
-
? ['--icons-specifier', options.iconsSpecifier]
|
|
1133
|
-
: []),
|
|
1134
|
-
...(options.check ? ['--check'] : []),
|
|
1135
|
-
],
|
|
1136
|
-
'build each theme on its own',
|
|
1137
|
-
),
|
|
1138
|
-
},
|
|
1139
|
-
],
|
|
1295
|
+
suggestions: [buildWithout([], 'each file once', once)],
|
|
1140
1296
|
},
|
|
1141
1297
|
);
|
|
1142
1298
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1299
|
+
seenFiles.add(key);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// Family mode is a thin orchestration branch over the existing build API.
|
|
1303
|
+
// Its key is required exactly with --family, and options that describe one
|
|
1304
|
+
// standalone output or a long-running loop remain intentionally separate.
|
|
1305
|
+
if (Boolean(options.family) !== Boolean(options.familyKey)) {
|
|
1306
|
+
return await refuse(
|
|
1307
|
+
options.family
|
|
1308
|
+
? '--family requires --family-key <key>'
|
|
1309
|
+
: '--family-key requires --family',
|
|
1310
|
+
{
|
|
1145
1311
|
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1146
1312
|
suggestions: [
|
|
1147
|
-
|
|
1313
|
+
buildRun(
|
|
1314
|
+
themeCommand(
|
|
1315
|
+
words,
|
|
1316
|
+
words.build,
|
|
1317
|
+
[
|
|
1318
|
+
...files,
|
|
1319
|
+
// --out names one output, so it goes with one file only.
|
|
1320
|
+
...(options.out && files.length === 1
|
|
1321
|
+
? ['--out', options.out]
|
|
1322
|
+
: []),
|
|
1323
|
+
...(options.iconsSpecifier
|
|
1324
|
+
? ['--icons-specifier', options.iconsSpecifier]
|
|
1325
|
+
: []),
|
|
1326
|
+
...(options.check ? ['--check'] : []),
|
|
1327
|
+
],
|
|
1328
|
+
'build each theme on its own',
|
|
1329
|
+
),
|
|
1330
|
+
files,
|
|
1331
|
+
{
|
|
1332
|
+
check: Boolean(options.check),
|
|
1333
|
+
family: false,
|
|
1334
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1335
|
+
out: files.length === 1 ? options.out : undefined,
|
|
1336
|
+
},
|
|
1337
|
+
),
|
|
1148
1338
|
],
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1339
|
+
},
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
if (options.family && options.out) {
|
|
1343
|
+
return await refuse('--family cannot be combined with --out', {
|
|
1344
|
+
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1345
|
+
suggestions: [
|
|
1346
|
+
buildWithout(['out'], 'family outputs go beside the family root'),
|
|
1347
|
+
],
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
if (options.family && options.watch) {
|
|
1351
|
+
return await refuse('--family cannot be combined with --watch', {
|
|
1352
|
+
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1353
|
+
suggestions: [buildWithout(['watch'], 'build the family once')],
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// --check and --watch are mutually exclusive: check is a one-shot,
|
|
1358
|
+
// exit-coded verification; watch is a long-running rebuild loop.
|
|
1359
|
+
if (options.check && options.watch) {
|
|
1360
|
+
return await refuse('--check cannot be combined with --watch', {
|
|
1361
|
+
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1362
|
+
suggestions: [buildWithout(['watch'], 'check once')],
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// --out names one output file, so it cannot describe N themes. Without
|
|
1367
|
+
// it each theme writes `<theme name>.css` beside its source, which is
|
|
1368
|
+
// what a multi-theme build wants anyway.
|
|
1369
|
+
if (options.out && entries.length > 1) {
|
|
1370
|
+
return await refuse(
|
|
1371
|
+
`--out takes a single output path and ${entries.length} theme files were given. ` +
|
|
1372
|
+
'Build them without --out (each theme writes <name>.css next to its source), ' +
|
|
1373
|
+
'or run one invocation per theme.',
|
|
1374
|
+
{
|
|
1153
1375
|
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1154
|
-
suggestions: [
|
|
1155
|
-
|
|
1156
|
-
|
|
1376
|
+
suggestions: [
|
|
1377
|
+
buildWithout(
|
|
1378
|
+
['out'],
|
|
1379
|
+
'each theme writes <name>.css next to its source',
|
|
1380
|
+
),
|
|
1381
|
+
],
|
|
1382
|
+
},
|
|
1383
|
+
);
|
|
1384
|
+
}
|
|
1157
1385
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1386
|
+
// Watch mode: run an initial build, then rebuild on every change to the
|
|
1387
|
+
// theme file. Watch is a human-interactive, long-running mode — it is not
|
|
1388
|
+
// supported in --json (machine) mode, which expects a single envelope.
|
|
1389
|
+
if (options.watch) {
|
|
1390
|
+
if (json) {
|
|
1391
|
+
return await refuse('--watch is not supported with --json', {
|
|
1162
1392
|
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
1163
|
-
suggestions: [
|
|
1393
|
+
suggestions: [
|
|
1394
|
+
buildWithout(['watch'], 'build once, with a JSON result'),
|
|
1395
|
+
],
|
|
1164
1396
|
});
|
|
1165
1397
|
}
|
|
1398
|
+
await runThemeBuildWatch(entries, {...options, detail}, words);
|
|
1399
|
+
return NO_RESULT_SET;
|
|
1400
|
+
}
|
|
1166
1401
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1402
|
+
// Non-watch: delegate to the API compiler, once per theme, in argument
|
|
1403
|
+
// order. Enable human output unless in --json mode (log → stdout via
|
|
1404
|
+
// humanLog, warn/error → stderr). The "Building theme from" line, the
|
|
1405
|
+
// [ok]/[warn] lines, and the install instructions are all emitted from
|
|
1406
|
+
// inside themeBuild via the shared logger.
|
|
1407
|
+
logger.setSilent(json);
|
|
1408
|
+
// Started by a watcher (runThemeBuildWatch): hand the editor-folder
|
|
1409
|
+
// warning to it, and let the channel not keep this build alive.
|
|
1410
|
+
const watchChild =
|
|
1411
|
+
typeof process.send === 'function' && process.argv0 === WATCH_CHILD_ARGV0;
|
|
1412
|
+
if (watchChild) {
|
|
1413
|
+
process.channel?.unref();
|
|
1414
|
+
setEditorFolderListener(warning => {
|
|
1415
|
+
// Held open until the message is out, then let go again.
|
|
1416
|
+
process.channel?.ref();
|
|
1417
|
+
process.send?.({type: WATCH_WARNING, text: warning}, () =>
|
|
1418
|
+
process.channel?.unref(),
|
|
1419
|
+
);
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
const refused = await words.preflight?.(files, {
|
|
1424
|
+
cwd: process.cwd(),
|
|
1425
|
+
check: options.check,
|
|
1426
|
+
family: Boolean(options.family),
|
|
1427
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1428
|
+
out: options.out,
|
|
1429
|
+
});
|
|
1430
|
+
if (refused)
|
|
1431
|
+
return await refuseTheme(
|
|
1432
|
+
(await words.follow?.(refused, process.cwd())) ?? refused,
|
|
1433
|
+
words,
|
|
1434
|
+
buildFallback,
|
|
1435
|
+
);
|
|
1436
|
+
|
|
1437
|
+
if (options.family) {
|
|
1438
|
+
try {
|
|
1439
|
+
const result = await themeBuildFamily(
|
|
1440
|
+
files,
|
|
1175
1441
|
{
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
['out'],
|
|
1180
|
-
'each theme writes <name>.css next to its source',
|
|
1181
|
-
),
|
|
1182
|
-
],
|
|
1442
|
+
familyKey: /** @type {string} */ (options.familyKey),
|
|
1443
|
+
check: options.check,
|
|
1444
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1183
1445
|
},
|
|
1446
|
+
{cwd: process.cwd()},
|
|
1447
|
+
{commandWords: words},
|
|
1184
1448
|
);
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
buildWithout(['watch'], 'build once, with a JSON result'),
|
|
1196
|
-
],
|
|
1197
|
-
});
|
|
1449
|
+
if (json) jsonOut(result);
|
|
1450
|
+
if (
|
|
1451
|
+
result.type === 'theme.build.check' &&
|
|
1452
|
+
!(
|
|
1453
|
+
/** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse} */ (
|
|
1454
|
+
result
|
|
1455
|
+
).data.upToDate
|
|
1456
|
+
)
|
|
1457
|
+
) {
|
|
1458
|
+
process.exitCode = 1;
|
|
1198
1459
|
}
|
|
1199
|
-
await runThemeBuildWatch(entries, {...options, detail}, words);
|
|
1200
1460
|
return NO_RESULT_SET;
|
|
1461
|
+
} catch (e) {
|
|
1462
|
+
const err =
|
|
1463
|
+
/** @type {import('../../../api/error.mjs').AstryxError} */ (e);
|
|
1464
|
+
return await refuseTheme(err, words, [
|
|
1465
|
+
buildWithout(['family'], 'build each theme on its own'),
|
|
1466
|
+
]);
|
|
1201
1467
|
}
|
|
1468
|
+
}
|
|
1202
1469
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1470
|
+
// --json and --check keep their own output at every detail level.
|
|
1471
|
+
const report = !json && !options.check && (entries.length > 1 || compact);
|
|
1472
|
+
/** @type {import('../../../api/theme/build/build.mjs').ThemeBuildTrailer[]} */
|
|
1473
|
+
const trailers = [];
|
|
1474
|
+
|
|
1475
|
+
/** @type {Array<{file: string, receipt: import('../../../api/theme/theme.type.mjs').ThemeBuildResponse | import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse | null}>} */
|
|
1476
|
+
const results = [];
|
|
1477
|
+
let stale = false;
|
|
1478
|
+
// A batch builds every theme first and then writes them in order, so
|
|
1479
|
+
// two themes that build the same files are refused before either
|
|
1480
|
+
// writes. Any other failure writes the themes built before it, as a
|
|
1481
|
+
// shell loop under `set -e` would have, and stops.
|
|
1482
|
+
const deferred = !options.check && entries.length > 1;
|
|
1483
|
+
// Each built theme keeps its writes and what it prints together; what
|
|
1484
|
+
// it prints waits until its outputs are written, so no `[ok]` line
|
|
1485
|
+
// names a file that is never written.
|
|
1486
|
+
/** @type {Array<{writes: Array<Array<{dest: string, content: string}>>, lines: Array<() => void>}>} */
|
|
1487
|
+
const built = [];
|
|
1488
|
+
const publish = () => {
|
|
1489
|
+
for (const theme of built.splice(0)) {
|
|
1490
|
+
writeDeferredBuildOutputs(theme.writes);
|
|
1491
|
+
for (const show of theme.lines) show();
|
|
1223
1492
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1493
|
+
};
|
|
1494
|
+
const writeFailed = async (/** @type {unknown} */ error) =>
|
|
1495
|
+
refuseTheme(
|
|
1496
|
+
/** @type {import('../../../api/error.mjs').AstryxError} */ (error),
|
|
1497
|
+
words,
|
|
1498
|
+
[
|
|
1499
|
+
buildWithout(
|
|
1500
|
+
[],
|
|
1501
|
+
'run the same build again once the files can be written',
|
|
1502
|
+
),
|
|
1503
|
+
],
|
|
1504
|
+
);
|
|
1505
|
+
/** @type {Map<string, string>} */
|
|
1506
|
+
const claimedOutputs = new Map();
|
|
1507
|
+
for (const entry of entries) {
|
|
1508
|
+
/** @type {Array<() => void>} */
|
|
1509
|
+
const lines = [];
|
|
1510
|
+
/** @type {Array<Array<{dest: string, content: string}>>} */
|
|
1511
|
+
const writes = [];
|
|
1512
|
+
const log = logger.log;
|
|
1513
|
+
const warn = logger.warn;
|
|
1514
|
+
// A group may know fonts the app loads that the theme file cannot
|
|
1515
|
+
// say (the editor's app copy stylesheet): the build leaves them out
|
|
1516
|
+
// of every "not loaded" note, family by family.
|
|
1517
|
+
const loads =
|
|
1518
|
+
(await words.loadedFonts?.(entry.file, process.cwd())) ?? null;
|
|
1519
|
+
// A check whose result a group may still fail holds its lines
|
|
1520
|
+
// until the group has looked.
|
|
1521
|
+
/** @type {Array<string | undefined> | null} */
|
|
1522
|
+
let held = null;
|
|
1523
|
+
if (options.check && words.extraData && !deferred) {
|
|
1524
|
+
held = [];
|
|
1525
|
+
logger.log = (/** @type {string | undefined} */ message) => {
|
|
1526
|
+
held?.push(message);
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
if (deferred) {
|
|
1530
|
+
logger.log = (/** @type {string | undefined} */ message) => {
|
|
1531
|
+
lines.push(() => log.call(logger, message));
|
|
1532
|
+
};
|
|
1533
|
+
logger.warn = (/** @type {string | undefined} */ message) => {
|
|
1534
|
+
lines.push(() => warn.call(logger, message));
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
try {
|
|
1538
|
+
const buildOptions = {
|
|
1539
|
+
out: options.out,
|
|
1540
|
+
check: options.check,
|
|
1541
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1542
|
+
};
|
|
1543
|
+
/** @type {import('../../../api/theme/build/build.mjs').ThemeBuildHandOff} */
|
|
1544
|
+
const handOff = {
|
|
1545
|
+
claimedOutputs,
|
|
1546
|
+
deferredWrites: deferred ? writes : undefined,
|
|
1547
|
+
commandWords: words,
|
|
1548
|
+
colorModes: words.colorModes?.(entry.file, process.cwd()) ?? null,
|
|
1549
|
+
fontHelp: words.fontHelp?.(entry.file, process.cwd()) ?? null,
|
|
1550
|
+
install: words.install?.(entry.file, process.cwd()) ?? null,
|
|
1551
|
+
loadedFonts: loads,
|
|
1552
|
+
};
|
|
1553
|
+
let result;
|
|
1554
|
+
if (report) {
|
|
1555
|
+
const built = await themeBuildForReport(
|
|
1556
|
+
entry.file,
|
|
1557
|
+
buildOptions,
|
|
1243
1558
|
{cwd: process.cwd()},
|
|
1244
|
-
{
|
|
1559
|
+
{compact},
|
|
1560
|
+
handOff,
|
|
1245
1561
|
);
|
|
1246
|
-
|
|
1247
|
-
if (
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1562
|
+
result = built.receipt;
|
|
1563
|
+
if (built.trailer) trailers.push(built.trailer);
|
|
1564
|
+
if (compact && result?.type === 'theme.build') {
|
|
1565
|
+
const {outputs, sizeKB, tokenCount, componentCount} = result.data;
|
|
1566
|
+
const show = () =>
|
|
1567
|
+
emit(
|
|
1568
|
+
text(
|
|
1569
|
+
`[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
|
|
1570
|
+
),
|
|
1571
|
+
);
|
|
1572
|
+
if (deferred) lines.push(show);
|
|
1573
|
+
else show();
|
|
1256
1574
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1575
|
+
} else {
|
|
1576
|
+
result = await themeBuildWithHandOff(
|
|
1577
|
+
entry.file,
|
|
1578
|
+
buildOptions,
|
|
1579
|
+
{cwd: process.cwd()},
|
|
1580
|
+
handOff,
|
|
1581
|
+
);
|
|
1264
1582
|
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1583
|
+
logger.log = log;
|
|
1584
|
+
logger.warn = warn;
|
|
1585
|
+
// A group may add to a build's result (the editor's app copy:
|
|
1586
|
+
// what keeps it behind, and in a check whether it is current).
|
|
1587
|
+
const extra = await words.extraData?.(entry.file, process.cwd(), {
|
|
1588
|
+
check: Boolean(options.check),
|
|
1589
|
+
upToDate: /** @type {any} */ (result)?.data?.upToDate,
|
|
1590
|
+
out: options.out,
|
|
1591
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1592
|
+
});
|
|
1593
|
+
if (extra && result?.data) mergeResultData(result.data, extra);
|
|
1594
|
+
// A check the group failed says so where the check said ok.
|
|
1595
|
+
if (held) {
|
|
1596
|
+
logger.log = log;
|
|
1597
|
+
for (const line of held)
|
|
1598
|
+
log.call(
|
|
1599
|
+
logger,
|
|
1600
|
+
extra?.upToDate === false &&
|
|
1601
|
+
typeof line === 'string' &&
|
|
1602
|
+
/^\s*\[ok\]/.test(line)
|
|
1603
|
+
? `[fail] ${String(extra.appCopyStale ?? 'not up to date')}`
|
|
1604
|
+
: line,
|
|
1605
|
+
);
|
|
1606
|
+
held = null;
|
|
1289
1607
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
),
|
|
1300
|
-
],
|
|
1301
|
-
);
|
|
1302
|
-
/** @type {Map<string, string>} */
|
|
1303
|
-
const claimedOutputs = new Map();
|
|
1304
|
-
for (const entry of entries) {
|
|
1305
|
-
/** @type {Array<() => void>} */
|
|
1306
|
-
const lines = [];
|
|
1307
|
-
/** @type {Array<Array<{dest: string, content: string}>>} */
|
|
1308
|
-
const writes = [];
|
|
1309
|
-
const log = logger.log;
|
|
1310
|
-
const warn = logger.warn;
|
|
1311
|
-
if (deferred) {
|
|
1312
|
-
logger.log = (/** @type {string | undefined} */ message) => {
|
|
1313
|
-
lines.push(() => log.call(logger, message));
|
|
1314
|
-
};
|
|
1315
|
-
logger.warn = (/** @type {string | undefined} */ message) => {
|
|
1316
|
-
lines.push(() => warn.call(logger, message));
|
|
1317
|
-
};
|
|
1608
|
+
results.push({file: entry.file, receipt: result ?? null});
|
|
1609
|
+
if (deferred) built.push({writes, lines});
|
|
1610
|
+
if (
|
|
1611
|
+
options.check &&
|
|
1612
|
+
result &&
|
|
1613
|
+
result.type === 'theme.build.check' &&
|
|
1614
|
+
!result.data.upToDate
|
|
1615
|
+
) {
|
|
1616
|
+
stale = true;
|
|
1318
1617
|
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
/** @type {import('../../../api/
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
const show = () =>
|
|
1345
|
-
emit(
|
|
1346
|
-
text(
|
|
1347
|
-
`[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
|
|
1348
|
-
),
|
|
1349
|
-
);
|
|
1350
|
-
if (deferred) lines.push(show);
|
|
1351
|
-
else show();
|
|
1352
|
-
}
|
|
1353
|
-
} else {
|
|
1354
|
-
result = await themeBuildWithHandOff(
|
|
1355
|
-
entry.file,
|
|
1356
|
-
buildOptions,
|
|
1357
|
-
{cwd: process.cwd()},
|
|
1358
|
-
handOff,
|
|
1359
|
-
);
|
|
1360
|
-
}
|
|
1361
|
-
logger.log = log;
|
|
1362
|
-
logger.warn = warn;
|
|
1363
|
-
results.push({file: entry.file, receipt: result ?? null});
|
|
1364
|
-
if (deferred) built.push({writes, lines});
|
|
1365
|
-
if (
|
|
1366
|
-
options.check &&
|
|
1367
|
-
result &&
|
|
1368
|
-
result.type === 'theme.build.check' &&
|
|
1369
|
-
!result.data.upToDate
|
|
1370
|
-
) {
|
|
1371
|
-
stale = true;
|
|
1372
|
-
}
|
|
1373
|
-
} catch (e) {
|
|
1374
|
-
logger.log = log;
|
|
1375
|
-
logger.warn = warn;
|
|
1376
|
-
const err =
|
|
1377
|
-
/** @type {import('../../../api/error.mjs').AstryxError} */ (e);
|
|
1378
|
-
// Stop at the first failure, as a shell loop under `set -e` does.
|
|
1379
|
-
// With several themes in flight the message alone rarely says which
|
|
1380
|
-
// one broke, so name it. Themes already written keep their install
|
|
1381
|
-
// and font guidance.
|
|
1382
|
-
if (/** @type {any} */ (err).outputCollision) {
|
|
1383
|
-
// Nothing is written, so only this theme's warnings are shown.
|
|
1384
|
-
for (const show of lines) show();
|
|
1385
|
-
return themeError(err, words, [
|
|
1386
|
-
buildWithout([], 'build the first theme on its own', [
|
|
1387
|
-
entries[0].file,
|
|
1388
|
-
]),
|
|
1389
|
-
]);
|
|
1390
|
-
}
|
|
1391
|
-
if (deferred) {
|
|
1392
|
-
try {
|
|
1393
|
-
publish();
|
|
1394
|
-
} catch (writeError) {
|
|
1395
|
-
return writeFailed(writeError);
|
|
1396
|
-
}
|
|
1397
|
-
// The failing theme's warnings, such as a missing package, say
|
|
1398
|
-
// why it failed.
|
|
1399
|
-
for (const show of lines) show();
|
|
1618
|
+
} catch (e) {
|
|
1619
|
+
logger.log = log;
|
|
1620
|
+
logger.warn = warn;
|
|
1621
|
+
for (const line of held ?? []) log.call(logger, line);
|
|
1622
|
+
held = null;
|
|
1623
|
+
const err =
|
|
1624
|
+
/** @type {import('../../../api/error.mjs').AstryxError} */ (e);
|
|
1625
|
+
// Stop at the first failure, as a shell loop under `set -e` does.
|
|
1626
|
+
// With several themes in flight the message alone rarely says which
|
|
1627
|
+
// one broke, so name it. Themes already written keep their install
|
|
1628
|
+
// and font guidance.
|
|
1629
|
+
if (/** @type {any} */ (err).outputCollision) {
|
|
1630
|
+
// Nothing is written, so only this theme's warnings are shown.
|
|
1631
|
+
for (const show of lines) show();
|
|
1632
|
+
return await refuseTheme(err, words, [
|
|
1633
|
+
buildWithout([], 'build the first theme on its own', [
|
|
1634
|
+
entries[0].file,
|
|
1635
|
+
]),
|
|
1636
|
+
]);
|
|
1637
|
+
}
|
|
1638
|
+
if (deferred) {
|
|
1639
|
+
try {
|
|
1640
|
+
publish();
|
|
1641
|
+
} catch (writeError) {
|
|
1642
|
+
return writeFailed(writeError);
|
|
1400
1643
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
return themeError(err, words, buildFallback);
|
|
1644
|
+
// The failing theme's warnings, such as a missing package, say
|
|
1645
|
+
// why it failed.
|
|
1646
|
+
for (const show of lines) show();
|
|
1405
1647
|
}
|
|
1648
|
+
if (report && compact) printCompactTrailer(trailers);
|
|
1649
|
+
else if (report) printBatchTrailer(trailers);
|
|
1650
|
+
if (entries.length > 1) err.message = `${entry.file}: ${err.message}`;
|
|
1651
|
+
return await refuseTheme(
|
|
1652
|
+
entries.length === 1
|
|
1653
|
+
? ((await words.follow?.(err, process.cwd())) ?? err)
|
|
1654
|
+
: err,
|
|
1655
|
+
words,
|
|
1656
|
+
buildFallback,
|
|
1657
|
+
);
|
|
1406
1658
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1659
|
+
}
|
|
1660
|
+
if (deferred) {
|
|
1661
|
+
try {
|
|
1662
|
+
publish();
|
|
1663
|
+
} catch (e) {
|
|
1664
|
+
return writeFailed(e);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
// A group follows the written outputs with writes of its own (the
|
|
1668
|
+
// editor's app copy), and each result says what they did.
|
|
1669
|
+
if (words.afterBuild && !options.check) {
|
|
1670
|
+
const more = await words.afterBuild(
|
|
1671
|
+
results.map(r => r.file),
|
|
1672
|
+
process.cwd(),
|
|
1673
|
+
);
|
|
1674
|
+
for (const r of results) {
|
|
1675
|
+
const data = /** @type {any} */ (r.receipt)?.data;
|
|
1676
|
+
if (data && more[r.file]) mergeResultData(data, more[r.file]);
|
|
1413
1677
|
}
|
|
1678
|
+
}
|
|
1414
1679
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
} else {
|
|
1421
|
-
/** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildBatchResponse} */
|
|
1422
|
-
const batch = {
|
|
1423
|
-
type: 'theme.build.batch',
|
|
1424
|
-
data: {count: results.length, results},
|
|
1425
|
-
};
|
|
1426
|
-
jsonOut(batch);
|
|
1427
|
-
}
|
|
1680
|
+
if (json) {
|
|
1681
|
+
// One theme keeps the single-envelope contract it has always had; a
|
|
1682
|
+
// batch gets its own discriminant rather than N envelopes on stdout.
|
|
1683
|
+
if (entries.length === 1) {
|
|
1684
|
+
if (results[0].receipt) jsonOut(results[0].receipt);
|
|
1428
1685
|
} else {
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
}
|
|
1686
|
+
/** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildBatchResponse} */
|
|
1687
|
+
const batch = {
|
|
1688
|
+
type: 'theme.build.batch',
|
|
1689
|
+
data: {count: results.length, results},
|
|
1690
|
+
};
|
|
1691
|
+
jsonOut(batch);
|
|
1434
1692
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
: `\n[ok] Built ${entries.length} themes.`,
|
|
1441
|
-
),
|
|
1442
|
-
);
|
|
1693
|
+
} else {
|
|
1694
|
+
if (report && compact) {
|
|
1695
|
+
printCompactTrailer(trailers, {hint: !detailChosen});
|
|
1696
|
+
} else if (report) {
|
|
1697
|
+
printBatchTrailer(trailers);
|
|
1443
1698
|
}
|
|
1699
|
+
}
|
|
1700
|
+
if (!json && entries.length > 1) {
|
|
1701
|
+
emit(
|
|
1702
|
+
text(
|
|
1703
|
+
options.check
|
|
1704
|
+
? `\n${stale ? '[fail]' : '[ok]'} Checked ${entries.length} themes.`
|
|
1705
|
+
: `\n[ok] Built ${entries.length} themes.`,
|
|
1706
|
+
),
|
|
1707
|
+
);
|
|
1708
|
+
}
|
|
1444
1709
|
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1710
|
+
// Stale --check output is a failure after its receipt has been emitted.
|
|
1711
|
+
if (options.check && stale) {
|
|
1712
|
+
process.exitCode = 1;
|
|
1713
|
+
}
|
|
1449
1714
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1715
|
+
// Compiling a theme writes CSS; `--check` compares what is on disk. Both
|
|
1716
|
+
// are effects — the receipt (and the exit code) carry the outcome.
|
|
1717
|
+
return NO_RESULT_SET;
|
|
1718
|
+
};
|
|
1719
|
+
const buildCli = defineCommand(theme, docs.build, {
|
|
1720
|
+
fn: themeBuildFn,
|
|
1721
|
+
// The locks taken for the run go when the action ends, however it ends:
|
|
1722
|
+
// a refusal that exits releases them on exit, and a run in process
|
|
1723
|
+
// (which has no exit) here.
|
|
1724
|
+
action: async (
|
|
1725
|
+
/** @type {string[]} */ typedFiles,
|
|
1726
|
+
/** @type {any} */ options,
|
|
1727
|
+
) => {
|
|
1728
|
+
try {
|
|
1729
|
+
return await buildAction(typedFiles, options);
|
|
1730
|
+
} finally {
|
|
1731
|
+
await release?.();
|
|
1732
|
+
release = undefined;
|
|
1733
|
+
}
|
|
1453
1734
|
},
|
|
1454
1735
|
});
|
|
1455
1736
|
// A group may hold locks while a build or check runs (the editor's theme
|
|
1456
1737
|
// lock), so it never reads a change half written.
|
|
1457
1738
|
if (words.hold) {
|
|
1458
|
-
/** @type {(() => Promise<void>) | undefined} */
|
|
1459
|
-
let release;
|
|
1460
1739
|
buildCli.hook('preAction', async (_, cmd) => {
|
|
1461
1740
|
// Under --watch each rebuild runs on its own and takes the locks
|
|
1462
1741
|
// itself; holding them for the whole watch would block every one.
|
|
1463
1742
|
if (cmd.opts().watch) return;
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1743
|
+
const o = cmd.opts();
|
|
1744
|
+
release = await words.hold?.(cmd.args, {
|
|
1745
|
+
cwd: process.cwd(),
|
|
1746
|
+
check: Boolean(o.check),
|
|
1747
|
+
out: o.out,
|
|
1748
|
+
});
|
|
1469
1749
|
});
|
|
1470
1750
|
}
|
|
1471
1751
|
|