@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -86
- package/api/build/_adapter.d.mts +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +4 -2
- package/api/build/kit/rank.mjs +125 -24
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +340 -43
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +28 -2
- package/api/docs/_adapter.mjs +249 -10
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/authoring-checks.mjs +6 -6
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +5 -0
- package/api/search/_lexical.mjs +8 -2
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +132 -1
- package/api/theme/build/build.mjs +482 -157
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +44 -5
- package/api/theme/build/font-warning.mjs +118 -10
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +115 -4
- package/api/theme-edit/_adapter.mjs +997 -83
- package/api/theme-edit/_catalog.d.mts +20 -2
- package/api/theme-edit/_catalog.mjs +50 -10
- package/api/theme-edit/_check.d.mts +75 -24
- package/api/theme-edit/_check.mjs +2672 -422
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +54 -1
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +133 -15
- package/api/theme-edit/_context.d.mts +14 -3
- package/api/theme-edit/_context.mjs +225 -65
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +54 -4
- package/api/theme-edit/_edit.mjs +2966 -286
- package/api/theme-edit/_how-commands.d.mts +72 -1
- package/api/theme-edit/_how-commands.mjs +770 -9
- package/api/theme-edit/_how-question.d.mts +82 -5
- package/api/theme-edit/_how-question.mjs +6983 -701
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +237 -41
- package/api/theme-edit/_importers.d.mts +38 -0
- package/api/theme-edit/_importers.mjs +188 -0
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +303 -0
- package/api/theme-edit/_normal.mjs +1517 -0
- package/api/theme-edit/_palette.d.mts +12 -0
- package/api/theme-edit/_palette.mjs +37 -4
- package/api/theme-edit/_part-words.d.mts +31 -0
- package/api/theme-edit/_part-words.mjs +126 -0
- package/api/theme-edit/_parts.d.mts +28 -2
- package/api/theme-edit/_parts.mjs +267 -31
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +814 -406
- package/api/theme-edit/_preview.d.mts +116 -16
- package/api/theme-edit/_preview.mjs +649 -152
- package/api/theme-edit/_project.d.mts +22 -1
- package/api/theme-edit/_project.mjs +83 -3
- package/api/theme-edit/_settings.d.mts +467 -42
- package/api/theme-edit/_settings.mjs +3527 -468
- package/api/theme-edit/_tables.d.mts +21 -0
- package/api/theme-edit/_tables.mjs +97 -3
- package/api/theme-edit/_vet.d.mts +31 -0
- package/api/theme-edit/_vet.mjs +114 -8
- package/api/theme-edit/theme-edit.type.d.mts +16 -2
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- package/assets/docs/tree/share-a-page.doc.mjs +157 -0
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +573 -119
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +718 -438
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +132 -24
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/core-component-docs.d.mts +29 -0
- package/foundation/discovery/core-component-docs.mjs +83 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +53 -1
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +31 -4
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.d.mts +6 -5
- package/foundation/discovery/theming-targets.mjs +31 -47
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +38 -0
- package/foundation/fonts/font-stylesheet.mjs +141 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +62 -4
- package/foundation/fs/gather-cache.mjs +517 -91
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +9 -0
- package/foundation/fs/read-record.mjs +19 -11
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +185 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +34 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +641 -96
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +2 -2
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/css-escape.d.mts +18 -0
- package/foundation/text/css-escape.mjs +35 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -32,17 +32,32 @@
|
|
|
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 {context, coreApp} from './_context.mjs';
|
|
56
|
+
import {APP_COPY_MARK} from './_marks.mjs';
|
|
57
|
+
import {
|
|
58
|
+
fontKey,
|
|
59
|
+
importedFontFamilies,
|
|
60
|
+
} from '../../foundation/fonts/font-stylesheet.mjs';
|
|
46
61
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
47
62
|
import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
|
|
48
63
|
import {
|
|
@@ -50,22 +65,44 @@ import {
|
|
|
50
65
|
quoteCommandArgument,
|
|
51
66
|
} from '../../foundation/env/package-manager.mjs';
|
|
52
67
|
import {LIKE, P} from './_tables.mjs';
|
|
68
|
+
|
|
69
|
+
/** The preview command, as a person runs it. */
|
|
70
|
+
const PREVIEW_WORDS = P.replace(/ editor$/, ' preview');
|
|
53
71
|
import {setLine} from './_check.mjs';
|
|
72
|
+
import {followLine, splitCommand} from './_vet.mjs';
|
|
54
73
|
import {
|
|
55
74
|
SHOWCASE_GROUPS,
|
|
75
|
+
appCopyBehind,
|
|
76
|
+
appCopyStale,
|
|
77
|
+
copyFontsCss,
|
|
56
78
|
takeFirstAppCopy,
|
|
57
79
|
writeAppCopy,
|
|
58
80
|
writeAppCopyAt,
|
|
59
81
|
} from './_preview.mjs';
|
|
60
82
|
import {humanWarn} from '../../foundation/response/json.mjs';
|
|
61
|
-
import {
|
|
83
|
+
import {
|
|
84
|
+
buildColorModes,
|
|
85
|
+
camel,
|
|
86
|
+
folderIsEmpty,
|
|
87
|
+
loadTheme,
|
|
88
|
+
setAfterBuild,
|
|
89
|
+
editedThemes,
|
|
90
|
+
themeFiles,
|
|
91
|
+
fontsourcePackageOf,
|
|
92
|
+
themeSourceRefusal,
|
|
93
|
+
typedThemeName,
|
|
94
|
+
} from './_settings.mjs';
|
|
62
95
|
|
|
63
96
|
// Every build of a theme writes its app copy (src/themes/<theme>/).
|
|
64
97
|
setAfterBuild(writeAppCopy);
|
|
65
98
|
import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
|
|
66
99
|
|
|
67
100
|
export {parsePoints} from './_how.mjs';
|
|
68
|
-
export {
|
|
101
|
+
export {
|
|
102
|
+
newFlagList,
|
|
103
|
+
checkedChangeLine as editorCheckedLine,
|
|
104
|
+
checkedNewLines as editorCheckedNewLines,
|
|
105
|
+
} from './_edit.mjs';
|
|
69
106
|
import {themeEditHow as howAt} from './_how.mjs';
|
|
70
107
|
|
|
71
108
|
/**
|
|
@@ -116,7 +153,7 @@ export const editorBaseIn = (slug, cwd) =>
|
|
|
116
153
|
/** The sections `show --section` takes. */
|
|
117
154
|
export const showSections = () => [...SHOWCASE_GROUPS];
|
|
118
155
|
|
|
119
|
-
export {dialValueFits} from './_settings.mjs';
|
|
156
|
+
export {dialValueFits, usableNewName as editorFreeName} from './_settings.mjs';
|
|
120
157
|
|
|
121
158
|
/**
|
|
122
159
|
* The project a command acts on: the Astryx project at or above `cwd`, found
|
|
@@ -367,16 +404,43 @@ const lockName = name =>
|
|
|
367
404
|
*/
|
|
368
405
|
function absolute(result, root, from) {
|
|
369
406
|
if (path.resolve(from) === root) return result;
|
|
370
|
-
/**
|
|
371
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Lines that name project files inside them: `see`, a picture note, the
|
|
409
|
+
* in-app preview's stale entries. Every project path in them (a theme
|
|
410
|
+
* file, an in-app preview folder) is made absolute, one style per line.
|
|
411
|
+
*/
|
|
412
|
+
const PROSE = new Set(['see', 'pictureProblem', 'previewStale', 'wiring']);
|
|
413
|
+
/** A project-relative path that names a file or folder there. @param {string} p */
|
|
414
|
+
const inRoot = p => {
|
|
415
|
+
const bare = p.replace(/\/+$/, '');
|
|
416
|
+
return (
|
|
417
|
+
Boolean(bare) &&
|
|
418
|
+
!path.isAbsolute(bare) &&
|
|
419
|
+
!bare.startsWith('.') &&
|
|
420
|
+
fs.existsSync(path.join(root, bare))
|
|
421
|
+
);
|
|
422
|
+
};
|
|
423
|
+
/** @param {any} v @param {string} [key] @returns {any} */
|
|
424
|
+
const map = (v, key) =>
|
|
372
425
|
typeof v === 'string'
|
|
373
|
-
?
|
|
426
|
+
? // A path alone; a line that starts with one is read as prose below.
|
|
427
|
+
/^themes\/\S*$/.test(v) && !(key && PROSE.has(key))
|
|
374
428
|
? path.join(root, v)
|
|
375
|
-
:
|
|
429
|
+
: key && PROSE.has(key)
|
|
430
|
+
? previewCommandsFrom(v, root, from).replace(
|
|
431
|
+
/(^|[\s(,])((?:themes|src|app)\/[^\s,;)]*)/g,
|
|
432
|
+
(all, before, file) =>
|
|
433
|
+
/^themes\//.test(file) || inRoot(file)
|
|
434
|
+
? `${before}${path.join(root, file)}`
|
|
435
|
+
: all,
|
|
436
|
+
)
|
|
437
|
+
: previewCommandsFrom(v, root, from)
|
|
376
438
|
: Array.isArray(v)
|
|
377
|
-
? v.map(map)
|
|
439
|
+
? v.map(x => map(x, key))
|
|
378
440
|
: v && typeof v === 'object'
|
|
379
|
-
? Object.fromEntries(
|
|
441
|
+
? Object.fromEntries(
|
|
442
|
+
Object.entries(v).map(([k, x]) => [k, map(x, k)]),
|
|
443
|
+
)
|
|
380
444
|
: v;
|
|
381
445
|
return map(result);
|
|
382
446
|
}
|
|
@@ -425,6 +489,23 @@ async function inProject(options, lock, fn, bestEffort = false, again = null) {
|
|
|
425
489
|
*/
|
|
426
490
|
function fromCaller(e, root, from) {
|
|
427
491
|
if (path.resolve(from) === root || !Array.isArray(e?.suggestions)) return e;
|
|
492
|
+
for (const s of e.suggestions)
|
|
493
|
+
if (typeof s?.name === 'string')
|
|
494
|
+
s.name = previewCommandsFrom(s.name, root, from);
|
|
495
|
+
return e;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* The preview commands in a line, rebased from the project root onto the
|
|
500
|
+
* folder the command ran in: each `--path` and each `preview app` folder,
|
|
501
|
+
* so a pointer works where it is printed (in a refusal, a `see` line, a
|
|
502
|
+
* note). A folder that comes out starting with `-` goes after `--`.
|
|
503
|
+
* @param {string} line
|
|
504
|
+
* @param {string} root
|
|
505
|
+
* @param {string} from
|
|
506
|
+
*/
|
|
507
|
+
export function previewCommandsFrom(line, root, from) {
|
|
508
|
+
if (path.resolve(from) === root) return line;
|
|
428
509
|
const ARG = String.raw`('(?:[^']|'\\'')*'|"[^"]*"|[^\s'"]+)`;
|
|
429
510
|
/** @param {string} v */
|
|
430
511
|
const unquote = v =>
|
|
@@ -437,32 +518,40 @@ function fromCaller(e, root, from) {
|
|
|
437
518
|
const rel = v =>
|
|
438
519
|
/^<.*>$/.test(v)
|
|
439
520
|
? v
|
|
440
|
-
:
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
521
|
+
: path.relative(path.resolve(from), path.resolve(root, unquote(v))) ||
|
|
522
|
+
'.';
|
|
523
|
+
const CMD = 'astryx experimental theme preview ';
|
|
524
|
+
const parts = line.split(CMD);
|
|
525
|
+
return parts
|
|
526
|
+
.map((part, i) => {
|
|
527
|
+
// A command after a `cd … &&` runs in the folder it names: as given.
|
|
528
|
+
if (i === 0 || /\bcd [^&]*&& (?:npx \S+ )?$/.test(parts[i - 1]))
|
|
529
|
+
return part;
|
|
530
|
+
let out = part.replace(
|
|
449
531
|
new RegExp(`(--path )${ARG}`, 'g'),
|
|
450
532
|
(
|
|
451
533
|
/** @type {string} */ _m,
|
|
452
534
|
/** @type {string} */ flag,
|
|
453
535
|
/** @type {string} */ v,
|
|
454
|
-
) => flag + rel(v),
|
|
455
|
-
)
|
|
456
|
-
.replace(
|
|
457
|
-
new RegExp(`^(
|
|
536
|
+
) => flag + quoteCommandArgument(rel(v)),
|
|
537
|
+
);
|
|
538
|
+
out = out.replace(
|
|
539
|
+
new RegExp(`^app ((?:--theme ${ARG} )?)(-- )?${ARG}`),
|
|
458
540
|
(
|
|
459
|
-
/** @type {string} */
|
|
460
|
-
/** @type {string} */
|
|
541
|
+
/** @type {string} */ m,
|
|
542
|
+
/** @type {string} */ flags,
|
|
543
|
+
/** @type {string} */ _t,
|
|
544
|
+
/** @type {string | undefined} */ dash,
|
|
461
545
|
/** @type {string} */ v,
|
|
462
|
-
) =>
|
|
546
|
+
) => {
|
|
547
|
+
if (!dash && v.startsWith('-')) return m;
|
|
548
|
+
const r = rel(v);
|
|
549
|
+
return `app ${flags}${r.startsWith('-') ? '-- ' : ''}${quoteCommandArgument(r)}`;
|
|
550
|
+
},
|
|
463
551
|
);
|
|
464
|
-
|
|
465
|
-
|
|
552
|
+
return out;
|
|
553
|
+
})
|
|
554
|
+
.join(CMD);
|
|
466
555
|
}
|
|
467
556
|
|
|
468
557
|
/**
|
|
@@ -550,37 +639,134 @@ export const themeEditShow = (theme, options = {}) =>
|
|
|
550
639
|
);
|
|
551
640
|
/** @type {typeof preview.themeEditPreviewAdd} */
|
|
552
641
|
export const themeEditPreviewAdd = (description, options = {}) =>
|
|
553
|
-
|
|
554
|
-
preview
|
|
642
|
+
stopTold(
|
|
643
|
+
`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)`,
|
|
644
|
+
() =>
|
|
645
|
+
inProject(options, 'preview', o =>
|
|
646
|
+
preview.themeEditPreviewAdd(description, withThemeLock(o)),
|
|
647
|
+
),
|
|
555
648
|
);
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Run a preview command with a stop (Ctrl-C, SIGTERM) heard for its whole
|
|
652
|
+
* run, and after it: the stop ends the process as stopped, with one line
|
|
653
|
+
* saying where the change stands (a change stopped part way is finished by
|
|
654
|
+
* the next preview command), never an ok with exit 0.
|
|
655
|
+
* @template T
|
|
656
|
+
* @param {string | (() => string)} where where the change stands, and what
|
|
657
|
+
* finishes it; a function is asked when the stop lands, so it can look
|
|
658
|
+
* @param {() => Promise<T>} fn
|
|
659
|
+
* @returns {Promise<T>}
|
|
660
|
+
*/
|
|
661
|
+
async function stopTold(where, fn) {
|
|
662
|
+
const on = (/** @type {NodeJS.Signals} */ sig) => {
|
|
663
|
+
process.removeListener('SIGINT', on);
|
|
664
|
+
process.removeListener('SIGTERM', on);
|
|
665
|
+
process.stderr.write(
|
|
666
|
+
`Stopped: ${typeof where === 'function' ? where() : where}.\n`,
|
|
667
|
+
);
|
|
668
|
+
// With no other listener (a lock's, which ends the process itself),
|
|
669
|
+
// the stop ends it here.
|
|
670
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
671
|
+
};
|
|
672
|
+
process.on('SIGINT', on);
|
|
673
|
+
process.on('SIGTERM', on);
|
|
674
|
+
try {
|
|
675
|
+
const r = await fn();
|
|
676
|
+
// A turn of the event loop, so a stop that came while the work ran
|
|
677
|
+
// without a pause is heard now, before the result is printed.
|
|
678
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
679
|
+
// Every listener added here is removed on return: the caller's process
|
|
680
|
+
// keeps its own stop handling. The CLI client, which owns its process,
|
|
681
|
+
// holds a stop that lands while it prints the result.
|
|
682
|
+
return r;
|
|
683
|
+
} finally {
|
|
684
|
+
process.removeListener('SIGINT', on);
|
|
685
|
+
process.removeListener('SIGTERM', on);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
556
688
|
/**
|
|
557
689
|
* `preview app` runs from the project root, with `dir` kept pointing where
|
|
558
690
|
* it was given. With a theme it holds that theme's lock, since it may build
|
|
559
691
|
* the theme and copies its files: a `set` beside it waits.
|
|
560
692
|
* @type {typeof preview.themeEditPreviewApp}
|
|
561
693
|
*/
|
|
562
|
-
export const themeEditPreviewApp = (dir, options = {}) => {
|
|
694
|
+
export const themeEditPreviewApp = async (dir, options = {}) => {
|
|
563
695
|
const from = options.cwd ?? process.cwd();
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
696
|
+
// The app is written into a temp folder and moved into place in one step,
|
|
697
|
+
// with no pause on the way: when a stop lands, the folder holds the whole
|
|
698
|
+
// app or is as it was. Which one is told.
|
|
699
|
+
const target =
|
|
700
|
+
typeof dir === 'string' && dir.trim() ? path.resolve(from, dir) : null;
|
|
701
|
+
/** @param {string} d */
|
|
702
|
+
const holdsApp = d => fs.existsSync(path.join(d, 'package.json'));
|
|
703
|
+
const hadApp = target != null && holdsApp(target);
|
|
704
|
+
const shownTarget = target
|
|
705
|
+
? path.relative(from, target).split(path.sep).join('/') || '.'
|
|
706
|
+
: null;
|
|
707
|
+
return fromHere(
|
|
708
|
+
await stopTold(
|
|
709
|
+
() =>
|
|
710
|
+
target && !hadApp && holdsApp(target)
|
|
711
|
+
? `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`
|
|
712
|
+
: `nothing was written${shownTarget ? ` (${shownTarget}/ is as it was)` : ''}; run the same command again`,
|
|
713
|
+
() =>
|
|
714
|
+
inProject(
|
|
715
|
+
options,
|
|
716
|
+
options.theme == null ? null : lockName(options.theme),
|
|
717
|
+
o =>
|
|
718
|
+
preview.themeEditPreviewApp(
|
|
719
|
+
typeof dir === 'string' && dir.trim() && dir === dir.trim()
|
|
720
|
+
? path.relative(o.cwd, path.resolve(from, dir)) || '.'
|
|
721
|
+
: dir,
|
|
722
|
+
o,
|
|
723
|
+
),
|
|
724
|
+
true,
|
|
725
|
+
),
|
|
726
|
+
),
|
|
727
|
+
from,
|
|
575
728
|
);
|
|
576
729
|
};
|
|
730
|
+
/**
|
|
731
|
+
* A new app's folder and its open line, as they work from where the command
|
|
732
|
+
* ran (`cd ../../theme-app` from src/app), not from the project root.
|
|
733
|
+
* @template T
|
|
734
|
+
* @param {T} r
|
|
735
|
+
* @param {string} from
|
|
736
|
+
* @returns {T}
|
|
737
|
+
*/
|
|
738
|
+
function fromHere(r, from) {
|
|
739
|
+
const d = /** @type {any} */ (r)?.data;
|
|
740
|
+
if (!d || typeof d.folder !== 'string') return r;
|
|
741
|
+
const root = projectRoot(from);
|
|
742
|
+
if (!root || path.resolve(from) === root) return r;
|
|
743
|
+
const here = path.relative(from, path.join(root, d.folder)) || '.';
|
|
744
|
+
const shown = here.split(path.sep).join('/');
|
|
745
|
+
const cdArg = quoteCommandArgument(
|
|
746
|
+
shown.startsWith('-') ? `./${shown}` : shown,
|
|
747
|
+
);
|
|
748
|
+
return /** @type {T} */ ({
|
|
749
|
+
...r,
|
|
750
|
+
data: {
|
|
751
|
+
...d,
|
|
752
|
+
folder: shown,
|
|
753
|
+
...(typeof d.open === 'string'
|
|
754
|
+
? {open: d.open.replace(/^cd \S+ &&/, `cd ${cdArg} &&`)}
|
|
755
|
+
: {}),
|
|
756
|
+
},
|
|
757
|
+
});
|
|
758
|
+
}
|
|
577
759
|
/** @type {typeof preview.themeEditPreviewList} */
|
|
578
760
|
export const themeEditPreviewList = (options = {}) =>
|
|
579
761
|
inProject(options, null, async o => preview.themeEditPreviewList(o));
|
|
580
762
|
/** @type {typeof preview.themeEditPreviewRemove} */
|
|
581
763
|
export const themeEditPreviewRemove = (page, options = {}) =>
|
|
582
|
-
|
|
583
|
-
|
|
764
|
+
stopTold(
|
|
765
|
+
`a removal stopped part way is finished by the next ${PREVIEW_WORDS} remove, and one made in full stands (${PREVIEW_WORDS} list says which)`,
|
|
766
|
+
() =>
|
|
767
|
+
inProject(options, 'preview', o =>
|
|
768
|
+
preview.themeEditPreviewRemove(page, withThemeLock(o)),
|
|
769
|
+
),
|
|
584
770
|
);
|
|
585
771
|
|
|
586
772
|
/**
|
|
@@ -669,8 +855,9 @@ function runLine(cwd, rest) {
|
|
|
669
855
|
* @returns {AstryxError | null}
|
|
670
856
|
*/
|
|
671
857
|
export function editorThemeRefusal(err, cwd) {
|
|
672
|
-
// A refused compile ends here: its theme locks go now, not at exit
|
|
673
|
-
|
|
858
|
+
// A refused compile ends here: its theme locks go now, not at exit, and
|
|
859
|
+
// it writes no app copy (from build files it refused).
|
|
860
|
+
void releaseCompileHold?.(true);
|
|
674
861
|
if (
|
|
675
862
|
err.code !== ERROR_CODES.ERR_UNKNOWN_THEME &&
|
|
676
863
|
!/unknown theme|is not added|not a theme package/i.test(err.message)
|
|
@@ -683,10 +870,43 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
683
870
|
const word = named ? typedThemeName(named[1] ?? named[2]) : '';
|
|
684
871
|
const slug = word ? editorThemeOf(root, word) : null;
|
|
685
872
|
if (!slug) return null;
|
|
873
|
+
// The command that refused: list, add, use, remove or eject.
|
|
874
|
+
const verb =
|
|
875
|
+
process.argv
|
|
876
|
+
.slice(2)
|
|
877
|
+
.find(a => ['list', 'add', 'use', 'remove', 'eject'].includes(a)) ?? null;
|
|
878
|
+
// eject copies a theme package's source into the app; an editor theme's
|
|
879
|
+
// source is the app's already.
|
|
880
|
+
if (verb === 'eject')
|
|
881
|
+
return new AstryxError(
|
|
882
|
+
`${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}.`,
|
|
883
|
+
[
|
|
884
|
+
{
|
|
885
|
+
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
886
|
+
reason: 'the theme as it is now',
|
|
887
|
+
},
|
|
888
|
+
],
|
|
889
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
890
|
+
);
|
|
891
|
+
const copyThere = !folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug));
|
|
892
|
+
// A path to the theme ("themes/d", "src/themes/d"): the commands take its
|
|
893
|
+
// name.
|
|
894
|
+
const typed = named ? (named[1] ?? named[2]) : '';
|
|
895
|
+
if (copyThere && verb && typed !== slug)
|
|
896
|
+
return new AstryxError(
|
|
897
|
+
`"${typed}" is ${/[\\/]|\.[a-z]+$/i.test(typed) ? 'a path' : "not the theme's name"}; the theme commands take the theme's name: ${slug}.`,
|
|
898
|
+
[
|
|
899
|
+
{
|
|
900
|
+
name: runLine(cwd, `theme ${verb} ${slug}`),
|
|
901
|
+
reason: 'the same, by name',
|
|
902
|
+
},
|
|
903
|
+
],
|
|
904
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
905
|
+
);
|
|
686
906
|
// A local theme of that name (a fork in the app's own themes folder) is
|
|
687
907
|
// one the stable commands take: their own message stands.
|
|
688
908
|
// A folder of only system files (or empty) holds no theme: as absent.
|
|
689
|
-
if (
|
|
909
|
+
if (copyThere) return null;
|
|
690
910
|
// No app copy yet (a theme made before the editor wrote one, or the
|
|
691
911
|
// copy removed): the next build writes it, then the same steps every
|
|
692
912
|
// place gives (`wiring` of new and show).
|
|
@@ -722,6 +942,112 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
722
942
|
);
|
|
723
943
|
}
|
|
724
944
|
|
|
945
|
+
/** The shared typo rule, for a typed subcommand. */
|
|
946
|
+
export {booleanWord, typoNear, typoOf} from './_normal.mjs';
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* The editor themes of the app the folder `cwd` is in, by name; none when
|
|
950
|
+
* the folder is in no app or its themes cannot be read.
|
|
951
|
+
* @param {string} cwd
|
|
952
|
+
* @returns {string[]}
|
|
953
|
+
*/
|
|
954
|
+
export function editorThemesAt(cwd) {
|
|
955
|
+
try {
|
|
956
|
+
return editedThemes(projectRoot(cwd));
|
|
957
|
+
} catch {
|
|
958
|
+
return [];
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* A refused compile whose first suggestion is another compile: that compile
|
|
964
|
+
* is run through compile's own checks before it is offered (in memory,
|
|
965
|
+
* nothing built), and each repair a refusal of it offers is folded into the
|
|
966
|
+
* one line. An --out outside the working folder is dropped, and the reason
|
|
967
|
+
* says why; when the rest cannot be repaired, the reason says so. A line
|
|
968
|
+
* that starts with `cd` runs elsewhere, so it is not checked from here.
|
|
969
|
+
* @param {AstryxError} err
|
|
970
|
+
* @param {string} cwd
|
|
971
|
+
* @returns {Promise<AstryxError>}
|
|
972
|
+
*/
|
|
973
|
+
export async function editorFollowCompile(err, cwd) {
|
|
974
|
+
const list = err.suggestions ?? [];
|
|
975
|
+
const first = list[0];
|
|
976
|
+
// The build's own refusals name `theme build`; the group's words replace
|
|
977
|
+
// those words when the refusal is shown.
|
|
978
|
+
const wordsIn = (/** @type {string} */ line) =>
|
|
979
|
+
[' experimental theme compile ', ' theme build '].find(w =>
|
|
980
|
+
line.includes(w),
|
|
981
|
+
);
|
|
982
|
+
const isCompile = (/** @type {string} */ line) =>
|
|
983
|
+
/^cd /.test(line) || Boolean(wordsIn(line));
|
|
984
|
+
if (!first || /^cd /.test(first.name) || !wordsIn(first.name)) return err;
|
|
985
|
+
/** @param {string} line */
|
|
986
|
+
const read = line => {
|
|
987
|
+
const words = wordsIn(line);
|
|
988
|
+
if (!words) return null;
|
|
989
|
+
const args = splitCommand(line.slice(line.indexOf(words) + words.length));
|
|
990
|
+
if (!args) return null;
|
|
991
|
+
/** @type {{source?: string, out?: string, iconsSpecifier?: string, check?: boolean}} */
|
|
992
|
+
const r = {};
|
|
993
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
994
|
+
const a = args[i];
|
|
995
|
+
if (a === '--check') r.check = true;
|
|
996
|
+
else if (a === '--out') r.out = args[(i += 1)];
|
|
997
|
+
else if (a === '--icons-specifier') r.iconsSpecifier = args[(i += 1)];
|
|
998
|
+
else if (a.startsWith('-') || r.source) return null;
|
|
999
|
+
else r.source = a;
|
|
1000
|
+
}
|
|
1001
|
+
return r.source ? r : null;
|
|
1002
|
+
};
|
|
1003
|
+
const COMPILE = {group: 'experimental theme', build: 'compile'};
|
|
1004
|
+
/** @type {string | null} */
|
|
1005
|
+
let outDropped = null;
|
|
1006
|
+
const followed = await followLine(
|
|
1007
|
+
first.name,
|
|
1008
|
+
async line => {
|
|
1009
|
+
// A line that runs elsewhere is not checked from here.
|
|
1010
|
+
if (/^cd /.test(line)) return null;
|
|
1011
|
+
const r = read(line);
|
|
1012
|
+
if (!r?.source) return null;
|
|
1013
|
+
const refused =
|
|
1014
|
+
(await editorCompileProblem([r.source], {cwd, ...r})) ??
|
|
1015
|
+
buildInputProblem(r.source, r, cwd);
|
|
1016
|
+
if (refused) return refused;
|
|
1017
|
+
// A build writes only inside the working folder: the same build
|
|
1018
|
+
// without --out writes beside the source.
|
|
1019
|
+
if (r.out && refusedOutput(path.resolve(cwd, r.out), cwd)) {
|
|
1020
|
+
outDropped = r.out;
|
|
1021
|
+
return new AstryxError(`--out ${r.out} is outside the working folder`, [
|
|
1022
|
+
{
|
|
1023
|
+
name: buildSuggestion(
|
|
1024
|
+
r.source,
|
|
1025
|
+
{check: r.check, iconsSpecifier: r.iconsSpecifier},
|
|
1026
|
+
cwd,
|
|
1027
|
+
COMPILE,
|
|
1028
|
+
),
|
|
1029
|
+
reason: 'do this instead',
|
|
1030
|
+
},
|
|
1031
|
+
]);
|
|
1032
|
+
}
|
|
1033
|
+
return null;
|
|
1034
|
+
},
|
|
1035
|
+
isCompile,
|
|
1036
|
+
);
|
|
1037
|
+
if (followed.line === first.name) return err;
|
|
1038
|
+
const reason = [
|
|
1039
|
+
outDropped && !/ --out /.test(followed.line)
|
|
1040
|
+
? `do this instead, without --out: ${outDropped} is outside the working folder, where a build may not write, so the outputs go beside the source`
|
|
1041
|
+
: first.reason,
|
|
1042
|
+
...(followed.why ? [`it is still refused: ${followed.why}`] : []),
|
|
1043
|
+
].join('; ');
|
|
1044
|
+
err.suggestions = [
|
|
1045
|
+
{...first, name: followed.line, reason},
|
|
1046
|
+
...list.slice(1).filter(x => x.name !== followed.line),
|
|
1047
|
+
];
|
|
1048
|
+
return err;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
725
1051
|
/**
|
|
726
1052
|
* A refusal before `compile` runs on an editor theme's files, or null: the
|
|
727
1053
|
* editor's generated settings are not a theme source, `--family` does not
|
|
@@ -757,25 +1083,173 @@ export async function editorCompileProblem(
|
|
|
757
1083
|
from,
|
|
758
1084
|
COMPILE,
|
|
759
1085
|
);
|
|
1086
|
+
/**
|
|
1087
|
+
* The compile of `source` from the app root, after a cd there: --out
|
|
1088
|
+
* names the same file from the root while it stays inside it (a build
|
|
1089
|
+
* writes only inside its working folder); one outside is left off, and
|
|
1090
|
+
* `why` says so.
|
|
1091
|
+
* @param {string} source @param {string} root
|
|
1092
|
+
*/
|
|
1093
|
+
const fromRootLine = (source, root) => {
|
|
1094
|
+
const rebased = out
|
|
1095
|
+
? path.relative(root, path.resolve(cwd, slashed(out)))
|
|
1096
|
+
: '';
|
|
1097
|
+
const escapes =
|
|
1098
|
+
!check &&
|
|
1099
|
+
!!rebased &&
|
|
1100
|
+
(rebased.startsWith('..') || path.isAbsolute(rebased));
|
|
1101
|
+
return {
|
|
1102
|
+
name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${
|
|
1103
|
+
escapes
|
|
1104
|
+
? buildSuggestion(source, {check, iconsSpecifier}, root, COMPILE)
|
|
1105
|
+
: compileLine(source, root)
|
|
1106
|
+
}`,
|
|
1107
|
+
why: escapes
|
|
1108
|
+
? ` --out ${out} is outside the app root, where a build may not write, so the compile below writes beside the source.`
|
|
1109
|
+
: '',
|
|
1110
|
+
};
|
|
1111
|
+
};
|
|
1112
|
+
// An --out into an editor theme's app copy folder: the copy refresh would
|
|
1113
|
+
// write the theme's own build over it. One into the theme's own editor
|
|
1114
|
+
// folder that is not its default output would leave that folder half
|
|
1115
|
+
// built (the module rewritten, the stylesheet not) and the copy made from
|
|
1116
|
+
// it.
|
|
1117
|
+
if (out) {
|
|
1118
|
+
// Any --out in the copy folder, the folder itself too, written with
|
|
1119
|
+
// backslashes, through a link or (on a case-insensitive disk) in
|
|
1120
|
+
// another case, as the build reads it: real paths name the folder as
|
|
1121
|
+
// the disk does.
|
|
1122
|
+
const rel = path
|
|
1123
|
+
.relative(
|
|
1124
|
+
realLocation(cwdRoot),
|
|
1125
|
+
realLocation(path.resolve(cwd, slashed(out))),
|
|
1126
|
+
)
|
|
1127
|
+
.split(path.sep)
|
|
1128
|
+
.filter(Boolean);
|
|
1129
|
+
const inCopy =
|
|
1130
|
+
rel[0] === 'src' &&
|
|
1131
|
+
rel[1] === 'themes' &&
|
|
1132
|
+
rel.length >= 3 &&
|
|
1133
|
+
fs.existsSync(themeFiles(cwdRoot, rel[2]).settings);
|
|
1134
|
+
// Only for a compile of that theme: another source written there is
|
|
1135
|
+
// the build's own case (it warns).
|
|
1136
|
+
const inEditor =
|
|
1137
|
+
rel[0] === 'themes' &&
|
|
1138
|
+
rel.length >= 3 &&
|
|
1139
|
+
fs.existsSync(themeFiles(cwdRoot, rel[1]).settings) &&
|
|
1140
|
+
files.some(
|
|
1141
|
+
file =>
|
|
1142
|
+
editorThemeAt(cwdRoot, path.resolve(cwd, file))?.slug === rel[1],
|
|
1143
|
+
) &&
|
|
1144
|
+
!outIsDefault(cwdRoot, rel[1], cwd, out);
|
|
1145
|
+
if (inCopy || inEditor) {
|
|
1146
|
+
const t = inCopy ? rel[2] : rel[1];
|
|
1147
|
+
return new AstryxError(
|
|
1148
|
+
inCopy
|
|
1149
|
+
? `--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.`
|
|
1150
|
+
: `--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}/.`,
|
|
1151
|
+
[
|
|
1152
|
+
{
|
|
1153
|
+
// The same compile without --out: it builds into themes/<t>/,
|
|
1154
|
+
// and the copy follows.
|
|
1155
|
+
// From a subfolder, with the cd to the app root, where an
|
|
1156
|
+
// editor theme compiles.
|
|
1157
|
+
name:
|
|
1158
|
+
path.resolve(cwd) === path.resolve(cwdRoot)
|
|
1159
|
+
? buildSuggestion(
|
|
1160
|
+
files.length === 1 ? files[0] : `themes/${t}/${t}.theme.ts`,
|
|
1161
|
+
{check, iconsSpecifier},
|
|
1162
|
+
cwd,
|
|
1163
|
+
COMPILE,
|
|
1164
|
+
)
|
|
1165
|
+
: `cd ${quoteCommandArgument(path.relative(cwd, cwdRoot) || '.')} && ${buildSuggestion(
|
|
1166
|
+
files.length === 1
|
|
1167
|
+
? path.relative(cwdRoot, path.resolve(cwd, files[0])) ||
|
|
1168
|
+
files[0]
|
|
1169
|
+
: `themes/${t}/${t}.theme.ts`,
|
|
1170
|
+
{check, iconsSpecifier},
|
|
1171
|
+
cwdRoot,
|
|
1172
|
+
COMPILE,
|
|
1173
|
+
)}`,
|
|
1174
|
+
reason: 'do this instead',
|
|
1175
|
+
},
|
|
1176
|
+
],
|
|
1177
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
760
1181
|
for (const file of files) {
|
|
761
|
-
const
|
|
1182
|
+
const abs = path.resolve(cwd, file);
|
|
1183
|
+
const relParts = path
|
|
1184
|
+
.relative(
|
|
1185
|
+
realLocation(cwdRoot),
|
|
1186
|
+
realLocation(path.resolve(cwd, slashed(file))),
|
|
1187
|
+
)
|
|
1188
|
+
.split(path.sep);
|
|
1189
|
+
// The app's theme module `theme add` writes: not a theme source.
|
|
1190
|
+
if (relParts.join('/') === 'src/astryx-themes.ts')
|
|
1191
|
+
return new AstryxError(
|
|
1192
|
+
`${file} is the app's theme module (\`theme add\` writes it), not a theme source; compile the editor theme instead.`,
|
|
1193
|
+
editedThemes(cwdRoot)
|
|
1194
|
+
.slice(0, 3)
|
|
1195
|
+
.map(t => ({
|
|
1196
|
+
name: compileLine(`themes/${t}/${t}.theme.ts`, cwdRoot),
|
|
1197
|
+
reason: 'do this instead',
|
|
1198
|
+
})),
|
|
1199
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1200
|
+
);
|
|
1201
|
+
// A file of an editor theme's app copy (src/themes/<t>/): the copy
|
|
1202
|
+
// is written from themes/<t>/, so that is what compiles.
|
|
1203
|
+
if (
|
|
1204
|
+
relParts[0] === 'src' &&
|
|
1205
|
+
relParts[1] === 'themes' &&
|
|
1206
|
+
(relParts.length === 3 || relParts.length === 4) &&
|
|
1207
|
+
fs.existsSync(themeFiles(cwdRoot, relParts[2]).settings) &&
|
|
1208
|
+
// A file of yours there (no editor mark, no build header) compiles
|
|
1209
|
+
// like any theme source.
|
|
1210
|
+
(relParts.length === 3 ||
|
|
1211
|
+
isCopyFile(path.join(cwdRoot, ...relParts)) ||
|
|
1212
|
+
relParts[3] === `${camel(relParts[2])}Theme.ts`)
|
|
1213
|
+
) {
|
|
1214
|
+
const t = relParts[2];
|
|
1215
|
+
const own = `themes/${t}/${t}.theme.ts`;
|
|
1216
|
+
if (path.resolve(cwd) !== path.resolve(cwdRoot)) {
|
|
1217
|
+
const line = fromRootLine(own, cwdRoot);
|
|
1218
|
+
return new AstryxError(
|
|
1219
|
+
`${t} is a theme the editor made; compile it from the app root (${path.relative(cwd, cwdRoot) || '.'}), where the editor builds it.${line.why}`,
|
|
1220
|
+
[{name: line.name, reason: 'do this instead'}],
|
|
1221
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
// Its source too: a compile of the copy builds neither the theme
|
|
1225
|
+
// nor a current copy.
|
|
1226
|
+
return new AstryxError(
|
|
1227
|
+
`${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.`,
|
|
1228
|
+
[
|
|
1229
|
+
{name: compileLine(own, cwd), reason: 'do this instead'},
|
|
1230
|
+
{
|
|
1231
|
+
name: runLine(cwdRoot, `experimental theme editor show ${t}`),
|
|
1232
|
+
reason: 'writes the app copy again from the theme',
|
|
1233
|
+
},
|
|
1234
|
+
],
|
|
1235
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
1238
|
+
const at = editorThemeAt(cwdRoot, abs);
|
|
762
1239
|
if (!at || !editorOwnFile(at.slug, file)) continue;
|
|
763
1240
|
const {root, slug} = at;
|
|
764
1241
|
const source = `themes/${slug}/${slug}.theme.ts`;
|
|
765
1242
|
// An editor theme is built from its project's root, as every editor
|
|
766
1243
|
// command runs there: from a subfolder the build would write outside
|
|
767
1244
|
// its working folder. The run names the root.
|
|
768
|
-
if (path.resolve(cwd) !== path.resolve(root))
|
|
1245
|
+
if (path.resolve(cwd) !== path.resolve(root)) {
|
|
1246
|
+
const line = fromRootLine(source, root);
|
|
769
1247
|
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
|
-
],
|
|
1248
|
+
`${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.${line.why}`,
|
|
1249
|
+
[{name: line.name, reason: 'do this instead'}],
|
|
777
1250
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
778
1251
|
);
|
|
1252
|
+
}
|
|
779
1253
|
if (/\.settings\.(ts|json)$/.test(file))
|
|
780
1254
|
return new AstryxError(
|
|
781
1255
|
`${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
|
|
@@ -790,6 +1264,13 @@ export async function editorCompileProblem(
|
|
|
790
1264
|
],
|
|
791
1265
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
792
1266
|
);
|
|
1267
|
+
// A source that no longer carries the settings (another theme's name,
|
|
1268
|
+
// or no extends of them) is refused as set refuses it: a build would
|
|
1269
|
+
// write another theme's files, or drop every setting.
|
|
1270
|
+
{
|
|
1271
|
+
const refusal = await themeSourceRefusal(root, slug);
|
|
1272
|
+
if (refusal) return refusal;
|
|
1273
|
+
}
|
|
793
1274
|
if (family)
|
|
794
1275
|
return new AstryxError(
|
|
795
1276
|
`${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
|
|
@@ -868,12 +1349,11 @@ export async function editorCompileProblem(
|
|
|
868
1349
|
],
|
|
869
1350
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
870
1351
|
);
|
|
871
|
-
//
|
|
872
|
-
//
|
|
873
|
-
// beside it), as the editor's own build reads it.
|
|
1352
|
+
// The file's own token values, judged as a build of it writes them
|
|
1353
|
+
// (never written beside it), by the check the editor's build runs.
|
|
874
1354
|
if (path.basename(file) === `${slug}.theme.ts`) {
|
|
875
|
-
const
|
|
876
|
-
if (
|
|
1355
|
+
const values = await edit.editorOwnTokenRefusal(root, slug);
|
|
1356
|
+
if (values) return values;
|
|
877
1357
|
}
|
|
878
1358
|
}
|
|
879
1359
|
}
|
|
@@ -883,18 +1363,48 @@ export async function editorCompileProblem(
|
|
|
883
1363
|
/** The editor themes a running `compile` holds the lock of, by project and name. */
|
|
884
1364
|
const COMPILE_HELD = new Set();
|
|
885
1365
|
|
|
886
|
-
/** @type {(() => Promise<void>) | null} The release of the running compile's hold. */
|
|
1366
|
+
/** @type {((refused?: boolean) => Promise<void>) | null} The release of the running compile's hold; `refused`: it wrote nothing, so no app copy either. */
|
|
887
1367
|
let releaseCompileHold = null;
|
|
888
1368
|
|
|
1369
|
+
/** @type {Array<{root: string, slug: string, copy: (refused: boolean) => boolean, report: () => Record<string, unknown> | null}>} The running compile's held themes. */
|
|
1370
|
+
let compileHoldItems = [];
|
|
1371
|
+
|
|
1372
|
+
/**
|
|
1373
|
+
* For `compile`, once its outputs are written: write each held editor
|
|
1374
|
+
* theme's app copy now, and say per file what the write did (`appCopy` on
|
|
1375
|
+
* a first write, `appCopyStale` when something keeps the copy behind), so
|
|
1376
|
+
* the JSON result carries what the text says.
|
|
1377
|
+
* @param {string[]} files
|
|
1378
|
+
* @param {string} cwd
|
|
1379
|
+
* @returns {Promise<Record<string, Record<string, unknown>>>}
|
|
1380
|
+
*/
|
|
1381
|
+
export async function editorAfterBuild(files, cwd) {
|
|
1382
|
+
const root = projectRoot(cwd);
|
|
1383
|
+
/** @type {Record<string, Record<string, unknown>>} */
|
|
1384
|
+
const out = {};
|
|
1385
|
+
for (const item of compileHoldItems) {
|
|
1386
|
+
item.copy(false);
|
|
1387
|
+
const report = item.report();
|
|
1388
|
+
if (!report) continue;
|
|
1389
|
+
for (const file of files) {
|
|
1390
|
+
const abs = path.resolve(cwd, file);
|
|
1391
|
+
const own = editorThemeAt(root, abs);
|
|
1392
|
+
if (own?.slug === item.slug && editorOwnFile(own.slug, file))
|
|
1393
|
+
out[file] = report;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return out;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
889
1399
|
/**
|
|
890
1400
|
* Hold the theme lock of every editor theme among the files while
|
|
891
1401
|
* `compile` builds or checks them, so it never reads a change half
|
|
892
1402
|
* written. Resolves to the release.
|
|
893
1403
|
* @param {string[]} files
|
|
894
|
-
* @param {{cwd: string}} options
|
|
1404
|
+
* @param {{cwd: string, check?: boolean, out?: string}} options
|
|
895
1405
|
* @returns {Promise<() => Promise<void>>}
|
|
896
1406
|
*/
|
|
897
|
-
export async function editorThemeHold(files, {cwd}) {
|
|
1407
|
+
export async function editorThemeHold(files, {cwd, check = false, out}) {
|
|
898
1408
|
// Two compiles of one theme in one process: the second waits for the
|
|
899
1409
|
// lock like any other command.
|
|
900
1410
|
const cwdRoot = projectRoot(cwd);
|
|
@@ -903,13 +1413,24 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
903
1413
|
const at = editorThemeAt(cwdRoot, path.resolve(cwd, f));
|
|
904
1414
|
if (at && editorOwnFile(at.slug, f))
|
|
905
1415
|
found.set(`${at.root}\0${at.slug}`, at);
|
|
1416
|
+
// The app copy's source (src/themes/<t>/<t>Theme.ts) of an editor
|
|
1417
|
+
// theme: built under the theme's lock, so it never lands between a
|
|
1418
|
+
// change's two writes.
|
|
1419
|
+
const copy = appCopyTheme(cwdRoot, path.resolve(cwd, f));
|
|
1420
|
+
if (copy) found.set(`${copy.root}\0${copy.slug}`, copy);
|
|
906
1421
|
}
|
|
907
1422
|
const themes = [...found.keys()].sort().map(k => found.get(k));
|
|
908
|
-
/** @type {Array<() => Promise<void
|
|
1423
|
+
/** @type {Array<{root: string, slug: string, copy: (refused: boolean) => boolean, report: () => Record<string, unknown> | null, finish: (later: boolean) => Promise<void>}>} */
|
|
909
1424
|
const releases = [];
|
|
910
|
-
|
|
1425
|
+
compileHoldItems = releases;
|
|
1426
|
+
// Every theme's copy is written first, at once (a refusal ends the run
|
|
1427
|
+
// without waiting), then each lock goes.
|
|
1428
|
+
const releaseAll = async (refused = false) => {
|
|
911
1429
|
if (releaseCompileHold === releaseAll) releaseCompileHold = null;
|
|
912
|
-
|
|
1430
|
+
const items = releases.splice(0);
|
|
1431
|
+
const later = items.map(x => x.copy(refused));
|
|
1432
|
+
for (const [i, x] of [...items.entries()].reverse())
|
|
1433
|
+
await x.finish(later[i]);
|
|
913
1434
|
};
|
|
914
1435
|
releaseCompileHold = releaseAll;
|
|
915
1436
|
for (const {
|
|
@@ -927,6 +1448,25 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
927
1448
|
ready = r;
|
|
928
1449
|
});
|
|
929
1450
|
const key = `${root}\0${slug}`;
|
|
1451
|
+
// When the lock was taken, and the context a copy write needs (its
|
|
1452
|
+
// font stylesheets), ready before the build so the copy is written at
|
|
1453
|
+
// once when the run ends.
|
|
1454
|
+
const heldAt = Date.now() - 1;
|
|
1455
|
+
// An --out elsewhere builds neither themes/<theme>/ nor its copy.
|
|
1456
|
+
const skipped = outSkipsCopy(root, slug, cwd, {check, out});
|
|
1457
|
+
let ran = false;
|
|
1458
|
+
let copied = false;
|
|
1459
|
+
/** @type {string[] | null} */
|
|
1460
|
+
let firstWrite = null;
|
|
1461
|
+
/** @type {string | null} */
|
|
1462
|
+
let keptBack = null;
|
|
1463
|
+
/** @type {any} */
|
|
1464
|
+
let copyCtx = null;
|
|
1465
|
+
try {
|
|
1466
|
+
copyCtx = await context(root);
|
|
1467
|
+
} catch {
|
|
1468
|
+
copyCtx = null;
|
|
1469
|
+
}
|
|
930
1470
|
const done = withLock(root, lockName(slug), async () => {
|
|
931
1471
|
COMPILE_HELD.add(key);
|
|
932
1472
|
ready();
|
|
@@ -941,30 +1481,373 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
941
1481
|
await releaseAll();
|
|
942
1482
|
throw err;
|
|
943
1483
|
}
|
|
944
|
-
releases.push(
|
|
1484
|
+
releases.push({
|
|
945
1485
|
// A compile that wrote the build refreshes the app's copy too
|
|
946
|
-
// (src/themes/<theme>/), under the same lock; a check writes
|
|
947
|
-
|
|
1486
|
+
// (src/themes/<theme>/), under the same lock; a check writes
|
|
1487
|
+
// nothing. Each theme's copy follows its own build: a theme this run
|
|
1488
|
+
// built (its build now matches its settings) gets its copy, whatever
|
|
1489
|
+
// a later theme did; one that was refused or failed keeps its copy.
|
|
1490
|
+
// True when the copy still needs its font stylesheet from the
|
|
1491
|
+
// theme's settings (written in finish).
|
|
1492
|
+
root,
|
|
1493
|
+
slug,
|
|
1494
|
+
copy: (/** @type {boolean} */ refused) => {
|
|
1495
|
+
// Once per run: after the build's writes when the command asks
|
|
1496
|
+
// (its result then says what the copy write did), else at release.
|
|
1497
|
+
if (copied) return false;
|
|
1498
|
+
copied = true;
|
|
1499
|
+
ran = !refused && (process.exitCode ?? 0) === 0;
|
|
1500
|
+
if (check || skipped) return false;
|
|
1501
|
+
// This run built the theme: its module and stylesheet, one unit,
|
|
1502
|
+
// were written since the lock was taken, or the run ended well. A
|
|
1503
|
+
// refused or failed compile writes no copy.
|
|
1504
|
+
const f = themeFiles(root, slug);
|
|
1505
|
+
const written = [f.css, f.js].every(x => {
|
|
1506
|
+
try {
|
|
1507
|
+
return fs.statSync(x).mtimeMs >= heldAt;
|
|
1508
|
+
} catch {
|
|
1509
|
+
return false;
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
if (!written && (refused || (process.exitCode ?? 0) !== 0))
|
|
1513
|
+
return false;
|
|
948
1514
|
try {
|
|
949
|
-
|
|
950
|
-
//
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1515
|
+
// From what was just built, its font stylesheets from the fonts
|
|
1516
|
+
// the theme loads now.
|
|
1517
|
+
if (copyCtx) writeAppCopy(copyCtx, slug, loadTheme(root, slug));
|
|
1518
|
+
else writeAppCopyAt(root, slug, null);
|
|
1519
|
+
} catch {
|
|
1520
|
+
try {
|
|
1521
|
+
writeAppCopyAt(root, slug, null);
|
|
1522
|
+
} catch {
|
|
1523
|
+
// A theme that does not load keeps its copy as it was.
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
// What the write did, for the result and the text alike: the
|
|
1527
|
+
// files of a first write, or what keeps the copy behind.
|
|
1528
|
+
firstWrite = takeFirstAppCopy(root, slug);
|
|
1529
|
+
keptBack = appCopyStale(root, slug).appCopyStale ?? null;
|
|
1530
|
+
return false;
|
|
1531
|
+
},
|
|
1532
|
+
report: () =>
|
|
1533
|
+
firstWrite || keptBack
|
|
1534
|
+
? {
|
|
1535
|
+
...(firstWrite ? {appCopy: {wrote: firstWrite}} : {}),
|
|
1536
|
+
...(keptBack ? {appCopyStale: keptBack} : {}),
|
|
1537
|
+
}
|
|
1538
|
+
: null,
|
|
1539
|
+
finish: async () => {
|
|
1540
|
+
// Said only after a build or check that ran: a refused one wrote
|
|
1541
|
+
// and checked nothing.
|
|
1542
|
+
if (skipped) {
|
|
1543
|
+
if (ran) humanWarn(skipped);
|
|
1544
|
+
} else if (!check) {
|
|
1545
|
+
// The first write of the app copy is named once.
|
|
1546
|
+
if (firstWrite)
|
|
954
1547
|
humanWarn(
|
|
955
|
-
`wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${
|
|
1548
|
+
`wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${firstWrite.join(', ')}`,
|
|
956
1549
|
);
|
|
957
|
-
|
|
958
|
-
//
|
|
1550
|
+
// A copy a file or a link keeps behind, or one that could not be
|
|
1551
|
+
// written, is said, as set and show say it.
|
|
1552
|
+
if (keptBack) humanWarn(keptBack);
|
|
959
1553
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1554
|
+
release();
|
|
1555
|
+
await done;
|
|
1556
|
+
},
|
|
963
1557
|
});
|
|
964
1558
|
}
|
|
965
1559
|
return releaseAll;
|
|
966
1560
|
}
|
|
967
1561
|
|
|
1562
|
+
/**
|
|
1563
|
+
* For `compile` of an editor theme's own source: how the app takes the
|
|
1564
|
+
* theme, in place of importing the build's own outputs. The app takes its
|
|
1565
|
+
* app copy (src/themes/<t>/, written after every build, with the font
|
|
1566
|
+
* stylesheet that loads the theme's fonts), which `theme add` wires in.
|
|
1567
|
+
* Null for any other file.
|
|
1568
|
+
* @param {string} file the path as given
|
|
1569
|
+
* @param {string} cwd
|
|
1570
|
+
* @returns {string | null}
|
|
1571
|
+
*/
|
|
1572
|
+
export function editorInstall(file, cwd) {
|
|
1573
|
+
const root = projectRoot(cwd);
|
|
1574
|
+
const at = editorThemeAt(root, path.resolve(cwd, file));
|
|
1575
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
1576
|
+
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:
|
|
1577
|
+
|
|
1578
|
+
${runLine(root, `theme add ${at.slug}`)}`;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
/**
|
|
1582
|
+
* For `compile` of an editor theme's own source: how to load a family the
|
|
1583
|
+
* build names, as the editor says it (the app copy imports a family's
|
|
1584
|
+
* installed Fontsource package); null for any other file.
|
|
1585
|
+
* @param {string} file the path as given
|
|
1586
|
+
* @param {string} cwd
|
|
1587
|
+
* @returns {import('../theme/build/build.mjs').FontHelp | null}
|
|
1588
|
+
*/
|
|
1589
|
+
export function editorFontHelp(file, cwd) {
|
|
1590
|
+
const root = projectRoot(cwd);
|
|
1591
|
+
const at = editorThemeAt(root, path.resolve(cwd, file));
|
|
1592
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
1593
|
+
const copy = `src/themes/${at.slug}/${at.slug}.fonts.css`;
|
|
1594
|
+
return {
|
|
1595
|
+
notice: family =>
|
|
1596
|
+
`Font "${family}" is named by this theme but not loaded; if Fontsource publishes it, ${installLine(root, [fontsourcePackageOf(family)])} installs its package, which ${copy} then imports`,
|
|
1597
|
+
recipe:
|
|
1598
|
+
families => ` The built CSS only sets font-family. ${at.slug}'s app copy loads a family
|
|
1599
|
+
once its package is installed (if Fontsource publishes it), importing it in
|
|
1600
|
+
${copy} on the next compile, set or show:
|
|
1601
|
+
|
|
1602
|
+
${installLine(root, families.map(fontsourcePackageOf))}
|
|
1603
|
+
|
|
1604
|
+
Recipe and fallback-stack guidance: ${runLine(root, 'docs typography')}
|
|
1605
|
+
`,
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* For `compile`: the path an editor theme's own file builds under when it
|
|
1611
|
+
* was named through a link (its real path, which every output's header
|
|
1612
|
+
* names and `--check` compares); null for any other file.
|
|
1613
|
+
* @param {string} file the path as given
|
|
1614
|
+
* @param {string} cwd
|
|
1615
|
+
* @returns {string | null}
|
|
1616
|
+
*/
|
|
1617
|
+
export function editorSourcePath(file, cwd) {
|
|
1618
|
+
const abs = path.resolve(cwd, slashed(file));
|
|
1619
|
+
const realCwd = realLocation(cwd);
|
|
1620
|
+
const real = realLocation(abs);
|
|
1621
|
+
if (real === path.join(realCwd, path.relative(cwd, abs))) return null;
|
|
1622
|
+
const at = editorThemeAt(projectRoot(cwd), real);
|
|
1623
|
+
if (!at || !editorOwnFile(at.slug, real)) return null;
|
|
1624
|
+
return path.relative(realCwd, real) || null;
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
/** @param {string} p a path as typed, with Windows separators read as `/` */
|
|
1628
|
+
const slashed = p => String(p).replace(/\\/g, '/');
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* Whether --out names an editor theme's default output, where the build
|
|
1632
|
+
* writes without --out: its folder, or its stylesheet file there (the same
|
|
1633
|
+
* file, as the file system tells files apart: a name that differs only in
|
|
1634
|
+
* case is another file on a case-sensitive disk). A folder form (a
|
|
1635
|
+
* trailing slash) names a folder, so it is the default only as the theme's
|
|
1636
|
+
* folder. No --out counts.
|
|
1637
|
+
* @param {string} root the app root
|
|
1638
|
+
* @param {string} slug
|
|
1639
|
+
* @param {string} cwd
|
|
1640
|
+
* @param {string | undefined} out
|
|
1641
|
+
*/
|
|
1642
|
+
function outIsDefault(root, slug, cwd, out) {
|
|
1643
|
+
if (!out) return true;
|
|
1644
|
+
const typed = slashed(out);
|
|
1645
|
+
const at = path.resolve(cwd, typed);
|
|
1646
|
+
const f = themeFiles(root, slug);
|
|
1647
|
+
if (sameFile(at, f.dir)) return true;
|
|
1648
|
+
return !typed.endsWith('/') && sameFile(at, f.css);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
/**
|
|
1652
|
+
* Whether two paths name one file: the same file on disk when both are
|
|
1653
|
+
* there, else the same real path.
|
|
1654
|
+
* @param {string} a
|
|
1655
|
+
* @param {string} b
|
|
1656
|
+
*/
|
|
1657
|
+
function sameFile(a, b) {
|
|
1658
|
+
try {
|
|
1659
|
+
const x = fs.statSync(a);
|
|
1660
|
+
const y = fs.statSync(b);
|
|
1661
|
+
return x.dev === y.dev && x.ino === y.ino;
|
|
1662
|
+
} catch {
|
|
1663
|
+
return realLocation(a) === realLocation(b);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
/**
|
|
1668
|
+
* Why an editor theme's app copy was not written, or checked, by a build
|
|
1669
|
+
* with --out elsewhere; null without one.
|
|
1670
|
+
* @param {string} root
|
|
1671
|
+
* @param {string} slug
|
|
1672
|
+
* @param {string} cwd
|
|
1673
|
+
* @param {{check?: boolean, out?: string}} opts
|
|
1674
|
+
*/
|
|
1675
|
+
function outSkipsCopy(root, slug, cwd, {check, out}) {
|
|
1676
|
+
if (outIsDefault(root, slug, cwd, out)) return null;
|
|
1677
|
+
return check
|
|
1678
|
+
? `--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.`
|
|
1679
|
+
: `--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.`;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* Whether a file in an app copy folder is the editor's: its mark, or the
|
|
1684
|
+
* header the build writes. A missing file counts (it would be the copy's).
|
|
1685
|
+
* @param {string} file
|
|
1686
|
+
*/
|
|
1687
|
+
function isCopyFile(file) {
|
|
1688
|
+
try {
|
|
1689
|
+
const head = fs.readFileSync(file, 'utf8').slice(0, 600);
|
|
1690
|
+
return (
|
|
1691
|
+
head.includes(APP_COPY_MARK) ||
|
|
1692
|
+
/@generated by `astryx theme build`/.test(head)
|
|
1693
|
+
);
|
|
1694
|
+
} catch {
|
|
1695
|
+
return true;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
/**
|
|
1700
|
+
* The editor theme whose app copy source a file is
|
|
1701
|
+
* (`src/themes/<t>/<t>Theme.ts`, with themes/<t>/ an editor theme), or
|
|
1702
|
+
* null.
|
|
1703
|
+
* @param {string} root the project root
|
|
1704
|
+
* @param {string} file absolute
|
|
1705
|
+
* @returns {{root: string, slug: string} | null}
|
|
1706
|
+
*/
|
|
1707
|
+
function appCopyTheme(root, file) {
|
|
1708
|
+
const rel = path.relative(root, file).split(path.sep);
|
|
1709
|
+
if (rel.length !== 4 || rel[0] !== 'src' || rel[1] !== 'themes') return null;
|
|
1710
|
+
const slug = rel[2];
|
|
1711
|
+
if (rel[3] !== `${camel(slug)}Theme.ts`) return null;
|
|
1712
|
+
return fs.existsSync(themeFiles(root, slug).settings) ? {root, slug} : null;
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* For `compile` of an editor theme: `appCopyStale` for its result data when
|
|
1717
|
+
* the app copy is behind (the same line set and show give), or
|
|
1718
|
+
* `appCopySkipped` when --out builds elsewhere (neither themes/<theme>/ nor
|
|
1719
|
+
* the copy is written or checked); null for any other file or a current
|
|
1720
|
+
* copy.
|
|
1721
|
+
* @param {string} file the path as given
|
|
1722
|
+
* @param {string} cwd
|
|
1723
|
+
* @param {{check: boolean, upToDate?: boolean, out?: string, iconsSpecifier?: string}} opts
|
|
1724
|
+
* `upToDate`: the check's own verdict on the theme's outputs
|
|
1725
|
+
* @returns {Promise<Record<string, unknown> | null>}
|
|
1726
|
+
*/
|
|
1727
|
+
export async function editorBuildExtra(file, cwd, opts) {
|
|
1728
|
+
const root = projectRoot(cwd);
|
|
1729
|
+
const abs = path.resolve(cwd, file);
|
|
1730
|
+
const own = editorThemeAt(root, abs);
|
|
1731
|
+
const slug =
|
|
1732
|
+
appCopyTheme(root, abs)?.slug ??
|
|
1733
|
+
(own && editorOwnFile(own.slug, file) ? own.slug : null);
|
|
1734
|
+
if (!slug) return null;
|
|
1735
|
+
{
|
|
1736
|
+
const skipped = outSkipsCopy(root, slug, cwd, opts);
|
|
1737
|
+
if (skipped) return {appCopySkipped: skipped};
|
|
1738
|
+
}
|
|
1739
|
+
if (!opts.check) {
|
|
1740
|
+
// Every set and show builds the theme again from its source, without
|
|
1741
|
+
// --icons-specifier: said, with the change that keeps it.
|
|
1742
|
+
const warnings = opts.iconsSpecifier
|
|
1743
|
+
? [
|
|
1744
|
+
`${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.`,
|
|
1745
|
+
]
|
|
1746
|
+
: [];
|
|
1747
|
+
// What show says of the source's own type on phones, said by the
|
|
1748
|
+
// compile that builds the app copy from it too.
|
|
1749
|
+
/** @type {string[]} */
|
|
1750
|
+
let notices;
|
|
1751
|
+
try {
|
|
1752
|
+
notices = edit.ownPhoneNotes(root, slug, loadTheme(root, slug));
|
|
1753
|
+
} catch {
|
|
1754
|
+
notices = [];
|
|
1755
|
+
}
|
|
1756
|
+
if (warnings.length || notices.length)
|
|
1757
|
+
return {
|
|
1758
|
+
...(warnings.length ? {warnings} : {}),
|
|
1759
|
+
...(notices.length ? {notices} : {}),
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
if (opts.check) {
|
|
1763
|
+
// A theme output that is stale is the check's own finding (it names
|
|
1764
|
+
// the file); the copy is compared only with a current build.
|
|
1765
|
+
if (opts.upToDate === false) return null;
|
|
1766
|
+
/** @type {string[] | null} */
|
|
1767
|
+
let fonts;
|
|
1768
|
+
try {
|
|
1769
|
+
fonts = copyFontsCss(await context(root), slug, loadTheme(root, slug));
|
|
1770
|
+
} catch {
|
|
1771
|
+
fonts = null;
|
|
1772
|
+
}
|
|
1773
|
+
const behind = appCopyBehind(root, slug, fonts);
|
|
1774
|
+
return behind
|
|
1775
|
+
? {
|
|
1776
|
+
upToDate: false,
|
|
1777
|
+
code: 'ERR_THEME_STALE',
|
|
1778
|
+
// Something of yours in the way: its own line says what to move;
|
|
1779
|
+
// no editor command writes over it.
|
|
1780
|
+
appCopyStale: appCopyStale(root, slug).appCopyStale
|
|
1781
|
+
? `${slug}'s app copy in src/themes/${slug}/ is not up to date: ${behind}`
|
|
1782
|
+
: `${slug}'s app copy in src/themes/${slug}/ is not up to date: ${behind}. ${runLine(root, `experimental theme editor show ${slug}`)} writes it again`,
|
|
1783
|
+
}
|
|
1784
|
+
: null;
|
|
1785
|
+
}
|
|
1786
|
+
// A build's copy write is reported once it has run (editorAfterBuild).
|
|
1787
|
+
return null;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
/**
|
|
1791
|
+
* For `compile` of an editor theme's own source (themes/<t>/<t>.theme.ts):
|
|
1792
|
+
* the one color mode a light-only or dark-only theme has, which its source
|
|
1793
|
+
* cannot say, for the build to write into the built module. Null for any
|
|
1794
|
+
* other file (the app copy's source re-exports it from its build).
|
|
1795
|
+
* @param {string} file the path as given
|
|
1796
|
+
* @param {string} cwd
|
|
1797
|
+
* @returns {['light'] | ['dark'] | null}
|
|
1798
|
+
*/
|
|
1799
|
+
export function editorColorModes(file, cwd) {
|
|
1800
|
+
const root = projectRoot(cwd);
|
|
1801
|
+
const at = editorThemeAt(root, path.resolve(cwd, file));
|
|
1802
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
1803
|
+
return buildColorModes(at.root, at.slug);
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
/**
|
|
1807
|
+
* For `compile` of an editor theme (themes/<t>/ or its app copy's source):
|
|
1808
|
+
* whether a font family is loaded by the app copy's font stylesheet as
|
|
1809
|
+
* this compile writes it (src/themes/<t>/<t>.fonts.css, from the fonts the
|
|
1810
|
+
* theme loads now: an @fontsource package by its name, a stylesheet by the
|
|
1811
|
+
* `family=` it requests), so the build's "named but not loaded" notice
|
|
1812
|
+
* leaves it out. Null for any other file.
|
|
1813
|
+
* @param {string} file the path as given
|
|
1814
|
+
* @param {string} cwd
|
|
1815
|
+
* @returns {Promise<((family: string) => boolean) | null>}
|
|
1816
|
+
*/
|
|
1817
|
+
export async function editorLoadedFonts(file, cwd) {
|
|
1818
|
+
const root = projectRoot(cwd);
|
|
1819
|
+
const abs = path.resolve(cwd, file);
|
|
1820
|
+
const slug =
|
|
1821
|
+
appCopyTheme(root, abs)?.slug ??
|
|
1822
|
+
(editorThemeAt(root, abs) &&
|
|
1823
|
+
editorOwnFile(editorThemeAt(root, abs)?.slug ?? '', file)
|
|
1824
|
+
? editorThemeAt(root, abs)?.slug
|
|
1825
|
+
: null);
|
|
1826
|
+
if (!slug) return null;
|
|
1827
|
+
// The stylesheets the copy's font file imports once this compile has
|
|
1828
|
+
// written it: from the fonts the theme loads now, as the copy write
|
|
1829
|
+
// computes them.
|
|
1830
|
+
/** @type {string[]} */
|
|
1831
|
+
let specs;
|
|
1832
|
+
try {
|
|
1833
|
+
specs = copyFontsCss(await context(root), slug, loadTheme(root, slug));
|
|
1834
|
+
} catch {
|
|
1835
|
+
return null;
|
|
1836
|
+
}
|
|
1837
|
+
const copyDir = path.join(root, 'src', 'themes', slug);
|
|
1838
|
+
const from = fs.existsSync(copyDir) ? copyDir : root;
|
|
1839
|
+
/** @type {Set<string>} */
|
|
1840
|
+
const loaded = new Set();
|
|
1841
|
+
for (const spec of specs)
|
|
1842
|
+
for (const f of importedFontFamilies(spec, from)) loaded.add(f);
|
|
1843
|
+
// A family the build names whose @fontsource package is installed: the
|
|
1844
|
+
// copy written after this build imports that package (copyFontsCss).
|
|
1845
|
+
/** @param {string} family */
|
|
1846
|
+
const installed = family =>
|
|
1847
|
+
packageInstalled(root, fontsourcePackageOf(family));
|
|
1848
|
+
return family => loaded.has(fontKey(family)) || installed(family);
|
|
1849
|
+
}
|
|
1850
|
+
|
|
968
1851
|
/**
|
|
969
1852
|
* For `compile` of a file that is not there: when it is an editor theme's
|
|
970
1853
|
* own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
|
|
@@ -974,6 +1857,37 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
974
1857
|
* @returns {{name: string, reason: string} | null}
|
|
975
1858
|
*/
|
|
976
1859
|
export function editorMissingSource(file, cwd) {
|
|
1860
|
+
// The app copy's source of an editor theme, its folder gone: the editor
|
|
1861
|
+
// writes it again.
|
|
1862
|
+
const copy = appCopyTheme(projectRoot(cwd), path.resolve(cwd, slashed(file)));
|
|
1863
|
+
if (copy)
|
|
1864
|
+
// A copy file named with Windows separators: the theme is what
|
|
1865
|
+
// compiles (the copy follows); with the copy gone, show writes it.
|
|
1866
|
+
return fs.existsSync(path.join(copy.root, 'src', 'themes', copy.slug))
|
|
1867
|
+
? {
|
|
1868
|
+
name: runLine(
|
|
1869
|
+
cwd,
|
|
1870
|
+
`experimental theme compile ${
|
|
1871
|
+
path
|
|
1872
|
+
.relative(
|
|
1873
|
+
cwd,
|
|
1874
|
+
path.join(
|
|
1875
|
+
copy.root,
|
|
1876
|
+
'themes',
|
|
1877
|
+
copy.slug,
|
|
1878
|
+
`${copy.slug}.theme.ts`,
|
|
1879
|
+
),
|
|
1880
|
+
)
|
|
1881
|
+
.split(path.sep)
|
|
1882
|
+
.join('/') || `themes/${copy.slug}/${copy.slug}.theme.ts`
|
|
1883
|
+
}`,
|
|
1884
|
+
),
|
|
1885
|
+
reason: `${copy.slug}'s app copy follows every compile of the theme`,
|
|
1886
|
+
}
|
|
1887
|
+
: {
|
|
1888
|
+
name: runLine(cwd, `experimental theme editor show ${copy.slug}`),
|
|
1889
|
+
reason: `the editor writes ${copy.slug}'s app copy in src/themes/${copy.slug}/ again`,
|
|
1890
|
+
};
|
|
977
1891
|
const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
|
|
978
1892
|
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
979
1893
|
return {
|