@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74
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 +17 -0
- package/api/build/_adapter.mjs +53 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/blocks/blocks.weights.json +1 -1
- 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 +6 -4
- package/api/build/kit/rank.mjs +132 -28
- package/api/build/kit/signals.d.mts +7 -1
- package/api/build/kit/signals.mjs +21 -10
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +14 -9
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +351 -46
- 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 +86 -0
- package/api/build/kit/words.mjs +241 -1
- package/api/build/tree.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -6
- package/api/component/_adapter.d.mts +26 -2
- package/api/component/_adapter.mjs +135 -8
- package/api/component/component.mjs +14 -1
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +11 -1
- package/api/discover/_adapter.mjs +95 -1
- package/api/discover/detail/item/item.mjs +5 -0
- package/api/discover/discover.mjs +12 -3
- package/api/discover/discover.type.d.mts +16 -3
- package/api/discover/discover.type.mjs +13 -3
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +57 -2
- package/api/docs/_adapter.mjs +266 -33
- package/api/docs/_entry-names-lazily.d.mts +22 -0
- package/api/docs/_entry-names-lazily.mjs +25 -0
- package/api/docs/_entry-names.d.mts +23 -0
- package/api/docs/_entry-names.mjs +105 -0
- 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 +54 -5
- package/api/doctor/_adapter.mjs +162 -11
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +15 -3
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +31 -7
- package/api/doctor/theme-checks.d.mts +35 -3
- package/api/doctor/theme-checks.mjs +377 -29
- package/api/hook/_adapter.d.mts +10 -4
- package/api/hook/_adapter.mjs +41 -5
- package/api/hook/detail/detail.mjs +5 -2
- package/api/hook/detail/params/params.mjs +10 -3
- 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/add-helpers.mjs +10 -0
- package/api/integration/authoring-checks.mjs +11 -8
- 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/pack-check.mjs +16 -1
- package/api/integration/validate-integration.d.mts +18 -6
- package/api/integration/validate-integration.mjs +129 -15
- package/api/integration/validate-integration.type.d.mts +22 -0
- package/api/integration/validate-integration.type.mjs +2 -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 +53 -1
- package/api/render/render.type.mjs +32 -2
- package/api/search/ORDERING.md +2 -2
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.d.mts +9 -4
- package/api/search/_candidate-score.mjs +133 -46
- 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 +14 -0
- package/api/search/_lexical.mjs +93 -11
- 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/template/_adapter.d.mts +16 -0
- package/api/template/_adapter.mjs +39 -2
- package/api/template/cdn/cdn.mjs +37 -8
- package/api/template/copy/copy.d.mts +6 -3
- package/api/template/copy/copy.mjs +40 -8
- package/api/template/template.doc.mjs +3 -3
- package/api/template/template.mjs +63 -11
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +1 -0
- package/api/theme/_adapter.d.mts +12 -1
- package/api/theme/_adapter.mjs +132 -13
- package/api/theme/_app-provider.d.mts +31 -0
- package/api/theme/_app-provider.mjs +135 -0
- package/api/theme/add/add.mjs +3 -1
- package/api/theme/build/build.d.mts +142 -1
- package/api/theme/build/build.mjs +692 -284
- 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 +80 -5
- package/api/theme/build/font-warning.mjs +323 -55
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/build/null-values.d.mts +28 -0
- package/api/theme/build/null-values.mjs +191 -0
- package/api/theme/list/list.mjs +17 -1
- package/api/theme/remove/remove.d.mts +2 -1
- package/api/theme/remove/remove.mjs +7 -3
- package/api/theme/theme.type.d.mts +78 -1
- package/api/theme/theme.type.mjs +38 -2
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +8 -5
- package/api/theme-edit/_adapter.d.mts +116 -4
- package/api/theme-edit/_adapter.mjs +1058 -93
- package/api/theme-edit/_catalog.d.mts +46 -2
- package/api/theme-edit/_catalog.mjs +115 -14
- package/api/theme-edit/_check.d.mts +133 -24
- package/api/theme-edit/_check.mjs +3392 -531
- package/api/theme-edit/_color.d.mts +26 -0
- package/api/theme-edit/_color.mjs +92 -2
- package/api/theme-edit/_compiler.d.mts +5 -1
- package/api/theme-edit/_compiler.mjs +141 -17
- package/api/theme-edit/_context.d.mts +74 -6
- package/api/theme-edit/_context.mjs +468 -76
- package/api/theme-edit/_css.d.mts +21 -0
- package/api/theme-edit/_css.mjs +87 -14
- package/api/theme-edit/_edit.d.mts +74 -7
- package/api/theme-edit/_edit.mjs +4426 -319
- package/api/theme-edit/_how-commands.d.mts +76 -1
- package/api/theme-edit/_how-commands.mjs +793 -9
- package/api/theme-edit/_how-question.d.mts +97 -6
- package/api/theme-edit/_how-question.mjs +9184 -747
- package/api/theme-edit/_how.d.mts +5 -2
- package/api/theme-edit/_how.mjs +255 -46
- 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 +322 -0
- package/api/theme-edit/_normal.mjs +1630 -0
- package/api/theme-edit/_palette.d.mts +49 -0
- package/api/theme-edit/_palette.mjs +180 -38
- package/api/theme-edit/_part-words.d.mts +39 -0
- package/api/theme-edit/_part-words.mjs +152 -0
- package/api/theme-edit/_parts.d.mts +55 -3
- package/api/theme-edit/_parts.mjs +421 -36
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +1108 -599
- package/api/theme-edit/_preview.d.mts +156 -19
- package/api/theme-edit/_preview.mjs +809 -180
- package/api/theme-edit/_project.d.mts +61 -1
- package/api/theme-edit/_project.mjs +177 -6
- package/api/theme-edit/_settings.d.mts +619 -48
- package/api/theme-edit/_settings.mjs +4910 -617
- package/api/theme-edit/_tables.d.mts +41 -0
- package/api/theme-edit/_tables.mjs +261 -41
- 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 +34 -2
- package/api/theme-edit/theme-edit.type.mjs +18 -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/api/upgrade/upgrade.mjs +16 -1
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/jscodeshift.d.ts +1 -1
- package/assets/codemods/run-codemod.mjs +151 -18
- package/assets/codemods/runner.mjs +1 -4
- 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 +2 -0
- package/assets/docs/theme.doc.dense.mjs +76 -7
- package/assets/docs/theme.doc.mjs +66 -2
- package/assets/docs/theme.doc.zh.mjs +51 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +2 -2
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +1 -1
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/render-pages.doc.mjs +46 -5
- 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/tree/write-good-templates.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/docs-routes.generated.json +1 -0
- 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/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -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/page.tsx +31 -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/page.tsx +1 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/page.tsx +60 -7
- 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/page.tsx +13 -13
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/page.tsx +14 -2
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/page.tsx +9 -0
- 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/form-wizard-vertical/page.tsx +23 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +33 -2
- package/assets/templates/pages/kanban-board/page.tsx +12 -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/page.tsx +16 -0
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/page.tsx +19 -6
- 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/messaging-shell/template.doc.mjs +6 -0
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/payment-form/page.tsx +30 -4
- package/assets/templates/pages/product-detail/page.tsx +26 -2
- 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/page.tsx +162 -12
- 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/page.tsx +11 -3
- 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/page.tsx +9 -0
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/page.tsx +161 -133
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/page.tsx +14 -1
- 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/page.tsx +47 -7
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +9 -2
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +9 -9
- 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/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +24 -1
- package/authoring/integration/schema.mjs +126 -4
- package/authoring/integration/type.ts +14 -0
- 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/discover.mjs +70 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +44 -6
- package/clients/cli/commands/doctor.mjs +84 -16
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +1032 -134
- 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 +2 -2
- 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 +2 -2
- 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-remove.doc.mjs +4 -4
- 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.doc.mjs +1 -1
- package/clients/cli/commands/template.mjs +15 -2
- package/clients/cli/commands/theme-add.doc.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +13 -5
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +849 -441
- package/clients/cli/commands/upgrade.mjs +46 -8
- package/clients/cli/index.mjs +9 -19
- 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 +265 -29
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/lib/stray-option.mjs +478 -0
- package/clients/cli/lib/unknown-command.mjs +353 -0
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/project.d.mts +8 -0
- package/foundation/config/project.mjs +26 -29
- package/foundation/config/theme-state.d.mts +31 -2
- package/foundation/config/theme-state.mjs +140 -8
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
- package/foundation/discovery/cli-self-doc-names.mjs +51 -0
- package/foundation/discovery/cli-self-docs.d.mts +0 -2
- package/foundation/discovery/cli-self-docs.mjs +2 -15
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +59 -10
- 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/core-theme-facts.d.mts +70 -0
- package/foundation/discovery/core-theme-facts.mjs +384 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/docs-discovery.d.mts +66 -9
- package/foundation/discovery/docs-discovery.mjs +126 -60
- package/foundation/discovery/entry-name-files.d.mts +106 -0
- package/foundation/discovery/entry-name-files.mjs +354 -0
- package/foundation/discovery/hook-discovery.d.mts +18 -2
- package/foundation/discovery/hook-discovery.mjs +93 -42
- 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-component-views.d.mts +15 -0
- package/foundation/discovery/integration-component-views.mjs +91 -0
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/module-exports.d.mts +26 -1
- package/foundation/discovery/module-exports.mjs +114 -40
- package/foundation/discovery/name-roots.d.mts +38 -0
- package/foundation/discovery/name-roots.mjs +108 -0
- package/foundation/discovery/next-routes.d.mts +48 -0
- package/foundation/discovery/next-routes.mjs +181 -0
- 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 +40 -18
- package/foundation/discovery/template-adapter.d.mts +49 -29
- package/foundation/discovery/template-adapter.mjs +89 -99
- package/foundation/discovery/template-destination.d.mts +28 -0
- package/foundation/discovery/template-destination.mjs +104 -0
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/template-ids.d.mts +69 -0
- package/foundation/discovery/template-ids.mjs +199 -0
- package/foundation/discovery/theme-discovery.d.mts +12 -0
- package/foundation/discovery/theme-discovery.mjs +34 -4
- package/foundation/discovery/theme-imports.d.mts +24 -0
- package/foundation/discovery/theme-imports.mjs +61 -4
- package/foundation/discovery/theming-targets.d.mts +13 -5
- package/foundation/discovery/theming-targets.mjs +41 -47
- package/foundation/doc-compiler/generated-levels.d.mts +43 -0
- package/foundation/doc-compiler/generated-levels.mjs +72 -0
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/literal-doc.d.mts +12 -0
- package/foundation/doc-compiler/literal-doc.mjs +322 -0
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +29 -0
- package/foundation/doc-compiler/stored-docs.mjs +63 -1
- package/foundation/doc-compiler/tree.d.mts +4 -84
- package/foundation/doc-compiler/tree.mjs +4 -62
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +46 -0
- package/foundation/fonts/font-stylesheet.mjs +173 -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 +16 -5
- package/foundation/fs/gather-cache.d.mts +94 -4
- package/foundation/fs/gather-cache.mjs +671 -106
- package/foundation/fs/glob.d.mts +16 -0
- package/foundation/fs/glob.mjs +105 -0
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +80 -0
- package/foundation/fs/kept-tree.mjs +240 -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/path-safety.d.mts +11 -2
- package/foundation/fs/path-safety.mjs +108 -18
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +56 -7
- package/foundation/fs/read-record.mjs +280 -56
- package/foundation/fs/regular-file.d.mts +29 -0
- package/foundation/fs/regular-file.mjs +77 -0
- 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/integrations.d.mts +23 -1
- package/foundation/integrations/integrations.mjs +18 -1
- package/foundation/integrations/pack-state.d.mts +75 -0
- package/foundation/integrations/pack-state.mjs +314 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/shipped-imports.d.mts +122 -0
- package/foundation/integrations/shipped-imports.mjs +497 -0
- package/foundation/integrations/validate-contributions.d.mts +0 -17
- package/foundation/integrations/validate-contributions.mjs +59 -333
- package/foundation/render/assets.mjs +52 -7
- package/foundation/render/charts.d.mts +78 -27
- package/foundation/render/charts.mjs +266 -90
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +70 -7
- package/foundation/render/embedded-imports.mjs +132 -41
- 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/layers.d.mts +30 -0
- package/foundation/render/layers.mjs +158 -0
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/offline.d.mts +32 -0
- package/foundation/render/offline.mjs +56 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +354 -21
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +192 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +46 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +79 -5
- package/foundation/render/render-page.mjs +735 -109
- 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 +6 -6
- package/foundation/suggest/name-index.d.mts +148 -0
- package/foundation/suggest/name-index.mjs +317 -0
- package/foundation/suggest/other-command.d.mts +140 -0
- package/foundation/suggest/other-command.mjs +756 -0
- 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/entry-names.d.mts +14 -0
- package/foundation/text/entry-names.mjs +14 -0
- package/foundation/text/string-utils.d.mts +46 -6
- package/foundation/text/string-utils.mjs +118 -20
- package/foundation/text/suggest-order.d.mts +47 -4
- package/foundation/text/suggest-order.mjs +174 -5
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -32,17 +32,33 @@
|
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
import {writeThemeTemplate} from '../theme/template/template.mjs';
|
|
35
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
buildInputProblem,
|
|
37
|
+
buildSuggestion,
|
|
38
|
+
realLocation,
|
|
39
|
+
refusedOutput,
|
|
40
|
+
} from '../theme/build/build.mjs';
|
|
36
41
|
import {createHash} from 'node:crypto';
|
|
37
42
|
import * as fs from 'node:fs';
|
|
38
43
|
import * as path from 'node:path';
|
|
39
44
|
import * as edit from './_edit.mjs';
|
|
40
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
baseInstalled,
|
|
47
|
+
installLine,
|
|
48
|
+
packageInstalled,
|
|
49
|
+
themeCacheRoot,
|
|
50
|
+
} from './_project.mjs';
|
|
41
51
|
import * as preview from './_preview-app.mjs';
|
|
42
52
|
import {AstryxError} from '../error.mjs';
|
|
43
53
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
44
54
|
import {findPackageRoot} from '../../foundation/fs/paths.mjs';
|
|
45
|
-
import {coreApp} from './_context.mjs';
|
|
55
|
+
import {baseWeightNotes, context, coreApp} from './_context.mjs';
|
|
56
|
+
import {APP_COPY_MARK} from './_marks.mjs';
|
|
57
|
+
import {irregularFileKind} from '../../foundation/fs/regular-file.mjs';
|
|
58
|
+
import {
|
|
59
|
+
fontKey,
|
|
60
|
+
importedFontFamilies,
|
|
61
|
+
} from '../../foundation/fonts/font-stylesheet.mjs';
|
|
46
62
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
47
63
|
import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
|
|
48
64
|
import {
|
|
@@ -50,22 +66,48 @@ import {
|
|
|
50
66
|
quoteCommandArgument,
|
|
51
67
|
} from '../../foundation/env/package-manager.mjs';
|
|
52
68
|
import {LIKE, P} from './_tables.mjs';
|
|
69
|
+
|
|
70
|
+
/** The preview command, as a person runs it. */
|
|
71
|
+
const PREVIEW_WORDS = P.replace(/ editor$/, ' preview');
|
|
53
72
|
import {setLine} from './_check.mjs';
|
|
73
|
+
import {followLine, splitCommand} from './_vet.mjs';
|
|
54
74
|
import {
|
|
55
75
|
SHOWCASE_GROUPS,
|
|
76
|
+
appCopyBehind,
|
|
77
|
+
appCopyStale,
|
|
78
|
+
copyFontsCss,
|
|
56
79
|
takeFirstAppCopy,
|
|
57
80
|
writeAppCopy,
|
|
58
81
|
writeAppCopyAt,
|
|
59
82
|
} from './_preview.mjs';
|
|
60
83
|
import {humanWarn} from '../../foundation/response/json.mjs';
|
|
61
|
-
import {
|
|
84
|
+
import {
|
|
85
|
+
buildColorModes,
|
|
86
|
+
camel,
|
|
87
|
+
folderIsEmpty,
|
|
88
|
+
editorMadeFolder,
|
|
89
|
+
loadTheme,
|
|
90
|
+
setAfterBuild,
|
|
91
|
+
editedThemes,
|
|
92
|
+
themeFiles,
|
|
93
|
+
fontsourcePackageOf,
|
|
94
|
+
fontsourceSuggestion,
|
|
95
|
+
themeSourceRefusal,
|
|
96
|
+
typedThemeName,
|
|
97
|
+
} from './_settings.mjs';
|
|
62
98
|
|
|
63
99
|
// Every build of a theme writes its app copy (src/themes/<theme>/).
|
|
64
100
|
setAfterBuild(writeAppCopy);
|
|
65
101
|
import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
|
|
66
102
|
|
|
67
103
|
export {parsePoints} from './_how.mjs';
|
|
68
|
-
export {
|
|
104
|
+
export {
|
|
105
|
+
newFlagList,
|
|
106
|
+
checkedChangeLine as editorCheckedLine,
|
|
107
|
+
checkedNewLines as editorCheckedNewLines,
|
|
108
|
+
checkedShowLines as editorCheckedShowLines,
|
|
109
|
+
} from './_edit.mjs';
|
|
110
|
+
export {splitCommand} from './_vet.mjs';
|
|
69
111
|
import {themeEditHow as howAt} from './_how.mjs';
|
|
70
112
|
|
|
71
113
|
/**
|
|
@@ -116,7 +158,11 @@ export const editorBaseIn = (slug, cwd) =>
|
|
|
116
158
|
/** The sections `show --section` takes. */
|
|
117
159
|
export const showSections = () => [...SHOWCASE_GROUPS];
|
|
118
160
|
|
|
119
|
-
export {
|
|
161
|
+
export {
|
|
162
|
+
dialTakesText,
|
|
163
|
+
dialValueFits,
|
|
164
|
+
usableNewName as editorFreeName,
|
|
165
|
+
} from './_settings.mjs';
|
|
120
166
|
|
|
121
167
|
/**
|
|
122
168
|
* The project a command acts on: the Astryx project at or above `cwd`, found
|
|
@@ -367,16 +413,43 @@ const lockName = name =>
|
|
|
367
413
|
*/
|
|
368
414
|
function absolute(result, root, from) {
|
|
369
415
|
if (path.resolve(from) === root) return result;
|
|
370
|
-
/**
|
|
371
|
-
|
|
416
|
+
/**
|
|
417
|
+
* Lines that name project files inside them: `see`, a picture note, the
|
|
418
|
+
* in-app preview's stale entries. Every project path in them (a theme
|
|
419
|
+
* file, an in-app preview folder) is made absolute, one style per line.
|
|
420
|
+
*/
|
|
421
|
+
const PROSE = new Set(['see', 'pictureProblem', 'previewStale', 'wiring']);
|
|
422
|
+
/** A project-relative path that names a file or folder there. @param {string} p */
|
|
423
|
+
const inRoot = p => {
|
|
424
|
+
const bare = p.replace(/\/+$/, '');
|
|
425
|
+
return (
|
|
426
|
+
Boolean(bare) &&
|
|
427
|
+
!path.isAbsolute(bare) &&
|
|
428
|
+
!bare.startsWith('.') &&
|
|
429
|
+
fs.existsSync(path.join(root, bare))
|
|
430
|
+
);
|
|
431
|
+
};
|
|
432
|
+
/** @param {any} v @param {string} [key] @returns {any} */
|
|
433
|
+
const map = (v, key) =>
|
|
372
434
|
typeof v === 'string'
|
|
373
|
-
?
|
|
435
|
+
? // A path alone; a line that starts with one is read as prose below.
|
|
436
|
+
/^themes\/\S*$/.test(v) && !(key && PROSE.has(key))
|
|
374
437
|
? path.join(root, v)
|
|
375
|
-
:
|
|
438
|
+
: key && PROSE.has(key)
|
|
439
|
+
? previewCommandsFrom(v, root, from).replace(
|
|
440
|
+
/(^|[\s(,])((?:themes|src|app)\/[^\s,;)]*)/g,
|
|
441
|
+
(all, before, file) =>
|
|
442
|
+
/^themes\//.test(file) || inRoot(file)
|
|
443
|
+
? `${before}${path.join(root, file)}`
|
|
444
|
+
: all,
|
|
445
|
+
)
|
|
446
|
+
: previewCommandsFrom(v, root, from)
|
|
376
447
|
: Array.isArray(v)
|
|
377
|
-
? v.map(map)
|
|
448
|
+
? v.map(x => map(x, key))
|
|
378
449
|
: v && typeof v === 'object'
|
|
379
|
-
? Object.fromEntries(
|
|
450
|
+
? Object.fromEntries(
|
|
451
|
+
Object.entries(v).map(([k, x]) => [k, map(x, k)]),
|
|
452
|
+
)
|
|
380
453
|
: v;
|
|
381
454
|
return map(result);
|
|
382
455
|
}
|
|
@@ -425,6 +498,23 @@ async function inProject(options, lock, fn, bestEffort = false, again = null) {
|
|
|
425
498
|
*/
|
|
426
499
|
function fromCaller(e, root, from) {
|
|
427
500
|
if (path.resolve(from) === root || !Array.isArray(e?.suggestions)) return e;
|
|
501
|
+
for (const s of e.suggestions)
|
|
502
|
+
if (typeof s?.name === 'string')
|
|
503
|
+
s.name = previewCommandsFrom(s.name, root, from);
|
|
504
|
+
return e;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* The preview commands in a line, rebased from the project root onto the
|
|
509
|
+
* folder the command ran in: each `--path` and each `preview app` folder,
|
|
510
|
+
* so a pointer works where it is printed (in a refusal, a `see` line, a
|
|
511
|
+
* note). A folder that comes out starting with `-` goes after `--`.
|
|
512
|
+
* @param {string} line
|
|
513
|
+
* @param {string} root
|
|
514
|
+
* @param {string} from
|
|
515
|
+
*/
|
|
516
|
+
export function previewCommandsFrom(line, root, from) {
|
|
517
|
+
if (path.resolve(from) === root) return line;
|
|
428
518
|
const ARG = String.raw`('(?:[^']|'\\'')*'|"[^"]*"|[^\s'"]+)`;
|
|
429
519
|
/** @param {string} v */
|
|
430
520
|
const unquote = v =>
|
|
@@ -437,32 +527,40 @@ function fromCaller(e, root, from) {
|
|
|
437
527
|
const rel = v =>
|
|
438
528
|
/^<.*>$/.test(v)
|
|
439
529
|
? v
|
|
440
|
-
:
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
530
|
+
: path.relative(path.resolve(from), path.resolve(root, unquote(v))) ||
|
|
531
|
+
'.';
|
|
532
|
+
const CMD = 'astryx experimental theme preview ';
|
|
533
|
+
const parts = line.split(CMD);
|
|
534
|
+
return parts
|
|
535
|
+
.map((part, i) => {
|
|
536
|
+
// A command after a `cd … &&` runs in the folder it names: as given.
|
|
537
|
+
if (i === 0 || /\bcd [^&]*&& (?:npx \S+ )?$/.test(parts[i - 1]))
|
|
538
|
+
return part;
|
|
539
|
+
let out = part.replace(
|
|
449
540
|
new RegExp(`(--path )${ARG}`, 'g'),
|
|
450
541
|
(
|
|
451
542
|
/** @type {string} */ _m,
|
|
452
543
|
/** @type {string} */ flag,
|
|
453
544
|
/** @type {string} */ v,
|
|
454
|
-
) => flag + rel(v),
|
|
455
|
-
)
|
|
456
|
-
.replace(
|
|
457
|
-
new RegExp(`^(
|
|
545
|
+
) => flag + quoteCommandArgument(rel(v)),
|
|
546
|
+
);
|
|
547
|
+
out = out.replace(
|
|
548
|
+
new RegExp(`^app ((?:--theme ${ARG} )?)(-- )?${ARG}`),
|
|
458
549
|
(
|
|
459
|
-
/** @type {string} */
|
|
460
|
-
/** @type {string} */
|
|
550
|
+
/** @type {string} */ m,
|
|
551
|
+
/** @type {string} */ flags,
|
|
552
|
+
/** @type {string} */ _t,
|
|
553
|
+
/** @type {string | undefined} */ dash,
|
|
461
554
|
/** @type {string} */ v,
|
|
462
|
-
) =>
|
|
555
|
+
) => {
|
|
556
|
+
if (!dash && v.startsWith('-')) return m;
|
|
557
|
+
const r = rel(v);
|
|
558
|
+
return `app ${flags}${r.startsWith('-') ? '-- ' : ''}${quoteCommandArgument(r)}`;
|
|
559
|
+
},
|
|
463
560
|
);
|
|
464
|
-
|
|
465
|
-
|
|
561
|
+
return out;
|
|
562
|
+
})
|
|
563
|
+
.join(CMD);
|
|
466
564
|
}
|
|
467
565
|
|
|
468
566
|
/**
|
|
@@ -550,37 +648,134 @@ export const themeEditShow = (theme, options = {}) =>
|
|
|
550
648
|
);
|
|
551
649
|
/** @type {typeof preview.themeEditPreviewAdd} */
|
|
552
650
|
export const themeEditPreviewAdd = (description, options = {}) =>
|
|
553
|
-
|
|
554
|
-
preview
|
|
651
|
+
stopTold(
|
|
652
|
+
`a preview change stopped part way is finished by the next ${PREVIEW_WORDS} add, and one written in full stands (${PREVIEW_WORDS} list says which)`,
|
|
653
|
+
() =>
|
|
654
|
+
inProject(options, 'preview', o =>
|
|
655
|
+
preview.themeEditPreviewAdd(description, withThemeLock(o)),
|
|
656
|
+
),
|
|
555
657
|
);
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Run a preview command with a stop (Ctrl-C, SIGTERM) heard for its whole
|
|
661
|
+
* run, and after it: the stop ends the process as stopped, with one line
|
|
662
|
+
* saying where the change stands (a change stopped part way is finished by
|
|
663
|
+
* the next preview command), never an ok with exit 0.
|
|
664
|
+
* @template T
|
|
665
|
+
* @param {string | (() => string)} where where the change stands, and what
|
|
666
|
+
* finishes it; a function is asked when the stop lands, so it can look
|
|
667
|
+
* @param {() => Promise<T>} fn
|
|
668
|
+
* @returns {Promise<T>}
|
|
669
|
+
*/
|
|
670
|
+
async function stopTold(where, fn) {
|
|
671
|
+
const on = (/** @type {NodeJS.Signals} */ sig) => {
|
|
672
|
+
process.removeListener('SIGINT', on);
|
|
673
|
+
process.removeListener('SIGTERM', on);
|
|
674
|
+
process.stderr.write(
|
|
675
|
+
`Stopped: ${typeof where === 'function' ? where() : where}.\n`,
|
|
676
|
+
);
|
|
677
|
+
// With no other listener (a lock's, which ends the process itself),
|
|
678
|
+
// the stop ends it here.
|
|
679
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
680
|
+
};
|
|
681
|
+
process.on('SIGINT', on);
|
|
682
|
+
process.on('SIGTERM', on);
|
|
683
|
+
try {
|
|
684
|
+
const r = await fn();
|
|
685
|
+
// A turn of the event loop, so a stop that came while the work ran
|
|
686
|
+
// without a pause is heard now, before the result is printed.
|
|
687
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
688
|
+
// Every listener added here is removed on return: the caller's process
|
|
689
|
+
// keeps its own stop handling. The CLI client, which owns its process,
|
|
690
|
+
// holds a stop that lands while it prints the result.
|
|
691
|
+
return r;
|
|
692
|
+
} finally {
|
|
693
|
+
process.removeListener('SIGINT', on);
|
|
694
|
+
process.removeListener('SIGTERM', on);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
556
697
|
/**
|
|
557
698
|
* `preview app` runs from the project root, with `dir` kept pointing where
|
|
558
699
|
* it was given. With a theme it holds that theme's lock, since it may build
|
|
559
700
|
* the theme and copies its files: a `set` beside it waits.
|
|
560
701
|
* @type {typeof preview.themeEditPreviewApp}
|
|
561
702
|
*/
|
|
562
|
-
export const themeEditPreviewApp = (dir, options = {}) => {
|
|
703
|
+
export const themeEditPreviewApp = async (dir, options = {}) => {
|
|
563
704
|
const from = options.cwd ?? process.cwd();
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
705
|
+
// The app is written into a temp folder and moved into place in one step,
|
|
706
|
+
// with no pause on the way: when a stop lands, the folder holds the whole
|
|
707
|
+
// app or is as it was. Which one is told.
|
|
708
|
+
const target =
|
|
709
|
+
typeof dir === 'string' && dir.trim() ? path.resolve(from, dir) : null;
|
|
710
|
+
/** @param {string} d */
|
|
711
|
+
const holdsApp = d => fs.existsSync(path.join(d, 'package.json'));
|
|
712
|
+
const hadApp = target != null && holdsApp(target);
|
|
713
|
+
const shownTarget = target
|
|
714
|
+
? path.relative(from, target).split(path.sep).join('/') || '.'
|
|
715
|
+
: null;
|
|
716
|
+
return fromHere(
|
|
717
|
+
await stopTold(
|
|
718
|
+
() =>
|
|
719
|
+
target && !hadApp && holdsApp(target)
|
|
720
|
+
? `the new app in ${shownTarget}/ is written whole (it is moved into place in one step); cd ${quoteCommandArgument(shownTarget?.startsWith('-') ? `./${shownTarget}` : (shownTarget ?? '.'))} && npm install && npm run dev opens it`
|
|
721
|
+
: `nothing was written${shownTarget ? ` (${shownTarget}/ is as it was)` : ''}; run the same command again`,
|
|
722
|
+
() =>
|
|
723
|
+
inProject(
|
|
724
|
+
options,
|
|
725
|
+
options.theme == null ? null : lockName(options.theme),
|
|
726
|
+
o =>
|
|
727
|
+
preview.themeEditPreviewApp(
|
|
728
|
+
typeof dir === 'string' && dir.trim() && dir === dir.trim()
|
|
729
|
+
? path.relative(o.cwd, path.resolve(from, dir)) || '.'
|
|
730
|
+
: dir,
|
|
731
|
+
o,
|
|
732
|
+
),
|
|
733
|
+
true,
|
|
734
|
+
),
|
|
735
|
+
),
|
|
736
|
+
from,
|
|
575
737
|
);
|
|
576
738
|
};
|
|
739
|
+
/**
|
|
740
|
+
* A new app's folder and its open line, as they work from where the command
|
|
741
|
+
* ran (`cd ../../theme-app` from src/app), not from the project root.
|
|
742
|
+
* @template T
|
|
743
|
+
* @param {T} r
|
|
744
|
+
* @param {string} from
|
|
745
|
+
* @returns {T}
|
|
746
|
+
*/
|
|
747
|
+
function fromHere(r, from) {
|
|
748
|
+
const d = /** @type {any} */ (r)?.data;
|
|
749
|
+
if (!d || typeof d.folder !== 'string') return r;
|
|
750
|
+
const root = projectRoot(from);
|
|
751
|
+
if (!root || path.resolve(from) === root) return r;
|
|
752
|
+
const here = path.relative(from, path.join(root, d.folder)) || '.';
|
|
753
|
+
const shown = here.split(path.sep).join('/');
|
|
754
|
+
const cdArg = quoteCommandArgument(
|
|
755
|
+
shown.startsWith('-') ? `./${shown}` : shown,
|
|
756
|
+
);
|
|
757
|
+
return /** @type {T} */ ({
|
|
758
|
+
...r,
|
|
759
|
+
data: {
|
|
760
|
+
...d,
|
|
761
|
+
folder: shown,
|
|
762
|
+
...(typeof d.open === 'string'
|
|
763
|
+
? {open: d.open.replace(/^cd \S+ &&/, `cd ${cdArg} &&`)}
|
|
764
|
+
: {}),
|
|
765
|
+
},
|
|
766
|
+
});
|
|
767
|
+
}
|
|
577
768
|
/** @type {typeof preview.themeEditPreviewList} */
|
|
578
769
|
export const themeEditPreviewList = (options = {}) =>
|
|
579
770
|
inProject(options, null, async o => preview.themeEditPreviewList(o));
|
|
580
771
|
/** @type {typeof preview.themeEditPreviewRemove} */
|
|
581
772
|
export const themeEditPreviewRemove = (page, options = {}) =>
|
|
582
|
-
|
|
583
|
-
|
|
773
|
+
stopTold(
|
|
774
|
+
`a removal stopped part way is finished by the next ${PREVIEW_WORDS} remove, and one made in full stands (${PREVIEW_WORDS} list says which)`,
|
|
775
|
+
() =>
|
|
776
|
+
inProject(options, 'preview', o =>
|
|
777
|
+
preview.themeEditPreviewRemove(page, withThemeLock(o)),
|
|
778
|
+
),
|
|
584
779
|
);
|
|
585
780
|
|
|
586
781
|
/**
|
|
@@ -591,11 +786,15 @@ export const themeEditPreviewRemove = (page, options = {}) =>
|
|
|
591
786
|
* does not).
|
|
592
787
|
* @param {string} root
|
|
593
788
|
* @param {string} word a path or a name
|
|
789
|
+
* @param {{made?: boolean}} [options] `made`: a folder the editor made that
|
|
790
|
+
* lost its settings counts too (the editor commands refuse it, and so
|
|
791
|
+
* does compile)
|
|
594
792
|
* @returns {{root: string, slug: string} | null}
|
|
595
793
|
*/
|
|
596
|
-
function editorThemeAt(root, word) {
|
|
794
|
+
function editorThemeAt(root, word, {made = false} = {}) {
|
|
597
795
|
const has = (/** @type {string} */ r, /** @type {string} */ slug) =>
|
|
598
|
-
fs.existsSync(path.join(r, 'themes', slug, `${slug}.settings.json`))
|
|
796
|
+
fs.existsSync(path.join(r, 'themes', slug, `${slug}.settings.json`)) ||
|
|
797
|
+
(made && editorMadeFolder(r, slug));
|
|
599
798
|
if (/^[a-z][a-z0-9-]*$/.test(word))
|
|
600
799
|
return has(root, word) ? {root, slug: word} : null;
|
|
601
800
|
// Through a link, the real path decides (a linked theme folder is the
|
|
@@ -669,8 +868,9 @@ function runLine(cwd, rest) {
|
|
|
669
868
|
* @returns {AstryxError | null}
|
|
670
869
|
*/
|
|
671
870
|
export function editorThemeRefusal(err, cwd) {
|
|
672
|
-
// A refused compile ends here: its theme locks go now, not at exit
|
|
673
|
-
|
|
871
|
+
// A refused compile ends here: its theme locks go now, not at exit, and
|
|
872
|
+
// it writes no app copy (from build files it refused).
|
|
873
|
+
void releaseCompileHold?.(true);
|
|
674
874
|
if (
|
|
675
875
|
err.code !== ERROR_CODES.ERR_UNKNOWN_THEME &&
|
|
676
876
|
!/unknown theme|is not added|not a theme package/i.test(err.message)
|
|
@@ -683,10 +883,43 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
683
883
|
const word = named ? typedThemeName(named[1] ?? named[2]) : '';
|
|
684
884
|
const slug = word ? editorThemeOf(root, word) : null;
|
|
685
885
|
if (!slug) return null;
|
|
886
|
+
// The command that refused: list, add, use, remove or eject.
|
|
887
|
+
const verb =
|
|
888
|
+
process.argv
|
|
889
|
+
.slice(2)
|
|
890
|
+
.find(a => ['list', 'add', 'use', 'remove', 'eject'].includes(a)) ?? null;
|
|
891
|
+
// eject copies a theme package's source into the app; an editor theme's
|
|
892
|
+
// source is the app's already.
|
|
893
|
+
if (verb === 'eject')
|
|
894
|
+
return new AstryxError(
|
|
895
|
+
`${slug} is a theme the editor made: its source is yours already, themes/${slug}/${slug}.theme.ts (your edits there survive every change), and the editor changes the rest. eject copies a theme package's source into the app, so it has nothing to do for ${slug}.`,
|
|
896
|
+
[
|
|
897
|
+
{
|
|
898
|
+
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
899
|
+
reason: 'the theme as it is now',
|
|
900
|
+
},
|
|
901
|
+
],
|
|
902
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
903
|
+
);
|
|
904
|
+
const copyThere = !folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug));
|
|
905
|
+
// A path to the theme ("themes/d", "src/themes/d"): the commands take its
|
|
906
|
+
// name.
|
|
907
|
+
const typed = named ? (named[1] ?? named[2]) : '';
|
|
908
|
+
if (copyThere && verb && typed !== slug)
|
|
909
|
+
return new AstryxError(
|
|
910
|
+
`"${typed}" is ${/[\\/]|\.[a-z]+$/i.test(typed) ? 'a path' : "not the theme's name"}; the theme commands take the theme's name: ${slug}.`,
|
|
911
|
+
[
|
|
912
|
+
{
|
|
913
|
+
name: runLine(cwd, `theme ${verb} ${slug}`),
|
|
914
|
+
reason: 'the same, by name',
|
|
915
|
+
},
|
|
916
|
+
],
|
|
917
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
918
|
+
);
|
|
686
919
|
// A local theme of that name (a fork in the app's own themes folder) is
|
|
687
920
|
// one the stable commands take: their own message stands.
|
|
688
921
|
// A folder of only system files (or empty) holds no theme: as absent.
|
|
689
|
-
if (
|
|
922
|
+
if (copyThere) return null;
|
|
690
923
|
// No app copy yet (a theme made before the editor wrote one, or the
|
|
691
924
|
// copy removed): the next build writes it, then the same steps every
|
|
692
925
|
// place gives (`wiring` of new and show).
|
|
@@ -722,6 +955,112 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
722
955
|
);
|
|
723
956
|
}
|
|
724
957
|
|
|
958
|
+
/** The shared typo rule, for a typed subcommand. */
|
|
959
|
+
export {booleanWord, typoNear, typoOf} from './_normal.mjs';
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* The editor themes of the app the folder `cwd` is in, by name; none when
|
|
963
|
+
* the folder is in no app or its themes cannot be read.
|
|
964
|
+
* @param {string} cwd
|
|
965
|
+
* @returns {string[]}
|
|
966
|
+
*/
|
|
967
|
+
export function editorThemesAt(cwd) {
|
|
968
|
+
try {
|
|
969
|
+
return editedThemes(projectRoot(cwd));
|
|
970
|
+
} catch {
|
|
971
|
+
return [];
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* A refused compile whose first suggestion is another compile: that compile
|
|
977
|
+
* is run through compile's own checks before it is offered (in memory,
|
|
978
|
+
* nothing built), and each repair a refusal of it offers is folded into the
|
|
979
|
+
* one line. An --out outside the working folder is dropped, and the reason
|
|
980
|
+
* says why; when the rest cannot be repaired, the reason says so. A line
|
|
981
|
+
* that starts with `cd` runs elsewhere, so it is not checked from here.
|
|
982
|
+
* @param {AstryxError} err
|
|
983
|
+
* @param {string} cwd
|
|
984
|
+
* @returns {Promise<AstryxError>}
|
|
985
|
+
*/
|
|
986
|
+
export async function editorFollowCompile(err, cwd) {
|
|
987
|
+
const list = err.suggestions ?? [];
|
|
988
|
+
const first = list[0];
|
|
989
|
+
// The build's own refusals name `theme build`; the group's words replace
|
|
990
|
+
// those words when the refusal is shown.
|
|
991
|
+
const wordsIn = (/** @type {string} */ line) =>
|
|
992
|
+
[' experimental theme compile ', ' theme build '].find(w =>
|
|
993
|
+
line.includes(w),
|
|
994
|
+
);
|
|
995
|
+
const isCompile = (/** @type {string} */ line) =>
|
|
996
|
+
/^cd /.test(line) || Boolean(wordsIn(line));
|
|
997
|
+
if (!first || /^cd /.test(first.name) || !wordsIn(first.name)) return err;
|
|
998
|
+
/** @param {string} line */
|
|
999
|
+
const read = line => {
|
|
1000
|
+
const words = wordsIn(line);
|
|
1001
|
+
if (!words) return null;
|
|
1002
|
+
const args = splitCommand(line.slice(line.indexOf(words) + words.length));
|
|
1003
|
+
if (!args) return null;
|
|
1004
|
+
/** @type {{source?: string, out?: string, iconsSpecifier?: string, check?: boolean}} */
|
|
1005
|
+
const r = {};
|
|
1006
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
1007
|
+
const a = args[i];
|
|
1008
|
+
if (a === '--check') r.check = true;
|
|
1009
|
+
else if (a === '--out') r.out = args[(i += 1)];
|
|
1010
|
+
else if (a === '--icons-specifier') r.iconsSpecifier = args[(i += 1)];
|
|
1011
|
+
else if (a.startsWith('-') || r.source) return null;
|
|
1012
|
+
else r.source = a;
|
|
1013
|
+
}
|
|
1014
|
+
return r.source ? r : null;
|
|
1015
|
+
};
|
|
1016
|
+
const COMPILE = {group: 'experimental theme', build: 'compile'};
|
|
1017
|
+
/** @type {string | null} */
|
|
1018
|
+
let outDropped = null;
|
|
1019
|
+
const followed = await followLine(
|
|
1020
|
+
first.name,
|
|
1021
|
+
async line => {
|
|
1022
|
+
// A line that runs elsewhere is not checked from here.
|
|
1023
|
+
if (/^cd /.test(line)) return null;
|
|
1024
|
+
const r = read(line);
|
|
1025
|
+
if (!r?.source) return null;
|
|
1026
|
+
const refused =
|
|
1027
|
+
(await editorCompileProblem([r.source], {cwd, ...r})) ??
|
|
1028
|
+
buildInputProblem(r.source, r, cwd);
|
|
1029
|
+
if (refused) return refused;
|
|
1030
|
+
// A build writes only inside the working folder: the same build
|
|
1031
|
+
// without --out writes beside the source.
|
|
1032
|
+
if (r.out && refusedOutput(path.resolve(cwd, r.out), cwd)) {
|
|
1033
|
+
outDropped = r.out;
|
|
1034
|
+
return new AstryxError(`--out ${r.out} is outside the working folder`, [
|
|
1035
|
+
{
|
|
1036
|
+
name: buildSuggestion(
|
|
1037
|
+
r.source,
|
|
1038
|
+
{check: r.check, iconsSpecifier: r.iconsSpecifier},
|
|
1039
|
+
cwd,
|
|
1040
|
+
COMPILE,
|
|
1041
|
+
),
|
|
1042
|
+
reason: 'do this instead',
|
|
1043
|
+
},
|
|
1044
|
+
]);
|
|
1045
|
+
}
|
|
1046
|
+
return null;
|
|
1047
|
+
},
|
|
1048
|
+
isCompile,
|
|
1049
|
+
);
|
|
1050
|
+
if (followed.line === first.name) return err;
|
|
1051
|
+
const reason = [
|
|
1052
|
+
outDropped && !/ --out /.test(followed.line)
|
|
1053
|
+
? `do this instead, without --out: ${outDropped} is outside the working folder, where a build may not write, so the outputs go beside the source`
|
|
1054
|
+
: first.reason,
|
|
1055
|
+
...(followed.why ? [`it is still refused: ${followed.why}`] : []),
|
|
1056
|
+
].join('; ');
|
|
1057
|
+
err.suggestions = [
|
|
1058
|
+
{...first, name: followed.line, reason},
|
|
1059
|
+
...list.slice(1).filter(x => x.name !== followed.line),
|
|
1060
|
+
];
|
|
1061
|
+
return err;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
725
1064
|
/**
|
|
726
1065
|
* A refusal before `compile` runs on an editor theme's files, or null: the
|
|
727
1066
|
* editor's generated settings are not a theme source, `--family` does not
|
|
@@ -757,25 +1096,185 @@ export async function editorCompileProblem(
|
|
|
757
1096
|
from,
|
|
758
1097
|
COMPILE,
|
|
759
1098
|
);
|
|
1099
|
+
/**
|
|
1100
|
+
* The compile of `source` from the app root, after a cd there: --out
|
|
1101
|
+
* names the same file from the root while it stays inside it (a build
|
|
1102
|
+
* writes only inside its working folder); one outside is left off, and
|
|
1103
|
+
* `why` says so.
|
|
1104
|
+
* @param {string} source @param {string} root
|
|
1105
|
+
*/
|
|
1106
|
+
const fromRootLine = (source, root) => {
|
|
1107
|
+
const rebased = out
|
|
1108
|
+
? path.relative(root, path.resolve(cwd, slashed(out)))
|
|
1109
|
+
: '';
|
|
1110
|
+
const escapes =
|
|
1111
|
+
!check &&
|
|
1112
|
+
!!rebased &&
|
|
1113
|
+
(rebased.startsWith('..') || path.isAbsolute(rebased));
|
|
1114
|
+
return {
|
|
1115
|
+
name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${
|
|
1116
|
+
escapes
|
|
1117
|
+
? buildSuggestion(source, {check, iconsSpecifier}, root, COMPILE)
|
|
1118
|
+
: compileLine(source, root)
|
|
1119
|
+
}`,
|
|
1120
|
+
why: escapes
|
|
1121
|
+
? ` --out ${out} is outside the app root, where a build may not write, so the compile below writes beside the source.`
|
|
1122
|
+
: '',
|
|
1123
|
+
};
|
|
1124
|
+
};
|
|
1125
|
+
// An --out into an editor theme's app copy folder: the copy refresh would
|
|
1126
|
+
// write the theme's own build over it. One into the theme's own editor
|
|
1127
|
+
// folder that is not its default output would leave that folder half
|
|
1128
|
+
// built (the module rewritten, the stylesheet not) and the copy made from
|
|
1129
|
+
// it.
|
|
1130
|
+
if (out) {
|
|
1131
|
+
// Any --out in the copy folder, the folder itself too, written with
|
|
1132
|
+
// backslashes, through a link or (on a case-insensitive disk) in
|
|
1133
|
+
// another case, as the build reads it: real paths name the folder as
|
|
1134
|
+
// the disk does.
|
|
1135
|
+
const rel = path
|
|
1136
|
+
.relative(
|
|
1137
|
+
realLocation(cwdRoot),
|
|
1138
|
+
realLocation(path.resolve(cwd, slashed(out))),
|
|
1139
|
+
)
|
|
1140
|
+
.split(path.sep)
|
|
1141
|
+
.filter(Boolean);
|
|
1142
|
+
const inCopy =
|
|
1143
|
+
rel[0] === 'src' &&
|
|
1144
|
+
rel[1] === 'themes' &&
|
|
1145
|
+
rel.length >= 3 &&
|
|
1146
|
+
fs.existsSync(themeFiles(cwdRoot, rel[2]).settings);
|
|
1147
|
+
// Only for a compile of that theme: another source written there is
|
|
1148
|
+
// the build's own case (it warns).
|
|
1149
|
+
const inEditor =
|
|
1150
|
+
rel[0] === 'themes' &&
|
|
1151
|
+
rel.length >= 3 &&
|
|
1152
|
+
fs.existsSync(themeFiles(cwdRoot, rel[1]).settings) &&
|
|
1153
|
+
files.some(
|
|
1154
|
+
file =>
|
|
1155
|
+
editorThemeAt(cwdRoot, path.resolve(cwd, file))?.slug === rel[1],
|
|
1156
|
+
) &&
|
|
1157
|
+
!outIsDefault(cwdRoot, rel[1], cwd, out);
|
|
1158
|
+
if (inCopy || inEditor) {
|
|
1159
|
+
const t = inCopy ? rel[2] : rel[1];
|
|
1160
|
+
return new AstryxError(
|
|
1161
|
+
inCopy
|
|
1162
|
+
? `--out ${out} is in ${t}'s app copy (src/themes/${t}/), which the editor writes after every build of themes/${t}/; write the build somewhere else.`
|
|
1163
|
+
: `--out ${out} is in ${t}'s own folder (themes/${t}/), where the theme's build writes its module and stylesheet together; compile without --out to build there, or write the build outside themes/${t}/.`,
|
|
1164
|
+
[
|
|
1165
|
+
{
|
|
1166
|
+
// The same compile without --out: it builds into themes/<t>/,
|
|
1167
|
+
// and the copy follows.
|
|
1168
|
+
// From a subfolder, with the cd to the app root, where an
|
|
1169
|
+
// editor theme compiles.
|
|
1170
|
+
name:
|
|
1171
|
+
path.resolve(cwd) === path.resolve(cwdRoot)
|
|
1172
|
+
? buildSuggestion(
|
|
1173
|
+
files.length === 1 ? files[0] : `themes/${t}/${t}.theme.ts`,
|
|
1174
|
+
{check, iconsSpecifier},
|
|
1175
|
+
cwd,
|
|
1176
|
+
COMPILE,
|
|
1177
|
+
)
|
|
1178
|
+
: `cd ${quoteCommandArgument(path.relative(cwd, cwdRoot) || '.')} && ${buildSuggestion(
|
|
1179
|
+
files.length === 1
|
|
1180
|
+
? path.relative(cwdRoot, path.resolve(cwd, files[0])) ||
|
|
1181
|
+
files[0]
|
|
1182
|
+
: `themes/${t}/${t}.theme.ts`,
|
|
1183
|
+
{check, iconsSpecifier},
|
|
1184
|
+
cwdRoot,
|
|
1185
|
+
COMPILE,
|
|
1186
|
+
)}`,
|
|
1187
|
+
reason: 'do this instead',
|
|
1188
|
+
},
|
|
1189
|
+
],
|
|
1190
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
760
1194
|
for (const file of files) {
|
|
761
|
-
const
|
|
1195
|
+
const abs = path.resolve(cwd, file);
|
|
1196
|
+
const relParts = path
|
|
1197
|
+
.relative(
|
|
1198
|
+
realLocation(cwdRoot),
|
|
1199
|
+
realLocation(path.resolve(cwd, slashed(file))),
|
|
1200
|
+
)
|
|
1201
|
+
.split(path.sep);
|
|
1202
|
+
// The app's theme module `theme add` writes: not a theme source.
|
|
1203
|
+
if (relParts.join('/') === 'src/astryx-themes.ts')
|
|
1204
|
+
return new AstryxError(
|
|
1205
|
+
`${file} is the app's theme module (\`theme add\` writes it), not a theme source; compile the editor theme instead.`,
|
|
1206
|
+
editedThemes(cwdRoot)
|
|
1207
|
+
.slice(0, 3)
|
|
1208
|
+
.map(t => ({
|
|
1209
|
+
name: compileLine(`themes/${t}/${t}.theme.ts`, cwdRoot),
|
|
1210
|
+
reason: 'do this instead',
|
|
1211
|
+
})),
|
|
1212
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1213
|
+
);
|
|
1214
|
+
// A file of an editor theme's app copy (src/themes/<t>/): the copy
|
|
1215
|
+
// is written from themes/<t>/, so that is what compiles.
|
|
1216
|
+
if (
|
|
1217
|
+
relParts[0] === 'src' &&
|
|
1218
|
+
relParts[1] === 'themes' &&
|
|
1219
|
+
(relParts.length === 3 || relParts.length === 4) &&
|
|
1220
|
+
fs.existsSync(themeFiles(cwdRoot, relParts[2]).settings) &&
|
|
1221
|
+
// A file of yours there (no editor mark, no build header) compiles
|
|
1222
|
+
// like any theme source.
|
|
1223
|
+
(relParts.length === 3 ||
|
|
1224
|
+
isCopyFile(path.join(cwdRoot, ...relParts)) ||
|
|
1225
|
+
relParts[3] === `${camel(relParts[2])}Theme.ts`)
|
|
1226
|
+
) {
|
|
1227
|
+
const t = relParts[2];
|
|
1228
|
+
const own = `themes/${t}/${t}.theme.ts`;
|
|
1229
|
+
if (path.resolve(cwd) !== path.resolve(cwdRoot)) {
|
|
1230
|
+
const line = fromRootLine(own, cwdRoot);
|
|
1231
|
+
return new AstryxError(
|
|
1232
|
+
`${t} is a theme the editor made; compile it from the app root (${path.relative(cwd, cwdRoot) || '.'}), where the editor builds it.${line.why}`,
|
|
1233
|
+
[{name: line.name, reason: 'do this instead'}],
|
|
1234
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
// Its source too: a compile of the copy builds neither the theme
|
|
1238
|
+
// nor a current copy.
|
|
1239
|
+
return new AstryxError(
|
|
1240
|
+
`${file} is ${relParts.length === 3 ? '' : 'part of '}${t}'s app copy, which the editor writes from themes/${t}/ after every build; compile the theme itself.`,
|
|
1241
|
+
[
|
|
1242
|
+
{name: compileLine(own, cwd), reason: 'do this instead'},
|
|
1243
|
+
{
|
|
1244
|
+
name: runLine(cwdRoot, `experimental theme editor show ${t}`),
|
|
1245
|
+
reason: 'writes the app copy again from the theme',
|
|
1246
|
+
},
|
|
1247
|
+
],
|
|
1248
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
const at = editorThemeAt(cwdRoot, abs, {made: true});
|
|
762
1252
|
if (!at || !editorOwnFile(at.slug, file)) continue;
|
|
763
1253
|
const {root, slug} = at;
|
|
1254
|
+
// An editor theme that lost its settings is refused as every editor
|
|
1255
|
+
// command refuses it, with the line that makes it again: a plain build
|
|
1256
|
+
// of it would drop the editor's settings and app copy.
|
|
1257
|
+
if (
|
|
1258
|
+
!fs.existsSync(path.join(root, 'themes', slug, `${slug}.settings.json`))
|
|
1259
|
+
)
|
|
1260
|
+
try {
|
|
1261
|
+
loadTheme(root, slug);
|
|
1262
|
+
} catch (e) {
|
|
1263
|
+
if (e instanceof AstryxError) return e;
|
|
1264
|
+
throw e;
|
|
1265
|
+
}
|
|
764
1266
|
const source = `themes/${slug}/${slug}.theme.ts`;
|
|
765
1267
|
// An editor theme is built from its project's root, as every editor
|
|
766
1268
|
// command runs there: from a subfolder the build would write outside
|
|
767
1269
|
// its working folder. The run names the root.
|
|
768
|
-
if (path.resolve(cwd) !== path.resolve(root))
|
|
1270
|
+
if (path.resolve(cwd) !== path.resolve(root)) {
|
|
1271
|
+
const line = fromRootLine(source, root);
|
|
769
1272
|
return new AstryxError(
|
|
770
|
-
`${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it
|
|
771
|
-
[
|
|
772
|
-
{
|
|
773
|
-
name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${compileLine(source, root)}`,
|
|
774
|
-
reason: 'do this instead',
|
|
775
|
-
},
|
|
776
|
-
],
|
|
1273
|
+
`${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.${line.why}`,
|
|
1274
|
+
[{name: line.name, reason: 'do this instead'}],
|
|
777
1275
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
778
1276
|
);
|
|
1277
|
+
}
|
|
779
1278
|
if (/\.settings\.(ts|json)$/.test(file))
|
|
780
1279
|
return new AstryxError(
|
|
781
1280
|
`${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
|
|
@@ -790,6 +1289,13 @@ export async function editorCompileProblem(
|
|
|
790
1289
|
],
|
|
791
1290
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
792
1291
|
);
|
|
1292
|
+
// A source that no longer carries the settings (another theme's name,
|
|
1293
|
+
// or no extends of them) is refused as set refuses it: a build would
|
|
1294
|
+
// write another theme's files, or drop every setting.
|
|
1295
|
+
{
|
|
1296
|
+
const refusal = await themeSourceRefusal(root, slug);
|
|
1297
|
+
if (refusal) return refusal;
|
|
1298
|
+
}
|
|
793
1299
|
if (family)
|
|
794
1300
|
return new AstryxError(
|
|
795
1301
|
`${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
|
|
@@ -820,8 +1326,9 @@ export async function editorCompileProblem(
|
|
|
820
1326
|
);
|
|
821
1327
|
} catch (e) {
|
|
822
1328
|
// A settings file damaged by hand is refused like any refusal,
|
|
823
|
-
// never as a raw error.
|
|
824
|
-
if (e instanceof AstryxError)
|
|
1329
|
+
// never as a raw error, with the lines every command gives it.
|
|
1330
|
+
if (e instanceof AstryxError)
|
|
1331
|
+
return edit.editorSavedRefusal(e, root, slug);
|
|
825
1332
|
throw e;
|
|
826
1333
|
}
|
|
827
1334
|
// An own change to the theme source is what compile builds (and what
|
|
@@ -833,12 +1340,10 @@ export async function editorCompileProblem(
|
|
|
833
1340
|
)
|
|
834
1341
|
)
|
|
835
1342
|
why = null;
|
|
836
|
-
// A missing built output is one compile writes itself
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
/^[^/]+\.(css|js|d\.ts|css\.d\.ts) was missing$/.test(why)
|
|
841
|
-
)
|
|
1343
|
+
// A missing built output is one compile writes itself, and one a
|
|
1344
|
+
// check names in its own result (the stale outputs, upToDate false):
|
|
1345
|
+
// never a reason to refuse either.
|
|
1346
|
+
if (why && /^[^/]+\.(css|js|d\.ts|css\.d\.ts) was missing$/.test(why))
|
|
842
1347
|
why = null;
|
|
843
1348
|
// Saved settings the editor no longer accepts: show refuses them too,
|
|
844
1349
|
// so the refusal names the undo that removes each.
|
|
@@ -868,12 +1373,11 @@ export async function editorCompileProblem(
|
|
|
868
1373
|
],
|
|
869
1374
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
870
1375
|
);
|
|
871
|
-
//
|
|
872
|
-
//
|
|
873
|
-
// beside it), as the editor's own build reads it.
|
|
1376
|
+
// The file's own token values, judged as a build of it writes them
|
|
1377
|
+
// (never written beside it), by the check the editor's build runs.
|
|
874
1378
|
if (path.basename(file) === `${slug}.theme.ts`) {
|
|
875
|
-
const
|
|
876
|
-
if (
|
|
1379
|
+
const values = await edit.editorOwnTokenRefusal(root, slug);
|
|
1380
|
+
if (values) return values;
|
|
877
1381
|
}
|
|
878
1382
|
}
|
|
879
1383
|
}
|
|
@@ -883,18 +1387,48 @@ export async function editorCompileProblem(
|
|
|
883
1387
|
/** The editor themes a running `compile` holds the lock of, by project and name. */
|
|
884
1388
|
const COMPILE_HELD = new Set();
|
|
885
1389
|
|
|
886
|
-
/** @type {(() => Promise<void>) | null} The release of the running compile's hold. */
|
|
1390
|
+
/** @type {((refused?: boolean) => Promise<void>) | null} The release of the running compile's hold; `refused`: it wrote nothing, so no app copy either. */
|
|
887
1391
|
let releaseCompileHold = null;
|
|
888
1392
|
|
|
1393
|
+
/** @type {Array<{root: string, slug: string, copy: (refused: boolean) => boolean, report: () => Record<string, unknown> | null}>} The running compile's held themes. */
|
|
1394
|
+
let compileHoldItems = [];
|
|
1395
|
+
|
|
1396
|
+
/**
|
|
1397
|
+
* For `compile`, once its outputs are written: write each held editor
|
|
1398
|
+
* theme's app copy now, and say per file what the write did (`appCopy` on
|
|
1399
|
+
* a first write, `appCopyStale` when something keeps the copy behind), so
|
|
1400
|
+
* the JSON result carries what the text says.
|
|
1401
|
+
* @param {string[]} files
|
|
1402
|
+
* @param {string} cwd
|
|
1403
|
+
* @returns {Promise<Record<string, Record<string, unknown>>>}
|
|
1404
|
+
*/
|
|
1405
|
+
export async function editorAfterBuild(files, cwd) {
|
|
1406
|
+
const root = projectRoot(cwd);
|
|
1407
|
+
/** @type {Record<string, Record<string, unknown>>} */
|
|
1408
|
+
const out = {};
|
|
1409
|
+
for (const item of compileHoldItems) {
|
|
1410
|
+
item.copy(false);
|
|
1411
|
+
const report = item.report();
|
|
1412
|
+
if (!report) continue;
|
|
1413
|
+
for (const file of files) {
|
|
1414
|
+
const abs = path.resolve(cwd, file);
|
|
1415
|
+
const own = editorThemeAt(root, abs);
|
|
1416
|
+
if (own?.slug === item.slug && editorOwnFile(own.slug, file))
|
|
1417
|
+
out[file] = report;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
return out;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
889
1423
|
/**
|
|
890
1424
|
* Hold the theme lock of every editor theme among the files while
|
|
891
1425
|
* `compile` builds or checks them, so it never reads a change half
|
|
892
1426
|
* written. Resolves to the release.
|
|
893
1427
|
* @param {string[]} files
|
|
894
|
-
* @param {{cwd: string}} options
|
|
1428
|
+
* @param {{cwd: string, check?: boolean, out?: string}} options
|
|
895
1429
|
* @returns {Promise<() => Promise<void>>}
|
|
896
1430
|
*/
|
|
897
|
-
export async function editorThemeHold(files, {cwd}) {
|
|
1431
|
+
export async function editorThemeHold(files, {cwd, check = false, out}) {
|
|
898
1432
|
// Two compiles of one theme in one process: the second waits for the
|
|
899
1433
|
// lock like any other command.
|
|
900
1434
|
const cwdRoot = projectRoot(cwd);
|
|
@@ -903,13 +1437,24 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
903
1437
|
const at = editorThemeAt(cwdRoot, path.resolve(cwd, f));
|
|
904
1438
|
if (at && editorOwnFile(at.slug, f))
|
|
905
1439
|
found.set(`${at.root}\0${at.slug}`, at);
|
|
1440
|
+
// The app copy's source (src/themes/<t>/<t>Theme.ts) of an editor
|
|
1441
|
+
// theme: built under the theme's lock, so it never lands between a
|
|
1442
|
+
// change's two writes.
|
|
1443
|
+
const copy = appCopyTheme(cwdRoot, path.resolve(cwd, f));
|
|
1444
|
+
if (copy) found.set(`${copy.root}\0${copy.slug}`, copy);
|
|
906
1445
|
}
|
|
907
1446
|
const themes = [...found.keys()].sort().map(k => found.get(k));
|
|
908
|
-
/** @type {Array<() => Promise<void
|
|
1447
|
+
/** @type {Array<{root: string, slug: string, copy: (refused: boolean) => boolean, report: () => Record<string, unknown> | null, finish: (later: boolean) => Promise<void>}>} */
|
|
909
1448
|
const releases = [];
|
|
910
|
-
|
|
1449
|
+
compileHoldItems = releases;
|
|
1450
|
+
// Every theme's copy is written first, at once (a refusal ends the run
|
|
1451
|
+
// without waiting), then each lock goes.
|
|
1452
|
+
const releaseAll = async (refused = false) => {
|
|
911
1453
|
if (releaseCompileHold === releaseAll) releaseCompileHold = null;
|
|
912
|
-
|
|
1454
|
+
const items = releases.splice(0);
|
|
1455
|
+
const later = items.map(x => x.copy(refused));
|
|
1456
|
+
for (const [i, x] of [...items.entries()].reverse())
|
|
1457
|
+
await x.finish(later[i]);
|
|
913
1458
|
};
|
|
914
1459
|
releaseCompileHold = releaseAll;
|
|
915
1460
|
for (const {
|
|
@@ -927,6 +1472,25 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
927
1472
|
ready = r;
|
|
928
1473
|
});
|
|
929
1474
|
const key = `${root}\0${slug}`;
|
|
1475
|
+
// When the lock was taken, and the context a copy write needs (its
|
|
1476
|
+
// font stylesheets), ready before the build so the copy is written at
|
|
1477
|
+
// once when the run ends.
|
|
1478
|
+
const heldAt = Date.now() - 1;
|
|
1479
|
+
// An --out elsewhere builds neither themes/<theme>/ nor its copy.
|
|
1480
|
+
const skipped = outSkipsCopy(root, slug, cwd, {check, out});
|
|
1481
|
+
let ran = false;
|
|
1482
|
+
let copied = false;
|
|
1483
|
+
/** @type {string[] | null} */
|
|
1484
|
+
let firstWrite = null;
|
|
1485
|
+
/** @type {string | null} */
|
|
1486
|
+
let keptBack = null;
|
|
1487
|
+
/** @type {any} */
|
|
1488
|
+
let copyCtx = null;
|
|
1489
|
+
try {
|
|
1490
|
+
copyCtx = await context(root);
|
|
1491
|
+
} catch {
|
|
1492
|
+
copyCtx = null;
|
|
1493
|
+
}
|
|
930
1494
|
const done = withLock(root, lockName(slug), async () => {
|
|
931
1495
|
COMPILE_HELD.add(key);
|
|
932
1496
|
ready();
|
|
@@ -941,30 +1505,400 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
941
1505
|
await releaseAll();
|
|
942
1506
|
throw err;
|
|
943
1507
|
}
|
|
944
|
-
releases.push(
|
|
1508
|
+
releases.push({
|
|
945
1509
|
// A compile that wrote the build refreshes the app's copy too
|
|
946
|
-
// (src/themes/<theme>/), under the same lock; a check writes
|
|
947
|
-
|
|
1510
|
+
// (src/themes/<theme>/), under the same lock; a check writes
|
|
1511
|
+
// nothing. Each theme's copy follows its own build: a theme this run
|
|
1512
|
+
// built (its build now matches its settings) gets its copy, whatever
|
|
1513
|
+
// a later theme did; one that was refused or failed keeps its copy.
|
|
1514
|
+
// True when the copy still needs its font stylesheet from the
|
|
1515
|
+
// theme's settings (written in finish).
|
|
1516
|
+
root,
|
|
1517
|
+
slug,
|
|
1518
|
+
copy: (/** @type {boolean} */ refused) => {
|
|
1519
|
+
// Once per run: after the build's writes when the command asks
|
|
1520
|
+
// (its result then says what the copy write did), else at release.
|
|
1521
|
+
if (copied) return false;
|
|
1522
|
+
copied = true;
|
|
1523
|
+
ran = !refused && (process.exitCode ?? 0) === 0;
|
|
1524
|
+
if (check || skipped) return false;
|
|
1525
|
+
// This run built the theme: its module and stylesheet, one unit,
|
|
1526
|
+
// were written since the lock was taken, or the run ended well. A
|
|
1527
|
+
// refused or failed compile writes no copy.
|
|
1528
|
+
const f = themeFiles(root, slug);
|
|
1529
|
+
const written = [f.css, f.js].every(x => {
|
|
1530
|
+
try {
|
|
1531
|
+
return fs.statSync(x).mtimeMs >= heldAt;
|
|
1532
|
+
} catch {
|
|
1533
|
+
return false;
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
if (!written && (refused || (process.exitCode ?? 0) !== 0))
|
|
1537
|
+
return false;
|
|
948
1538
|
try {
|
|
949
|
-
|
|
950
|
-
//
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1539
|
+
// From what was just built, its font stylesheets from the fonts
|
|
1540
|
+
// the theme loads now.
|
|
1541
|
+
if (copyCtx) writeAppCopy(copyCtx, slug, loadTheme(root, slug));
|
|
1542
|
+
else writeAppCopyAt(root, slug, null);
|
|
1543
|
+
} catch {
|
|
1544
|
+
try {
|
|
1545
|
+
writeAppCopyAt(root, slug, null);
|
|
1546
|
+
} catch {
|
|
1547
|
+
// A theme that does not load keeps its copy as it was.
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
// What the write did, for the result and the text alike: the
|
|
1551
|
+
// files of a first write, or what keeps the copy behind.
|
|
1552
|
+
firstWrite = takeFirstAppCopy(root, slug);
|
|
1553
|
+
keptBack = appCopyStale(root, slug).appCopyStale ?? null;
|
|
1554
|
+
return false;
|
|
1555
|
+
},
|
|
1556
|
+
report: () =>
|
|
1557
|
+
firstWrite || keptBack
|
|
1558
|
+
? {
|
|
1559
|
+
...(firstWrite ? {appCopy: {wrote: firstWrite}} : {}),
|
|
1560
|
+
...(keptBack ? {appCopyStale: keptBack} : {}),
|
|
1561
|
+
}
|
|
1562
|
+
: null,
|
|
1563
|
+
finish: async () => {
|
|
1564
|
+
// Said only after a build or check that ran: a refused one wrote
|
|
1565
|
+
// and checked nothing.
|
|
1566
|
+
if (skipped) {
|
|
1567
|
+
if (ran) humanWarn(skipped);
|
|
1568
|
+
} else if (!check) {
|
|
1569
|
+
// The first write of the app copy is named once.
|
|
1570
|
+
if (firstWrite)
|
|
954
1571
|
humanWarn(
|
|
955
|
-
`wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${
|
|
1572
|
+
`wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${firstWrite.join(', ')}`,
|
|
956
1573
|
);
|
|
957
|
-
|
|
958
|
-
//
|
|
1574
|
+
// A copy a file or a link keeps behind, or one that could not be
|
|
1575
|
+
// written, is said, as set and show say it.
|
|
1576
|
+
if (keptBack) humanWarn(keptBack);
|
|
959
1577
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1578
|
+
release();
|
|
1579
|
+
await done;
|
|
1580
|
+
},
|
|
963
1581
|
});
|
|
964
1582
|
}
|
|
965
1583
|
return releaseAll;
|
|
966
1584
|
}
|
|
967
1585
|
|
|
1586
|
+
/**
|
|
1587
|
+
* For `compile` of an editor theme's own source: how the app takes the
|
|
1588
|
+
* theme, in place of importing the build's own outputs. The app takes its
|
|
1589
|
+
* app copy (src/themes/<t>/, written after every build, with the font
|
|
1590
|
+
* stylesheet that loads the theme's fonts), which `theme add` wires in.
|
|
1591
|
+
* Null for any other file.
|
|
1592
|
+
* @param {string} file the path as given
|
|
1593
|
+
* @param {string} cwd
|
|
1594
|
+
* @returns {string | null}
|
|
1595
|
+
*/
|
|
1596
|
+
export function editorInstall(file, cwd) {
|
|
1597
|
+
const root = projectRoot(cwd);
|
|
1598
|
+
const at = editorThemeAt(root, path.resolve(cwd, file));
|
|
1599
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
1600
|
+
return `Install in your app: the editor writes ${at.slug}'s app copy in src/themes/${at.slug}/ after every build (its module, stylesheet and font stylesheet), and the app takes that copy, not themes/${at.slug}/. Wire it in once:
|
|
1601
|
+
|
|
1602
|
+
${runLine(root, `theme add ${at.slug}`)}`;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
/**
|
|
1606
|
+
* For `compile` of an editor theme's own source: how to load a family the
|
|
1607
|
+
* build names, as the editor says it (the app copy imports a family's
|
|
1608
|
+
* installed Fontsource package); null for any other file.
|
|
1609
|
+
* @param {string} file the path as given
|
|
1610
|
+
* @param {string} cwd
|
|
1611
|
+
* @returns {import('../theme/build/build.mjs').FontHelp | null}
|
|
1612
|
+
*/
|
|
1613
|
+
export function editorFontHelp(file, cwd) {
|
|
1614
|
+
const root = projectRoot(cwd);
|
|
1615
|
+
const at = editorThemeAt(root, path.resolve(cwd, file));
|
|
1616
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
1617
|
+
const copy = `src/themes/${at.slug}/${at.slug}.fonts.css`;
|
|
1618
|
+
/** @param {string} family */
|
|
1619
|
+
const notice = family => {
|
|
1620
|
+
const s = fontsourceSuggestion(family);
|
|
1621
|
+
return s
|
|
1622
|
+
? `Font "${family}" is named by this theme but not loaded; ${s.known ? '' : 'if Fontsource publishes it, '}${installLine(root, [s.pkg])} installs its package, which ${copy} then imports`
|
|
1623
|
+
: `Font "${family}" is named by this theme but not loaded, and no font package is named for it: the app must load it, or it falls back`;
|
|
1624
|
+
};
|
|
1625
|
+
return {
|
|
1626
|
+
notice,
|
|
1627
|
+
recipe: families => {
|
|
1628
|
+
const all = families.map(fontsourceSuggestion).filter(s => s !== null);
|
|
1629
|
+
// Packages the editor knows Fontsource publishes go on one install
|
|
1630
|
+
// line; a name it cannot vouch for gets its own, so one that does
|
|
1631
|
+
// not exist never stops the others installing.
|
|
1632
|
+
const known = all.filter(s => s.known).map(s => s.pkg);
|
|
1633
|
+
const guessed = all.filter(s => !s.known).map(s => s.pkg);
|
|
1634
|
+
const lines = [
|
|
1635
|
+
...(known.length ? [installLine(root, known)] : []),
|
|
1636
|
+
...guessed.map(
|
|
1637
|
+
pkg => `${installLine(root, [pkg])} (if Fontsource publishes it)`,
|
|
1638
|
+
),
|
|
1639
|
+
];
|
|
1640
|
+
return ` The built CSS only sets font-family. ${at.slug}'s app copy loads a family
|
|
1641
|
+
once its package is installed, importing it in ${copy} on the next
|
|
1642
|
+
compile, set or show:
|
|
1643
|
+
${lines.length ? `\n${lines.map(l => ` ${l}`).join('\n')}\n` : '\n (no Fontsource package is named for these families: load them in your app)\n'}
|
|
1644
|
+
Recipe and fallback-stack guidance: ${runLine(root, 'docs typography')}
|
|
1645
|
+
`;
|
|
1646
|
+
},
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
/**
|
|
1651
|
+
* For `compile`: the path an editor theme's own file builds under when it
|
|
1652
|
+
* was named through a link (its real path, which every output's header
|
|
1653
|
+
* names and `--check` compares); null for any other file.
|
|
1654
|
+
* @param {string} file the path as given
|
|
1655
|
+
* @param {string} cwd
|
|
1656
|
+
* @returns {string | null}
|
|
1657
|
+
*/
|
|
1658
|
+
export function editorSourcePath(file, cwd) {
|
|
1659
|
+
const abs = path.resolve(cwd, slashed(file));
|
|
1660
|
+
const realCwd = realLocation(cwd);
|
|
1661
|
+
const real = realLocation(abs);
|
|
1662
|
+
if (real === path.join(realCwd, path.relative(cwd, abs))) return null;
|
|
1663
|
+
const at = editorThemeAt(projectRoot(cwd), real);
|
|
1664
|
+
if (!at || !editorOwnFile(at.slug, real)) return null;
|
|
1665
|
+
return path.relative(realCwd, real) || null;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/** @param {string} p a path as typed, with Windows separators read as `/` */
|
|
1669
|
+
const slashed = p => String(p).replace(/\\/g, '/');
|
|
1670
|
+
|
|
1671
|
+
/**
|
|
1672
|
+
* Whether --out names an editor theme's default output, where the build
|
|
1673
|
+
* writes without --out: its folder, or its stylesheet file there (the same
|
|
1674
|
+
* file, as the file system tells files apart: a name that differs only in
|
|
1675
|
+
* case is another file on a case-sensitive disk). A folder form (a
|
|
1676
|
+
* trailing slash) names a folder, so it is the default only as the theme's
|
|
1677
|
+
* folder. No --out counts.
|
|
1678
|
+
* @param {string} root the app root
|
|
1679
|
+
* @param {string} slug
|
|
1680
|
+
* @param {string} cwd
|
|
1681
|
+
* @param {string | undefined} out
|
|
1682
|
+
*/
|
|
1683
|
+
function outIsDefault(root, slug, cwd, out) {
|
|
1684
|
+
if (!out) return true;
|
|
1685
|
+
const typed = slashed(out);
|
|
1686
|
+
const at = path.resolve(cwd, typed);
|
|
1687
|
+
const f = themeFiles(root, slug);
|
|
1688
|
+
if (sameFile(at, f.dir)) return true;
|
|
1689
|
+
return !typed.endsWith('/') && sameFile(at, f.css);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
/**
|
|
1693
|
+
* Whether two paths name one file: the same file on disk when both are
|
|
1694
|
+
* there, else the same real path.
|
|
1695
|
+
* @param {string} a
|
|
1696
|
+
* @param {string} b
|
|
1697
|
+
*/
|
|
1698
|
+
function sameFile(a, b) {
|
|
1699
|
+
try {
|
|
1700
|
+
const x = fs.statSync(a);
|
|
1701
|
+
const y = fs.statSync(b);
|
|
1702
|
+
return x.dev === y.dev && x.ino === y.ino;
|
|
1703
|
+
} catch {
|
|
1704
|
+
return realLocation(a) === realLocation(b);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* Why an editor theme's app copy was not written, or checked, by a build
|
|
1710
|
+
* with --out elsewhere; null without one.
|
|
1711
|
+
* @param {string} root
|
|
1712
|
+
* @param {string} slug
|
|
1713
|
+
* @param {string} cwd
|
|
1714
|
+
* @param {{check?: boolean, out?: string}} opts
|
|
1715
|
+
*/
|
|
1716
|
+
function outSkipsCopy(root, slug, cwd, {check, out}) {
|
|
1717
|
+
if (outIsDefault(root, slug, cwd, out)) return null;
|
|
1718
|
+
return check
|
|
1719
|
+
? `--check with --out checks only the files --out names: themes/${slug}/ and ${slug}'s app copy in src/themes/${slug}/ are not checked. Check without --out to check them.`
|
|
1720
|
+
: `--out builds only the files it names: themes/${slug}/ and ${slug}'s app copy in src/themes/${slug}/ were not written. Compile without --out to write them.`;
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* Whether a file in an app copy folder is the editor's: its mark, or the
|
|
1725
|
+
* header the build writes. A missing file counts (it would be the copy's).
|
|
1726
|
+
* @param {string} file
|
|
1727
|
+
*/
|
|
1728
|
+
function isCopyFile(file) {
|
|
1729
|
+
// A pipe or a device there is never opened: it stands where the copy's
|
|
1730
|
+
// file goes.
|
|
1731
|
+
if (irregularFileKind(file)) return true;
|
|
1732
|
+
try {
|
|
1733
|
+
const head = fs.readFileSync(file, 'utf8').slice(0, 600);
|
|
1734
|
+
return (
|
|
1735
|
+
head.includes(APP_COPY_MARK) ||
|
|
1736
|
+
/@generated by `astryx theme build`/.test(head)
|
|
1737
|
+
);
|
|
1738
|
+
} catch {
|
|
1739
|
+
return true;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
/**
|
|
1744
|
+
* The editor theme whose app copy source a file is
|
|
1745
|
+
* (`src/themes/<t>/<t>Theme.ts`, with themes/<t>/ an editor theme), or
|
|
1746
|
+
* null.
|
|
1747
|
+
* @param {string} root the project root
|
|
1748
|
+
* @param {string} file absolute
|
|
1749
|
+
* @returns {{root: string, slug: string} | null}
|
|
1750
|
+
*/
|
|
1751
|
+
function appCopyTheme(root, file) {
|
|
1752
|
+
const rel = path.relative(root, file).split(path.sep);
|
|
1753
|
+
if (rel.length !== 4 || rel[0] !== 'src' || rel[1] !== 'themes') return null;
|
|
1754
|
+
const slug = rel[2];
|
|
1755
|
+
if (rel[3] !== `${camel(slug)}Theme.ts`) return null;
|
|
1756
|
+
return fs.existsSync(themeFiles(root, slug).settings) ? {root, slug} : null;
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
/**
|
|
1760
|
+
* For `compile` of an editor theme: `appCopyStale` for its result data when
|
|
1761
|
+
* the app copy is behind (the same line set and show give), or
|
|
1762
|
+
* `appCopySkipped` when --out builds elsewhere (neither themes/<theme>/ nor
|
|
1763
|
+
* the copy is written or checked); null for any other file or a current
|
|
1764
|
+
* copy.
|
|
1765
|
+
* @param {string} file the path as given
|
|
1766
|
+
* @param {string} cwd
|
|
1767
|
+
* @param {{check: boolean, upToDate?: boolean, out?: string, iconsSpecifier?: string}} opts
|
|
1768
|
+
* `upToDate`: the check's own verdict on the theme's outputs
|
|
1769
|
+
* @returns {Promise<Record<string, unknown> | null>}
|
|
1770
|
+
*/
|
|
1771
|
+
export async function editorBuildExtra(file, cwd, opts) {
|
|
1772
|
+
const root = projectRoot(cwd);
|
|
1773
|
+
const abs = path.resolve(cwd, file);
|
|
1774
|
+
const own = editorThemeAt(root, abs);
|
|
1775
|
+
const slug =
|
|
1776
|
+
appCopyTheme(root, abs)?.slug ??
|
|
1777
|
+
(own && editorOwnFile(own.slug, file) ? own.slug : null);
|
|
1778
|
+
if (!slug) return null;
|
|
1779
|
+
{
|
|
1780
|
+
const skipped = outSkipsCopy(root, slug, cwd, opts);
|
|
1781
|
+
if (skipped) return {appCopySkipped: skipped};
|
|
1782
|
+
}
|
|
1783
|
+
if (!opts.check) {
|
|
1784
|
+
// Every set and show builds the theme again from its source, without
|
|
1785
|
+
// --icons-specifier: said, with the change that keeps it.
|
|
1786
|
+
const warnings = opts.iconsSpecifier
|
|
1787
|
+
? [
|
|
1788
|
+
`${slug} is a theme the editor made: every set and show builds it again from themes/${slug}/${slug}.theme.ts without --icons-specifier, which puts the theme's own import of the registry back. To keep this one, import the registry from its package in ${slug}.theme.ts.`,
|
|
1789
|
+
]
|
|
1790
|
+
: [];
|
|
1791
|
+
// What show says of the source's own type on phones, said by the
|
|
1792
|
+
// compile that builds the app copy from it too.
|
|
1793
|
+
/** @type {string[]} */
|
|
1794
|
+
let notices;
|
|
1795
|
+
try {
|
|
1796
|
+
const data = loadTheme(root, slug);
|
|
1797
|
+
notices = [
|
|
1798
|
+
...edit.ownPhoneNotes(root, slug, data),
|
|
1799
|
+
// A weight the base theme's font stylesheet does not load.
|
|
1800
|
+
...baseWeightNotes(await context(root), data),
|
|
1801
|
+
];
|
|
1802
|
+
} catch {
|
|
1803
|
+
notices = [];
|
|
1804
|
+
}
|
|
1805
|
+
if (warnings.length || notices.length)
|
|
1806
|
+
return {
|
|
1807
|
+
...(warnings.length ? {warnings} : {}),
|
|
1808
|
+
...(notices.length ? {notices} : {}),
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
if (opts.check) {
|
|
1812
|
+
// A theme output that is stale is the check's own finding (it names
|
|
1813
|
+
// the file); the copy is compared only with a current build.
|
|
1814
|
+
if (opts.upToDate === false) return null;
|
|
1815
|
+
/** @type {string[] | null} */
|
|
1816
|
+
let fonts;
|
|
1817
|
+
try {
|
|
1818
|
+
fonts = copyFontsCss(await context(root), slug, loadTheme(root, slug));
|
|
1819
|
+
} catch {
|
|
1820
|
+
fonts = null;
|
|
1821
|
+
}
|
|
1822
|
+
const behind = appCopyBehind(root, slug, fonts);
|
|
1823
|
+
return behind
|
|
1824
|
+
? {
|
|
1825
|
+
upToDate: false,
|
|
1826
|
+
code: 'ERR_THEME_STALE',
|
|
1827
|
+
// Something of yours in the way: its own line says what to move;
|
|
1828
|
+
// no editor command writes over it.
|
|
1829
|
+
appCopyStale: appCopyStale(root, slug).appCopyStale
|
|
1830
|
+
? `${slug}'s app copy in src/themes/${slug}/ is not up to date: ${behind}`
|
|
1831
|
+
: `${slug}'s app copy in src/themes/${slug}/ is not up to date: ${behind}. ${runLine(root, `experimental theme editor show ${slug}`)} writes it again`,
|
|
1832
|
+
}
|
|
1833
|
+
: null;
|
|
1834
|
+
}
|
|
1835
|
+
// A build's copy write is reported once it has run (editorAfterBuild).
|
|
1836
|
+
return null;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
/**
|
|
1840
|
+
* For `compile` of an editor theme's own source (themes/<t>/<t>.theme.ts):
|
|
1841
|
+
* the one color mode a light-only or dark-only theme has, which its source
|
|
1842
|
+
* cannot say, for the build to write into the built module. Null for any
|
|
1843
|
+
* other file (the app copy's source re-exports it from its build).
|
|
1844
|
+
* @param {string} file the path as given
|
|
1845
|
+
* @param {string} cwd
|
|
1846
|
+
* @returns {['light'] | ['dark'] | null}
|
|
1847
|
+
*/
|
|
1848
|
+
export function editorColorModes(file, cwd) {
|
|
1849
|
+
const root = projectRoot(cwd);
|
|
1850
|
+
const at = editorThemeAt(root, path.resolve(cwd, file));
|
|
1851
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
1852
|
+
return buildColorModes(at.root, at.slug);
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
/**
|
|
1856
|
+
* For `compile` of an editor theme (themes/<t>/ or its app copy's source):
|
|
1857
|
+
* whether a font family is loaded by the app copy's font stylesheet as
|
|
1858
|
+
* this compile writes it (src/themes/<t>/<t>.fonts.css, from the fonts the
|
|
1859
|
+
* theme loads now: an @fontsource package by its name, a stylesheet by the
|
|
1860
|
+
* `family=` it requests), so the build's "named but not loaded" notice
|
|
1861
|
+
* leaves it out. Null for any other file.
|
|
1862
|
+
* @param {string} file the path as given
|
|
1863
|
+
* @param {string} cwd
|
|
1864
|
+
* @returns {Promise<((family: string) => boolean) | null>}
|
|
1865
|
+
*/
|
|
1866
|
+
export async function editorLoadedFonts(file, cwd) {
|
|
1867
|
+
const root = projectRoot(cwd);
|
|
1868
|
+
const abs = path.resolve(cwd, file);
|
|
1869
|
+
const slug =
|
|
1870
|
+
appCopyTheme(root, abs)?.slug ??
|
|
1871
|
+
(editorThemeAt(root, abs) &&
|
|
1872
|
+
editorOwnFile(editorThemeAt(root, abs)?.slug ?? '', file)
|
|
1873
|
+
? editorThemeAt(root, abs)?.slug
|
|
1874
|
+
: null);
|
|
1875
|
+
if (!slug) return null;
|
|
1876
|
+
// The stylesheets the copy's font file imports once this compile has
|
|
1877
|
+
// written it: from the fonts the theme loads now, as the copy write
|
|
1878
|
+
// computes them.
|
|
1879
|
+
/** @type {string[]} */
|
|
1880
|
+
let specs;
|
|
1881
|
+
try {
|
|
1882
|
+
specs = copyFontsCss(await context(root), slug, loadTheme(root, slug));
|
|
1883
|
+
} catch {
|
|
1884
|
+
return null;
|
|
1885
|
+
}
|
|
1886
|
+
const copyDir = path.join(root, 'src', 'themes', slug);
|
|
1887
|
+
const from = fs.existsSync(copyDir) ? copyDir : root;
|
|
1888
|
+
/** @type {Set<string>} */
|
|
1889
|
+
const loaded = new Set();
|
|
1890
|
+
for (const spec of specs)
|
|
1891
|
+
for (const f of importedFontFamilies(spec, from)) loaded.add(f);
|
|
1892
|
+
// A family the build names whose @fontsource package is installed: the
|
|
1893
|
+
// copy written after this build imports that package (copyFontsCss).
|
|
1894
|
+
/** @param {string} family */
|
|
1895
|
+
const installed = family => {
|
|
1896
|
+
const pkg = fontsourcePackageOf(family);
|
|
1897
|
+
return pkg !== null && packageInstalled(root, pkg);
|
|
1898
|
+
};
|
|
1899
|
+
return family => loaded.has(fontKey(family)) || installed(family);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
968
1902
|
/**
|
|
969
1903
|
* For `compile` of a file that is not there: when it is an editor theme's
|
|
970
1904
|
* own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
|
|
@@ -974,6 +1908,37 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
974
1908
|
* @returns {{name: string, reason: string} | null}
|
|
975
1909
|
*/
|
|
976
1910
|
export function editorMissingSource(file, cwd) {
|
|
1911
|
+
// The app copy's source of an editor theme, its folder gone: the editor
|
|
1912
|
+
// writes it again.
|
|
1913
|
+
const copy = appCopyTheme(projectRoot(cwd), path.resolve(cwd, slashed(file)));
|
|
1914
|
+
if (copy)
|
|
1915
|
+
// A copy file named with Windows separators: the theme is what
|
|
1916
|
+
// compiles (the copy follows); with the copy gone, show writes it.
|
|
1917
|
+
return fs.existsSync(path.join(copy.root, 'src', 'themes', copy.slug))
|
|
1918
|
+
? {
|
|
1919
|
+
name: runLine(
|
|
1920
|
+
cwd,
|
|
1921
|
+
`experimental theme compile ${
|
|
1922
|
+
path
|
|
1923
|
+
.relative(
|
|
1924
|
+
cwd,
|
|
1925
|
+
path.join(
|
|
1926
|
+
copy.root,
|
|
1927
|
+
'themes',
|
|
1928
|
+
copy.slug,
|
|
1929
|
+
`${copy.slug}.theme.ts`,
|
|
1930
|
+
),
|
|
1931
|
+
)
|
|
1932
|
+
.split(path.sep)
|
|
1933
|
+
.join('/') || `themes/${copy.slug}/${copy.slug}.theme.ts`
|
|
1934
|
+
}`,
|
|
1935
|
+
),
|
|
1936
|
+
reason: `${copy.slug}'s app copy follows every compile of the theme`,
|
|
1937
|
+
}
|
|
1938
|
+
: {
|
|
1939
|
+
name: runLine(cwd, `experimental theme editor show ${copy.slug}`),
|
|
1940
|
+
reason: `the editor writes ${copy.slug}'s app copy in src/themes/${copy.slug}/ again`,
|
|
1941
|
+
};
|
|
977
1942
|
const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
|
|
978
1943
|
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
979
1944
|
return {
|