@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
|
@@ -15,13 +15,17 @@
|
|
|
15
15
|
import {createHash} from 'node:crypto';
|
|
16
16
|
import * as fs from 'node:fs';
|
|
17
17
|
import * as path from 'node:path';
|
|
18
|
-
import {
|
|
19
|
-
import
|
|
18
|
+
import {spawn} from 'node:child_process';
|
|
19
|
+
import * as os from 'node:os';
|
|
20
|
+
import {fileURLToPath} from 'node:url';
|
|
20
21
|
import {
|
|
21
22
|
SAMPLE_PAGE,
|
|
22
23
|
SHEET_ORDER,
|
|
23
24
|
elementNames,
|
|
24
25
|
pageSource,
|
|
26
|
+
bindingFrom,
|
|
27
|
+
SAMPLE_SEARCH_ITEMS,
|
|
28
|
+
SAMPLE_SOURCE,
|
|
25
29
|
} from './_catalog.mjs';
|
|
26
30
|
import {
|
|
27
31
|
catalogVariants,
|
|
@@ -32,21 +36,31 @@ import {
|
|
|
32
36
|
} from './_parts.mjs';
|
|
33
37
|
import {OVERVIEW_SECTIONS} from './_overview.mjs';
|
|
34
38
|
import {
|
|
35
|
-
FOLDER_JUNK,
|
|
36
|
-
folderIsEmpty,
|
|
37
39
|
camel,
|
|
40
|
+
folderIsEmpty,
|
|
41
|
+
builtFontWeights,
|
|
38
42
|
fontPackages,
|
|
39
43
|
modesOf,
|
|
40
|
-
themeFiles,
|
|
41
44
|
shown,
|
|
45
|
+
themeFiles,
|
|
46
|
+
APP_COPY_BUILT,
|
|
47
|
+
appCopyNames,
|
|
42
48
|
} from './_settings.mjs';
|
|
43
49
|
import {writeWhole} from './_palette.mjs';
|
|
44
50
|
import {cliVersion} from '../../foundation/release/run-context.mjs';
|
|
45
51
|
import {importPathOf, installLine} from './_project.mjs';
|
|
46
|
-
import {
|
|
52
|
+
import {
|
|
53
|
+
COLOR_PROP_PARTS,
|
|
54
|
+
DIRECT,
|
|
55
|
+
P,
|
|
56
|
+
SHOWCASE_GROUPS,
|
|
57
|
+
wordTable,
|
|
58
|
+
} from './_tables.mjs';
|
|
47
59
|
import {extractImportedPackages} from '../../foundation/discovery/template-needs.mjs';
|
|
48
60
|
import {findNodeModulesPackage} from '../../foundation/fs/paths.mjs';
|
|
61
|
+
import {themeFileImports} from '../../foundation/discovery/theme-discovery.mjs';
|
|
49
62
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
63
|
+
import {compareText} from '../../foundation/text/compare-text.mjs';
|
|
50
64
|
|
|
51
65
|
const TEMPLATES_DIR = path.resolve(
|
|
52
66
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
@@ -54,17 +68,14 @@ const TEMPLATES_DIR = path.resolve(
|
|
|
54
68
|
);
|
|
55
69
|
|
|
56
70
|
/** The groups of the theme-building page, in order. */
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'overlays',
|
|
66
|
-
'pages',
|
|
67
|
-
];
|
|
71
|
+
export {SHOWCASE_GROUPS};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Packages whose output is drawn in the browser once the page runs (a
|
|
75
|
+
* recharts chart measures and draws itself after it mounts): a server
|
|
76
|
+
* render, which the sheet is, has none of it.
|
|
77
|
+
*/
|
|
78
|
+
const DRAWN_IN_BROWSER = Object.freeze(['recharts']);
|
|
68
79
|
|
|
69
80
|
/** Real template pages the theme-building page shows in full. */
|
|
70
81
|
const PAGE_TEMPLATES = ['dashboard', 'contact-form', 'settings'];
|
|
@@ -72,6 +83,9 @@ const PAGE_TEMPLATES = ['dashboard', 'contact-form', 'settings'];
|
|
|
72
83
|
const SELECTION =
|
|
73
84
|
/Select|Checkbox|Radio|Switch|Segmented|Toggle|Slider|Typeahead|Tokenizer/;
|
|
74
85
|
|
|
86
|
+
/** Props a doc names that open a part's own menu or list. */
|
|
87
|
+
const OPENERS = ['isMenuOpen', 'isDefaultOpen'];
|
|
88
|
+
|
|
75
89
|
/**
|
|
76
90
|
* The group a component belongs to on the theme-building page.
|
|
77
91
|
* @param {string} name
|
|
@@ -98,7 +112,7 @@ function groupOf(name, category) {
|
|
|
98
112
|
* whose packages the project has.
|
|
99
113
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
100
114
|
* @param {string | undefined} group only this group
|
|
101
|
-
* @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string,
|
|
115
|
+
* @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string, import('./_catalog.mjs').Binding>, skipped: string[], notes: string[]}}
|
|
102
116
|
*/
|
|
103
117
|
export function showcaseItems(project, group) {
|
|
104
118
|
/** @type {import('./_catalog.mjs').CatalogItem[]} */
|
|
@@ -117,13 +131,44 @@ export function showcaseItems(project, group) {
|
|
|
117
131
|
if (!g) continue;
|
|
118
132
|
const inParent = inParentOf(project, name);
|
|
119
133
|
if (inParent === null) continue;
|
|
120
|
-
|
|
134
|
+
// A component no Core module exports by its name cannot be imported,
|
|
135
|
+
// so it would draw an empty cell: it gets none.
|
|
136
|
+
if (!importPathOf(project, name)) continue;
|
|
137
|
+
const info = project.components[name];
|
|
138
|
+
catalogVariants(project, name, 12, {shown: true}).forEach((v, i) =>
|
|
121
139
|
items.push({
|
|
122
140
|
group: g,
|
|
123
141
|
name,
|
|
124
142
|
label: v.label,
|
|
125
143
|
tree: inParent({__element: name, props: v.props}),
|
|
126
|
-
|
|
144
|
+
// An overlay shown open is drawn open: Core places a popover,
|
|
145
|
+
// tooltip or hover card only once it is mounted. Any other part, as
|
|
146
|
+
// first shown, is shown open with the overlays too when a press
|
|
147
|
+
// opens one from it (the page sees which: _catalog.mjs).
|
|
148
|
+
...(info?.opens
|
|
149
|
+
? {open: true}
|
|
150
|
+
: i === 0 && g !== 'overlays'
|
|
151
|
+
? {
|
|
152
|
+
openable: true,
|
|
153
|
+
// A prop its doc names that opens it opens it; else the
|
|
154
|
+
// drawing's press does.
|
|
155
|
+
...(OPENERS.some(p => info?.props?.[p])
|
|
156
|
+
? {
|
|
157
|
+
openTree: inParent({
|
|
158
|
+
__element: name,
|
|
159
|
+
props: {
|
|
160
|
+
...v.props,
|
|
161
|
+
[/** @type {string} */ (
|
|
162
|
+
OPENERS.find(p => info?.props?.[p])
|
|
163
|
+
)]: true,
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
}
|
|
167
|
+
: {}),
|
|
168
|
+
}
|
|
169
|
+
: {}),
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
127
172
|
}
|
|
128
173
|
items.push({
|
|
129
174
|
group: 'pages',
|
|
@@ -133,7 +178,9 @@ export function showcaseItems(project, group) {
|
|
|
133
178
|
});
|
|
134
179
|
/** @type {string[]} */
|
|
135
180
|
const skipped = [];
|
|
136
|
-
/** @type {
|
|
181
|
+
/** What a page in the sheet cannot show, said in the result. @type {string[]} */
|
|
182
|
+
const notes = [];
|
|
183
|
+
/** @type {Record<string, import('./_catalog.mjs').Binding>} */
|
|
137
184
|
const templateImports = {};
|
|
138
185
|
for (const t of PAGE_TEMPLATES) {
|
|
139
186
|
const file = path.join(TEMPLATES_DIR, t, 'page.tsx');
|
|
@@ -148,8 +195,16 @@ export function showcaseItems(project, group) {
|
|
|
148
195
|
);
|
|
149
196
|
continue;
|
|
150
197
|
}
|
|
198
|
+
const drawn = [...extractImportedPackages(src)].filter(pkg =>
|
|
199
|
+
DRAWN_IN_BROWSER.includes(pkg),
|
|
200
|
+
);
|
|
201
|
+
if (drawn.length && (!group || group === 'pages'))
|
|
202
|
+
notes.push(
|
|
203
|
+
`the ${t} page's charts are drawn in the browser (${drawn.join(', ')}), so sheet.html and its pictures show the page with their space empty; the in-app preview draws them (astryx experimental theme preview add --template ${t})`,
|
|
204
|
+
);
|
|
151
205
|
const local = `Template_${t.replace(/-/g, '_')}`;
|
|
152
|
-
|
|
206
|
+
// A template page is its file's default export.
|
|
207
|
+
templateImports[local] = {from: `./templates/${t}.tsx`, export: 'default'};
|
|
153
208
|
items.push({
|
|
154
209
|
group: 'pages',
|
|
155
210
|
name: `${t} template`,
|
|
@@ -161,10 +216,18 @@ export function showcaseItems(project, group) {
|
|
|
161
216
|
const i = SHEET_ORDER.indexOf(it.name);
|
|
162
217
|
return SHOWCASE_GROUPS.indexOf(it.group ?? '') * 1000 + (i < 0 ? 500 : i);
|
|
163
218
|
};
|
|
219
|
+
// The overlays section also shows open each part another section holds
|
|
220
|
+
// that opens one (a dropdown's menu), and only open.
|
|
164
221
|
const chosen = items
|
|
165
|
-
.
|
|
166
|
-
|
|
167
|
-
|
|
222
|
+
.flatMap(it =>
|
|
223
|
+
!group || it.group === group
|
|
224
|
+
? [it]
|
|
225
|
+
: group === 'overlays' && it.openable
|
|
226
|
+
? [{...it, onlyOpen: true}]
|
|
227
|
+
: [],
|
|
228
|
+
)
|
|
229
|
+
.sort((a, b) => order(a) - order(b) || compareText(a.name, b.name));
|
|
230
|
+
/** @type {Record<string, import('./_catalog.mjs').Binding>} */
|
|
168
231
|
const imports = {};
|
|
169
232
|
for (const n of elementNames(chosen.map(i => i.tree))) {
|
|
170
233
|
if (templateImports[n]) {
|
|
@@ -178,6 +241,7 @@ export function showcaseItems(project, group) {
|
|
|
178
241
|
items: chosen,
|
|
179
242
|
imports,
|
|
180
243
|
skipped: !group || group === 'pages' ? skipped : [],
|
|
244
|
+
notes,
|
|
181
245
|
};
|
|
182
246
|
}
|
|
183
247
|
|
|
@@ -226,12 +290,12 @@ function inParentOf(project, name) {
|
|
|
226
290
|
|
|
227
291
|
/**
|
|
228
292
|
* Template page modules the theme-building page imports, copied beside it.
|
|
229
|
-
* @param {Record<string,
|
|
293
|
+
* @param {Record<string, import('./_catalog.mjs').Binding>} imports
|
|
230
294
|
* @returns {Array<{name: string, from: string}>}
|
|
231
295
|
*/
|
|
232
296
|
function templateFiles(imports) {
|
|
233
|
-
return Object.values(imports).flatMap(
|
|
234
|
-
const m = /^\.\/templates\/([a-z0-9-]+)\.tsx$/.exec(
|
|
297
|
+
return Object.values(imports).flatMap(b => {
|
|
298
|
+
const m = /^\.\/templates\/([a-z0-9-]+)\.tsx$/.exec(bindingFrom(b));
|
|
235
299
|
return m
|
|
236
300
|
? [
|
|
237
301
|
{
|
|
@@ -254,7 +318,23 @@ function templateFiles(imports) {
|
|
|
254
318
|
* @returns {string[]}
|
|
255
319
|
*/
|
|
256
320
|
export function baseFontsCss(ctx, data) {
|
|
257
|
-
|
|
321
|
+
const sheet = baseFontsSheet(ctx, data);
|
|
322
|
+
return sheet ? [sheet.spec] : [];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The base theme's fonts stylesheet as {@link baseFontsCss} imports it: its
|
|
327
|
+
* import spec, the families it loads, and the remote stylesheets it loads
|
|
328
|
+
* them from (a Google Fonts `@import`), which a static page cannot load.
|
|
329
|
+
* Null when the base ships none or the build names none of its families.
|
|
330
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
331
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
332
|
+
* With the weights it loads of each family (`weights`, by family; none
|
|
333
|
+
* for a family whose weights it does not say, such as a variable face).
|
|
334
|
+
* @returns {{spec: string, families: string[], remote: string[], weights: Map<string, number[]>} | null}
|
|
335
|
+
*/
|
|
336
|
+
export function baseFontsSheet(ctx, data) {
|
|
337
|
+
if (!data.like) return null;
|
|
258
338
|
const pkg = `@astryxdesign/theme-${data.like}`;
|
|
259
339
|
const sheet = `${pkg}/fonts.css`;
|
|
260
340
|
// Read off disk: the package must export the sheet for an app to import
|
|
@@ -263,7 +343,7 @@ export function baseFontsCss(ctx, data) {
|
|
|
263
343
|
/** @type {string} */
|
|
264
344
|
let text;
|
|
265
345
|
try {
|
|
266
|
-
if (!found) return
|
|
346
|
+
if (!found) return null;
|
|
267
347
|
const exportsMap = JSON.parse(
|
|
268
348
|
fs.readFileSync(path.join(found.packageDir, 'package.json'), 'utf8'),
|
|
269
349
|
).exports;
|
|
@@ -272,10 +352,10 @@ export function baseFontsCss(ctx, data) {
|
|
|
272
352
|
typeof exportsMap !== 'object' ||
|
|
273
353
|
!('./fonts.css' in exportsMap)
|
|
274
354
|
)
|
|
275
|
-
return
|
|
355
|
+
return null;
|
|
276
356
|
text = fs.readFileSync(path.join(found.packageDir, 'fonts.css'), 'utf8');
|
|
277
357
|
} catch {
|
|
278
|
-
return
|
|
358
|
+
return null;
|
|
279
359
|
}
|
|
280
360
|
// The families the sheet loads; with the theme's build at hand, the sheet
|
|
281
361
|
// is imported only while the build still names one of them.
|
|
@@ -291,9 +371,101 @@ export function baseFontsCss(ctx, data) {
|
|
|
291
371
|
}
|
|
292
372
|
if (built != null && families.length) {
|
|
293
373
|
const css = built;
|
|
294
|
-
if (!families.some(f => css.includes(f))) return
|
|
374
|
+
if (!families.some(f => css.includes(f))) return null;
|
|
375
|
+
}
|
|
376
|
+
const remote = [
|
|
377
|
+
...text.matchAll(
|
|
378
|
+
/@import\s+(?:url\(\s*)?["']?((?:[a-z]+:)?\/\/[^"')\s]+)/gi,
|
|
379
|
+
),
|
|
380
|
+
].map(m => m[1]);
|
|
381
|
+
// The weights a font service request names: its axes (`wght`,
|
|
382
|
+
// `ital,wght`, `opsz,wght`) and one tuple of values per face
|
|
383
|
+
// (`Figtree:wght@400;500`, `Fraunces:opsz,wght@9..144,400`), the weight
|
|
384
|
+
// at the wght axis's place in each tuple.
|
|
385
|
+
/** @type {Map<string, number[]>} */
|
|
386
|
+
const weights = new Map();
|
|
387
|
+
for (const m of text.matchAll(/family=([^:&'")]+):([a-z,]+)@([0-9;,.]+)/gi)) {
|
|
388
|
+
const family = decodeURIComponent(m[1].replace(/\+/g, ' '));
|
|
389
|
+
const at = m[2].toLowerCase().split(',').indexOf('wght');
|
|
390
|
+
if (at < 0) continue;
|
|
391
|
+
const values = m[3].split(';').map(t => t.split(',')[at] ?? '');
|
|
392
|
+
// A range (`100..900`) is a variable face: every weight in it.
|
|
393
|
+
if (values.some(v => v.includes('..'))) continue;
|
|
394
|
+
const list = values.map(Number).filter(n => Number.isInteger(n));
|
|
395
|
+
if (list.length)
|
|
396
|
+
weights.set(
|
|
397
|
+
family,
|
|
398
|
+
[...new Set(list)].sort((a, b) => a - b),
|
|
399
|
+
);
|
|
295
400
|
}
|
|
296
|
-
return
|
|
401
|
+
return {spec: sheet, families, remote, weights};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* The stylesheets of an installed font package that load the theme's
|
|
406
|
+
* fonts in every weight it uses: a variable package's one stylesheet
|
|
407
|
+
* (every weight); for a package with a stylesheet per weight, as
|
|
408
|
+
* Fontsource ships them, each weight the theme's build uses that the
|
|
409
|
+
* package has; else its index stylesheet.
|
|
410
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
411
|
+
* @param {string} slug
|
|
412
|
+
* @param {string} pkg
|
|
413
|
+
* @returns {string[]}
|
|
414
|
+
*/
|
|
415
|
+
export function fontPackageSheets(ctx, slug, pkg) {
|
|
416
|
+
const index = `${pkg}/index.css`;
|
|
417
|
+
const faces = fontPackageWeights(ctx, pkg);
|
|
418
|
+
if (!faces?.length) return [index];
|
|
419
|
+
// Each weight the theme uses loads the face CSS font matching shows for
|
|
420
|
+
// it (550 shows the 600 face), once.
|
|
421
|
+
const shown = new Set(
|
|
422
|
+
(builtFontWeights(ctx, slug) ?? [400]).map(w => shownWeight(w, faces)),
|
|
423
|
+
);
|
|
424
|
+
return faces.filter(w => shown.has(w)).map(w => `${pkg}/${w}.css`);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The weights an installed font package has a stylesheet of its own for
|
|
429
|
+
* (`@fontsource/lobster/400.css`), as Fontsource ships a static family;
|
|
430
|
+
* null for a variable package or one with no stylesheet per weight, which
|
|
431
|
+
* loads every weight it has from its index stylesheet.
|
|
432
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
433
|
+
* @param {string} pkg
|
|
434
|
+
* @returns {number[] | null}
|
|
435
|
+
*/
|
|
436
|
+
export function fontPackageWeights(ctx, pkg) {
|
|
437
|
+
if (pkg.startsWith('@fontsource-variable/')) return null;
|
|
438
|
+
const faces = [100, 200, 300, 400, 500, 600, 700, 800, 900].filter(w => {
|
|
439
|
+
try {
|
|
440
|
+
ctx.project.req.resolve(`${pkg}/${w}.css`);
|
|
441
|
+
return true;
|
|
442
|
+
} catch {
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
return faces.length ? faces : null;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* The face a browser shows for a font weight among the weights a family
|
|
451
|
+
* loads, by CSS font matching: from 400 to 500, the weights up to 500
|
|
452
|
+
* first, then lighter, then heavier; below 400, lighter first; above 500,
|
|
453
|
+
* heavier first.
|
|
454
|
+
* @param {number} weight
|
|
455
|
+
* @param {number[]} faces
|
|
456
|
+
* @returns {number}
|
|
457
|
+
*/
|
|
458
|
+
export function shownWeight(weight, faces) {
|
|
459
|
+
if (faces.includes(weight)) return weight;
|
|
460
|
+
const up = faces.filter(w => w > weight).sort((a, b) => a - b);
|
|
461
|
+
const down = faces.filter(w => w < weight).sort((a, b) => b - a);
|
|
462
|
+
const order =
|
|
463
|
+
weight >= 400 && weight <= 500
|
|
464
|
+
? [...up.filter(w => w <= 500), ...down, ...up.filter(w => w > 500)]
|
|
465
|
+
: weight < 400
|
|
466
|
+
? [...down, ...up]
|
|
467
|
+
: [...up, ...down];
|
|
468
|
+
return order[0] ?? weight;
|
|
297
469
|
}
|
|
298
470
|
|
|
299
471
|
/**
|
|
@@ -314,7 +486,7 @@ export function themeImports(ctx, slug, data, fromDir) {
|
|
|
314
486
|
const modes = modesOf(data);
|
|
315
487
|
const fonts = fontPackages(ctx, data)
|
|
316
488
|
.filter(x => x.installed)
|
|
317
|
-
.
|
|
489
|
+
.flatMap(x => fontPackageSheets(ctx, slug, x.pkg));
|
|
318
490
|
return {
|
|
319
491
|
module: rel(f.js),
|
|
320
492
|
css: [rel(f.css), ...baseFontsCss(ctx, data), ...fonts],
|
|
@@ -538,11 +710,14 @@ export async function renderPreview(ctx, slug, data) {
|
|
|
538
710
|
* @param {string} slug
|
|
539
711
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
540
712
|
* @param {{group?: string, out?: string}} [options]
|
|
541
|
-
* @returns {Promise<{file: string, components: number, skipped: string[]}>}
|
|
713
|
+
* @returns {Promise<{file: string, components: number, skipped: string[], notes: string[]}>} `notes`: what a page in the sheet cannot show
|
|
542
714
|
*/
|
|
543
715
|
export async function renderSheet(ctx, slug, data, options = {}) {
|
|
544
716
|
const {project} = ctx;
|
|
545
|
-
const {items, imports, skipped} = showcaseItems(
|
|
717
|
+
const {items, imports, skipped, notes} = showcaseItems(
|
|
718
|
+
project,
|
|
719
|
+
options.group,
|
|
720
|
+
);
|
|
546
721
|
const source = pageSource({
|
|
547
722
|
items,
|
|
548
723
|
imports,
|
|
@@ -562,6 +737,7 @@ export async function renderSheet(ctx, slug, data, options = {}) {
|
|
|
562
737
|
file: shown(project.cwd, out),
|
|
563
738
|
components: new Set(items.map(i => i.name)).size,
|
|
564
739
|
skipped,
|
|
740
|
+
notes,
|
|
565
741
|
};
|
|
566
742
|
// Rendered from the same inputs before: the sheet is as it would be.
|
|
567
743
|
if (renderedFrom(out, key)) return result;
|
|
@@ -578,6 +754,7 @@ export async function renderSheet(ctx, slug, data, options = {}) {
|
|
|
578
754
|
file: shown(project.cwd, out),
|
|
579
755
|
components: new Set(items.map(i => i.name)).size,
|
|
580
756
|
skipped,
|
|
757
|
+
notes,
|
|
581
758
|
};
|
|
582
759
|
}
|
|
583
760
|
|
|
@@ -741,12 +918,11 @@ const SAFE = [
|
|
|
741
918
|
];
|
|
742
919
|
|
|
743
920
|
/** The search source the page hands a part that needs one: a few fixed items. */
|
|
744
|
-
const
|
|
921
|
+
const SAMPLE_SOURCE_LINES = [
|
|
745
922
|
'const SAMPLE_ITEMS = [',
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
" {id: 'marketing', label: 'Marketing'},",
|
|
923
|
+
...SAMPLE_SEARCH_ITEMS.map(
|
|
924
|
+
i => ` {id: ${JSON.stringify(i.id)}, label: ${JSON.stringify(i.label)}},`,
|
|
925
|
+
),
|
|
750
926
|
'];',
|
|
751
927
|
'const SAMPLE_SOURCE = {',
|
|
752
928
|
' search: (query: string) => SAMPLE_ITEMS.filter(item => item.label.toLowerCase().includes(query.toLowerCase())),',
|
|
@@ -777,7 +953,7 @@ function withSources(project, v) {
|
|
|
777
953
|
project.components[v.__element]?.props ?? {},
|
|
778
954
|
))
|
|
779
955
|
if (p.required && p.type.startsWith('SearchSource') && !(k in props))
|
|
780
|
-
props[k] =
|
|
956
|
+
props[k] = SAMPLE_SOURCE;
|
|
781
957
|
return {
|
|
782
958
|
...v,
|
|
783
959
|
props,
|
|
@@ -832,7 +1008,7 @@ function withHandlers(v) {
|
|
|
832
1008
|
*/
|
|
833
1009
|
const usesSource = v =>
|
|
834
1010
|
isCode(v)
|
|
835
|
-
? v.__code ===
|
|
1011
|
+
? v.__code === SAMPLE_SOURCE.__code
|
|
836
1012
|
: Boolean(v && typeof v === 'object') &&
|
|
837
1013
|
Object.values(/** @type {object} */ (v)).some(usesSource);
|
|
838
1014
|
|
|
@@ -990,7 +1166,7 @@ function componentsPage(project, {theme = null, C}) {
|
|
|
990
1166
|
'',
|
|
991
1167
|
...CELL,
|
|
992
1168
|
'',
|
|
993
|
-
...(usesSource(items) ? [...
|
|
1169
|
+
...(usesSource(items) ? [...SAMPLE_SOURCE_LINES, ''] : []),
|
|
994
1170
|
'export default function ComponentsPage() {',
|
|
995
1171
|
' return (',
|
|
996
1172
|
' <div>',
|
|
@@ -1303,7 +1479,9 @@ export function previewRouteSource({
|
|
|
1303
1479
|
' <AppShell',
|
|
1304
1480
|
' height="fill"',
|
|
1305
1481
|
' topNav={',
|
|
1306
|
-
|
|
1482
|
+
// Core's own heading, as an app's top bar draws it, so a setting on the
|
|
1483
|
+
// header (its text color) shows here as it does in the app.
|
|
1484
|
+
` <TopNav label="Theme preview" heading={<TopNavHeading heading={${JSON.stringify(name)}} />} endContent={`,
|
|
1307
1485
|
...(mode.length ? mode : [' null']),
|
|
1308
1486
|
' } />',
|
|
1309
1487
|
' }',
|
|
@@ -1328,7 +1506,7 @@ export function previewRouteSource({
|
|
|
1328
1506
|
"import * as React from 'react';",
|
|
1329
1507
|
"import {AppShell} from '@astryxdesign/core/AppShell';",
|
|
1330
1508
|
"import {SideNav, SideNavItem} from '@astryxdesign/core/SideNav';",
|
|
1331
|
-
"import {TopNav} from '@astryxdesign/core/TopNav';",
|
|
1509
|
+
"import {TopNav, TopNavHeading} from '@astryxdesign/core/TopNav';",
|
|
1332
1510
|
...(theme
|
|
1333
1511
|
? [
|
|
1334
1512
|
// The mode switch only for a theme with both modes: an import the
|
|
@@ -1408,91 +1586,165 @@ export function previewRouteSource({
|
|
|
1408
1586
|
/** @param {string} slug */
|
|
1409
1587
|
const camelName = camel;
|
|
1410
1588
|
|
|
1589
|
+
/** The script that takes one picture through the project's Playwright. */
|
|
1590
|
+
const PLAYWRIGHT_PICTURE = fileURLToPath(
|
|
1591
|
+
new URL('../../foundation/render/picture-playwright.mjs', import.meta.url),
|
|
1592
|
+
);
|
|
1593
|
+
|
|
1594
|
+
/** The script that takes one picture through a Chrome or Chromium. */
|
|
1595
|
+
const CHROME_PICTURE = fileURLToPath(
|
|
1596
|
+
new URL('../../foundation/render/picture-chrome.mjs', import.meta.url),
|
|
1597
|
+
);
|
|
1598
|
+
|
|
1599
|
+
/** How long a stopped browser may take to close before it is killed. */
|
|
1600
|
+
const STOP_GRACE_MS = 5_000;
|
|
1601
|
+
|
|
1602
|
+
/** The signals that stop a picture run, the terminal closing among them. */
|
|
1603
|
+
const STOP_SIGNALS = /** @type {const} */ (['SIGINT', 'SIGTERM', 'SIGHUP']);
|
|
1604
|
+
|
|
1605
|
+
/** How long a browser may take for one picture before it is stopped. */
|
|
1606
|
+
const BROWSER_BOUND_MS = 60_000;
|
|
1607
|
+
|
|
1608
|
+
/**
|
|
1609
|
+
* What the pictures of one run share: the browsers that failed or hung,
|
|
1610
|
+
* each with its reason, so a later picture does not wait on them again.
|
|
1611
|
+
* @typedef {{failed: Map<string, string>}} PictureRun
|
|
1612
|
+
*/
|
|
1613
|
+
|
|
1614
|
+
/** A new picture run. @returns {PictureRun} */
|
|
1615
|
+
export function newPictureRun() {
|
|
1616
|
+
return {failed: new Map()};
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1411
1619
|
/**
|
|
1412
|
-
* A PNG of an HTML file, with a Playwright the project has
|
|
1413
|
-
* a Chrome or Chromium found on the machine.
|
|
1414
|
-
*
|
|
1415
|
-
*
|
|
1620
|
+
* A whole-page PNG of an HTML file, with a Playwright the project has
|
|
1621
|
+
* installed, else a Chrome or Chromium found on the machine. Each browser
|
|
1622
|
+
* gets its own time bound, and the next one its turn when one fails or
|
|
1623
|
+
* hangs. Not ok with a reason when none is there or every one failed: the
|
|
1624
|
+
* reason then names each one's real error. When a later browser took the
|
|
1625
|
+
* picture, `note` says why an earlier one did not.
|
|
1416
1626
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
1417
1627
|
* @param {string} html absolute
|
|
1418
1628
|
* @param {string} png absolute
|
|
1419
1629
|
* @param {'light' | 'dark'} mode
|
|
1420
|
-
* @
|
|
1630
|
+
* @param {PictureRun} [run] what earlier pictures of the same run learned:
|
|
1631
|
+
* a browser that failed or hung there is not tried again
|
|
1632
|
+
* @returns {Promise<{ok: true, file: string, note?: string} | {ok: false, reason: string, stopped?: string}>}
|
|
1421
1633
|
*/
|
|
1422
|
-
export async function screenshot(
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1634
|
+
export async function screenshot(
|
|
1635
|
+
project,
|
|
1636
|
+
html,
|
|
1637
|
+
png,
|
|
1638
|
+
mode,
|
|
1639
|
+
run = newPictureRun(),
|
|
1640
|
+
) {
|
|
1641
|
+
/** What was tried and why it could not take the picture. @type {string[]} */
|
|
1642
|
+
const failed = [...run.failed.values()];
|
|
1643
|
+
/** Whether a Playwright was found without its own browser installed. */
|
|
1644
|
+
let pwMissing = false;
|
|
1645
|
+
/** Whether a Playwright was found at all. */
|
|
1646
|
+
let pwFound = false;
|
|
1647
|
+
/** A line with no path of this machine. @param {string} line */
|
|
1648
|
+
const local = line => line.split(project.cwd).join('.');
|
|
1649
|
+
/**
|
|
1650
|
+
* Why a browser did not take the picture: Playwright's first line names
|
|
1651
|
+
* only the call ("browserType.launch: Target … closed"); the cause, such
|
|
1652
|
+
* as a missing library, is in a later line, so that line comes too.
|
|
1653
|
+
* Chrome's startup warnings (dbus, GPU) are not a cause.
|
|
1654
|
+
* @param {string} text
|
|
1655
|
+
*/
|
|
1656
|
+
const causeOf = text => {
|
|
1657
|
+
const lines = String(text ?? '')
|
|
1428
1658
|
.split('\n')
|
|
1429
|
-
.map(l => l.trim())
|
|
1430
|
-
.
|
|
1431
|
-
|
|
1432
|
-
.join('
|
|
1659
|
+
.map(l => l.replace(/^[\s=<>-]+/, '').trim())
|
|
1660
|
+
.filter(Boolean);
|
|
1661
|
+
const head =
|
|
1662
|
+
meaningfulLine(lines.join('\n')) || 'it stopped with no message';
|
|
1663
|
+
const rest = lines
|
|
1664
|
+
.slice(lines.indexOf(head) + 1)
|
|
1665
|
+
.find(l =>
|
|
1666
|
+
/error|cannot|can't|missing|not found|while loading|no such|failed|denied/i.test(
|
|
1667
|
+
l,
|
|
1668
|
+
),
|
|
1669
|
+
);
|
|
1670
|
+
return local(rest ? `${head} (${rest})` : head);
|
|
1671
|
+
};
|
|
1672
|
+
/** The browsers to try, in order: each a picture script and its args. */
|
|
1673
|
+
/** @type {Array<{who: string, script: string, args: string[]}>} */
|
|
1674
|
+
const tries = [];
|
|
1433
1675
|
for (const pkg of ['playwright', 'playwright-core']) {
|
|
1434
|
-
/** @type {string} */
|
|
1435
|
-
let entry;
|
|
1436
1676
|
try {
|
|
1437
|
-
entry = project.req.resolve(pkg);
|
|
1677
|
+
const entry = project.req.resolve(pkg);
|
|
1678
|
+
pwFound = true;
|
|
1679
|
+
tries.push({
|
|
1680
|
+
who: `${pkg}'s own browser`,
|
|
1681
|
+
script: PLAYWRIGHT_PICTURE,
|
|
1682
|
+
args: [entry, html, png, mode],
|
|
1683
|
+
});
|
|
1684
|
+
break;
|
|
1438
1685
|
} catch {
|
|
1439
|
-
|
|
1440
|
-
}
|
|
1441
|
-
try {
|
|
1442
|
-
const pw = await import(pathToFileURL(entry).href);
|
|
1443
|
-
const chromium = pw.chromium ?? pw.default?.chromium;
|
|
1444
|
-
const browser = await chromium.launch(
|
|
1445
|
-
chromeBinary() ? {executablePath: chromeBinary()} : {},
|
|
1446
|
-
);
|
|
1447
|
-
try {
|
|
1448
|
-
const page = await browser.newPage({
|
|
1449
|
-
viewport: {width: 1280, height: 900},
|
|
1450
|
-
colorScheme: mode,
|
|
1451
|
-
});
|
|
1452
|
-
await page.goto(pathToFileURL(html).href, {waitUntil: 'load'});
|
|
1453
|
-
await page.screenshot({path: png, fullPage: true});
|
|
1454
|
-
} finally {
|
|
1455
|
-
await browser.close();
|
|
1456
|
-
}
|
|
1457
|
-
return {ok: true, file: shown(project.cwd, png)};
|
|
1458
|
-
} catch (e) {
|
|
1459
|
-
// This Playwright could not launch its browser: try Chrome directly.
|
|
1460
|
-
failed.push(`${pkg}: ${firstLine(e)}`);
|
|
1686
|
+
// Not installed here.
|
|
1461
1687
|
}
|
|
1462
1688
|
}
|
|
1463
1689
|
const chrome = chromeBinary();
|
|
1464
|
-
if (chrome)
|
|
1465
|
-
|
|
1466
|
-
chrome,
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1690
|
+
if (chrome)
|
|
1691
|
+
tries.push({
|
|
1692
|
+
who: chrome,
|
|
1693
|
+
script: CHROME_PICTURE,
|
|
1694
|
+
args: [chrome, html, png, mode],
|
|
1695
|
+
});
|
|
1696
|
+
for (const t of tries) {
|
|
1697
|
+
if (run.failed.has(t.who)) continue;
|
|
1698
|
+
const r = await runBrowser(t.script, t.args, BROWSER_BOUND_MS, {
|
|
1699
|
+
drop: [png],
|
|
1700
|
+
});
|
|
1701
|
+
if (r.stoppedBy)
|
|
1702
|
+
return {
|
|
1703
|
+
ok: false,
|
|
1704
|
+
stopped: r.stoppedBy,
|
|
1705
|
+
reason: `the pictures were stopped (${r.stoppedBy}) before the browser finished`,
|
|
1706
|
+
};
|
|
1707
|
+
if (r.noTemp)
|
|
1708
|
+
return {
|
|
1709
|
+
ok: false,
|
|
1710
|
+
reason: `no browser was started: the system temp folder cannot be written (${r.noTemp}), and a browser needs a profile folder of its own there; fix the temp folder (TMPDIR), then run the command again`,
|
|
1711
|
+
};
|
|
1480
1712
|
if (r.status === 0 && fs.existsSync(png))
|
|
1481
|
-
return {
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
);
|
|
1713
|
+
return {
|
|
1714
|
+
ok: true,
|
|
1715
|
+
file: shown(project.cwd, png),
|
|
1716
|
+
...(failed.length
|
|
1717
|
+
? {
|
|
1718
|
+
note: `the picture was taken with ${t.who}; ${failed.join('; ')}`,
|
|
1719
|
+
}
|
|
1720
|
+
: {}),
|
|
1721
|
+
};
|
|
1722
|
+
const text = r.error ? String(r.error.message) : r.stderr;
|
|
1723
|
+
if (
|
|
1724
|
+
t.script === PLAYWRIGHT_PICTURE &&
|
|
1725
|
+
/Executable doesn't exist|playwright install/i.test(text)
|
|
1726
|
+
)
|
|
1727
|
+
pwMissing = true;
|
|
1728
|
+
const why = r.timedOut
|
|
1729
|
+
? `${t.who} did not finish within ${BROWSER_BOUND_MS / 1000} seconds, so it was stopped`
|
|
1730
|
+
: `${t.who} could not take it: ${causeOf(text)}`;
|
|
1731
|
+
run.failed.set(t.who, why);
|
|
1732
|
+
failed.push(why);
|
|
1491
1733
|
}
|
|
1492
1734
|
if (failed.length)
|
|
1493
1735
|
return {
|
|
1494
1736
|
ok: false,
|
|
1495
|
-
|
|
1737
|
+
// Advice that can change the result: Playwright's browser only when
|
|
1738
|
+
// it is missing; a Chrome to check only when there is one.
|
|
1739
|
+
// What went wrong for this picture, and what can change it; the run
|
|
1740
|
+
// that asked for it says which pictures were and were not taken.
|
|
1741
|
+
reason: `${failed.join('; ')}. ${
|
|
1742
|
+
!pwFound
|
|
1743
|
+
? `Install Playwright with its browser (${installLine(project.cwd, ['playwright'])}, then npx playwright install chromium), or`
|
|
1744
|
+
: pwMissing
|
|
1745
|
+
? 'Give Playwright its browser (npx playwright install chromium), or'
|
|
1746
|
+
: "Fix what Playwright's browser needs (the reason is above), or"
|
|
1747
|
+
} ${chrome ? `check that ${chrome} starts on this machine` : 'install Google Chrome or Chromium'}. The HTML preview needs neither.`,
|
|
1496
1748
|
};
|
|
1497
1749
|
return {
|
|
1498
1750
|
ok: false,
|
|
@@ -1515,11 +1767,23 @@ function chromeBinary() {
|
|
|
1515
1767
|
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
1516
1768
|
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
1517
1769
|
];
|
|
1518
|
-
|
|
1770
|
+
// Only a file that runs: a folder or a file with no execute permission
|
|
1771
|
+
// by a browser's name is passed over, and the search goes on.
|
|
1772
|
+
/** @param {string} f */
|
|
1773
|
+
const runs = f => {
|
|
1774
|
+
try {
|
|
1775
|
+
if (!fs.statSync(f).isFile()) return false;
|
|
1776
|
+
if (process.platform !== 'win32') fs.accessSync(f, fs.constants.X_OK);
|
|
1777
|
+
return true;
|
|
1778
|
+
} catch {
|
|
1779
|
+
return false;
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
for (const f of fixed) if (runs(f)) return f;
|
|
1519
1783
|
for (const dir of (process.env.PATH ?? '').split(path.delimiter)) {
|
|
1520
1784
|
for (const n of names) {
|
|
1521
1785
|
const f = path.join(dir, n);
|
|
1522
|
-
if (dir &&
|
|
1786
|
+
if (dir && runs(f)) return f;
|
|
1523
1787
|
}
|
|
1524
1788
|
}
|
|
1525
1789
|
return null;
|
|
@@ -1527,7 +1791,25 @@ function chromeBinary() {
|
|
|
1527
1791
|
|
|
1528
1792
|
/** The first line of every file the editor writes into a theme's app copy. */
|
|
1529
1793
|
export {APP_COPY_MARK} from './_marks.mjs';
|
|
1530
|
-
import {APP_COPY_MARK} from './_marks.mjs';
|
|
1794
|
+
import {APP_COPY_MARK, appCopyMark} from './_marks.mjs';
|
|
1795
|
+
import {builtColorMode} from '../../foundation/discovery/theme-imports.mjs';
|
|
1796
|
+
|
|
1797
|
+
/**
|
|
1798
|
+
* The font stylesheets a theme's app copy imports, from the fonts the theme
|
|
1799
|
+
* loads now (an installed font package, the base theme's fonts).
|
|
1800
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1801
|
+
* @param {string} slug
|
|
1802
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1803
|
+
* @returns {string[]}
|
|
1804
|
+
*/
|
|
1805
|
+
export function copyFontsCss(ctx, slug, data) {
|
|
1806
|
+
return themeImports(
|
|
1807
|
+
ctx,
|
|
1808
|
+
slug,
|
|
1809
|
+
data,
|
|
1810
|
+
path.join(ctx.project.cwd, 'src', 'themes', slug),
|
|
1811
|
+
).css.slice(1);
|
|
1812
|
+
}
|
|
1531
1813
|
|
|
1532
1814
|
/**
|
|
1533
1815
|
* The app's copy of an editor theme: a standard local theme in
|
|
@@ -1545,38 +1827,26 @@ import {APP_COPY_MARK} from './_marks.mjs';
|
|
|
1545
1827
|
* @returns {string | null}
|
|
1546
1828
|
*/
|
|
1547
1829
|
export function writeAppCopy(ctx, slug, data) {
|
|
1548
|
-
return writeAppCopyAt(
|
|
1549
|
-
ctx.project.cwd,
|
|
1550
|
-
slug,
|
|
1551
|
-
themeImports(
|
|
1552
|
-
ctx,
|
|
1553
|
-
slug,
|
|
1554
|
-
data,
|
|
1555
|
-
path.join(ctx.project.cwd, 'src', 'themes', slug),
|
|
1556
|
-
).css.slice(1),
|
|
1557
|
-
);
|
|
1830
|
+
return writeAppCopyAt(ctx.project.cwd, slug, copyFontsCss(ctx, slug, data));
|
|
1558
1831
|
}
|
|
1559
1832
|
|
|
1560
1833
|
/**
|
|
1561
|
-
*
|
|
1562
|
-
* copy
|
|
1834
|
+
* The files of a theme's app copy as the editor would write them now, by
|
|
1835
|
+
* name; null with no build to copy. Font stylesheets as given, or null for
|
|
1836
|
+
* the copy's own.
|
|
1563
1837
|
* @param {string} cwd
|
|
1564
1838
|
* @param {string} slug
|
|
1565
1839
|
* @param {string[] | null} fontsCss
|
|
1566
|
-
* @returns {string | null}
|
|
1840
|
+
* @returns {Record<string, string> | null}
|
|
1567
1841
|
*/
|
|
1568
|
-
|
|
1842
|
+
function appCopyFiles(cwd, slug, fontsCss) {
|
|
1569
1843
|
const f = themeFiles(cwd, slug);
|
|
1570
1844
|
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1571
1845
|
const name = `${camel(slug)}Theme`;
|
|
1572
|
-
const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
|
|
1573
1846
|
if (!fs.existsSync(f.js) || !fs.existsSync(f.css)) return null;
|
|
1574
|
-
// The copy's source, as the stable build's header names it.
|
|
1575
1847
|
const source = `src/themes/${slug}/${name}.ts`;
|
|
1576
|
-
// Only the editor's own copy is written over.
|
|
1577
|
-
if (appCopyBlocker(cwd, slug) !== null) return null;
|
|
1578
1848
|
const head = (/** @type {string} */ open, /** @type {string} */ close) =>
|
|
1579
|
-
`${open} ${
|
|
1849
|
+
`${open} ${appCopyMark(slug)} after every build of themes/${slug}/; do not edit it here. Change the theme with the editor. ${close}\n`;
|
|
1580
1850
|
const keptFonts = path.join(dir, `${slug}.fonts.css`);
|
|
1581
1851
|
const fonts =
|
|
1582
1852
|
fontsCss ??
|
|
@@ -1598,27 +1868,115 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
|
1598
1868
|
if (fs.existsSync(from))
|
|
1599
1869
|
built[`${slug}${ext}`] = asBuilt(fs.readFileSync(from, 'utf8'));
|
|
1600
1870
|
}
|
|
1871
|
+
// A light-only or dark-only theme's build exports its one color mode
|
|
1872
|
+
// (`colorModes`); the copy's source re-exports it, so a build of the copy
|
|
1873
|
+
// writes it too and `theme add` reads it.
|
|
1874
|
+
const oneMode = builtColorMode(f.js).mode;
|
|
1601
1875
|
const files = {
|
|
1602
1876
|
[`${name}.doc.mjs`]: `${head('//', '')}\n/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */\nexport default {\n type: 'theme',\n name: ${JSON.stringify(slug)},\n displayName: ${JSON.stringify(slug)},\n description: ${JSON.stringify(`The ${slug} theme, made with the theme editor (themes/${slug}/).`)},\n maintained: false,\n};\n`,
|
|
1603
|
-
[`${name}.ts`]: `${head('//', '')}export {${name}} from './${slug}';\n`,
|
|
1877
|
+
[`${name}.ts`]: `${head('//', '')}export {${name}${oneMode ? ', colorModes' : ''}} from './${slug}';\n`,
|
|
1604
1878
|
...built,
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
: {})
|
|
1879
|
+
// Always there, so the app theme module's import of it holds when the
|
|
1880
|
+
// theme's fonts change (none: a comment only).
|
|
1881
|
+
[`${slug}.fonts.css`]: fonts.length
|
|
1882
|
+
? `${head('/*', '*/')}${fonts.map(c => `@import ${JSON.stringify(c)};`).join('\n')}\n`
|
|
1883
|
+
: `${head('/*', '*/')}/* No font stylesheets: no installed package loads the theme's fonts. A font the system does not have shows only once its package is installed (experimental theme editor show ${slug} names it). */\n`,
|
|
1610
1884
|
};
|
|
1611
|
-
|
|
1885
|
+
return files;
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
/**
|
|
1889
|
+
* Why a theme's app copy is behind its build, or null when it is current:
|
|
1890
|
+
* something in its way (appCopyStale), a copy file missing, or a file
|
|
1891
|
+
* whose content is not what the editor would write now.
|
|
1892
|
+
* @param {string} cwd
|
|
1893
|
+
* @param {string} slug
|
|
1894
|
+
* @param {string[] | null} [fontsCss] the font stylesheets the copy should
|
|
1895
|
+
* import now (null: the copy's own)
|
|
1896
|
+
* @returns {string | null}
|
|
1897
|
+
*/
|
|
1898
|
+
export function appCopyBehind(cwd, slug, fontsCss = null) {
|
|
1899
|
+
const stale = appCopyStale(cwd, slug).appCopyStale;
|
|
1900
|
+
if (stale) return stale;
|
|
1901
|
+
const files = appCopyFiles(cwd, slug, fontsCss);
|
|
1902
|
+
if (!files) return null;
|
|
1903
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1904
|
+
if (!fs.existsSync(dir))
|
|
1905
|
+
return `the app copy in src/themes/${slug}/ is gone; the editor writes it again`;
|
|
1612
1906
|
for (const [n, text] of Object.entries(files)) {
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1907
|
+
/** @type {string} */
|
|
1908
|
+
let now;
|
|
1909
|
+
try {
|
|
1910
|
+
now = fs.readFileSync(path.join(dir, n), 'utf8');
|
|
1911
|
+
} catch {
|
|
1912
|
+
return `src/themes/${slug}/${n} is missing from the app copy`;
|
|
1913
|
+
}
|
|
1914
|
+
// Line endings as a checkout writes them (CRLF on Windows) are the
|
|
1915
|
+
// same content, as the outputs check reads them.
|
|
1916
|
+
const lf = (/** @type {string} */ x) => x.replace(/\r\n/g, '\n');
|
|
1917
|
+
if (lf(now) !== lf(text))
|
|
1918
|
+
return `src/themes/${slug}/${n} is not the current build of themes/${slug}/`;
|
|
1616
1919
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1920
|
+
return null;
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
/**
|
|
1924
|
+
* {@link writeAppCopy} with the font stylesheets given, or null to keep the
|
|
1925
|
+
* copy's own (a compile, which changes no setting).
|
|
1926
|
+
* @param {string} cwd
|
|
1927
|
+
* @param {string} slug
|
|
1928
|
+
* @param {string[] | null} fontsCss
|
|
1929
|
+
* @returns {string | null}
|
|
1930
|
+
*/
|
|
1931
|
+
export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
1932
|
+
const f = themeFiles(cwd, slug);
|
|
1933
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1934
|
+
const name = `${camel(slug)}Theme`;
|
|
1935
|
+
const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
|
|
1936
|
+
if (!fs.existsSync(f.js) || !fs.existsSync(f.css)) return null;
|
|
1937
|
+
// Only the editor's own copy is written over.
|
|
1938
|
+
if (appCopyBlocker(cwd, slug) !== null) return null;
|
|
1939
|
+
const files = appCopyFiles(cwd, slug, fontsCss);
|
|
1940
|
+
if (!files) return null;
|
|
1941
|
+
const failKey = `${path.resolve(cwd)}\0${slug}`;
|
|
1942
|
+
try {
|
|
1943
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
1944
|
+
for (const [n, text] of Object.entries(files)) {
|
|
1945
|
+
const file = path.join(dir, n);
|
|
1946
|
+
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === text)
|
|
1947
|
+
continue;
|
|
1948
|
+
writeWhole(file, text);
|
|
1949
|
+
}
|
|
1950
|
+
// A copy's own file this build no longer writes goes; anything else in
|
|
1951
|
+
// the folder (yours, or the system's) stays as it is.
|
|
1952
|
+
for (const n of fs.readdirSync(dir))
|
|
1953
|
+
if (appCopyNames(slug).has(n) && !(n in files))
|
|
1954
|
+
fs.rmSync(path.join(dir, n), {force: true});
|
|
1955
|
+
} catch (e) {
|
|
1956
|
+
// A copy that cannot be written is said, with the system's reason;
|
|
1957
|
+
// the change itself stands.
|
|
1958
|
+
const code = /** @type {any} */ (e)?.code ?? 'error';
|
|
1959
|
+
// The folder that failed: the copy's, or a parent it could not be
|
|
1960
|
+
// made in.
|
|
1961
|
+
const failed = /** @type {any} */ (e)?.path
|
|
1962
|
+
? path.resolve(String(/** @type {any} */ (e).path))
|
|
1963
|
+
: dir;
|
|
1964
|
+
const at = fs.existsSync(failed) ? failed : path.dirname(failed);
|
|
1965
|
+
const rel = path.relative(cwd, at).split(path.sep).join('/');
|
|
1966
|
+
const unwritable =
|
|
1967
|
+
code === 'EACCES' || code === 'EPERM' || code === 'EROFS';
|
|
1968
|
+
COPY_FAILED.set(failKey, {
|
|
1969
|
+
why: unwritable
|
|
1970
|
+
? `${rel} is not writable (${code})`
|
|
1971
|
+
: code === 'ENOSPC'
|
|
1972
|
+
? `the disk is full (${code})`
|
|
1973
|
+
: `${rel} could not be written (${code})`,
|
|
1974
|
+
// A folder that was not writable, to see whether it still is.
|
|
1975
|
+
...(unwritable ? {folder: at} : {}),
|
|
1976
|
+
});
|
|
1977
|
+
return null;
|
|
1978
|
+
}
|
|
1979
|
+
COPY_FAILED.delete(failKey);
|
|
1622
1980
|
// The first write is named in the command's result; later ones are not.
|
|
1623
1981
|
if (first)
|
|
1624
1982
|
FIRST_COPIES.set(
|
|
@@ -1633,13 +1991,30 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
|
1633
1991
|
}
|
|
1634
1992
|
|
|
1635
1993
|
/**
|
|
1636
|
-
*
|
|
1637
|
-
*
|
|
1638
|
-
*
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
|
|
1642
|
-
|
|
1994
|
+
* The note for a copy a file of yours keeps from being written, as a
|
|
1995
|
+
* result field: `{appCopyStale}` when one does, else nothing.
|
|
1996
|
+
* @param {string} cwd
|
|
1997
|
+
* @param {string} slug
|
|
1998
|
+
* @returns {{appCopyStale?: string}}
|
|
1999
|
+
*/
|
|
2000
|
+
export function appCopyStale(cwd, slug) {
|
|
2001
|
+
const blocker = appCopyBlocker(cwd, slug) ?? copyFailure(cwd, slug) ?? null;
|
|
2002
|
+
return blocker
|
|
2003
|
+
? {
|
|
2004
|
+
appCopyStale: `the app copy in src/themes/${slug}/ was not updated: ${blocker}. The app keeps the theme as it was until that is out of the way; then any set or show writes it.`,
|
|
2005
|
+
}
|
|
2006
|
+
: {};
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
/**
|
|
2010
|
+
* Why the editor will not write a theme's app copy, or null when it will.
|
|
2011
|
+
* Only a file of yours AT one of the copy's names stops it: a descriptor,
|
|
2012
|
+
* source or font stylesheet without the editor's mark, or any copy file
|
|
2013
|
+
* while the descriptor is not the editor's. Other files there (a note, a
|
|
2014
|
+
* swap file, desktop.ini) are left as they are and the copy is written
|
|
2015
|
+
* around them. Built bytes are not compared, so a stable rebuild of the
|
|
2016
|
+
* copy leaves it the editor's. The one test the copy's writer, the change
|
|
2017
|
+
* results and `wiring` use. Returns the file in the way.
|
|
1643
2018
|
* @param {string} cwd
|
|
1644
2019
|
* @param {string} slug
|
|
1645
2020
|
* @returns {string | null}
|
|
@@ -1648,36 +2023,129 @@ export function appCopyBlocker(cwd, slug) {
|
|
|
1648
2023
|
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1649
2024
|
const name = `${camel(slug)}Theme`;
|
|
1650
2025
|
const rel = path.relative(cwd, dir).split(path.sep).join('/');
|
|
2026
|
+
// The copy carries the built module whole, and a local theme imports
|
|
2027
|
+
// only files of its own folder: a module that imports a file beside it
|
|
2028
|
+
// (an icon registry of the theme's folder) would break in the app.
|
|
2029
|
+
{
|
|
2030
|
+
const built = themeFiles(cwd, slug).js;
|
|
2031
|
+
/** @type {string[]} */
|
|
2032
|
+
let specifiers;
|
|
2033
|
+
try {
|
|
2034
|
+
specifiers = themeFileImports(built);
|
|
2035
|
+
} catch {
|
|
2036
|
+
specifiers = [];
|
|
2037
|
+
}
|
|
2038
|
+
const local = specifiers.find(s => s.startsWith('.'));
|
|
2039
|
+
if (local)
|
|
2040
|
+
return `themes/${slug}/${path.basename(built)} imports ${local}, a file beside the theme, which the copy cannot carry (a local theme imports only files of its own folder); import it from a package instead`;
|
|
2041
|
+
}
|
|
2042
|
+
// Nothing is written through a link on the way from the app to the copy
|
|
2043
|
+
// (src/, src/themes/, the copy's folder), as for themes/.
|
|
2044
|
+
for (const part of ['src', 'src/themes', rel]) {
|
|
2045
|
+
try {
|
|
2046
|
+
const st = fs.lstatSync(path.join(cwd, part));
|
|
2047
|
+
if (st.isSymbolicLink())
|
|
2048
|
+
return `${part} is a link (to ${fs.readlinkSync(path.join(cwd, part))}), and the editor writes nothing through a link`;
|
|
2049
|
+
// A file where a folder on the way goes: nothing is half-written.
|
|
2050
|
+
if (!st.isDirectory())
|
|
2051
|
+
return part === rel
|
|
2052
|
+
? `${rel} is a file, where the copy's folder goes`
|
|
2053
|
+
: `${part} is a file, where a folder on the way to the copy goes`;
|
|
2054
|
+
} catch {
|
|
2055
|
+
break;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
try {
|
|
2059
|
+
if (!fs.lstatSync(dir).isDirectory())
|
|
2060
|
+
return `${rel} is a file, where the copy's folder goes`;
|
|
2061
|
+
} catch {
|
|
2062
|
+
// Not there yet: the copy makes it.
|
|
2063
|
+
}
|
|
1651
2064
|
if (folderIsEmpty(dir)) return null;
|
|
1652
2065
|
/** @type {string[]} */
|
|
1653
2066
|
let names;
|
|
1654
2067
|
try {
|
|
1655
2068
|
names = fs.readdirSync(dir);
|
|
1656
|
-
} catch {
|
|
1657
|
-
return rel
|
|
2069
|
+
} catch (e) {
|
|
2070
|
+
return `${rel} cannot be read (${/** @type {any} */ (e)?.code ?? 'error'})`;
|
|
1658
2071
|
}
|
|
1659
|
-
/** @
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
2072
|
+
/** @param {string} n */
|
|
2073
|
+
const marked = n => {
|
|
2074
|
+
try {
|
|
2075
|
+
return fs.readFileSync(path.join(dir, n), 'utf8').includes(APP_COPY_MARK);
|
|
2076
|
+
} catch {
|
|
2077
|
+
return false;
|
|
2078
|
+
}
|
|
2079
|
+
};
|
|
2080
|
+
const own = appCopyNames(slug);
|
|
2081
|
+
const present = names.filter(n => own.has(n));
|
|
2082
|
+
// A link at a copy name is never written through or replaced.
|
|
2083
|
+
for (const n of present)
|
|
2084
|
+
try {
|
|
2085
|
+
const st = fs.lstatSync(path.join(dir, n));
|
|
2086
|
+
if (st.isSymbolicLink())
|
|
2087
|
+
return `${rel}/${n} is a link (to ${fs.readlinkSync(path.join(dir, n))}), at a name the copy uses, and the editor writes nothing through a link`;
|
|
2088
|
+
if (st.isDirectory())
|
|
2089
|
+
return `${rel}/${n} is a folder, at a name the copy uses for a file`;
|
|
2090
|
+
} catch {
|
|
2091
|
+
// Gone since it was listed.
|
|
2092
|
+
}
|
|
2093
|
+
// The copy is the editor's when any of its marked files carries the
|
|
2094
|
+
// mark (one of them deleted is written back); then only a marked name
|
|
2095
|
+
// without the mark is yours.
|
|
2096
|
+
const markedNames = [`${name}.doc.mjs`, `${name}.ts`, `${slug}.fonts.css`];
|
|
2097
|
+
// A build output of the copy's source carries the build's own header.
|
|
2098
|
+
const generated = (/** @type {string} */ n) => {
|
|
2099
|
+
try {
|
|
2100
|
+
return /@generated by `astryx theme build`/.test(
|
|
2101
|
+
fs.readFileSync(path.join(dir, n), 'utf8').slice(0, 600),
|
|
2102
|
+
);
|
|
2103
|
+
} catch {
|
|
2104
|
+
return false;
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
const ours =
|
|
2108
|
+
markedNames.some(n => present.includes(n) && marked(n)) ||
|
|
2109
|
+
(present.length > 0 &&
|
|
2110
|
+
present.every(n => !markedNames.includes(n) && generated(n)));
|
|
2111
|
+
const foreign = ours
|
|
2112
|
+
? present.find(n => markedNames.includes(n) && !marked(n))
|
|
2113
|
+
: present[0];
|
|
2114
|
+
return foreign
|
|
2115
|
+
? `${rel}/${foreign} is yours, at a name the copy uses, and the editor never writes over your files`
|
|
2116
|
+
: null;
|
|
1677
2117
|
}
|
|
1678
2118
|
|
|
1679
|
-
/**
|
|
1680
|
-
|
|
2119
|
+
/**
|
|
2120
|
+
* Why the last write of a theme's app copy failed, by app and theme, and
|
|
2121
|
+
* the folder that was not writable when that was why.
|
|
2122
|
+
* @type {Map<string, {why: string, folder?: string}>}
|
|
2123
|
+
*/
|
|
2124
|
+
const COPY_FAILED = new Map();
|
|
2125
|
+
|
|
2126
|
+
/**
|
|
2127
|
+
* Why the last write of a theme's app copy failed, while that still holds:
|
|
2128
|
+
* a folder that was not writable and is now is no reason any more (a
|
|
2129
|
+
* process that runs several commands, as an API caller does, reads the
|
|
2130
|
+
* folder as it is now).
|
|
2131
|
+
* @param {string} cwd
|
|
2132
|
+
* @param {string} slug
|
|
2133
|
+
* @returns {string | null}
|
|
2134
|
+
*/
|
|
2135
|
+
function copyFailure(cwd, slug) {
|
|
2136
|
+
const key = `${path.resolve(cwd)}\0${slug}`;
|
|
2137
|
+
const failed = COPY_FAILED.get(key);
|
|
2138
|
+
if (!failed) return null;
|
|
2139
|
+
if (failed.folder)
|
|
2140
|
+
try {
|
|
2141
|
+
fs.accessSync(failed.folder, fs.constants.W_OK);
|
|
2142
|
+
COPY_FAILED.delete(key);
|
|
2143
|
+
return null;
|
|
2144
|
+
} catch {
|
|
2145
|
+
// Still not writable.
|
|
2146
|
+
}
|
|
2147
|
+
return failed.why;
|
|
2148
|
+
}
|
|
1681
2149
|
|
|
1682
2150
|
/** App copies written for the first time in this process, by app and theme. @type {Map<string, string[]>} */
|
|
1683
2151
|
const FIRST_COPIES = new Map();
|
|
@@ -1695,3 +2163,164 @@ export function takeFirstAppCopy(cwd, slug) {
|
|
|
1695
2163
|
FIRST_COPIES.delete(key);
|
|
1696
2164
|
return wrote;
|
|
1697
2165
|
}
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
* Run a picture script (one browser, one picture) as its own process group,
|
|
2169
|
+
* without blocking this process. The one owner of every browser run:
|
|
2170
|
+
* - a temp folder of its own (TMPDIR, TMP, TEMP), where the browser keeps
|
|
2171
|
+
* its profile; with none to make, nothing runs (`noTemp`);
|
|
2172
|
+
* - a time bound (`timedOut`);
|
|
2173
|
+
* - a stop (SIGINT, SIGTERM, SIGHUP) that reaches the run stops it
|
|
2174
|
+
* (`stoppedBy`), then ends this process as the stop would have.
|
|
2175
|
+
* A stop or the bound asks the whole group to close, waits for it (killing
|
|
2176
|
+
* it past a short grace), then removes the temp folder and the `drop` files
|
|
2177
|
+
* (a picture part a stopped run leaves); a run that ends on its own removes
|
|
2178
|
+
* the temp folder only.
|
|
2179
|
+
* @param {string} script a picture script
|
|
2180
|
+
* @param {string[]} args
|
|
2181
|
+
* @param {number} [bound] milliseconds before the run is stopped
|
|
2182
|
+
* @param {{drop?: string[]}} [opts]
|
|
2183
|
+
* @returns {Promise<{status: number | null, signal: string | null, stderr: string, error?: Error, stoppedBy?: string, timedOut?: boolean, noTemp?: string}>}
|
|
2184
|
+
*/
|
|
2185
|
+
export function runBrowser(script, args, bound = BROWSER_BOUND_MS, opts = {}) {
|
|
2186
|
+
const drop = opts.drop ?? [];
|
|
2187
|
+
/** @type {string} */
|
|
2188
|
+
let temp;
|
|
2189
|
+
try {
|
|
2190
|
+
temp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-browser-'));
|
|
2191
|
+
} catch (e) {
|
|
2192
|
+
return Promise.resolve({
|
|
2193
|
+
status: null,
|
|
2194
|
+
signal: null,
|
|
2195
|
+
stderr: '',
|
|
2196
|
+
noTemp: String(/** @type {any} */ (e)?.code ?? e),
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
return new Promise(resolve => {
|
|
2200
|
+
let stderr = '';
|
|
2201
|
+
const posix = process.platform !== 'win32';
|
|
2202
|
+
const child = spawn(process.execPath, [script, ...args], {
|
|
2203
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
2204
|
+
env: {...process.env, TMPDIR: temp, TMP: temp, TEMP: temp},
|
|
2205
|
+
// A group of its own, so a stop reaches the browser it starts too.
|
|
2206
|
+
detached: posix,
|
|
2207
|
+
});
|
|
2208
|
+
/** @param {NodeJS.Signals} sig */
|
|
2209
|
+
const signalAll = sig => {
|
|
2210
|
+
try {
|
|
2211
|
+
if (posix && child.pid) process.kill(-child.pid, sig);
|
|
2212
|
+
else child.kill(sig);
|
|
2213
|
+
} catch {
|
|
2214
|
+
// Gone already.
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
const closed = new Promise(done => child.once('close', done));
|
|
2218
|
+
/** @param {string[]} files */
|
|
2219
|
+
const remove = files => {
|
|
2220
|
+
for (const f of files)
|
|
2221
|
+
try {
|
|
2222
|
+
fs.rmSync(f, {recursive: true, force: true});
|
|
2223
|
+
} catch {
|
|
2224
|
+
// Gone already.
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
/** The temp folder goes on every way out; `drop` only with a stop. */
|
|
2228
|
+
const clean = () => remove([temp]);
|
|
2229
|
+
/** Close the group (killed past the grace), then clean up. */
|
|
2230
|
+
const finish = async () => {
|
|
2231
|
+
signalAll('SIGTERM');
|
|
2232
|
+
const grace = new Promise(done =>
|
|
2233
|
+
setTimeout(done, STOP_GRACE_MS).unref(),
|
|
2234
|
+
);
|
|
2235
|
+
if ((await Promise.race([closed.then(() => true), grace])) !== true) {
|
|
2236
|
+
signalAll('SIGKILL');
|
|
2237
|
+
await closed;
|
|
2238
|
+
}
|
|
2239
|
+
remove([temp, ...drop]);
|
|
2240
|
+
};
|
|
2241
|
+
// This process ending some other way: the group is killed, and the temp
|
|
2242
|
+
// folder and the unfinished files removed, as far as an exit allows.
|
|
2243
|
+
const onExit = () => {
|
|
2244
|
+
signalAll('SIGKILL');
|
|
2245
|
+
remove([temp, ...drop]);
|
|
2246
|
+
};
|
|
2247
|
+
process.once('exit', onExit);
|
|
2248
|
+
child.stderr?.setEncoding('utf8');
|
|
2249
|
+
child.stderr?.on('data', d => {
|
|
2250
|
+
if (stderr.length < 8000) stderr += d;
|
|
2251
|
+
});
|
|
2252
|
+
/** Set once the run is being stopped (bound, signal): it ends there. */
|
|
2253
|
+
let stopping = false;
|
|
2254
|
+
let settled = false;
|
|
2255
|
+
/** @param {Awaited<ReturnType<typeof runBrowser>>} out */
|
|
2256
|
+
const settle = out => {
|
|
2257
|
+
if (settled) return;
|
|
2258
|
+
settled = true;
|
|
2259
|
+
clearTimeout(timer);
|
|
2260
|
+
process.removeListener('exit', onExit);
|
|
2261
|
+
for (const sig of STOP_SIGNALS) process.removeListener(sig, onStop);
|
|
2262
|
+
resolve(out);
|
|
2263
|
+
};
|
|
2264
|
+
const timer = setTimeout(() => {
|
|
2265
|
+
stopping = true;
|
|
2266
|
+
void finish().then(() =>
|
|
2267
|
+
settle({status: null, signal: null, stderr, timedOut: true}),
|
|
2268
|
+
);
|
|
2269
|
+
}, bound);
|
|
2270
|
+
/** @param {NodeJS.Signals} sig */
|
|
2271
|
+
const onStop = async sig => {
|
|
2272
|
+
stopping = true;
|
|
2273
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onStop);
|
|
2274
|
+
// A second stop during the grace does not wait for it: the group is
|
|
2275
|
+
// killed and the files removed at once, then the process ends.
|
|
2276
|
+
/** @param {NodeJS.Signals} again */
|
|
2277
|
+
const onAgain = again => {
|
|
2278
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
|
|
2279
|
+
signalAll('SIGKILL');
|
|
2280
|
+
remove([temp, ...drop]);
|
|
2281
|
+
if (process.listenerCount(again) === 0)
|
|
2282
|
+
process.kill(process.pid, again);
|
|
2283
|
+
};
|
|
2284
|
+
for (const s of STOP_SIGNALS) process.once(s, onAgain);
|
|
2285
|
+
await finish();
|
|
2286
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
|
|
2287
|
+
settle({status: null, signal: null, stderr, stoppedBy: sig});
|
|
2288
|
+
// Nothing else listening: the stop ends this process, as it would
|
|
2289
|
+
// have without this listener.
|
|
2290
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
2291
|
+
};
|
|
2292
|
+
for (const sig of STOP_SIGNALS) process.once(sig, onStop);
|
|
2293
|
+
child.once('error', error => {
|
|
2294
|
+
clean();
|
|
2295
|
+
settle({status: null, signal: null, stderr, error});
|
|
2296
|
+
});
|
|
2297
|
+
child.once('close', (status, signal) => {
|
|
2298
|
+
if (stopping) return;
|
|
2299
|
+
clean();
|
|
2300
|
+
settle({status, signal, stderr});
|
|
2301
|
+
});
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
/**
|
|
2306
|
+
* The first stderr line that says something about the picture: Chrome's
|
|
2307
|
+
* startup warnings (dbus, GPU, sandbox notices) come first on Linux and
|
|
2308
|
+
* say nothing about why no picture was written.
|
|
2309
|
+
* @param {string} text
|
|
2310
|
+
*/
|
|
2311
|
+
export function meaningfulLine(text) {
|
|
2312
|
+
const lines = String(text ?? '')
|
|
2313
|
+
.split(/\r?\n/)
|
|
2314
|
+
.map(l => l.trim())
|
|
2315
|
+
.filter(Boolean);
|
|
2316
|
+
return (
|
|
2317
|
+
lines.find(
|
|
2318
|
+
l =>
|
|
2319
|
+
!/dbus|bus\.cc|gpu_|gl_|sandbox|fontconfig|crashpad|DevTools listening|WARNING:/i.test(
|
|
2320
|
+
l,
|
|
2321
|
+
),
|
|
2322
|
+
) ??
|
|
2323
|
+
lines[0] ??
|
|
2324
|
+
''
|
|
2325
|
+
);
|
|
2326
|
+
}
|