@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
|
@@ -15,13 +15,15 @@
|
|
|
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,
|
|
25
27
|
} from './_catalog.mjs';
|
|
26
28
|
import {
|
|
27
29
|
catalogVariants,
|
|
@@ -32,13 +34,12 @@ import {
|
|
|
32
34
|
} from './_parts.mjs';
|
|
33
35
|
import {OVERVIEW_SECTIONS} from './_overview.mjs';
|
|
34
36
|
import {
|
|
35
|
-
FOLDER_JUNK,
|
|
36
|
-
folderIsEmpty,
|
|
37
37
|
camel,
|
|
38
|
+
folderIsEmpty,
|
|
38
39
|
fontPackages,
|
|
39
40
|
modesOf,
|
|
40
|
-
themeFiles,
|
|
41
41
|
shown,
|
|
42
|
+
themeFiles,
|
|
42
43
|
} from './_settings.mjs';
|
|
43
44
|
import {writeWhole} from './_palette.mjs';
|
|
44
45
|
import {cliVersion} from '../../foundation/release/run-context.mjs';
|
|
@@ -46,7 +47,9 @@ import {importPathOf, installLine} from './_project.mjs';
|
|
|
46
47
|
import {COLOR_PROP_PARTS, DIRECT, P, wordTable} from './_tables.mjs';
|
|
47
48
|
import {extractImportedPackages} from '../../foundation/discovery/template-needs.mjs';
|
|
48
49
|
import {findNodeModulesPackage} from '../../foundation/fs/paths.mjs';
|
|
50
|
+
import {themeFileImports} from '../../foundation/discovery/theme-discovery.mjs';
|
|
49
51
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
52
|
+
import {compareText} from '../../foundation/text/compare-text.mjs';
|
|
50
53
|
|
|
51
54
|
const TEMPLATES_DIR = path.resolve(
|
|
52
55
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
@@ -98,7 +101,7 @@ function groupOf(name, category) {
|
|
|
98
101
|
* whose packages the project has.
|
|
99
102
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
100
103
|
* @param {string | undefined} group only this group
|
|
101
|
-
* @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string,
|
|
104
|
+
* @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string, import('./_catalog.mjs').Binding>, skipped: string[]}}
|
|
102
105
|
*/
|
|
103
106
|
export function showcaseItems(project, group) {
|
|
104
107
|
/** @type {import('./_catalog.mjs').CatalogItem[]} */
|
|
@@ -117,6 +120,9 @@ export function showcaseItems(project, group) {
|
|
|
117
120
|
if (!g) continue;
|
|
118
121
|
const inParent = inParentOf(project, name);
|
|
119
122
|
if (inParent === null) continue;
|
|
123
|
+
// A component no Core module exports by its name cannot be imported,
|
|
124
|
+
// so it would draw an empty cell: it gets none.
|
|
125
|
+
if (!importPathOf(project, name)) continue;
|
|
120
126
|
for (const v of catalogVariants(project, name, 12, {shown: true}))
|
|
121
127
|
items.push({
|
|
122
128
|
group: g,
|
|
@@ -133,7 +139,7 @@ export function showcaseItems(project, group) {
|
|
|
133
139
|
});
|
|
134
140
|
/** @type {string[]} */
|
|
135
141
|
const skipped = [];
|
|
136
|
-
/** @type {Record<string,
|
|
142
|
+
/** @type {Record<string, import('./_catalog.mjs').Binding>} */
|
|
137
143
|
const templateImports = {};
|
|
138
144
|
for (const t of PAGE_TEMPLATES) {
|
|
139
145
|
const file = path.join(TEMPLATES_DIR, t, 'page.tsx');
|
|
@@ -149,7 +155,8 @@ export function showcaseItems(project, group) {
|
|
|
149
155
|
continue;
|
|
150
156
|
}
|
|
151
157
|
const local = `Template_${t.replace(/-/g, '_')}`;
|
|
152
|
-
|
|
158
|
+
// A template page is its file's default export.
|
|
159
|
+
templateImports[local] = {from: `./templates/${t}.tsx`, export: 'default'};
|
|
153
160
|
items.push({
|
|
154
161
|
group: 'pages',
|
|
155
162
|
name: `${t} template`,
|
|
@@ -163,8 +170,8 @@ export function showcaseItems(project, group) {
|
|
|
163
170
|
};
|
|
164
171
|
const chosen = items
|
|
165
172
|
.filter(it => !group || it.group === group)
|
|
166
|
-
.sort((a, b) => order(a) - order(b) || a.name
|
|
167
|
-
/** @type {Record<string,
|
|
173
|
+
.sort((a, b) => order(a) - order(b) || compareText(a.name, b.name));
|
|
174
|
+
/** @type {Record<string, import('./_catalog.mjs').Binding>} */
|
|
168
175
|
const imports = {};
|
|
169
176
|
for (const n of elementNames(chosen.map(i => i.tree))) {
|
|
170
177
|
if (templateImports[n]) {
|
|
@@ -226,12 +233,12 @@ function inParentOf(project, name) {
|
|
|
226
233
|
|
|
227
234
|
/**
|
|
228
235
|
* Template page modules the theme-building page imports, copied beside it.
|
|
229
|
-
* @param {Record<string,
|
|
236
|
+
* @param {Record<string, import('./_catalog.mjs').Binding>} imports
|
|
230
237
|
* @returns {Array<{name: string, from: string}>}
|
|
231
238
|
*/
|
|
232
239
|
function templateFiles(imports) {
|
|
233
|
-
return Object.values(imports).flatMap(
|
|
234
|
-
const m = /^\.\/templates\/([a-z0-9-]+)\.tsx$/.exec(
|
|
240
|
+
return Object.values(imports).flatMap(b => {
|
|
241
|
+
const m = /^\.\/templates\/([a-z0-9-]+)\.tsx$/.exec(bindingFrom(b));
|
|
235
242
|
return m
|
|
236
243
|
? [
|
|
237
244
|
{
|
|
@@ -254,7 +261,21 @@ function templateFiles(imports) {
|
|
|
254
261
|
* @returns {string[]}
|
|
255
262
|
*/
|
|
256
263
|
export function baseFontsCss(ctx, data) {
|
|
257
|
-
|
|
264
|
+
const sheet = baseFontsSheet(ctx, data);
|
|
265
|
+
return sheet ? [sheet.spec] : [];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The base theme's fonts stylesheet as {@link baseFontsCss} imports it: its
|
|
270
|
+
* import spec, the families it loads, and the remote stylesheets it loads
|
|
271
|
+
* them from (a Google Fonts `@import`), which a static page cannot load.
|
|
272
|
+
* Null when the base ships none or the build names none of its families.
|
|
273
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
274
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
275
|
+
* @returns {{spec: string, families: string[], remote: string[]} | null}
|
|
276
|
+
*/
|
|
277
|
+
export function baseFontsSheet(ctx, data) {
|
|
278
|
+
if (!data.like) return null;
|
|
258
279
|
const pkg = `@astryxdesign/theme-${data.like}`;
|
|
259
280
|
const sheet = `${pkg}/fonts.css`;
|
|
260
281
|
// Read off disk: the package must export the sheet for an app to import
|
|
@@ -263,7 +284,7 @@ export function baseFontsCss(ctx, data) {
|
|
|
263
284
|
/** @type {string} */
|
|
264
285
|
let text;
|
|
265
286
|
try {
|
|
266
|
-
if (!found) return
|
|
287
|
+
if (!found) return null;
|
|
267
288
|
const exportsMap = JSON.parse(
|
|
268
289
|
fs.readFileSync(path.join(found.packageDir, 'package.json'), 'utf8'),
|
|
269
290
|
).exports;
|
|
@@ -272,10 +293,10 @@ export function baseFontsCss(ctx, data) {
|
|
|
272
293
|
typeof exportsMap !== 'object' ||
|
|
273
294
|
!('./fonts.css' in exportsMap)
|
|
274
295
|
)
|
|
275
|
-
return
|
|
296
|
+
return null;
|
|
276
297
|
text = fs.readFileSync(path.join(found.packageDir, 'fonts.css'), 'utf8');
|
|
277
298
|
} catch {
|
|
278
|
-
return
|
|
299
|
+
return null;
|
|
279
300
|
}
|
|
280
301
|
// The families the sheet loads; with the theme's build at hand, the sheet
|
|
281
302
|
// is imported only while the build still names one of them.
|
|
@@ -291,9 +312,14 @@ export function baseFontsCss(ctx, data) {
|
|
|
291
312
|
}
|
|
292
313
|
if (built != null && families.length) {
|
|
293
314
|
const css = built;
|
|
294
|
-
if (!families.some(f => css.includes(f))) return
|
|
315
|
+
if (!families.some(f => css.includes(f))) return null;
|
|
295
316
|
}
|
|
296
|
-
|
|
317
|
+
const remote = [
|
|
318
|
+
...text.matchAll(
|
|
319
|
+
/@import\s+(?:url\(\s*)?["']?((?:[a-z]+:)?\/\/[^"')\s]+)/gi,
|
|
320
|
+
),
|
|
321
|
+
].map(m => m[1]);
|
|
322
|
+
return {spec: sheet, families, remote};
|
|
297
323
|
}
|
|
298
324
|
|
|
299
325
|
/**
|
|
@@ -1303,7 +1329,9 @@ export function previewRouteSource({
|
|
|
1303
1329
|
' <AppShell',
|
|
1304
1330
|
' height="fill"',
|
|
1305
1331
|
' topNav={',
|
|
1306
|
-
|
|
1332
|
+
// Core's own heading, as an app's top bar draws it, so a setting on the
|
|
1333
|
+
// header (its text color) shows here as it does in the app.
|
|
1334
|
+
` <TopNav label="Theme preview" heading={<TopNavHeading heading={${JSON.stringify(name)}} />} endContent={`,
|
|
1307
1335
|
...(mode.length ? mode : [' null']),
|
|
1308
1336
|
' } />',
|
|
1309
1337
|
' }',
|
|
@@ -1328,7 +1356,7 @@ export function previewRouteSource({
|
|
|
1328
1356
|
"import * as React from 'react';",
|
|
1329
1357
|
"import {AppShell} from '@astryxdesign/core/AppShell';",
|
|
1330
1358
|
"import {SideNav, SideNavItem} from '@astryxdesign/core/SideNav';",
|
|
1331
|
-
"import {TopNav} from '@astryxdesign/core/TopNav';",
|
|
1359
|
+
"import {TopNav, TopNavHeading} from '@astryxdesign/core/TopNav';",
|
|
1332
1360
|
...(theme
|
|
1333
1361
|
? [
|
|
1334
1362
|
// The mode switch only for a theme with both modes: an import the
|
|
@@ -1408,91 +1436,165 @@ export function previewRouteSource({
|
|
|
1408
1436
|
/** @param {string} slug */
|
|
1409
1437
|
const camelName = camel;
|
|
1410
1438
|
|
|
1439
|
+
/** The script that takes one picture through the project's Playwright. */
|
|
1440
|
+
const PLAYWRIGHT_PICTURE = fileURLToPath(
|
|
1441
|
+
new URL('../../foundation/render/picture-playwright.mjs', import.meta.url),
|
|
1442
|
+
);
|
|
1443
|
+
|
|
1444
|
+
/** The script that takes one picture through a Chrome or Chromium. */
|
|
1445
|
+
const CHROME_PICTURE = fileURLToPath(
|
|
1446
|
+
new URL('../../foundation/render/picture-chrome.mjs', import.meta.url),
|
|
1447
|
+
);
|
|
1448
|
+
|
|
1449
|
+
/** How long a stopped browser may take to close before it is killed. */
|
|
1450
|
+
const STOP_GRACE_MS = 5_000;
|
|
1451
|
+
|
|
1452
|
+
/** The signals that stop a picture run, the terminal closing among them. */
|
|
1453
|
+
const STOP_SIGNALS = /** @type {const} */ (['SIGINT', 'SIGTERM', 'SIGHUP']);
|
|
1454
|
+
|
|
1455
|
+
/** How long a browser may take for one picture before it is stopped. */
|
|
1456
|
+
const BROWSER_BOUND_MS = 60_000;
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* What the pictures of one run share: the browsers that failed or hung,
|
|
1460
|
+
* each with its reason, so a later picture does not wait on them again.
|
|
1461
|
+
* @typedef {{failed: Map<string, string>}} PictureRun
|
|
1462
|
+
*/
|
|
1463
|
+
|
|
1464
|
+
/** A new picture run. @returns {PictureRun} */
|
|
1465
|
+
export function newPictureRun() {
|
|
1466
|
+
return {failed: new Map()};
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1411
1469
|
/**
|
|
1412
|
-
* A PNG of an HTML file, with a Playwright the project has
|
|
1413
|
-
* a Chrome or Chromium found on the machine.
|
|
1414
|
-
*
|
|
1415
|
-
*
|
|
1470
|
+
* A whole-page PNG of an HTML file, with a Playwright the project has
|
|
1471
|
+
* installed, else a Chrome or Chromium found on the machine. Each browser
|
|
1472
|
+
* gets its own time bound, and the next one its turn when one fails or
|
|
1473
|
+
* hangs. Not ok with a reason when none is there or every one failed: the
|
|
1474
|
+
* reason then names each one's real error. When a later browser took the
|
|
1475
|
+
* picture, `note` says why an earlier one did not.
|
|
1416
1476
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
1417
1477
|
* @param {string} html absolute
|
|
1418
1478
|
* @param {string} png absolute
|
|
1419
1479
|
* @param {'light' | 'dark'} mode
|
|
1420
|
-
* @
|
|
1480
|
+
* @param {PictureRun} [run] what earlier pictures of the same run learned:
|
|
1481
|
+
* a browser that failed or hung there is not tried again
|
|
1482
|
+
* @returns {Promise<{ok: true, file: string, note?: string} | {ok: false, reason: string, stopped?: string}>}
|
|
1421
1483
|
*/
|
|
1422
|
-
export async function screenshot(
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1484
|
+
export async function screenshot(
|
|
1485
|
+
project,
|
|
1486
|
+
html,
|
|
1487
|
+
png,
|
|
1488
|
+
mode,
|
|
1489
|
+
run = newPictureRun(),
|
|
1490
|
+
) {
|
|
1491
|
+
/** What was tried and why it could not take the picture. @type {string[]} */
|
|
1492
|
+
const failed = [...run.failed.values()];
|
|
1493
|
+
/** Whether a Playwright was found without its own browser installed. */
|
|
1494
|
+
let pwMissing = false;
|
|
1495
|
+
/** Whether a Playwright was found at all. */
|
|
1496
|
+
let pwFound = false;
|
|
1497
|
+
/** A line with no path of this machine. @param {string} line */
|
|
1498
|
+
const local = line => line.split(project.cwd).join('.');
|
|
1499
|
+
/**
|
|
1500
|
+
* Why a browser did not take the picture: Playwright's first line names
|
|
1501
|
+
* only the call ("browserType.launch: Target … closed"); the cause, such
|
|
1502
|
+
* as a missing library, is in a later line, so that line comes too.
|
|
1503
|
+
* Chrome's startup warnings (dbus, GPU) are not a cause.
|
|
1504
|
+
* @param {string} text
|
|
1505
|
+
*/
|
|
1506
|
+
const causeOf = text => {
|
|
1507
|
+
const lines = String(text ?? '')
|
|
1428
1508
|
.split('\n')
|
|
1429
|
-
.map(l => l.trim())
|
|
1430
|
-
.
|
|
1431
|
-
|
|
1432
|
-
.join('
|
|
1509
|
+
.map(l => l.replace(/^[\s=<>-]+/, '').trim())
|
|
1510
|
+
.filter(Boolean);
|
|
1511
|
+
const head =
|
|
1512
|
+
meaningfulLine(lines.join('\n')) || 'it stopped with no message';
|
|
1513
|
+
const rest = lines
|
|
1514
|
+
.slice(lines.indexOf(head) + 1)
|
|
1515
|
+
.find(l =>
|
|
1516
|
+
/error|cannot|can't|missing|not found|while loading|no such|failed|denied/i.test(
|
|
1517
|
+
l,
|
|
1518
|
+
),
|
|
1519
|
+
);
|
|
1520
|
+
return local(rest ? `${head} (${rest})` : head);
|
|
1521
|
+
};
|
|
1522
|
+
/** The browsers to try, in order: each a picture script and its args. */
|
|
1523
|
+
/** @type {Array<{who: string, script: string, args: string[]}>} */
|
|
1524
|
+
const tries = [];
|
|
1433
1525
|
for (const pkg of ['playwright', 'playwright-core']) {
|
|
1434
|
-
/** @type {string} */
|
|
1435
|
-
let entry;
|
|
1436
1526
|
try {
|
|
1437
|
-
entry = project.req.resolve(pkg);
|
|
1527
|
+
const entry = project.req.resolve(pkg);
|
|
1528
|
+
pwFound = true;
|
|
1529
|
+
tries.push({
|
|
1530
|
+
who: `${pkg}'s own browser`,
|
|
1531
|
+
script: PLAYWRIGHT_PICTURE,
|
|
1532
|
+
args: [entry, html, png, mode],
|
|
1533
|
+
});
|
|
1534
|
+
break;
|
|
1438
1535
|
} 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)}`);
|
|
1536
|
+
// Not installed here.
|
|
1461
1537
|
}
|
|
1462
1538
|
}
|
|
1463
1539
|
const chrome = chromeBinary();
|
|
1464
|
-
if (chrome)
|
|
1465
|
-
|
|
1466
|
-
chrome,
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1540
|
+
if (chrome)
|
|
1541
|
+
tries.push({
|
|
1542
|
+
who: chrome,
|
|
1543
|
+
script: CHROME_PICTURE,
|
|
1544
|
+
args: [chrome, html, png, mode],
|
|
1545
|
+
});
|
|
1546
|
+
for (const t of tries) {
|
|
1547
|
+
if (run.failed.has(t.who)) continue;
|
|
1548
|
+
const r = await runBrowser(t.script, t.args, BROWSER_BOUND_MS, {
|
|
1549
|
+
drop: [png],
|
|
1550
|
+
});
|
|
1551
|
+
if (r.stoppedBy)
|
|
1552
|
+
return {
|
|
1553
|
+
ok: false,
|
|
1554
|
+
stopped: r.stoppedBy,
|
|
1555
|
+
reason: `the pictures were stopped (${r.stoppedBy}) before the browser finished`,
|
|
1556
|
+
};
|
|
1557
|
+
if (r.noTemp)
|
|
1558
|
+
return {
|
|
1559
|
+
ok: false,
|
|
1560
|
+
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`,
|
|
1561
|
+
};
|
|
1480
1562
|
if (r.status === 0 && fs.existsSync(png))
|
|
1481
|
-
return {
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
);
|
|
1563
|
+
return {
|
|
1564
|
+
ok: true,
|
|
1565
|
+
file: shown(project.cwd, png),
|
|
1566
|
+
...(failed.length
|
|
1567
|
+
? {
|
|
1568
|
+
note: `the picture was taken with ${t.who}; ${failed.join('; ')}`,
|
|
1569
|
+
}
|
|
1570
|
+
: {}),
|
|
1571
|
+
};
|
|
1572
|
+
const text = r.error ? String(r.error.message) : r.stderr;
|
|
1573
|
+
if (
|
|
1574
|
+
t.script === PLAYWRIGHT_PICTURE &&
|
|
1575
|
+
/Executable doesn't exist|playwright install/i.test(text)
|
|
1576
|
+
)
|
|
1577
|
+
pwMissing = true;
|
|
1578
|
+
const why = r.timedOut
|
|
1579
|
+
? `${t.who} did not finish within ${BROWSER_BOUND_MS / 1000} seconds, so it was stopped`
|
|
1580
|
+
: `${t.who} could not take it: ${causeOf(text)}`;
|
|
1581
|
+
run.failed.set(t.who, why);
|
|
1582
|
+
failed.push(why);
|
|
1491
1583
|
}
|
|
1492
1584
|
if (failed.length)
|
|
1493
1585
|
return {
|
|
1494
1586
|
ok: false,
|
|
1495
|
-
|
|
1587
|
+
// Advice that can change the result: Playwright's browser only when
|
|
1588
|
+
// it is missing; a Chrome to check only when there is one.
|
|
1589
|
+
// What went wrong for this picture, and what can change it; the run
|
|
1590
|
+
// that asked for it says which pictures were and were not taken.
|
|
1591
|
+
reason: `${failed.join('; ')}. ${
|
|
1592
|
+
!pwFound
|
|
1593
|
+
? `Install Playwright with its browser (${installLine(project.cwd, ['playwright'])}, then npx playwright install chromium), or`
|
|
1594
|
+
: pwMissing
|
|
1595
|
+
? 'Give Playwright its browser (npx playwright install chromium), or'
|
|
1596
|
+
: "Fix what Playwright's browser needs (the reason is above), or"
|
|
1597
|
+
} ${chrome ? `check that ${chrome} starts on this machine` : 'install Google Chrome or Chromium'}. The HTML preview needs neither.`,
|
|
1496
1598
|
};
|
|
1497
1599
|
return {
|
|
1498
1600
|
ok: false,
|
|
@@ -1515,11 +1617,23 @@ function chromeBinary() {
|
|
|
1515
1617
|
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
1516
1618
|
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
1517
1619
|
];
|
|
1518
|
-
|
|
1620
|
+
// Only a file that runs: a folder or a file with no execute permission
|
|
1621
|
+
// by a browser's name is passed over, and the search goes on.
|
|
1622
|
+
/** @param {string} f */
|
|
1623
|
+
const runs = f => {
|
|
1624
|
+
try {
|
|
1625
|
+
if (!fs.statSync(f).isFile()) return false;
|
|
1626
|
+
if (process.platform !== 'win32') fs.accessSync(f, fs.constants.X_OK);
|
|
1627
|
+
return true;
|
|
1628
|
+
} catch {
|
|
1629
|
+
return false;
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
for (const f of fixed) if (runs(f)) return f;
|
|
1519
1633
|
for (const dir of (process.env.PATH ?? '').split(path.delimiter)) {
|
|
1520
1634
|
for (const n of names) {
|
|
1521
1635
|
const f = path.join(dir, n);
|
|
1522
|
-
if (dir &&
|
|
1636
|
+
if (dir && runs(f)) return f;
|
|
1523
1637
|
}
|
|
1524
1638
|
}
|
|
1525
1639
|
return null;
|
|
@@ -1527,7 +1641,25 @@ function chromeBinary() {
|
|
|
1527
1641
|
|
|
1528
1642
|
/** The first line of every file the editor writes into a theme's app copy. */
|
|
1529
1643
|
export {APP_COPY_MARK} from './_marks.mjs';
|
|
1530
|
-
import {APP_COPY_MARK} from './_marks.mjs';
|
|
1644
|
+
import {APP_COPY_MARK, appCopyMark} from './_marks.mjs';
|
|
1645
|
+
import {builtColorMode} from '../../foundation/discovery/theme-imports.mjs';
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* The font stylesheets a theme's app copy imports, from the fonts the theme
|
|
1649
|
+
* loads now (an installed font package, the base theme's fonts).
|
|
1650
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1651
|
+
* @param {string} slug
|
|
1652
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1653
|
+
* @returns {string[]}
|
|
1654
|
+
*/
|
|
1655
|
+
export function copyFontsCss(ctx, slug, data) {
|
|
1656
|
+
return themeImports(
|
|
1657
|
+
ctx,
|
|
1658
|
+
slug,
|
|
1659
|
+
data,
|
|
1660
|
+
path.join(ctx.project.cwd, 'src', 'themes', slug),
|
|
1661
|
+
).css.slice(1);
|
|
1662
|
+
}
|
|
1531
1663
|
|
|
1532
1664
|
/**
|
|
1533
1665
|
* The app's copy of an editor theme: a standard local theme in
|
|
@@ -1545,38 +1677,26 @@ import {APP_COPY_MARK} from './_marks.mjs';
|
|
|
1545
1677
|
* @returns {string | null}
|
|
1546
1678
|
*/
|
|
1547
1679
|
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
|
-
);
|
|
1680
|
+
return writeAppCopyAt(ctx.project.cwd, slug, copyFontsCss(ctx, slug, data));
|
|
1558
1681
|
}
|
|
1559
1682
|
|
|
1560
1683
|
/**
|
|
1561
|
-
*
|
|
1562
|
-
* copy
|
|
1684
|
+
* The files of a theme's app copy as the editor would write them now, by
|
|
1685
|
+
* name; null with no build to copy. Font stylesheets as given, or null for
|
|
1686
|
+
* the copy's own.
|
|
1563
1687
|
* @param {string} cwd
|
|
1564
1688
|
* @param {string} slug
|
|
1565
1689
|
* @param {string[] | null} fontsCss
|
|
1566
|
-
* @returns {string | null}
|
|
1690
|
+
* @returns {Record<string, string> | null}
|
|
1567
1691
|
*/
|
|
1568
|
-
|
|
1692
|
+
function appCopyFiles(cwd, slug, fontsCss) {
|
|
1569
1693
|
const f = themeFiles(cwd, slug);
|
|
1570
1694
|
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1571
1695
|
const name = `${camel(slug)}Theme`;
|
|
1572
|
-
const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
|
|
1573
1696
|
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
1697
|
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
1698
|
const head = (/** @type {string} */ open, /** @type {string} */ close) =>
|
|
1579
|
-
`${open} ${
|
|
1699
|
+
`${open} ${appCopyMark(slug)} after every build of themes/${slug}/; do not edit it here. Change the theme with the editor. ${close}\n`;
|
|
1580
1700
|
const keptFonts = path.join(dir, `${slug}.fonts.css`);
|
|
1581
1701
|
const fonts =
|
|
1582
1702
|
fontsCss ??
|
|
@@ -1598,27 +1718,115 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
|
1598
1718
|
if (fs.existsSync(from))
|
|
1599
1719
|
built[`${slug}${ext}`] = asBuilt(fs.readFileSync(from, 'utf8'));
|
|
1600
1720
|
}
|
|
1721
|
+
// A light-only or dark-only theme's build exports its one color mode
|
|
1722
|
+
// (`colorModes`); the copy's source re-exports it, so a build of the copy
|
|
1723
|
+
// writes it too and `theme add` reads it.
|
|
1724
|
+
const oneMode = builtColorMode(f.js).mode;
|
|
1601
1725
|
const files = {
|
|
1602
1726
|
[`${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`,
|
|
1727
|
+
[`${name}.ts`]: `${head('//', '')}export {${name}${oneMode ? ', colorModes' : ''}} from './${slug}';\n`,
|
|
1604
1728
|
...built,
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
: {})
|
|
1729
|
+
// Always there, so the app theme module's import of it holds when the
|
|
1730
|
+
// theme's fonts change (none: a comment only).
|
|
1731
|
+
[`${slug}.fonts.css`]: fonts.length
|
|
1732
|
+
? `${head('/*', '*/')}${fonts.map(c => `@import ${JSON.stringify(c)};`).join('\n')}\n`
|
|
1733
|
+
: `${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
1734
|
};
|
|
1611
|
-
|
|
1735
|
+
return files;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
/**
|
|
1739
|
+
* Why a theme's app copy is behind its build, or null when it is current:
|
|
1740
|
+
* something in its way (appCopyStale), a copy file missing, or a file
|
|
1741
|
+
* whose content is not what the editor would write now.
|
|
1742
|
+
* @param {string} cwd
|
|
1743
|
+
* @param {string} slug
|
|
1744
|
+
* @param {string[] | null} [fontsCss] the font stylesheets the copy should
|
|
1745
|
+
* import now (null: the copy's own)
|
|
1746
|
+
* @returns {string | null}
|
|
1747
|
+
*/
|
|
1748
|
+
export function appCopyBehind(cwd, slug, fontsCss = null) {
|
|
1749
|
+
const stale = appCopyStale(cwd, slug).appCopyStale;
|
|
1750
|
+
if (stale) return stale;
|
|
1751
|
+
const files = appCopyFiles(cwd, slug, fontsCss);
|
|
1752
|
+
if (!files) return null;
|
|
1753
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1754
|
+
if (!fs.existsSync(dir))
|
|
1755
|
+
return `the app copy in src/themes/${slug}/ is gone; the editor writes it again`;
|
|
1612
1756
|
for (const [n, text] of Object.entries(files)) {
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1757
|
+
/** @type {string} */
|
|
1758
|
+
let now;
|
|
1759
|
+
try {
|
|
1760
|
+
now = fs.readFileSync(path.join(dir, n), 'utf8');
|
|
1761
|
+
} catch {
|
|
1762
|
+
return `src/themes/${slug}/${n} is missing from the app copy`;
|
|
1763
|
+
}
|
|
1764
|
+
// Line endings as a checkout writes them (CRLF on Windows) are the
|
|
1765
|
+
// same content, as the outputs check reads them.
|
|
1766
|
+
const lf = (/** @type {string} */ x) => x.replace(/\r\n/g, '\n');
|
|
1767
|
+
if (lf(now) !== lf(text))
|
|
1768
|
+
return `src/themes/${slug}/${n} is not the current build of themes/${slug}/`;
|
|
1616
1769
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1770
|
+
return null;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* {@link writeAppCopy} with the font stylesheets given, or null to keep the
|
|
1775
|
+
* copy's own (a compile, which changes no setting).
|
|
1776
|
+
* @param {string} cwd
|
|
1777
|
+
* @param {string} slug
|
|
1778
|
+
* @param {string[] | null} fontsCss
|
|
1779
|
+
* @returns {string | null}
|
|
1780
|
+
*/
|
|
1781
|
+
export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
1782
|
+
const f = themeFiles(cwd, slug);
|
|
1783
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1784
|
+
const name = `${camel(slug)}Theme`;
|
|
1785
|
+
const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
|
|
1786
|
+
if (!fs.existsSync(f.js) || !fs.existsSync(f.css)) return null;
|
|
1787
|
+
// Only the editor's own copy is written over.
|
|
1788
|
+
if (appCopyBlocker(cwd, slug) !== null) return null;
|
|
1789
|
+
const files = appCopyFiles(cwd, slug, fontsCss);
|
|
1790
|
+
if (!files) return null;
|
|
1791
|
+
const failKey = `${path.resolve(cwd)}\0${slug}`;
|
|
1792
|
+
try {
|
|
1793
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
1794
|
+
for (const [n, text] of Object.entries(files)) {
|
|
1795
|
+
const file = path.join(dir, n);
|
|
1796
|
+
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === text)
|
|
1797
|
+
continue;
|
|
1798
|
+
writeWhole(file, text);
|
|
1799
|
+
}
|
|
1800
|
+
// A copy's own file this build no longer writes goes; anything else in
|
|
1801
|
+
// the folder (yours, or the system's) stays as it is.
|
|
1802
|
+
for (const n of fs.readdirSync(dir))
|
|
1803
|
+
if (appCopyNames(slug).has(n) && !(n in files))
|
|
1804
|
+
fs.rmSync(path.join(dir, n), {force: true});
|
|
1805
|
+
} catch (e) {
|
|
1806
|
+
// A copy that cannot be written is said, with the system's reason;
|
|
1807
|
+
// the change itself stands.
|
|
1808
|
+
const code = /** @type {any} */ (e)?.code ?? 'error';
|
|
1809
|
+
// The folder that failed: the copy's, or a parent it could not be
|
|
1810
|
+
// made in.
|
|
1811
|
+
const failed = /** @type {any} */ (e)?.path
|
|
1812
|
+
? path.resolve(String(/** @type {any} */ (e).path))
|
|
1813
|
+
: dir;
|
|
1814
|
+
const at = fs.existsSync(failed) ? failed : path.dirname(failed);
|
|
1815
|
+
const rel = path.relative(cwd, at).split(path.sep).join('/');
|
|
1816
|
+
const unwritable =
|
|
1817
|
+
code === 'EACCES' || code === 'EPERM' || code === 'EROFS';
|
|
1818
|
+
COPY_FAILED.set(failKey, {
|
|
1819
|
+
why: unwritable
|
|
1820
|
+
? `${rel} is not writable (${code})`
|
|
1821
|
+
: code === 'ENOSPC'
|
|
1822
|
+
? `the disk is full (${code})`
|
|
1823
|
+
: `${rel} could not be written (${code})`,
|
|
1824
|
+
// A folder that was not writable, to see whether it still is.
|
|
1825
|
+
...(unwritable ? {folder: at} : {}),
|
|
1826
|
+
});
|
|
1827
|
+
return null;
|
|
1828
|
+
}
|
|
1829
|
+
COPY_FAILED.delete(failKey);
|
|
1622
1830
|
// The first write is named in the command's result; later ones are not.
|
|
1623
1831
|
if (first)
|
|
1624
1832
|
FIRST_COPIES.set(
|
|
@@ -1633,13 +1841,45 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
|
1633
1841
|
}
|
|
1634
1842
|
|
|
1635
1843
|
/**
|
|
1636
|
-
*
|
|
1637
|
-
*
|
|
1638
|
-
*
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
|
|
1642
|
-
|
|
1844
|
+
* The note for a copy a file of yours keeps from being written, as a
|
|
1845
|
+
* result field: `{appCopyStale}` when one does, else nothing.
|
|
1846
|
+
* @param {string} cwd
|
|
1847
|
+
* @param {string} slug
|
|
1848
|
+
* @returns {{appCopyStale?: string}}
|
|
1849
|
+
*/
|
|
1850
|
+
export function appCopyStale(cwd, slug) {
|
|
1851
|
+
const blocker = appCopyBlocker(cwd, slug) ?? copyFailure(cwd, slug) ?? null;
|
|
1852
|
+
return blocker
|
|
1853
|
+
? {
|
|
1854
|
+
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.`,
|
|
1855
|
+
}
|
|
1856
|
+
: {};
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
/**
|
|
1860
|
+
* The names of a theme's app copy files.
|
|
1861
|
+
* @param {string} slug
|
|
1862
|
+
* @returns {Set<string>}
|
|
1863
|
+
*/
|
|
1864
|
+
function appCopyNames(slug) {
|
|
1865
|
+
const name = `${camel(slug)}Theme`;
|
|
1866
|
+
return new Set([
|
|
1867
|
+
`${name}.doc.mjs`,
|
|
1868
|
+
`${name}.ts`,
|
|
1869
|
+
`${slug}.fonts.css`,
|
|
1870
|
+
...APP_COPY_BUILT.map(ext => `${slug}${ext}`),
|
|
1871
|
+
]);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Why the editor will not write a theme's app copy, or null when it will.
|
|
1876
|
+
* Only a file of yours AT one of the copy's names stops it: a descriptor,
|
|
1877
|
+
* source or font stylesheet without the editor's mark, or any copy file
|
|
1878
|
+
* while the descriptor is not the editor's. Other files there (a note, a
|
|
1879
|
+
* swap file, desktop.ini) are left as they are and the copy is written
|
|
1880
|
+
* around them. Built bytes are not compared, so a stable rebuild of the
|
|
1881
|
+
* copy leaves it the editor's. The one test the copy's writer, the change
|
|
1882
|
+
* results and `wiring` use. Returns the file in the way.
|
|
1643
1883
|
* @param {string} cwd
|
|
1644
1884
|
* @param {string} slug
|
|
1645
1885
|
* @returns {string | null}
|
|
@@ -1648,37 +1888,133 @@ export function appCopyBlocker(cwd, slug) {
|
|
|
1648
1888
|
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1649
1889
|
const name = `${camel(slug)}Theme`;
|
|
1650
1890
|
const rel = path.relative(cwd, dir).split(path.sep).join('/');
|
|
1891
|
+
// The copy carries the built module whole, and a local theme imports
|
|
1892
|
+
// only files of its own folder: a module that imports a file beside it
|
|
1893
|
+
// (an icon registry of the theme's folder) would break in the app.
|
|
1894
|
+
{
|
|
1895
|
+
const built = themeFiles(cwd, slug).js;
|
|
1896
|
+
/** @type {string[]} */
|
|
1897
|
+
let specifiers;
|
|
1898
|
+
try {
|
|
1899
|
+
specifiers = themeFileImports(built);
|
|
1900
|
+
} catch {
|
|
1901
|
+
specifiers = [];
|
|
1902
|
+
}
|
|
1903
|
+
const local = specifiers.find(s => s.startsWith('.'));
|
|
1904
|
+
if (local)
|
|
1905
|
+
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`;
|
|
1906
|
+
}
|
|
1907
|
+
// Nothing is written through a link on the way from the app to the copy
|
|
1908
|
+
// (src/, src/themes/, the copy's folder), as for themes/.
|
|
1909
|
+
for (const part of ['src', 'src/themes', rel]) {
|
|
1910
|
+
try {
|
|
1911
|
+
const st = fs.lstatSync(path.join(cwd, part));
|
|
1912
|
+
if (st.isSymbolicLink())
|
|
1913
|
+
return `${part} is a link (to ${fs.readlinkSync(path.join(cwd, part))}), and the editor writes nothing through a link`;
|
|
1914
|
+
// A file where a folder on the way goes: nothing is half-written.
|
|
1915
|
+
if (!st.isDirectory())
|
|
1916
|
+
return part === rel
|
|
1917
|
+
? `${rel} is a file, where the copy's folder goes`
|
|
1918
|
+
: `${part} is a file, where a folder on the way to the copy goes`;
|
|
1919
|
+
} catch {
|
|
1920
|
+
break;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
try {
|
|
1924
|
+
if (!fs.lstatSync(dir).isDirectory())
|
|
1925
|
+
return `${rel} is a file, where the copy's folder goes`;
|
|
1926
|
+
} catch {
|
|
1927
|
+
// Not there yet: the copy makes it.
|
|
1928
|
+
}
|
|
1651
1929
|
if (folderIsEmpty(dir)) return null;
|
|
1652
1930
|
/** @type {string[]} */
|
|
1653
1931
|
let names;
|
|
1654
1932
|
try {
|
|
1655
1933
|
names = fs.readdirSync(dir);
|
|
1656
|
-
} catch {
|
|
1657
|
-
return rel
|
|
1934
|
+
} catch (e) {
|
|
1935
|
+
return `${rel} cannot be read (${/** @type {any} */ (e)?.code ?? 'error'})`;
|
|
1658
1936
|
}
|
|
1659
|
-
/** @
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1937
|
+
/** @param {string} n */
|
|
1938
|
+
const marked = n => {
|
|
1939
|
+
try {
|
|
1940
|
+
return fs.readFileSync(path.join(dir, n), 'utf8').includes(APP_COPY_MARK);
|
|
1941
|
+
} catch {
|
|
1942
|
+
return false;
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
const own = appCopyNames(slug);
|
|
1946
|
+
const present = names.filter(n => own.has(n));
|
|
1947
|
+
// A link at a copy name is never written through or replaced.
|
|
1948
|
+
for (const n of present)
|
|
1949
|
+
try {
|
|
1950
|
+
const st = fs.lstatSync(path.join(dir, n));
|
|
1951
|
+
if (st.isSymbolicLink())
|
|
1952
|
+
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`;
|
|
1953
|
+
if (st.isDirectory())
|
|
1954
|
+
return `${rel}/${n} is a folder, at a name the copy uses for a file`;
|
|
1955
|
+
} catch {
|
|
1956
|
+
// Gone since it was listed.
|
|
1957
|
+
}
|
|
1958
|
+
// The copy is the editor's when any of its marked files carries the
|
|
1959
|
+
// mark (one of them deleted is written back); then only a marked name
|
|
1960
|
+
// without the mark is yours.
|
|
1961
|
+
const markedNames = [`${name}.doc.mjs`, `${name}.ts`, `${slug}.fonts.css`];
|
|
1962
|
+
// A build output of the copy's source carries the build's own header.
|
|
1963
|
+
const generated = (/** @type {string} */ n) => {
|
|
1964
|
+
try {
|
|
1965
|
+
return /@generated by `astryx theme build`/.test(
|
|
1966
|
+
fs.readFileSync(path.join(dir, n), 'utf8').slice(0, 600),
|
|
1967
|
+
);
|
|
1968
|
+
} catch {
|
|
1969
|
+
return false;
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
const ours =
|
|
1973
|
+
markedNames.some(n => present.includes(n) && marked(n)) ||
|
|
1974
|
+
(present.length > 0 &&
|
|
1975
|
+
present.every(n => !markedNames.includes(n) && generated(n)));
|
|
1976
|
+
const foreign = ours
|
|
1977
|
+
? present.find(n => markedNames.includes(n) && !marked(n))
|
|
1978
|
+
: present[0];
|
|
1979
|
+
return foreign
|
|
1980
|
+
? `${rel}/${foreign} is yours, at a name the copy uses, and the editor never writes over your files`
|
|
1981
|
+
: null;
|
|
1677
1982
|
}
|
|
1678
1983
|
|
|
1679
1984
|
/** The build outputs of a theme, by their ending after `<theme>`. */
|
|
1680
1985
|
const APP_COPY_BUILT = ['.css', '.css.d.ts', '.js', '.d.ts', '.variants.d.ts'];
|
|
1681
1986
|
|
|
1987
|
+
/**
|
|
1988
|
+
* Why the last write of a theme's app copy failed, by app and theme, and
|
|
1989
|
+
* the folder that was not writable when that was why.
|
|
1990
|
+
* @type {Map<string, {why: string, folder?: string}>}
|
|
1991
|
+
*/
|
|
1992
|
+
const COPY_FAILED = new Map();
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Why the last write of a theme's app copy failed, while that still holds:
|
|
1996
|
+
* a folder that was not writable and is now is no reason any more (a
|
|
1997
|
+
* process that runs several commands, as an API caller does, reads the
|
|
1998
|
+
* folder as it is now).
|
|
1999
|
+
* @param {string} cwd
|
|
2000
|
+
* @param {string} slug
|
|
2001
|
+
* @returns {string | null}
|
|
2002
|
+
*/
|
|
2003
|
+
function copyFailure(cwd, slug) {
|
|
2004
|
+
const key = `${path.resolve(cwd)}\0${slug}`;
|
|
2005
|
+
const failed = COPY_FAILED.get(key);
|
|
2006
|
+
if (!failed) return null;
|
|
2007
|
+
if (failed.folder)
|
|
2008
|
+
try {
|
|
2009
|
+
fs.accessSync(failed.folder, fs.constants.W_OK);
|
|
2010
|
+
COPY_FAILED.delete(key);
|
|
2011
|
+
return null;
|
|
2012
|
+
} catch {
|
|
2013
|
+
// Still not writable.
|
|
2014
|
+
}
|
|
2015
|
+
return failed.why;
|
|
2016
|
+
}
|
|
2017
|
+
|
|
1682
2018
|
/** App copies written for the first time in this process, by app and theme. @type {Map<string, string[]>} */
|
|
1683
2019
|
const FIRST_COPIES = new Map();
|
|
1684
2020
|
|
|
@@ -1695,3 +2031,164 @@ export function takeFirstAppCopy(cwd, slug) {
|
|
|
1695
2031
|
FIRST_COPIES.delete(key);
|
|
1696
2032
|
return wrote;
|
|
1697
2033
|
}
|
|
2034
|
+
|
|
2035
|
+
/**
|
|
2036
|
+
* Run a picture script (one browser, one picture) as its own process group,
|
|
2037
|
+
* without blocking this process. The one owner of every browser run:
|
|
2038
|
+
* - a temp folder of its own (TMPDIR, TMP, TEMP), where the browser keeps
|
|
2039
|
+
* its profile; with none to make, nothing runs (`noTemp`);
|
|
2040
|
+
* - a time bound (`timedOut`);
|
|
2041
|
+
* - a stop (SIGINT, SIGTERM, SIGHUP) that reaches the run stops it
|
|
2042
|
+
* (`stoppedBy`), then ends this process as the stop would have.
|
|
2043
|
+
* A stop or the bound asks the whole group to close, waits for it (killing
|
|
2044
|
+
* it past a short grace), then removes the temp folder and the `drop` files
|
|
2045
|
+
* (a picture part a stopped run leaves); a run that ends on its own removes
|
|
2046
|
+
* the temp folder only.
|
|
2047
|
+
* @param {string} script a picture script
|
|
2048
|
+
* @param {string[]} args
|
|
2049
|
+
* @param {number} [bound] milliseconds before the run is stopped
|
|
2050
|
+
* @param {{drop?: string[]}} [opts]
|
|
2051
|
+
* @returns {Promise<{status: number | null, signal: string | null, stderr: string, error?: Error, stoppedBy?: string, timedOut?: boolean, noTemp?: string}>}
|
|
2052
|
+
*/
|
|
2053
|
+
export function runBrowser(script, args, bound = BROWSER_BOUND_MS, opts = {}) {
|
|
2054
|
+
const drop = opts.drop ?? [];
|
|
2055
|
+
/** @type {string} */
|
|
2056
|
+
let temp;
|
|
2057
|
+
try {
|
|
2058
|
+
temp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-browser-'));
|
|
2059
|
+
} catch (e) {
|
|
2060
|
+
return Promise.resolve({
|
|
2061
|
+
status: null,
|
|
2062
|
+
signal: null,
|
|
2063
|
+
stderr: '',
|
|
2064
|
+
noTemp: String(/** @type {any} */ (e)?.code ?? e),
|
|
2065
|
+
});
|
|
2066
|
+
}
|
|
2067
|
+
return new Promise(resolve => {
|
|
2068
|
+
let stderr = '';
|
|
2069
|
+
const posix = process.platform !== 'win32';
|
|
2070
|
+
const child = spawn(process.execPath, [script, ...args], {
|
|
2071
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
2072
|
+
env: {...process.env, TMPDIR: temp, TMP: temp, TEMP: temp},
|
|
2073
|
+
// A group of its own, so a stop reaches the browser it starts too.
|
|
2074
|
+
detached: posix,
|
|
2075
|
+
});
|
|
2076
|
+
/** @param {NodeJS.Signals} sig */
|
|
2077
|
+
const signalAll = sig => {
|
|
2078
|
+
try {
|
|
2079
|
+
if (posix && child.pid) process.kill(-child.pid, sig);
|
|
2080
|
+
else child.kill(sig);
|
|
2081
|
+
} catch {
|
|
2082
|
+
// Gone already.
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
const closed = new Promise(done => child.once('close', done));
|
|
2086
|
+
/** @param {string[]} files */
|
|
2087
|
+
const remove = files => {
|
|
2088
|
+
for (const f of files)
|
|
2089
|
+
try {
|
|
2090
|
+
fs.rmSync(f, {recursive: true, force: true});
|
|
2091
|
+
} catch {
|
|
2092
|
+
// Gone already.
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
/** The temp folder goes on every way out; `drop` only with a stop. */
|
|
2096
|
+
const clean = () => remove([temp]);
|
|
2097
|
+
/** Close the group (killed past the grace), then clean up. */
|
|
2098
|
+
const finish = async () => {
|
|
2099
|
+
signalAll('SIGTERM');
|
|
2100
|
+
const grace = new Promise(done =>
|
|
2101
|
+
setTimeout(done, STOP_GRACE_MS).unref(),
|
|
2102
|
+
);
|
|
2103
|
+
if ((await Promise.race([closed.then(() => true), grace])) !== true) {
|
|
2104
|
+
signalAll('SIGKILL');
|
|
2105
|
+
await closed;
|
|
2106
|
+
}
|
|
2107
|
+
remove([temp, ...drop]);
|
|
2108
|
+
};
|
|
2109
|
+
// This process ending some other way: the group is killed, and the temp
|
|
2110
|
+
// folder and the unfinished files removed, as far as an exit allows.
|
|
2111
|
+
const onExit = () => {
|
|
2112
|
+
signalAll('SIGKILL');
|
|
2113
|
+
remove([temp, ...drop]);
|
|
2114
|
+
};
|
|
2115
|
+
process.once('exit', onExit);
|
|
2116
|
+
child.stderr?.setEncoding('utf8');
|
|
2117
|
+
child.stderr?.on('data', d => {
|
|
2118
|
+
if (stderr.length < 8000) stderr += d;
|
|
2119
|
+
});
|
|
2120
|
+
/** Set once the run is being stopped (bound, signal): it ends there. */
|
|
2121
|
+
let stopping = false;
|
|
2122
|
+
let settled = false;
|
|
2123
|
+
/** @param {Awaited<ReturnType<typeof runBrowser>>} out */
|
|
2124
|
+
const settle = out => {
|
|
2125
|
+
if (settled) return;
|
|
2126
|
+
settled = true;
|
|
2127
|
+
clearTimeout(timer);
|
|
2128
|
+
process.removeListener('exit', onExit);
|
|
2129
|
+
for (const sig of STOP_SIGNALS) process.removeListener(sig, onStop);
|
|
2130
|
+
resolve(out);
|
|
2131
|
+
};
|
|
2132
|
+
const timer = setTimeout(() => {
|
|
2133
|
+
stopping = true;
|
|
2134
|
+
void finish().then(() =>
|
|
2135
|
+
settle({status: null, signal: null, stderr, timedOut: true}),
|
|
2136
|
+
);
|
|
2137
|
+
}, bound);
|
|
2138
|
+
/** @param {NodeJS.Signals} sig */
|
|
2139
|
+
const onStop = async sig => {
|
|
2140
|
+
stopping = true;
|
|
2141
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onStop);
|
|
2142
|
+
// A second stop during the grace does not wait for it: the group is
|
|
2143
|
+
// killed and the files removed at once, then the process ends.
|
|
2144
|
+
/** @param {NodeJS.Signals} again */
|
|
2145
|
+
const onAgain = again => {
|
|
2146
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
|
|
2147
|
+
signalAll('SIGKILL');
|
|
2148
|
+
remove([temp, ...drop]);
|
|
2149
|
+
if (process.listenerCount(again) === 0)
|
|
2150
|
+
process.kill(process.pid, again);
|
|
2151
|
+
};
|
|
2152
|
+
for (const s of STOP_SIGNALS) process.once(s, onAgain);
|
|
2153
|
+
await finish();
|
|
2154
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
|
|
2155
|
+
settle({status: null, signal: null, stderr, stoppedBy: sig});
|
|
2156
|
+
// Nothing else listening: the stop ends this process, as it would
|
|
2157
|
+
// have without this listener.
|
|
2158
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
2159
|
+
};
|
|
2160
|
+
for (const sig of STOP_SIGNALS) process.once(sig, onStop);
|
|
2161
|
+
child.once('error', error => {
|
|
2162
|
+
clean();
|
|
2163
|
+
settle({status: null, signal: null, stderr, error});
|
|
2164
|
+
});
|
|
2165
|
+
child.once('close', (status, signal) => {
|
|
2166
|
+
if (stopping) return;
|
|
2167
|
+
clean();
|
|
2168
|
+
settle({status, signal, stderr});
|
|
2169
|
+
});
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
/**
|
|
2174
|
+
* The first stderr line that says something about the picture: Chrome's
|
|
2175
|
+
* startup warnings (dbus, GPU, sandbox notices) come first on Linux and
|
|
2176
|
+
* say nothing about why no picture was written.
|
|
2177
|
+
* @param {string} text
|
|
2178
|
+
*/
|
|
2179
|
+
export function meaningfulLine(text) {
|
|
2180
|
+
const lines = String(text ?? '')
|
|
2181
|
+
.split(/\r?\n/)
|
|
2182
|
+
.map(l => l.trim())
|
|
2183
|
+
.filter(Boolean);
|
|
2184
|
+
return (
|
|
2185
|
+
lines.find(
|
|
2186
|
+
l =>
|
|
2187
|
+
!/dbus|bus\.cc|gpu_|gl_|sandbox|fontconfig|crashpad|DevTools listening|WARNING:/i.test(
|
|
2188
|
+
l,
|
|
2189
|
+
),
|
|
2190
|
+
) ??
|
|
2191
|
+
lines[0] ??
|
|
2192
|
+
''
|
|
2193
|
+
);
|
|
2194
|
+
}
|