@astryxdesign/cli 0.7.16 → 0.7.17-canary.g335a172
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.mjs +69 -16
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +251 -35
- 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 +26 -2
- package/api/docs/_adapter.mjs +219 -6
- 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/_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 +60 -0
- package/api/theme/build/build.mjs +210 -54
- package/api/theme/build/font-warning.d.mts +8 -0
- package/api/theme/build/font-warning.mjs +19 -0
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +55 -0
- package/api/theme-edit/_adapter.mjs +673 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1858 -312
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +49 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1533 -92
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +587 -1
- package/api/theme-edit/_how-question.d.mts +78 -0
- package/api/theme-edit/_how-question.mjs +4716 -235
- package/api/theme-edit/_how.mjs +134 -8
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +219 -0
- package/api/theme-edit/_normal.mjs +1041 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_playwright-picture.d.mts +4 -0
- package/api/theme-edit/_playwright-picture.mjs +34 -0
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +394 -74
- package/api/theme-edit/_preview.d.mts +69 -8
- package/api/theme-edit/_preview.mjs +531 -108
- package/api/theme-edit/_settings.d.mts +243 -6
- package/api/theme-edit/_settings.mjs +2415 -147
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +44 -1
- package/api/theme-edit/_vet.d.mts +18 -0
- package/api/theme-edit/_vet.mjs +32 -0
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- 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/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/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 +2 -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 +145 -16
- 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 +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- 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/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 +183 -6
- 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 +77 -21
- 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/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-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +3 -2
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.mjs +3 -2
- 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 +31 -0
- package/foundation/fonts/font-stylesheet.mjs +115 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +164 -55
- 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/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/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +316 -42
- 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/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
|
@@ -14,8 +14,11 @@
|
|
|
14
14
|
|
|
15
15
|
import {createHash} from 'node:crypto';
|
|
16
16
|
import * as fs from 'node:fs';
|
|
17
|
+
import {declarationValues} from '../../foundation/fonts/font-stylesheet.mjs';
|
|
18
|
+
import {loadableFontFamilies} from '../theme/build/font-warning.mjs';
|
|
17
19
|
import * as path from 'node:path';
|
|
18
|
-
import {
|
|
20
|
+
import {spawn} from 'node:child_process';
|
|
21
|
+
import * as os from 'node:os';
|
|
19
22
|
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
20
23
|
import {
|
|
21
24
|
SAMPLE_PAGE,
|
|
@@ -32,13 +35,13 @@ import {
|
|
|
32
35
|
} from './_parts.mjs';
|
|
33
36
|
import {OVERVIEW_SECTIONS} from './_overview.mjs';
|
|
34
37
|
import {
|
|
35
|
-
FOLDER_JUNK,
|
|
36
|
-
folderIsEmpty,
|
|
37
38
|
camel,
|
|
39
|
+
folderIsEmpty,
|
|
38
40
|
fontPackages,
|
|
41
|
+
fontsourcePackageOf,
|
|
39
42
|
modesOf,
|
|
40
|
-
themeFiles,
|
|
41
43
|
shown,
|
|
44
|
+
themeFiles,
|
|
42
45
|
} from './_settings.mjs';
|
|
43
46
|
import {writeWhole} from './_palette.mjs';
|
|
44
47
|
import {cliVersion} from '../../foundation/release/run-context.mjs';
|
|
@@ -47,6 +50,7 @@ import {COLOR_PROP_PARTS, DIRECT, P, wordTable} from './_tables.mjs';
|
|
|
47
50
|
import {extractImportedPackages} from '../../foundation/discovery/template-needs.mjs';
|
|
48
51
|
import {findNodeModulesPackage} from '../../foundation/fs/paths.mjs';
|
|
49
52
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
53
|
+
import {compareText} from '../../foundation/text/compare-text.mjs';
|
|
50
54
|
|
|
51
55
|
const TEMPLATES_DIR = path.resolve(
|
|
52
56
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
@@ -163,7 +167,7 @@ export function showcaseItems(project, group) {
|
|
|
163
167
|
};
|
|
164
168
|
const chosen = items
|
|
165
169
|
.filter(it => !group || it.group === group)
|
|
166
|
-
.sort((a, b) => order(a) - order(b) || a.name
|
|
170
|
+
.sort((a, b) => order(a) - order(b) || compareText(a.name, b.name));
|
|
167
171
|
/** @type {Record<string, string>} */
|
|
168
172
|
const imports = {};
|
|
169
173
|
for (const n of elementNames(chosen.map(i => i.tree))) {
|
|
@@ -1408,6 +1412,14 @@ export function previewRouteSource({
|
|
|
1408
1412
|
/** @param {string} slug */
|
|
1409
1413
|
const camelName = camel;
|
|
1410
1414
|
|
|
1415
|
+
/** The script that takes one picture through the project's Playwright. */
|
|
1416
|
+
const PLAYWRIGHT_PICTURE = fileURLToPath(
|
|
1417
|
+
new URL('./_playwright-picture.mjs', import.meta.url),
|
|
1418
|
+
);
|
|
1419
|
+
|
|
1420
|
+
/** How long a browser may take for one picture before it is stopped. */
|
|
1421
|
+
const BROWSER_BOUND_MS = 60_000;
|
|
1422
|
+
|
|
1411
1423
|
/**
|
|
1412
1424
|
* A PNG of an HTML file, with a Playwright the project has installed, else
|
|
1413
1425
|
* a Chrome or Chromium found on the machine. Not ok with a reason when
|
|
@@ -1417,11 +1429,15 @@ const camelName = camel;
|
|
|
1417
1429
|
* @param {string} html absolute
|
|
1418
1430
|
* @param {string} png absolute
|
|
1419
1431
|
* @param {'light' | 'dark'} mode
|
|
1420
|
-
* @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string}>} `cut` when the picture is of the window, not the whole page
|
|
1432
|
+
* @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string, stopped?: string}>} `cut` when the picture is of the window, not the whole page
|
|
1421
1433
|
*/
|
|
1422
1434
|
export async function screenshot(project, html, png, mode) {
|
|
1423
1435
|
/** What was found and why it could not take the picture. @type {string[]} */
|
|
1424
1436
|
const failed = [];
|
|
1437
|
+
/** Whether a Playwright was found without its own browser installed. */
|
|
1438
|
+
let pwMissing = false;
|
|
1439
|
+
/** Whether a Playwright was found at all. */
|
|
1440
|
+
let pwFound = false;
|
|
1425
1441
|
/** The first line of an error, with no path of this machine. @param {unknown} e */
|
|
1426
1442
|
const firstLine = e =>
|
|
1427
1443
|
String(/** @type {any} */ (e)?.message ?? e ?? '')
|
|
@@ -1430,6 +1446,30 @@ export async function screenshot(project, html, png, mode) {
|
|
|
1430
1446
|
.find(Boolean)
|
|
1431
1447
|
?.split(project.cwd)
|
|
1432
1448
|
.join('.') ?? 'it stopped with no message';
|
|
1449
|
+
/**
|
|
1450
|
+
* Why a browser did not start: Playwright's first line names only the
|
|
1451
|
+
* call ("browserType.launch: Target … closed"); the cause, such as a
|
|
1452
|
+
* missing library, is in a later line, so that line comes too.
|
|
1453
|
+
*/
|
|
1454
|
+
const causeOf = (/** @type {string} */ text) => {
|
|
1455
|
+
const head = firstLine(text);
|
|
1456
|
+
const rest = String(text ?? '')
|
|
1457
|
+
.split('\n')
|
|
1458
|
+
.slice(1)
|
|
1459
|
+
.map(l => l.replace(/^[\s=<>-]+/, '').trim())
|
|
1460
|
+
.filter(Boolean)
|
|
1461
|
+
.find(l =>
|
|
1462
|
+
/error|cannot|can't|missing|not found|while loading|no such|failed|denied/i.test(
|
|
1463
|
+
l,
|
|
1464
|
+
),
|
|
1465
|
+
);
|
|
1466
|
+
return rest ? `${head} (${rest.split(project.cwd).join('.')})` : head;
|
|
1467
|
+
};
|
|
1468
|
+
// The project's Playwright, its own browser first and the system Chrome
|
|
1469
|
+
// when that one is missing or does not start. Each run is a process of
|
|
1470
|
+
// its own under the browser runner: one temp folder, one time bound and
|
|
1471
|
+
// one stop for every browser the editor starts.
|
|
1472
|
+
const sys = chromeBinary();
|
|
1433
1473
|
for (const pkg of ['playwright', 'playwright-core']) {
|
|
1434
1474
|
/** @type {string} */
|
|
1435
1475
|
let entry;
|
|
@@ -1438,61 +1478,100 @@ export async function screenshot(project, html, png, mode) {
|
|
|
1438
1478
|
} catch {
|
|
1439
1479
|
continue;
|
|
1440
1480
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1481
|
+
pwFound = true;
|
|
1482
|
+
const deadline = Date.now() + BROWSER_BOUND_MS;
|
|
1483
|
+
for (const exe of sys ? [null, sys] : [null]) {
|
|
1484
|
+
const r = await runBrowser(
|
|
1485
|
+
process.execPath,
|
|
1486
|
+
[PLAYWRIGHT_PICTURE, entry, html, png, mode, ...(exe ? [exe] : [])],
|
|
1487
|
+
Math.max(1, deadline - Date.now()),
|
|
1488
|
+
{profileArg: false},
|
|
1489
|
+
);
|
|
1490
|
+
if (r.stoppedBy)
|
|
1491
|
+
return {
|
|
1492
|
+
ok: false,
|
|
1493
|
+
stopped: r.stoppedBy,
|
|
1494
|
+
reason: `the pictures were stopped (${r.stoppedBy}) before the browser finished`,
|
|
1495
|
+
};
|
|
1496
|
+
if (r.timedOut)
|
|
1497
|
+
return {
|
|
1498
|
+
ok: false,
|
|
1499
|
+
reason: `the browser did not finish the picture within ${BROWSER_BOUND_MS / 1000} seconds, so it was stopped; run the command again, or open the .html beside the picture to look without one`,
|
|
1500
|
+
};
|
|
1501
|
+
if (r.status === 0 && fs.existsSync(png))
|
|
1502
|
+
return {ok: true, file: shown(project.cwd, png)};
|
|
1503
|
+
const text = r.error ? String(r.error.message) : r.stderr;
|
|
1504
|
+
if (!exe && /Executable doesn't exist|playwright install/i.test(text))
|
|
1505
|
+
pwMissing = true;
|
|
1506
|
+
failed.push(
|
|
1507
|
+
`${pkg}${exe ? ` with ${exe}` : sys ? ' with its own browser' : ''}: ${causeOf(text)}`,
|
|
1446
1508
|
);
|
|
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)}`);
|
|
1461
1509
|
}
|
|
1462
1510
|
}
|
|
1463
1511
|
const chrome = chromeBinary();
|
|
1464
1512
|
if (chrome) {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
)
|
|
1513
|
+
// Run without blocking, so a stop (Ctrl-C, SIGTERM) reaches this
|
|
1514
|
+
// process while the browser runs: the browser is stopped with it, and
|
|
1515
|
+
// the stop is reported as a stop, never as a browser that failed.
|
|
1516
|
+
const r = await runBrowser(chrome, [
|
|
1517
|
+
'--headless=new',
|
|
1518
|
+
'--disable-gpu',
|
|
1519
|
+
'--no-sandbox',
|
|
1520
|
+
'--hide-scrollbars',
|
|
1521
|
+
`--screenshot=${png}`,
|
|
1522
|
+
'--window-size=1280,2400',
|
|
1523
|
+
...(mode === 'dark' ? ['--force-dark-mode'] : []),
|
|
1524
|
+
pathToFileURL(html).href,
|
|
1525
|
+
]);
|
|
1526
|
+
if (r.stoppedBy)
|
|
1527
|
+
return {
|
|
1528
|
+
ok: false,
|
|
1529
|
+
stopped: r.stoppedBy,
|
|
1530
|
+
reason: `the pictures were stopped (${r.stoppedBy}) before the browser finished`,
|
|
1531
|
+
};
|
|
1532
|
+
// The editor's own bound, not an outside kill: said so, with a retry.
|
|
1533
|
+
if (r.timedOut)
|
|
1534
|
+
return {
|
|
1535
|
+
ok: false,
|
|
1536
|
+
reason: `the browser (${chrome}) did not finish the picture within 60 seconds, so it was stopped; run the command again, or open the .html beside the picture to look without one`,
|
|
1537
|
+
};
|
|
1538
|
+
// A picture folder it cannot write: the folder, never the browser.
|
|
1539
|
+
try {
|
|
1540
|
+
fs.accessSync(path.dirname(png), fs.constants.W_OK);
|
|
1541
|
+
} catch (e) {
|
|
1542
|
+
return {
|
|
1543
|
+
ok: false,
|
|
1544
|
+
reason: `${shown(project.cwd, path.dirname(png))}/ cannot be written (${/** @type {any} */ (e)?.code ?? 'no access'}), so no picture was taken; fix its permissions, then run the command again`,
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1479
1547
|
// Chrome alone takes the window, not the whole page.
|
|
1480
1548
|
if (r.status === 0 && fs.existsSync(png))
|
|
1481
1549
|
return {ok: true, file: shown(project.cwd, png), cut: true};
|
|
1482
1550
|
failed.push(
|
|
1483
1551
|
`${chrome}: ${firstLine(
|
|
1484
1552
|
r.error ??
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1553
|
+
// A browser stopped by a signal says so first: its stderr opens
|
|
1554
|
+
// with unrelated noise (dbus) on Linux.
|
|
1555
|
+
(r.signal
|
|
1556
|
+
? `stopped by ${r.signal}`
|
|
1557
|
+
: meaningfulLine(r.stderr) ||
|
|
1558
|
+
`exit ${r.status}, and no picture was written`),
|
|
1489
1559
|
)}`,
|
|
1490
1560
|
);
|
|
1491
1561
|
}
|
|
1492
1562
|
if (failed.length)
|
|
1493
1563
|
return {
|
|
1494
1564
|
ok: false,
|
|
1495
|
-
|
|
1565
|
+
// Advice that can change the result: Playwright's browser only when
|
|
1566
|
+
// it is missing, else the browsers that were tried.
|
|
1567
|
+
// A Chrome to check only when there is one; else one to install.
|
|
1568
|
+
reason: `A browser was found, but it could not take the picture (${failed.join('; ')}). ${
|
|
1569
|
+
!pwFound
|
|
1570
|
+
? `Install Playwright with its browser (${installLine(project.cwd, ['playwright'])}, then npx playwright install chromium), or`
|
|
1571
|
+
: pwMissing
|
|
1572
|
+
? 'Give Playwright its browser (npx playwright install chromium), or'
|
|
1573
|
+
: "Playwright's own browser did not start (the reason is above):"
|
|
1574
|
+
} ${chrome ? `check that ${chrome} starts on this machine` : 'install Google Chrome or Chromium'}. The HTML preview needs neither.`,
|
|
1496
1575
|
};
|
|
1497
1576
|
return {
|
|
1498
1577
|
ok: false,
|
|
@@ -1515,11 +1594,23 @@ function chromeBinary() {
|
|
|
1515
1594
|
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
1516
1595
|
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
1517
1596
|
];
|
|
1518
|
-
|
|
1597
|
+
// Only a file that runs: a folder or a file with no execute permission
|
|
1598
|
+
// by a browser's name is passed over, and the search goes on.
|
|
1599
|
+
/** @param {string} f */
|
|
1600
|
+
const runs = f => {
|
|
1601
|
+
try {
|
|
1602
|
+
if (!fs.statSync(f).isFile()) return false;
|
|
1603
|
+
if (process.platform !== 'win32') fs.accessSync(f, fs.constants.X_OK);
|
|
1604
|
+
return true;
|
|
1605
|
+
} catch {
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
for (const f of fixed) if (runs(f)) return f;
|
|
1519
1610
|
for (const dir of (process.env.PATH ?? '').split(path.delimiter)) {
|
|
1520
1611
|
for (const n of names) {
|
|
1521
1612
|
const f = path.join(dir, n);
|
|
1522
|
-
if (dir &&
|
|
1613
|
+
if (dir && runs(f)) return f;
|
|
1523
1614
|
}
|
|
1524
1615
|
}
|
|
1525
1616
|
return null;
|
|
@@ -1527,7 +1618,47 @@ function chromeBinary() {
|
|
|
1527
1618
|
|
|
1528
1619
|
/** The first line of every file the editor writes into a theme's app copy. */
|
|
1529
1620
|
export {APP_COPY_MARK} from './_marks.mjs';
|
|
1530
|
-
import {APP_COPY_MARK} from './_marks.mjs';
|
|
1621
|
+
import {APP_COPY_MARK, appCopyMark} from './_marks.mjs';
|
|
1622
|
+
import {builtColorMode} from '../../foundation/discovery/theme-imports.mjs';
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* The font stylesheets a theme's app copy imports, from the fonts the theme
|
|
1626
|
+
* loads now (an installed font package, the base theme's fonts).
|
|
1627
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1628
|
+
* @param {string} slug
|
|
1629
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1630
|
+
* @returns {string[]}
|
|
1631
|
+
*/
|
|
1632
|
+
export function copyFontsCss(ctx, slug, data) {
|
|
1633
|
+
const css = themeImports(
|
|
1634
|
+
ctx,
|
|
1635
|
+
slug,
|
|
1636
|
+
data,
|
|
1637
|
+
path.join(ctx.project.cwd, 'src', 'themes', slug),
|
|
1638
|
+
).css.slice(1);
|
|
1639
|
+
// A family the built theme uses that its settings do not name (set in
|
|
1640
|
+
// the theme's own source, by a token or typography): its installed
|
|
1641
|
+
// @fontsource package loads it too.
|
|
1642
|
+
/** @type {string} */
|
|
1643
|
+
let built;
|
|
1644
|
+
try {
|
|
1645
|
+
built = fs.readFileSync(themeFiles(ctx.project.cwd, slug).css, 'utf8');
|
|
1646
|
+
} catch {
|
|
1647
|
+
return css;
|
|
1648
|
+
}
|
|
1649
|
+
for (const value of declarationValues(built, /^--font-family-/))
|
|
1650
|
+
for (const family of loadableFontFamilies(value)) {
|
|
1651
|
+
const pkg = fontsourcePackageOf(family);
|
|
1652
|
+
if (css.some(c => c.startsWith(`${pkg}/`))) continue;
|
|
1653
|
+
try {
|
|
1654
|
+
ctx.project.req.resolve(`${pkg}/package.json`);
|
|
1655
|
+
css.push(`${pkg}/index.css`);
|
|
1656
|
+
} catch {
|
|
1657
|
+
// Not installed: nothing to import.
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
return css;
|
|
1661
|
+
}
|
|
1531
1662
|
|
|
1532
1663
|
/**
|
|
1533
1664
|
* The app's copy of an editor theme: a standard local theme in
|
|
@@ -1545,38 +1676,26 @@ import {APP_COPY_MARK} from './_marks.mjs';
|
|
|
1545
1676
|
* @returns {string | null}
|
|
1546
1677
|
*/
|
|
1547
1678
|
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
|
-
);
|
|
1679
|
+
return writeAppCopyAt(ctx.project.cwd, slug, copyFontsCss(ctx, slug, data));
|
|
1558
1680
|
}
|
|
1559
1681
|
|
|
1560
1682
|
/**
|
|
1561
|
-
*
|
|
1562
|
-
* copy
|
|
1683
|
+
* The files of a theme's app copy as the editor would write them now, by
|
|
1684
|
+
* name; null with no build to copy. Font stylesheets as given, or null for
|
|
1685
|
+
* the copy's own.
|
|
1563
1686
|
* @param {string} cwd
|
|
1564
1687
|
* @param {string} slug
|
|
1565
1688
|
* @param {string[] | null} fontsCss
|
|
1566
|
-
* @returns {string | null}
|
|
1689
|
+
* @returns {Record<string, string> | null}
|
|
1567
1690
|
*/
|
|
1568
|
-
|
|
1691
|
+
function appCopyFiles(cwd, slug, fontsCss) {
|
|
1569
1692
|
const f = themeFiles(cwd, slug);
|
|
1570
1693
|
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1571
1694
|
const name = `${camel(slug)}Theme`;
|
|
1572
|
-
const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
|
|
1573
1695
|
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
1696
|
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
1697
|
const head = (/** @type {string} */ open, /** @type {string} */ close) =>
|
|
1579
|
-
`${open} ${
|
|
1698
|
+
`${open} ${appCopyMark(slug)} after every build of themes/${slug}/; do not edit it here. Change the theme with the editor. ${close}\n`;
|
|
1580
1699
|
const keptFonts = path.join(dir, `${slug}.fonts.css`);
|
|
1581
1700
|
const fonts =
|
|
1582
1701
|
fontsCss ??
|
|
@@ -1598,27 +1717,112 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
|
1598
1717
|
if (fs.existsSync(from))
|
|
1599
1718
|
built[`${slug}${ext}`] = asBuilt(fs.readFileSync(from, 'utf8'));
|
|
1600
1719
|
}
|
|
1720
|
+
// A light-only or dark-only theme's build exports its one color mode
|
|
1721
|
+
// (`colorModes`); the copy's source re-exports it, so a build of the copy
|
|
1722
|
+
// writes it too and `theme add` reads it.
|
|
1723
|
+
const oneMode = builtColorMode(f.js).mode;
|
|
1601
1724
|
const files = {
|
|
1602
1725
|
[`${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`,
|
|
1726
|
+
[`${name}.ts`]: `${head('//', '')}export {${name}${oneMode ? ', colorModes' : ''}} from './${slug}';\n`,
|
|
1604
1727
|
...built,
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
: {})
|
|
1728
|
+
// Always there, so the app theme module's import of it holds when the
|
|
1729
|
+
// theme's fonts change (none: a comment only).
|
|
1730
|
+
[`${slug}.fonts.css`]: fonts.length
|
|
1731
|
+
? `${head('/*', '*/')}${fonts.map(c => `@import ${JSON.stringify(c)};`).join('\n')}\n`
|
|
1732
|
+
: `${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
1733
|
};
|
|
1611
|
-
|
|
1734
|
+
return files;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
/**
|
|
1738
|
+
* Why a theme's app copy is behind its build, or null when it is current:
|
|
1739
|
+
* something in its way (appCopyStale), a copy file missing, or a file
|
|
1740
|
+
* whose content is not what the editor would write now.
|
|
1741
|
+
* @param {string} cwd
|
|
1742
|
+
* @param {string} slug
|
|
1743
|
+
* @param {string[] | null} [fontsCss] the font stylesheets the copy should
|
|
1744
|
+
* import now (null: the copy's own)
|
|
1745
|
+
* @returns {string | null}
|
|
1746
|
+
*/
|
|
1747
|
+
export function appCopyBehind(cwd, slug, fontsCss = null) {
|
|
1748
|
+
const stale = appCopyStale(cwd, slug).appCopyStale;
|
|
1749
|
+
if (stale) return stale;
|
|
1750
|
+
const files = appCopyFiles(cwd, slug, fontsCss);
|
|
1751
|
+
if (!files) return null;
|
|
1752
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1753
|
+
if (!fs.existsSync(dir))
|
|
1754
|
+
return `the app copy in src/themes/${slug}/ is gone; the editor writes it again`;
|
|
1612
1755
|
for (const [n, text] of Object.entries(files)) {
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1756
|
+
/** @type {string} */
|
|
1757
|
+
let now;
|
|
1758
|
+
try {
|
|
1759
|
+
now = fs.readFileSync(path.join(dir, n), 'utf8');
|
|
1760
|
+
} catch {
|
|
1761
|
+
return `src/themes/${slug}/${n} is missing from the app copy`;
|
|
1762
|
+
}
|
|
1763
|
+
// Line endings as a checkout writes them (CRLF on Windows) are the
|
|
1764
|
+
// same content, as the outputs check reads them.
|
|
1765
|
+
const lf = (/** @type {string} */ x) => x.replace(/\r\n/g, '\n');
|
|
1766
|
+
if (lf(now) !== lf(text))
|
|
1767
|
+
return `src/themes/${slug}/${n} is not the current build of themes/${slug}/`;
|
|
1768
|
+
}
|
|
1769
|
+
return null;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
/**
|
|
1773
|
+
* {@link writeAppCopy} with the font stylesheets given, or null to keep the
|
|
1774
|
+
* copy's own (a compile, which changes no setting).
|
|
1775
|
+
* @param {string} cwd
|
|
1776
|
+
* @param {string} slug
|
|
1777
|
+
* @param {string[] | null} fontsCss
|
|
1778
|
+
* @returns {string | null}
|
|
1779
|
+
*/
|
|
1780
|
+
export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
1781
|
+
const f = themeFiles(cwd, slug);
|
|
1782
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1783
|
+
const name = `${camel(slug)}Theme`;
|
|
1784
|
+
const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
|
|
1785
|
+
if (!fs.existsSync(f.js) || !fs.existsSync(f.css)) return null;
|
|
1786
|
+
// Only the editor's own copy is written over.
|
|
1787
|
+
if (appCopyBlocker(cwd, slug) !== null) return null;
|
|
1788
|
+
const files = appCopyFiles(cwd, slug, fontsCss);
|
|
1789
|
+
if (!files) return null;
|
|
1790
|
+
const failKey = `${path.resolve(cwd)}\0${slug}`;
|
|
1791
|
+
try {
|
|
1792
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
1793
|
+
for (const [n, text] of Object.entries(files)) {
|
|
1794
|
+
const file = path.join(dir, n);
|
|
1795
|
+
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === text)
|
|
1796
|
+
continue;
|
|
1797
|
+
writeWhole(file, text);
|
|
1798
|
+
}
|
|
1799
|
+
// A copy's own file this build no longer writes goes; anything else in
|
|
1800
|
+
// the folder (yours, or the system's) stays as it is.
|
|
1801
|
+
for (const n of fs.readdirSync(dir))
|
|
1802
|
+
if (appCopyNames(slug).has(n) && !(n in files))
|
|
1803
|
+
fs.rmSync(path.join(dir, n), {force: true});
|
|
1804
|
+
} catch (e) {
|
|
1805
|
+
// A copy that cannot be written is said, with the system's reason;
|
|
1806
|
+
// the change itself stands.
|
|
1807
|
+
const code = /** @type {any} */ (e)?.code ?? 'error';
|
|
1808
|
+
// The folder that failed: the copy's, or a parent it could not be
|
|
1809
|
+
// made in.
|
|
1810
|
+
const failed = /** @type {any} */ (e)?.path
|
|
1811
|
+
? path.resolve(String(/** @type {any} */ (e).path))
|
|
1812
|
+
: dir;
|
|
1813
|
+
const at = fs.existsSync(failed) ? failed : path.dirname(failed);
|
|
1814
|
+
const rel = path.relative(cwd, at).split(path.sep).join('/');
|
|
1815
|
+
COPY_FAILED.set(
|
|
1816
|
+
failKey,
|
|
1817
|
+
code === 'EACCES' || code === 'EPERM' || code === 'EROFS'
|
|
1818
|
+
? `${rel} is not writable (${code})`
|
|
1819
|
+
: code === 'ENOSPC'
|
|
1820
|
+
? `the disk is full (${code})`
|
|
1821
|
+
: `${rel} could not be written (${code})`,
|
|
1822
|
+
);
|
|
1823
|
+
return null;
|
|
1616
1824
|
}
|
|
1617
|
-
|
|
1618
|
-
// system files stay.
|
|
1619
|
-
for (const n of fs.readdirSync(dir))
|
|
1620
|
-
if (!(n in files) && !FOLDER_JUNK.has(n))
|
|
1621
|
-
fs.rmSync(path.join(dir, n), {force: true});
|
|
1825
|
+
COPY_FAILED.delete(failKey);
|
|
1622
1826
|
// The first write is named in the command's result; later ones are not.
|
|
1623
1827
|
if (first)
|
|
1624
1828
|
FIRST_COPIES.set(
|
|
@@ -1633,13 +1837,48 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
|
1633
1837
|
}
|
|
1634
1838
|
|
|
1635
1839
|
/**
|
|
1636
|
-
*
|
|
1637
|
-
*
|
|
1638
|
-
*
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
|
|
1642
|
-
|
|
1840
|
+
* The note for a copy a file of yours keeps from being written, as a
|
|
1841
|
+
* result field: `{appCopyStale}` when one does, else nothing.
|
|
1842
|
+
* @param {string} cwd
|
|
1843
|
+
* @param {string} slug
|
|
1844
|
+
* @returns {{appCopyStale?: string}}
|
|
1845
|
+
*/
|
|
1846
|
+
export function appCopyStale(cwd, slug) {
|
|
1847
|
+
const blocker =
|
|
1848
|
+
appCopyBlocker(cwd, slug) ??
|
|
1849
|
+
COPY_FAILED.get(`${path.resolve(cwd)}\0${slug}`) ??
|
|
1850
|
+
null;
|
|
1851
|
+
return blocker
|
|
1852
|
+
? {
|
|
1853
|
+
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.`,
|
|
1854
|
+
}
|
|
1855
|
+
: {};
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
/**
|
|
1859
|
+
* The names of a theme's app copy files.
|
|
1860
|
+
* @param {string} slug
|
|
1861
|
+
* @returns {Set<string>}
|
|
1862
|
+
*/
|
|
1863
|
+
function appCopyNames(slug) {
|
|
1864
|
+
const name = `${camel(slug)}Theme`;
|
|
1865
|
+
return new Set([
|
|
1866
|
+
`${name}.doc.mjs`,
|
|
1867
|
+
`${name}.ts`,
|
|
1868
|
+
`${slug}.fonts.css`,
|
|
1869
|
+
...APP_COPY_BUILT.map(ext => `${slug}${ext}`),
|
|
1870
|
+
]);
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
/**
|
|
1874
|
+
* Why the editor will not write a theme's app copy, or null when it will.
|
|
1875
|
+
* Only a file of yours AT one of the copy's names stops it: a descriptor,
|
|
1876
|
+
* source or font stylesheet without the editor's mark, or any copy file
|
|
1877
|
+
* while the descriptor is not the editor's. Other files there (a note, a
|
|
1878
|
+
* swap file, desktop.ini) are left as they are and the copy is written
|
|
1879
|
+
* around them. Built bytes are not compared, so a stable rebuild of the
|
|
1880
|
+
* copy leaves it the editor's. The one test the copy's writer, the change
|
|
1881
|
+
* results and `wiring` use. Returns the file in the way.
|
|
1643
1882
|
* @param {string} cwd
|
|
1644
1883
|
* @param {string} slug
|
|
1645
1884
|
* @returns {string | null}
|
|
@@ -1648,37 +1887,89 @@ export function appCopyBlocker(cwd, slug) {
|
|
|
1648
1887
|
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1649
1888
|
const name = `${camel(slug)}Theme`;
|
|
1650
1889
|
const rel = path.relative(cwd, dir).split(path.sep).join('/');
|
|
1890
|
+
// Nothing is written through a link on the way from the app to the copy
|
|
1891
|
+
// (src/, src/themes/, the copy's folder), as for themes/.
|
|
1892
|
+
for (const part of ['src', 'src/themes', rel]) {
|
|
1893
|
+
try {
|
|
1894
|
+
const st = fs.lstatSync(path.join(cwd, part));
|
|
1895
|
+
if (st.isSymbolicLink())
|
|
1896
|
+
return `${part} is a link (to ${fs.readlinkSync(path.join(cwd, part))}), and the editor writes nothing through a link`;
|
|
1897
|
+
// A file where a folder on the way goes: nothing is half-written.
|
|
1898
|
+
if (!st.isDirectory())
|
|
1899
|
+
return part === rel
|
|
1900
|
+
? `${rel} is a file, where the copy's folder goes`
|
|
1901
|
+
: `${part} is a file, where a folder on the way to the copy goes`;
|
|
1902
|
+
} catch {
|
|
1903
|
+
break;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
try {
|
|
1907
|
+
if (!fs.lstatSync(dir).isDirectory())
|
|
1908
|
+
return `${rel} is a file, where the copy's folder goes`;
|
|
1909
|
+
} catch {
|
|
1910
|
+
// Not there yet: the copy makes it.
|
|
1911
|
+
}
|
|
1651
1912
|
if (folderIsEmpty(dir)) return null;
|
|
1652
1913
|
/** @type {string[]} */
|
|
1653
1914
|
let names;
|
|
1654
1915
|
try {
|
|
1655
1916
|
names = fs.readdirSync(dir);
|
|
1656
|
-
} catch {
|
|
1657
|
-
return rel
|
|
1917
|
+
} catch (e) {
|
|
1918
|
+
return `${rel} cannot be read (${/** @type {any} */ (e)?.code ?? 'error'})`;
|
|
1658
1919
|
}
|
|
1659
|
-
/** @
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1920
|
+
/** @param {string} n */
|
|
1921
|
+
const marked = n => {
|
|
1922
|
+
try {
|
|
1923
|
+
return fs.readFileSync(path.join(dir, n), 'utf8').includes(APP_COPY_MARK);
|
|
1924
|
+
} catch {
|
|
1925
|
+
return false;
|
|
1926
|
+
}
|
|
1927
|
+
};
|
|
1928
|
+
const own = appCopyNames(slug);
|
|
1929
|
+
const present = names.filter(n => own.has(n));
|
|
1930
|
+
// A link at a copy name is never written through or replaced.
|
|
1931
|
+
for (const n of present)
|
|
1932
|
+
try {
|
|
1933
|
+
const st = fs.lstatSync(path.join(dir, n));
|
|
1934
|
+
if (st.isSymbolicLink())
|
|
1935
|
+
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`;
|
|
1936
|
+
if (st.isDirectory())
|
|
1937
|
+
return `${rel}/${n} is a folder, at a name the copy uses for a file`;
|
|
1938
|
+
} catch {
|
|
1939
|
+
// Gone since it was listed.
|
|
1940
|
+
}
|
|
1941
|
+
// The copy is the editor's when any of its marked files carries the
|
|
1942
|
+
// mark (one of them deleted is written back); then only a marked name
|
|
1943
|
+
// without the mark is yours.
|
|
1944
|
+
const markedNames = [`${name}.doc.mjs`, `${name}.ts`, `${slug}.fonts.css`];
|
|
1945
|
+
// A build output of the copy's source carries the build's own header.
|
|
1946
|
+
const generated = (/** @type {string} */ n) => {
|
|
1947
|
+
try {
|
|
1948
|
+
return /@generated by `astryx theme build`/.test(
|
|
1949
|
+
fs.readFileSync(path.join(dir, n), 'utf8').slice(0, 600),
|
|
1950
|
+
);
|
|
1951
|
+
} catch {
|
|
1952
|
+
return false;
|
|
1953
|
+
}
|
|
1954
|
+
};
|
|
1955
|
+
const ours =
|
|
1956
|
+
markedNames.some(n => present.includes(n) && marked(n)) ||
|
|
1957
|
+
(present.length > 0 &&
|
|
1958
|
+
present.every(n => !markedNames.includes(n) && generated(n)));
|
|
1959
|
+
const foreign = ours
|
|
1960
|
+
? present.find(n => markedNames.includes(n) && !marked(n))
|
|
1961
|
+
: present[0];
|
|
1962
|
+
return foreign
|
|
1963
|
+
? `${rel}/${foreign} is yours, at a name the copy uses, and the editor never writes over your files`
|
|
1964
|
+
: null;
|
|
1677
1965
|
}
|
|
1678
1966
|
|
|
1679
1967
|
/** The build outputs of a theme, by their ending after `<theme>`. */
|
|
1680
1968
|
const APP_COPY_BUILT = ['.css', '.css.d.ts', '.js', '.d.ts', '.variants.d.ts'];
|
|
1681
1969
|
|
|
1970
|
+
/** Why the last write of a theme's app copy failed, by app and theme. @type {Map<string, string>} */
|
|
1971
|
+
const COPY_FAILED = new Map();
|
|
1972
|
+
|
|
1682
1973
|
/** App copies written for the first time in this process, by app and theme. @type {Map<string, string[]>} */
|
|
1683
1974
|
const FIRST_COPIES = new Map();
|
|
1684
1975
|
|
|
@@ -1695,3 +1986,135 @@ export function takeFirstAppCopy(cwd, slug) {
|
|
|
1695
1986
|
FIRST_COPIES.delete(key);
|
|
1696
1987
|
return wrote;
|
|
1697
1988
|
}
|
|
1989
|
+
|
|
1990
|
+
/**
|
|
1991
|
+
* Run a browser for a picture without blocking this process: a stop that
|
|
1992
|
+
* reaches it (SIGINT, SIGTERM) stops the browser too, and is reported.
|
|
1993
|
+
* Bounded to 60 seconds, as a picture run always was.
|
|
1994
|
+
* @param {string} bin
|
|
1995
|
+
* @param {string[]} args
|
|
1996
|
+
* @param {number} [bound] milliseconds before the browser is stopped
|
|
1997
|
+
* @param {{profileArg?: boolean}} [opts] `profileArg`: give Chrome the
|
|
1998
|
+
* temp folder as its profile (`--user-data-dir`); off for a process that
|
|
1999
|
+
* starts its browser itself, which still gets the folder as its temp
|
|
2000
|
+
* @returns {Promise<{status: number | null, signal: string | null, stderr: string, error?: Error, stoppedBy?: string, timedOut?: boolean}>}
|
|
2001
|
+
*/
|
|
2002
|
+
export function runBrowser(
|
|
2003
|
+
bin,
|
|
2004
|
+
args,
|
|
2005
|
+
bound = BROWSER_BOUND_MS,
|
|
2006
|
+
{profileArg = true} = {},
|
|
2007
|
+
) {
|
|
2008
|
+
return new Promise(resolve => {
|
|
2009
|
+
/** @type {string | undefined} */
|
|
2010
|
+
let stoppedBy;
|
|
2011
|
+
let stderr = '';
|
|
2012
|
+
// A temp folder of its own, removed on every way out (done, failed,
|
|
2013
|
+
// timed out, stopped): Chrome leaves its org.chromium.* folders and
|
|
2014
|
+
// Playwright its profile and artifacts folders in the system temp
|
|
2015
|
+
// folder otherwise.
|
|
2016
|
+
/** @type {string | null} */
|
|
2017
|
+
let profile = null;
|
|
2018
|
+
try {
|
|
2019
|
+
profile = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-browser-'));
|
|
2020
|
+
} catch {
|
|
2021
|
+
// No temp folder: Chrome's own default.
|
|
2022
|
+
}
|
|
2023
|
+
const dropProfile = () => {
|
|
2024
|
+
if (profile)
|
|
2025
|
+
try {
|
|
2026
|
+
fs.rmSync(profile, {recursive: true, force: true});
|
|
2027
|
+
} catch {
|
|
2028
|
+
// Gone already.
|
|
2029
|
+
}
|
|
2030
|
+
};
|
|
2031
|
+
process.once('exit', dropProfile);
|
|
2032
|
+
const child = spawn(
|
|
2033
|
+
bin,
|
|
2034
|
+
[
|
|
2035
|
+
...(profile && profileArg ? [`--user-data-dir=${profile}`] : []),
|
|
2036
|
+
...args,
|
|
2037
|
+
],
|
|
2038
|
+
{
|
|
2039
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
2040
|
+
env: profile
|
|
2041
|
+
? {...process.env, TMPDIR: profile, TMP: profile, TEMP: profile}
|
|
2042
|
+
: process.env,
|
|
2043
|
+
// A group of its own, so a stop takes Chrome's helper processes
|
|
2044
|
+
// with it, before its profile folder is removed.
|
|
2045
|
+
detached: process.platform !== 'win32',
|
|
2046
|
+
},
|
|
2047
|
+
);
|
|
2048
|
+
const killAll = () => {
|
|
2049
|
+
try {
|
|
2050
|
+
if (process.platform !== 'win32' && child.pid)
|
|
2051
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
2052
|
+
else child.kill('SIGKILL');
|
|
2053
|
+
} catch {
|
|
2054
|
+
child.kill('SIGKILL');
|
|
2055
|
+
}
|
|
2056
|
+
};
|
|
2057
|
+
child.stderr?.setEncoding('utf8');
|
|
2058
|
+
child.stderr?.on('data', d => {
|
|
2059
|
+
if (stderr.length < 8000) stderr += d;
|
|
2060
|
+
});
|
|
2061
|
+
let timedOut = false;
|
|
2062
|
+
const timer = setTimeout(() => {
|
|
2063
|
+
timedOut = true;
|
|
2064
|
+
killAll();
|
|
2065
|
+
}, bound);
|
|
2066
|
+
/** @param {NodeJS.Signals} sig */
|
|
2067
|
+
const onStop = sig => {
|
|
2068
|
+
stoppedBy = sig;
|
|
2069
|
+
killAll();
|
|
2070
|
+
dropProfile();
|
|
2071
|
+
// Nothing else listening: the stop ends this process, as it would
|
|
2072
|
+
// have without this listener.
|
|
2073
|
+
if (process.listenerCount(sig) === 0) {
|
|
2074
|
+
process.removeListener('SIGINT', onStop);
|
|
2075
|
+
process.removeListener('SIGTERM', onStop);
|
|
2076
|
+
process.kill(process.pid, sig);
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
process.once('SIGINT', onStop);
|
|
2080
|
+
process.once('SIGTERM', onStop);
|
|
2081
|
+
const done = (/** @type {any} */ out) => {
|
|
2082
|
+
clearTimeout(timer);
|
|
2083
|
+
dropProfile();
|
|
2084
|
+
process.removeListener('exit', dropProfile);
|
|
2085
|
+
process.removeListener('SIGINT', onStop);
|
|
2086
|
+
process.removeListener('SIGTERM', onStop);
|
|
2087
|
+
resolve({
|
|
2088
|
+
...out,
|
|
2089
|
+
stderr,
|
|
2090
|
+
...(stoppedBy ? {stoppedBy} : {}),
|
|
2091
|
+
...(timedOut ? {timedOut} : {}),
|
|
2092
|
+
});
|
|
2093
|
+
};
|
|
2094
|
+
child.on('error', error => done({status: null, signal: null, error}));
|
|
2095
|
+
child.on('close', (status, signal) => done({status, signal}));
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
/**
|
|
2100
|
+
* The first stderr line that says something about the picture: Chrome's
|
|
2101
|
+
* startup warnings (dbus, GPU, sandbox notices) come first on Linux and
|
|
2102
|
+
* say nothing about why no picture was written.
|
|
2103
|
+
* @param {string} text
|
|
2104
|
+
*/
|
|
2105
|
+
export function meaningfulLine(text) {
|
|
2106
|
+
const lines = String(text ?? '')
|
|
2107
|
+
.split(/\r?\n/)
|
|
2108
|
+
.map(l => l.trim())
|
|
2109
|
+
.filter(Boolean);
|
|
2110
|
+
return (
|
|
2111
|
+
lines.find(
|
|
2112
|
+
l =>
|
|
2113
|
+
!/dbus|bus\.cc|gpu_|gl_|sandbox|fontconfig|crashpad|DevTools listening|WARNING:/i.test(
|
|
2114
|
+
l,
|
|
2115
|
+
),
|
|
2116
|
+
) ??
|
|
2117
|
+
lines[0] ??
|
|
2118
|
+
''
|
|
2119
|
+
);
|
|
2120
|
+
}
|