@iksnerd/blazon 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +259 -2
- package/THIRD-PARTY-NOTICES.md +60 -0
- package/bin/blazon.js +4 -0
- package/dist/builder/site-builder.d.ts +10 -0
- package/dist/builder/site-builder.d.ts.map +1 -0
- package/dist/chunks/site-builder-CPfjBOmR.js +13804 -0
- package/dist/cli/commands/approvals.d.ts +8 -0
- package/dist/cli/commands/approvals.d.ts.map +1 -0
- package/dist/cli/commands/build.d.ts +8 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/check.d.ts +33 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/cwd.d.ts +14 -0
- package/dist/cli/commands/cwd.d.ts.map +1 -0
- package/dist/cli/commands/dev.d.ts +5 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/doctor.d.ts +34 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/drift.d.ts +11 -0
- package/dist/cli/commands/drift.d.ts.map +1 -0
- package/dist/cli/commands/explain.d.ts +5 -0
- package/dist/cli/commands/explain.d.ts.map +1 -0
- package/dist/cli/commands/init.d.ts +46 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/mcp-check.d.ts +57 -0
- package/dist/cli/commands/mcp-check.d.ts.map +1 -0
- package/dist/cli/commands/mcp.d.ts +13 -0
- package/dist/cli/commands/mcp.d.ts.map +1 -0
- package/dist/cli/commands/pin.d.ts +7 -0
- package/dist/cli/commands/pin.d.ts.map +1 -0
- package/dist/cli/commands/plugin.d.ts +32 -0
- package/dist/cli/commands/plugin.d.ts.map +1 -0
- package/dist/cli/commands/preview.d.ts +5 -0
- package/dist/cli/commands/preview.d.ts.map +1 -0
- package/dist/cli/commands/tokens.d.ts +5 -0
- package/dist/cli/commands/tokens.d.ts.map +1 -0
- package/dist/cli/errors.d.ts +53 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/handlers/brand.d.ts +7 -0
- package/dist/cli/handlers/brand.d.ts.map +1 -0
- package/dist/cli/handlers/can.d.ts +7 -0
- package/dist/cli/handlers/can.d.ts.map +1 -0
- package/dist/cli/handlers/fonts.d.ts +4 -0
- package/dist/cli/handlers/fonts.d.ts.map +1 -0
- package/dist/cli/handlers/get.d.ts +7 -0
- package/dist/cli/handlers/get.d.ts.map +1 -0
- package/dist/cli/handlers/index.d.ts +8 -0
- package/dist/cli/handlers/index.d.ts.map +1 -0
- package/dist/cli/handlers/list.d.ts +7 -0
- package/dist/cli/handlers/list.d.ts.map +1 -0
- package/dist/cli/handlers/logo.d.ts +4 -0
- package/dist/cli/handlers/logo.d.ts.map +1 -0
- package/dist/cli/handlers/rules.d.ts +10 -0
- package/dist/cli/handlers/rules.d.ts.map +1 -0
- package/dist/cli/handlers/types.d.ts +17 -0
- package/dist/cli/handlers/types.d.ts.map +1 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +3850 -0
- package/dist/cli/init-flow.d.ts +24 -0
- package/dist/cli/init-flow.d.ts.map +1 -0
- package/dist/cli/init-ui.d.ts +20 -0
- package/dist/cli/init-ui.d.ts.map +1 -0
- package/dist/cli/json.d.ts +18 -0
- package/dist/cli/json.d.ts.map +1 -0
- package/dist/cli/operations.d.ts +11 -0
- package/dist/cli/operations.d.ts.map +1 -0
- package/dist/cli/options.d.ts +8 -0
- package/dist/cli/options.d.ts.map +1 -0
- package/dist/cli/project.d.ts +8 -0
- package/dist/cli/project.d.ts.map +1 -0
- package/dist/cli/read.d.ts +13 -0
- package/dist/cli/read.d.ts.map +1 -0
- package/dist/cli/where.d.ts +10 -0
- package/dist/cli/where.d.ts.map +1 -0
- package/dist/core/assets/categories.d.ts +47 -0
- package/dist/core/assets/categories.d.ts.map +1 -0
- package/dist/core/assets/fields.d.ts +12 -0
- package/dist/core/assets/fields.d.ts.map +1 -0
- package/dist/core/assets/image-size.d.ts +10 -0
- package/dist/core/assets/image-size.d.ts.map +1 -0
- package/dist/core/assets/measure.d.ts +22 -0
- package/dist/core/assets/measure.d.ts.map +1 -0
- package/dist/core/assets/scanner.d.ts +26 -0
- package/dist/core/assets/scanner.d.ts.map +1 -0
- package/dist/core/assets/sidecar.d.ts +22 -0
- package/dist/core/assets/sidecar.d.ts.map +1 -0
- package/dist/core/blazon-pin.d.ts +36 -0
- package/dist/core/blazon-pin.d.ts.map +1 -0
- package/dist/core/brand/export.d.ts +128 -0
- package/dist/core/brand/export.d.ts.map +1 -0
- package/dist/core/brand/schema.d.ts +1000 -0
- package/dist/core/brand/schema.d.ts.map +1 -0
- package/dist/core/brand-theme.d.ts +16 -0
- package/dist/core/brand-theme.d.ts.map +1 -0
- package/dist/core/checker/approvals.d.ts +15 -0
- package/dist/core/checker/approvals.d.ts.map +1 -0
- package/dist/core/checker/cascade.d.ts +8 -0
- package/dist/core/checker/cascade.d.ts.map +1 -0
- package/dist/core/checker/catalogue.d.ts +609 -0
- package/dist/core/checker/catalogue.d.ts.map +1 -0
- package/dist/core/checker/contrast.d.ts +30 -0
- package/dist/core/checker/contrast.d.ts.map +1 -0
- package/dist/core/checker/duplicates.d.ts +3 -0
- package/dist/core/checker/duplicates.d.ts.map +1 -0
- package/dist/core/checker/fixes.d.ts +6 -0
- package/dist/core/checker/fixes.d.ts.map +1 -0
- package/dist/core/checker/font-meta.d.ts +8 -0
- package/dist/core/checker/font-meta.d.ts.map +1 -0
- package/dist/core/checker/index.d.ts +23 -0
- package/dist/core/checker/index.d.ts.map +1 -0
- package/dist/core/checker/location.d.ts +7 -0
- package/dist/core/checker/location.d.ts.map +1 -0
- package/dist/core/checker/logo-rules.d.ts +19 -0
- package/dist/core/checker/logo-rules.d.ts.map +1 -0
- package/dist/core/checker/logo-surfaces.d.ts +7 -0
- package/dist/core/checker/logo-surfaces.d.ts.map +1 -0
- package/dist/core/checker/page-tokens.d.ts +5 -0
- package/dist/core/checker/page-tokens.d.ts.map +1 -0
- package/dist/core/checker/print.d.ts +9 -0
- package/dist/core/checker/print.d.ts.map +1 -0
- package/dist/core/checker/proportion.d.ts +3 -0
- package/dist/core/checker/proportion.d.ts.map +1 -0
- package/dist/core/checker/review.d.ts +40 -0
- package/dist/core/checker/review.d.ts.map +1 -0
- package/dist/core/checker/source.d.ts +4 -0
- package/dist/core/checker/source.d.ts.map +1 -0
- package/dist/core/checker/spdx.d.ts +8 -0
- package/dist/core/checker/spdx.d.ts.map +1 -0
- package/dist/core/checker/tier.d.ts +3 -0
- package/dist/core/checker/tier.d.ts.map +1 -0
- package/dist/core/checker/usage.d.ts +4 -0
- package/dist/core/checker/usage.d.ts.map +1 -0
- package/dist/core/checker/variables.d.ts +8 -0
- package/dist/core/checker/variables.d.ts.map +1 -0
- package/dist/core/colors.d.ts +10 -0
- package/dist/core/colors.d.ts.map +1 -0
- package/dist/core/config/defaults.d.ts +3 -0
- package/dist/core/config/defaults.d.ts.map +1 -0
- package/dist/core/config/index.d.ts +15 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/validate.d.ts +21 -0
- package/dist/core/config/validate.d.ts.map +1 -0
- package/dist/core/config/vocabulary.d.ts +10 -0
- package/dist/core/config/vocabulary.d.ts.map +1 -0
- package/dist/core/confine.d.ts +25 -0
- package/dist/core/confine.d.ts.map +1 -0
- package/dist/core/docs/directives.d.ts +161 -0
- package/dist/core/docs/directives.d.ts.map +1 -0
- package/dist/core/docs/parser.d.ts +7 -0
- package/dist/core/docs/parser.d.ts.map +1 -0
- package/dist/core/docs/sections.d.ts +11 -0
- package/dist/core/docs/sections.d.ts.map +1 -0
- package/dist/core/drift/compare.d.ts +30 -0
- package/dist/core/drift/compare.d.ts.map +1 -0
- package/dist/core/drift/read.d.ts +22 -0
- package/dist/core/drift/read.d.ts.map +1 -0
- package/dist/core/email-signature.d.ts +35 -0
- package/dist/core/email-signature.d.ts.map +1 -0
- package/dist/core/emit.d.ts +22 -0
- package/dist/core/emit.d.ts.map +1 -0
- package/dist/core/fonts.d.ts +43 -0
- package/dist/core/fonts.d.ts.map +1 -0
- package/dist/core/icons/icon-sets.d.ts +22 -0
- package/dist/core/icons/icon-sets.d.ts.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/init/answers.d.ts +45 -0
- package/dist/core/init/answers.d.ts.map +1 -0
- package/dist/core/init/from-site/apply.d.ts +7 -0
- package/dist/core/init/from-site/apply.d.ts.map +1 -0
- package/dist/core/init/from-site/clean-colors.d.ts +21 -0
- package/dist/core/init/from-site/clean-colors.d.ts.map +1 -0
- package/dist/core/init/from-site/colors.d.ts +10 -0
- package/dist/core/init/from-site/colors.d.ts.map +1 -0
- package/dist/core/init/from-site/context.d.ts +24 -0
- package/dist/core/init/from-site/context.d.ts.map +1 -0
- package/dist/core/init/from-site/fonts.d.ts +10 -0
- package/dist/core/init/from-site/fonts.d.ts.map +1 -0
- package/dist/core/init/from-site/html.d.ts +10 -0
- package/dist/core/init/from-site/html.d.ts.map +1 -0
- package/dist/core/init/from-site/index.d.ts +6 -0
- package/dist/core/init/from-site/index.d.ts.map +1 -0
- package/dist/core/init/from-site/inspect.d.ts +4 -0
- package/dist/core/init/from-site/inspect.d.ts.map +1 -0
- package/dist/core/init/from-site/logo.d.ts +20 -0
- package/dist/core/init/from-site/logo.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/colors.d.ts +4 -0
- package/dist/core/init/from-site/sections/colors.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/config.d.ts +10 -0
- package/dist/core/init/from-site/sections/config.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/directives.d.ts +3 -0
- package/dist/core/init/from-site/sections/directives.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/fonts.d.ts +8 -0
- package/dist/core/init/from-site/sections/fonts.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/intro.d.ts +4 -0
- package/dist/core/init/from-site/sections/intro.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/logo.d.ts +9 -0
- package/dist/core/init/from-site/sections/logo.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/placeholder.d.ts +5 -0
- package/dist/core/init/from-site/sections/placeholder.d.ts.map +1 -0
- package/dist/core/init/from-site/tree.d.ts +14 -0
- package/dist/core/init/from-site/tree.d.ts.map +1 -0
- package/dist/core/init/from-site/types.d.ts +37 -0
- package/dist/core/init/from-site/types.d.ts.map +1 -0
- package/dist/core/init/palette.d.ts +34 -0
- package/dist/core/init/palette.d.ts.map +1 -0
- package/dist/core/init/prompts.d.ts +78 -0
- package/dist/core/init/prompts.d.ts.map +1 -0
- package/dist/core/init/shared/google-fonts.d.ts +4 -0
- package/dist/core/init/shared/google-fonts.d.ts.map +1 -0
- package/dist/core/init/shared/hex.d.ts +6 -0
- package/dist/core/init/shared/hex.d.ts.map +1 -0
- package/dist/core/init/shared/svg.d.ts +3 -0
- package/dist/core/init/shared/svg.d.ts.map +1 -0
- package/dist/core/init/vocabulary.d.ts +42 -0
- package/dist/core/init/vocabulary.d.ts.map +1 -0
- package/dist/core/inputs.d.ts +25 -0
- package/dist/core/inputs.d.ts.map +1 -0
- package/dist/core/logo/lockup.d.ts +54 -0
- package/dist/core/logo/lockup.d.ts.map +1 -0
- package/dist/core/logo.d.ts +23 -0
- package/dist/core/logo.d.ts.map +1 -0
- package/dist/core/mcp-config.d.ts +65 -0
- package/dist/core/mcp-config.d.ts.map +1 -0
- package/dist/core/operations/check.d.ts +8 -0
- package/dist/core/operations/check.d.ts.map +1 -0
- package/dist/core/operations/index.d.ts +7 -0
- package/dist/core/operations/index.d.ts.map +1 -0
- package/dist/core/operations/limits.d.ts +6 -0
- package/dist/core/operations/limits.d.ts.map +1 -0
- package/dist/core/operations/list.d.ts +8 -0
- package/dist/core/operations/list.d.ts.map +1 -0
- package/dist/core/operations/project.d.ts +10 -0
- package/dist/core/operations/project.d.ts.map +1 -0
- package/dist/core/operations/types.d.ts +96 -0
- package/dist/core/operations/types.d.ts.map +1 -0
- package/dist/core/operations/validate.d.ts +4 -0
- package/dist/core/operations/validate.d.ts.map +1 -0
- package/dist/core/order.d.ts +9 -0
- package/dist/core/order.d.ts.map +1 -0
- package/dist/core/outputs.d.ts +22 -0
- package/dist/core/outputs.d.ts.map +1 -0
- package/dist/core/package-name.d.ts +3 -0
- package/dist/core/package-name.d.ts.map +1 -0
- package/dist/core/package-root.d.ts +3 -0
- package/dist/core/package-root.d.ts.map +1 -0
- package/dist/core/plugin-name.d.ts +27 -0
- package/dist/core/plugin-name.d.ts.map +1 -0
- package/dist/core/preflight.d.ts +10 -0
- package/dist/core/preflight.d.ts.map +1 -0
- package/dist/core/read/can.d.ts +44 -0
- package/dist/core/read/can.d.ts.map +1 -0
- package/dist/core/read/fonts.d.ts +47 -0
- package/dist/core/read/fonts.d.ts.map +1 -0
- package/dist/core/read/index.d.ts +8 -0
- package/dist/core/read/index.d.ts.map +1 -0
- package/dist/core/read/list.d.ts +28 -0
- package/dist/core/read/list.d.ts.map +1 -0
- package/dist/core/read/logo.d.ts +34 -0
- package/dist/core/read/logo.d.ts.map +1 -0
- package/dist/core/read/lookup.d.ts +9 -0
- package/dist/core/read/lookup.d.ts.map +1 -0
- package/dist/core/read/rules.d.ts +80 -0
- package/dist/core/read/rules.d.ts.map +1 -0
- package/dist/core/read/token.d.ts +46 -0
- package/dist/core/read/token.d.ts.map +1 -0
- package/dist/core/shipped-names.d.ts +9 -0
- package/dist/core/shipped-names.d.ts.map +1 -0
- package/dist/core/starter.d.ts +31 -0
- package/dist/core/starter.d.ts.map +1 -0
- package/dist/core/suggest.d.ts +7 -0
- package/dist/core/suggest.d.ts.map +1 -0
- package/dist/core/tokens/alias.d.ts +18 -0
- package/dist/core/tokens/alias.d.ts.map +1 -0
- package/dist/core/tokens/contexts.d.ts +10 -0
- package/dist/core/tokens/contexts.d.ts.map +1 -0
- package/dist/core/tokens/formatters/css.d.ts +15 -0
- package/dist/core/tokens/formatters/css.d.ts.map +1 -0
- package/dist/core/tokens/formatters/json.d.ts +4 -0
- package/dist/core/tokens/formatters/json.d.ts.map +1 -0
- package/dist/core/tokens/formatters/tailwind.d.ts +37 -0
- package/dist/core/tokens/formatters/tailwind.d.ts.map +1 -0
- package/dist/core/tokens/formatters/ts.d.ts +6 -0
- package/dist/core/tokens/formatters/ts.d.ts.map +1 -0
- package/dist/core/tokens/groups.d.ts +44 -0
- package/dist/core/tokens/groups.d.ts.map +1 -0
- package/dist/core/tokens/key-lines.d.ts +8 -0
- package/dist/core/tokens/key-lines.d.ts.map +1 -0
- package/dist/core/tokens/load.d.ts +12 -0
- package/dist/core/tokens/load.d.ts.map +1 -0
- package/dist/core/tokens/merge.d.ts +17 -0
- package/dist/core/tokens/merge.d.ts.map +1 -0
- package/dist/core/tokens/names.d.ts +5 -0
- package/dist/core/tokens/names.d.ts.map +1 -0
- package/dist/core/tokens/resolve.d.ts +8 -0
- package/dist/core/tokens/resolve.d.ts.map +1 -0
- package/dist/core/tokens/resolver/compile.d.ts +17 -0
- package/dist/core/tokens/resolver/compile.d.ts.map +1 -0
- package/dist/core/tokens/resolver/inputs.d.ts +7 -0
- package/dist/core/tokens/resolver/inputs.d.ts.map +1 -0
- package/dist/core/tokens/resolver/parse.d.ts +34 -0
- package/dist/core/tokens/resolver/parse.d.ts.map +1 -0
- package/dist/core/tokens/resolver/sources.d.ts +17 -0
- package/dist/core/tokens/resolver/sources.d.ts.map +1 -0
- package/dist/core/tokens/shadcn.d.ts +43 -0
- package/dist/core/tokens/shadcn.d.ts.map +1 -0
- package/dist/core/tokens/theme.d.ts +17 -0
- package/dist/core/tokens/theme.d.ts.map +1 -0
- package/dist/core/tokens/values/color.d.ts +2 -0
- package/dist/core/tokens/values/color.d.ts.map +1 -0
- package/dist/core/tokens/values/composite.d.ts +7 -0
- package/dist/core/tokens/values/composite.d.ts.map +1 -0
- package/dist/core/tokens/values/font.d.ts +3 -0
- package/dist/core/tokens/values/font.d.ts.map +1 -0
- package/dist/core/tokens/values/index.d.ts +9 -0
- package/dist/core/tokens/values/index.d.ts.map +1 -0
- package/dist/core/tokens/values/shared.d.ts +5 -0
- package/dist/core/tokens/values/shared.d.ts.map +1 -0
- package/dist/core/tokens/values/simple.d.ts +3 -0
- package/dist/core/tokens/values/simple.d.ts.map +1 -0
- package/dist/core/tokens/values/units.d.ts +3 -0
- package/dist/core/tokens/values/units.d.ts.map +1 -0
- package/dist/core/tokens/walk.d.ts +30 -0
- package/dist/core/tokens/walk.d.ts.map +1 -0
- package/dist/core/version.d.ts +3 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/plugins/host/admit.d.ts +35 -0
- package/dist/plugins/host/admit.d.ts.map +1 -0
- package/dist/plugins/host/call.d.ts +59 -0
- package/dist/plugins/host/call.d.ts.map +1 -0
- package/dist/plugins/host/check.d.ts +54 -0
- package/dist/plugins/host/check.d.ts.map +1 -0
- package/dist/plugins/host/scrub.d.ts +17 -0
- package/dist/plugins/host/scrub.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +14 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/pins/interpreter.d.ts +49 -0
- package/dist/plugins/pins/interpreter.d.ts.map +1 -0
- package/dist/plugins/pins/lock.d.ts +47 -0
- package/dist/plugins/pins/lock.d.ts.map +1 -0
- package/dist/plugins/pins/pin.d.ts +65 -0
- package/dist/plugins/pins/pin.d.ts.map +1 -0
- package/dist/plugins/pins/shipped.d.ts +40 -0
- package/dist/plugins/pins/shipped.d.ts.map +1 -0
- package/dist/plugins/roles/breaker.d.ts +18 -0
- package/dist/plugins/roles/breaker.d.ts.map +1 -0
- package/dist/plugins/roles/check-cases.d.ts +4 -0
- package/dist/plugins/roles/check-cases.d.ts.map +1 -0
- package/dist/plugins/roles/dev.d.ts +35 -0
- package/dist/plugins/roles/dev.d.ts.map +1 -0
- package/dist/plugins/roles/fixes.d.ts +24 -0
- package/dist/plugins/roles/fixes.d.ts.map +1 -0
- package/dist/plugins/roles/gate.d.ts +26 -0
- package/dist/plugins/roles/gate.d.ts.map +1 -0
- package/dist/plugins/roles/integrate.d.ts +12 -0
- package/dist/plugins/roles/integrate.d.ts.map +1 -0
- package/dist/plugins/roles/roles.d.ts +73 -0
- package/dist/plugins/roles/roles.d.ts.map +1 -0
- package/dist/plugins/wire/environment.d.ts +9 -0
- package/dist/plugins/wire/environment.d.ts.map +1 -0
- package/dist/plugins/wire/forms.d.ts +13 -0
- package/dist/plugins/wire/forms.d.ts.map +1 -0
- package/dist/plugins/wire/limits.d.ts +11 -0
- package/dist/plugins/wire/limits.d.ts.map +1 -0
- package/dist/plugins/wire/manifest.d.ts +31 -0
- package/dist/plugins/wire/manifest.d.ts.map +1 -0
- package/dist/plugins/wire/profile.d.ts +36 -0
- package/dist/plugins/wire/profile.d.ts.map +1 -0
- package/dist/plugins/wire/text.d.ts +14 -0
- package/dist/plugins/wire/text.d.ts.map +1 -0
- package/dist/server/assets.d.ts +13 -0
- package/dist/server/assets.d.ts.map +1 -0
- package/dist/server/coalesce.d.ts +12 -0
- package/dist/server/coalesce.d.ts.map +1 -0
- package/dist/server/data-script.d.ts +8 -0
- package/dist/server/data-script.d.ts.map +1 -0
- package/dist/server/dev-server.d.ts +34 -0
- package/dist/server/dev-server.d.ts.map +1 -0
- package/dist/server/editor-guard.d.ts +13 -0
- package/dist/server/editor-guard.d.ts.map +1 -0
- package/dist/server/error-reporter.d.ts +11 -0
- package/dist/server/error-reporter.d.ts.map +1 -0
- package/dist/server/icon-sets.d.ts +9 -0
- package/dist/server/icon-sets.d.ts.map +1 -0
- package/dist/server/plugin.d.ts +4 -0
- package/dist/server/plugin.d.ts.map +1 -0
- package/dist/server/preview-guard.d.ts +11 -0
- package/dist/server/preview-guard.d.ts.map +1 -0
- package/dist/types/assets.d.ts +130 -0
- package/dist/types/assets.d.ts.map +1 -0
- package/dist/types/catalog.d.ts +95 -0
- package/dist/types/catalog.d.ts.map +1 -0
- package/dist/types/config.d.ts +97 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/data.d.ts +38 -0
- package/dist/types/data.d.ts.map +1 -0
- package/dist/types/docs.d.ts +47 -0
- package/dist/types/docs.d.ts.map +1 -0
- package/dist/types/findings.d.ts +18 -0
- package/dist/types/findings.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/parsed.d.ts +86 -0
- package/dist/types/parsed.d.ts.map +1 -0
- package/dist/types/theme.d.ts +19 -0
- package/dist/types/theme.d.ts.map +1 -0
- package/dist/types/tokens.d.ts +101 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/ui/assets/geist-OFL.txt +93 -0
- package/dist/ui/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/ui/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/ui/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/ui/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/ui/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/ui/assets/index-D0WCUmtA.css +2 -0
- package/dist/ui/assets/index-DhSc0Zxv.js +75 -0
- package/dist/ui/index.html +14 -0
- package/package.json +151 -4
- package/plugins/blazon.brand-deck/README.md +38 -0
- package/plugins/blazon.brand-deck/bin/blazon-blazon.brand-deck./360/237/224/214 +2695 -0
- package/plugins/blazon.brand-deck/package.json +3 -0
- package/plugins/blazon.copy/README.md +29 -0
- package/plugins/blazon.copy/bin/blazon-blazon.copy./360/237/224/214 +438 -0
- package/plugins/blazon.copy/package.json +3 -0
- package/plugins/blazon.favicons/README.md +13 -0
- package/plugins/blazon.favicons/bin/blazon-blazon.favicons./360/237/224/214 +8816 -0
- package/plugins/blazon.favicons/package.json +3 -0
- package/plugins/blazon.logo-geometry/README.md +5 -0
- package/plugins/blazon.logo-geometry/bin/blazon-blazon.logo-geometry./360/237/224/214 +1522 -0
- package/plugins/blazon.logo-geometry/package.json +3 -0
- package/plugins/blazon.logo-kit/README.md +5 -0
- package/plugins/blazon.logo-kit/bin/blazon-blazon.logo-kit./360/237/224/214 +617 -0
- package/plugins/blazon.logo-kit/package.json +3 -0
- package/plugins/blazon.office-template/README.md +29 -0
- package/plugins/blazon.office-template/bin/blazon-blazon.office-template./360/237/224/214 +1788 -0
- package/plugins/blazon.office-template/package.json +3 -0
- package/plugins/blazon.platform-tokens/README.md +22 -0
- package/plugins/blazon.platform-tokens/bin/blazon-blazon.platform-tokens./360/237/224/214 +8418 -0
- package/plugins/blazon.platform-tokens/package.json +3 -0
- package/plugins/blazon.press-kit/README.md +17 -0
- package/plugins/blazon.press-kit/bin/blazon-blazon.press-kit./360/237/224/214 +897 -0
- package/plugins/blazon.press-kit/package.json +3 -0
- package/plugins/blazon.print-book/README.md +40 -0
- package/plugins/blazon.print-book/bin/blazon-blazon.print-book./360/237/224/214 +9268 -0
- package/plugins/blazon.print-book/package.json +3 -0
- package/plugins/blazon.social-cards/README.md +5 -0
- package/plugins/blazon.social-cards/bin/blazon-blazon.social-cards./360/237/224/214 +1165 -0
- package/plugins/blazon.social-cards/package.json +3 -0
- package/plugins/shipped.lock +75 -0
- package/template/AGENTS.md +55 -0
- package/template/CLAUDE.md +1 -0
- package/template/assets/backgrounds/aurora.json +5 -0
- package/template/assets/backgrounds/aurora.svg +39 -0
- package/template/assets/construction/blazon-mark.json +9 -0
- package/template/assets/construction/blazon-mark.svg +54 -0
- package/template/assets/icons/arrow-right.json +5 -0
- package/template/assets/icons/arrow-right.svg +1 -0
- package/template/assets/icons/check.json +5 -0
- package/template/assets/icons/check.svg +1 -0
- package/template/assets/icons/download.json +5 -0
- package/template/assets/icons/download.svg +1 -0
- package/template/assets/icons/file.json +5 -0
- package/template/assets/icons/file.svg +1 -0
- package/template/assets/icons/token.json +5 -0
- package/template/assets/icons/token.svg +1 -0
- package/template/assets/icons/warning.json +5 -0
- package/template/assets/icons/warning.svg +1 -0
- package/template/assets/logos/blazon-bone.json +6 -0
- package/template/assets/logos/blazon-bone.svg +1 -0
- package/template/assets/logos/blazon-graphite.json +6 -0
- package/template/assets/logos/blazon-graphite.svg +1 -0
- package/template/assets/logos/blazon-mark.json +6 -0
- package/template/assets/logos/blazon-mark.svg +1 -0
- package/template/blazon.json +104 -0
- package/template/blazon.resolver.json +46 -0
- package/template/docs/01-principles.md +47 -0
- package/template/docs/02-logo.md +43 -0
- package/template/docs/03-color.md +79 -0
- package/template/docs/04-type.md +36 -0
- package/template/docs/05-form.md +80 -0
- package/template/docs/06-layout.md +28 -0
- package/template/docs/07-icons.md +22 -0
- package/template/docs/08-diagrams.md +20 -0
- package/template/docs/09-social.md +21 -0
- package/template/docs/10-applications.md +20 -0
- package/template/docs/11-voice.md +74 -0
- package/template/docs/12-web.md +167 -0
- package/template/fonts/IBMPlexMono-Regular-latin.woff2 +0 -0
- package/template/fonts/IBMPlexMono-SemiBold-latin.woff2 +0 -0
- package/template/fonts/OFL.txt +93 -0
- package/template/tokens/colors.json +257 -0
- package/template/tokens/form.json +199 -0
- package/template/tokens/social.json +26 -0
- package/template/tokens/spacing.json +65 -0
- package/template/tokens/theme/dark.json +121 -0
- package/template/tokens/typography.json +233 -0
|
@@ -0,0 +1,3850 @@
|
|
|
1
|
+
import { $t as e, At as t, C as n, D as r, Dn as i, E as a, En as o, F as s, H as c, I as l, It as u, Jt as d, Kt as f, Lt as p, Mt as m, Nt as h, O as g, Ot as _, Pt as v, Qt as y, Rt as b, S as x, St as ee, T as S, Tt as C, U as w, V as te, Vt as ne, W as re, Xt as ie, Yt as ae, Zt as oe, _ as se, _t as ce, a as le, an as ue, b as de, bt as fe, c as pe, cn as me, d as he, dn as ge, dt as T, f as _e, fn as ve, ft as ye, g as be, gt as xe, h as Se, hn as Ce, ht as we, i as Te, in as Ee, jt as De, k as E, kt as Oe, l as ke, ln as D, m as Ae, mt as je, on as Me, p as Ne, pn as Pe, pt as Fe, rn as Ie, s as Le, sn as Re, st as ze, t as Be, u as Ve, un as He, v as Ue, w as We, wt as Ge, x as Ke, xt as qe, y as Je, zt as Ye } from "../chunks/site-builder-CPfjBOmR.js";
|
|
2
|
+
import O from "node:path";
|
|
3
|
+
import k from "node:fs";
|
|
4
|
+
import { spawn as Xe } from "node:child_process";
|
|
5
|
+
import Ze from "node:os";
|
|
6
|
+
import { preview as Qe } from "vite";
|
|
7
|
+
import { cac as $e } from "cac";
|
|
8
|
+
import * as A from "@clack/prompts";
|
|
9
|
+
// src/cli/errors.ts
|
|
10
|
+
var j = class extends Error {
|
|
11
|
+
fix;
|
|
12
|
+
code;
|
|
13
|
+
constructor(e, t, n = "error") {
|
|
14
|
+
super(e), this.fix = t, this.code = n;
|
|
15
|
+
}
|
|
16
|
+
}, M = class extends j {}, et = (e) => new M(`port ${e} is in use`, "Pick another with --port, or leave out --strict-port to take the next free one.", "port-in-use"), tt = (e) => e.replace(/^./, (e) => e.toLowerCase()).replace(/\.$/, "");
|
|
17
|
+
function nt(e, t, n) {
|
|
18
|
+
return `blazon${e ? ` ${e}` : ""}: ${t}${n ? `\n ${n}` : ""}`;
|
|
19
|
+
}
|
|
20
|
+
var rt = (e, t) => t ? `${e}; ${tt(t)}` : e, it;
|
|
21
|
+
function at(e) {
|
|
22
|
+
it = e;
|
|
23
|
+
}
|
|
24
|
+
function ot(e) {
|
|
25
|
+
console.error(e.replace(/^blazon(?: [a-z]+)*:/, (e) => n.red(e)));
|
|
26
|
+
}
|
|
27
|
+
var st = (e, t, n) => ({
|
|
28
|
+
code: e,
|
|
29
|
+
message: t,
|
|
30
|
+
...n !== void 0 && { fix: n }
|
|
31
|
+
});
|
|
32
|
+
function ct(e, t, n) {
|
|
33
|
+
it !== void 0 && process.stdout.write(`${JSON.stringify({
|
|
34
|
+
command: it,
|
|
35
|
+
passed: !1,
|
|
36
|
+
error: st(e, t, n)
|
|
37
|
+
})}\n`);
|
|
38
|
+
}
|
|
39
|
+
function N(e, t, n = {}) {
|
|
40
|
+
return ot(e), n.stack && console.error(n.stack), ct(t, n.json ?? e.replace(/^blazon(?: [a-z]+)?: /, ""), n.fix), process.exit(2);
|
|
41
|
+
}
|
|
42
|
+
var lt = (e) => e.replace(/`([^`]*)`/g, "\"$1\"").replace(/^./, (e) => e.toLowerCase()), ut = (e) => e instanceof Error && e.name === "CACError";
|
|
43
|
+
function P(e, t, r) {
|
|
44
|
+
let i = t instanceof j ? t.fix : void 0;
|
|
45
|
+
if (t instanceof M) return N(nt(e, t.message, i), t.code, {
|
|
46
|
+
stack: r ? t.stack : void 0,
|
|
47
|
+
json: rt(t.message, i),
|
|
48
|
+
fix: i
|
|
49
|
+
});
|
|
50
|
+
let a = t instanceof Error ? t.message : String(t);
|
|
51
|
+
return console.error(), ot(nt(e, a, i ?? (r || t instanceof j ? void 0 : n.dim("Run again with --debug for the stack.")))), r && t instanceof Error && t.stack && console.error(t.stack), ct(t instanceof j ? t.code : "error", rt(a, i), i), process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
// src/cli/where.ts
|
|
54
|
+
function F(e, t = process.cwd()) {
|
|
55
|
+
let n = O.relative(t, O.resolve(t, e));
|
|
56
|
+
return n === "" ? "" : n.startsWith("..") || O.isAbsolute(n) ? O.resolve(t, e) : n.split(O.sep).join("/");
|
|
57
|
+
}
|
|
58
|
+
var I = (e, t) => e ? `${e}/${t}` : t, dt = (e) => /^[\w./@%+=:,-]+$/.test(e) ? e : `'${e.replace(/'/g, "'\\''")}'`, L = (e, t) => `blazon ${e}${t ? ` ${dt(t)}` : ""}`, ft = (e) => k.statSync(e, { throwIfNoEntry: !1 })?.isDirectory() ?? !1, pt = (e) => `Run ${L("init", F(e))} to start a brand book there`;
|
|
59
|
+
function mt(e) {
|
|
60
|
+
if (!ft(e)) throw new M(`no folder "${e}"`, `${pt(e)}.`, "no-folder");
|
|
61
|
+
}
|
|
62
|
+
function ht(e, t) {
|
|
63
|
+
if (!ft(O.resolve(e, t))) throw new M(`no tokens folder (${t.replace(/^\.\//, "").replace(/\/$/, "")}) in "${e}"`, `${pt(e)}, or set tokensDir in blazon.json.`, "no-tokens-folder");
|
|
64
|
+
}
|
|
65
|
+
async function R(e, t) {
|
|
66
|
+
mt(e);
|
|
67
|
+
let n = await ae(e, t);
|
|
68
|
+
return ht(e, n.tokensDir), n;
|
|
69
|
+
}
|
|
70
|
+
// src/cli/commands/dev.ts
|
|
71
|
+
var gt = /* @__PURE__ */ i({ runDev: () => _t });
|
|
72
|
+
async function _t(e = process.cwd(), t, n = {}) {
|
|
73
|
+
let r = await R(e, t ? { port: t } : void 0);
|
|
74
|
+
try {
|
|
75
|
+
await Te(r, e, n);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ? et(r.port) : e;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// src/cli/commands/check.ts
|
|
81
|
+
var vt = class extends j {
|
|
82
|
+
findings;
|
|
83
|
+
constructor(e, t, n, r = "check-failed") {
|
|
84
|
+
super(e, n, r), this.findings = t;
|
|
85
|
+
}
|
|
86
|
+
}, yt = (e) => e?.plugins === !1, bt = (e) => e?.plugin === void 0 ? [] : [e.plugin].flat();
|
|
87
|
+
function xt(e) {
|
|
88
|
+
return e.context ? `${e.path} (${e.context})` : e.path;
|
|
89
|
+
}
|
|
90
|
+
var St = 5;
|
|
91
|
+
function Ct(e) {
|
|
92
|
+
let t = e.slice(0, St).join(", ");
|
|
93
|
+
return e.length > St ? `${t} and ${e.length - St} more` : t;
|
|
94
|
+
}
|
|
95
|
+
var wt = (e) => e.path.split("/")[0];
|
|
96
|
+
function Tt(e, t) {
|
|
97
|
+
let r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = e.filter((e) => e.code === "page-review-pending");
|
|
98
|
+
for (let t of e) t.code === "starter-file-unchanged" && a.set(wt(t), [...a.get(wt(t)) ?? [], t]), t.code === "review-pending" && o.set(t.message, [...o.get(t.message) ?? [], t]);
|
|
99
|
+
for (let c of e) {
|
|
100
|
+
if (i.has(c)) continue;
|
|
101
|
+
let e = c.code === "starter-file-unchanged" ? a.get(wt(c)) : void 0, l = c.code === "review-pending" ? o.get(c.message) : void 0;
|
|
102
|
+
if (c.code === "page-review-pending" && s.length > 1) s.forEach((e) => i.add(e)), r.push(`${n.bold(`page-review-pending (${s.length} pages)`)}: ${Ct(s.map(xt))}: show assets still marked needs-review ${n.dim("[page-review-pending]")}`);
|
|
103
|
+
else if (e && e.length > 1) {
|
|
104
|
+
e.forEach((e) => i.add(e));
|
|
105
|
+
let t = wt(c), a = e.map((e) => e.path.slice(t.length + 1));
|
|
106
|
+
r.push(`${n.bold(`${t}/`)}: ${e.length} files are still the starter's text (${Ct(a)}) ${n.dim("[starter-file-unchanged]")}`);
|
|
107
|
+
} else if (l && l.length > 1) l.forEach((e) => i.add(e)), r.push(`${n.bold(`review-pending (${l.length})`)}: ${Ct(l.map(xt))}: ${c.message} ${n.dim("[review-pending]")}`);
|
|
108
|
+
else {
|
|
109
|
+
let e = Ne(c, t), i = e === void 0 ? n.bold(xt(c)) : c.path === c.file ? n.bold(e) : `${n.bold(e)} ${xt(c)}`;
|
|
110
|
+
r.push(`${i}: ${c.message} ${n.dim(`[${c.code}]`)}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return r;
|
|
114
|
+
}
|
|
115
|
+
function Et(e, t = "") {
|
|
116
|
+
for (let r of Tt(e.errors, t)) console.log(` ${n.bgRed(n.white(" ERROR "))} ${r}`);
|
|
117
|
+
for (let r of Tt(e.warnings, t)) console.log(` ${n.bgYellow(n.black(" WARN "))} ${r}`);
|
|
118
|
+
for (let r of Tt(e.infos, t)) console.log(` ${n.bgCyan(n.black(" NOTE "))} ${r}`);
|
|
119
|
+
}
|
|
120
|
+
var Dt = 5;
|
|
121
|
+
function Ot(e, t = "") {
|
|
122
|
+
e.infos.filter((e) => e.code === "starter-file-unchanged").length < Dt || (console.log(n.bold("Next:")), console.log(` 1. Edit ${n.cyan(I(t, "tokens/colors.json"))} with your colors`), console.log(` 2. Run ${n.cyan(L("dev", t))} to see the book`), console.log(` 3. Replace blazon's artwork in ${n.cyan(I(t, "assets/"))} and the text in ${n.cyan(I(t, "docs/"))}`), console.log());
|
|
123
|
+
}
|
|
124
|
+
var kt = 3;
|
|
125
|
+
function At(e, t = "") {
|
|
126
|
+
let r = /* @__PURE__ */ new Map();
|
|
127
|
+
for (let t of e.errors) {
|
|
128
|
+
let e = Se(t);
|
|
129
|
+
e && !r.has(`${t.code}\n${e}`) && r.set(`${t.code}\n${e}`, {
|
|
130
|
+
code: t.code,
|
|
131
|
+
fix: e
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
let i = [...r.values()].slice(0, kt);
|
|
135
|
+
console.log(n.bold("Next:")), i.forEach(({ code: e, fix: t }, r) => console.log(` ${r + 1}. ${n.cyan(e)}: ${t}`)), console.log(` ${i.length + 1}. Run ${n.cyan(L("check", t))} again`), console.log();
|
|
136
|
+
}
|
|
137
|
+
function jt(e, t = process.cwd()) {
|
|
138
|
+
let n = Ge(e.findings);
|
|
139
|
+
if (n.all.length === 0) return;
|
|
140
|
+
let r = F(t);
|
|
141
|
+
if (console.log(), Et(n, r), console.log(), n.errors.length > 0) throw new vt(`blazon check found ${n.errors.length} error(s)`, e.findings, `Fix them, or run ${L("check", r)} for details.`);
|
|
142
|
+
}
|
|
143
|
+
async function Mt(e = process.cwd(), t = !1, r) {
|
|
144
|
+
let i = await R(e);
|
|
145
|
+
console.log(n.cyan("\n[blazon] Checking design tokens..."));
|
|
146
|
+
let a = await T(i, e);
|
|
147
|
+
a.findings.push(...we(e)), yt(r) || await de(a, i, e, new be(i, e, { named: bt(r) }));
|
|
148
|
+
let o = Ge(a.findings, { strict: t });
|
|
149
|
+
if (o.all.length === 0) return console.log(n.green(`\n ✔ ${a.tokens.items.length} tokens, no findings.\n`)), {
|
|
150
|
+
findings: o.all,
|
|
151
|
+
passed: !0
|
|
152
|
+
};
|
|
153
|
+
let s = [
|
|
154
|
+
o.errors.length > 0 && `${o.errors.length} error(s)`,
|
|
155
|
+
o.warnings.length > 0 && `${o.warnings.length} warning(s)`,
|
|
156
|
+
o.infos.length > 0 && `${o.infos.length} note(s)`
|
|
157
|
+
].filter(Boolean), c = o.errors.length + o.warnings.length > 0 ? `${o.errors.length} error(s) and ${o.warnings.length} warning(s)${o.infos.length > 0 ? ` and ${o.infos.length} note(s)` : ""}` : s.join(" and "), l = F(e);
|
|
158
|
+
return console.log(`\nFound ${c}:\n`), Et(o, l), console.log(), o.errors.length > 0 ? At(o, l) : Ot(o, l), o.passed ? (console.log(o.warnings.length > 0 ? n.yellow("✔ Check passed with warnings.\n") : n.green("✔ Check passed.\n")), {
|
|
159
|
+
findings: o.all,
|
|
160
|
+
passed: !0
|
|
161
|
+
}) : (console.error(n.red(`✖ Check failed${t ? " (--strict treats warnings as errors)" : ""}.\n`)), {
|
|
162
|
+
findings: o.all,
|
|
163
|
+
passed: !1
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
// src/cli/commands/build.ts
|
|
167
|
+
async function Nt(e = process.cwd(), t, r) {
|
|
168
|
+
let i = await R(e, t ? { outDir: t } : void 0), a = await T(i, e);
|
|
169
|
+
a.findings.push(...we(e));
|
|
170
|
+
let o = new be(i, e, { named: bt(r) });
|
|
171
|
+
yt(r) || await de(a, i, e, o), jt(a, e);
|
|
172
|
+
let { siteOutDir: s } = await Be(i, e, { data: a }), c = yt(r) ? [] : await Je(a, i, e, o, s);
|
|
173
|
+
if (c.length === 0) return { findings: a.findings };
|
|
174
|
+
let l = Ge(c);
|
|
175
|
+
if (console.log(), Et(l, F(e)), console.log(), l.errors.length > 0) throw new vt(`a build plugin reported ${l.errors.length} error(s)`, [...a.findings, ...c], "The site is built; the plugin's findings above say what to fix.", "plugin-failed");
|
|
176
|
+
return console.log(n.dim(" Build plugins finished.")), { findings: [...a.findings, ...c] };
|
|
177
|
+
}
|
|
178
|
+
// src/cli/commands/tokens.ts
|
|
179
|
+
async function Pt(e = process.cwd(), t) {
|
|
180
|
+
let r = await R(e);
|
|
181
|
+
console.log(n.cyan("\n[blazon] Compiling design tokens..."));
|
|
182
|
+
let i = await T(r, e);
|
|
183
|
+
i.findings.push(...we(e)), yt(t) || await de(i, r, e, new be(r, e, { named: bt(t) })), jt(i, e);
|
|
184
|
+
let a = await ye(i, r, e);
|
|
185
|
+
for (let e of [
|
|
186
|
+
a.cssPath,
|
|
187
|
+
a.typographyPath,
|
|
188
|
+
a.tailwindPath,
|
|
189
|
+
a.tailwindResetPath,
|
|
190
|
+
a.tsPath,
|
|
191
|
+
a.jsonPath
|
|
192
|
+
]) e && console.log(` ${n.green("✔")} Emitted ${n.bold(e)}`);
|
|
193
|
+
return console.log(), { findings: i.findings };
|
|
194
|
+
}
|
|
195
|
+
// src/core/drift/compare.ts
|
|
196
|
+
var Ft = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i, It = /^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/i, Lt = (e) => e.trim().toLowerCase().replace(/\s+/g, " ");
|
|
197
|
+
function Rt(e) {
|
|
198
|
+
let t = e.trim();
|
|
199
|
+
if (!Ft.test(t)) return Lt(t);
|
|
200
|
+
let n = t.slice(1).toLowerCase();
|
|
201
|
+
return `#${n.length <= 4 ? [...n].map((e) => e + e).join("") : n}`;
|
|
202
|
+
}
|
|
203
|
+
function zt(e) {
|
|
204
|
+
let t = e.trim().match(It);
|
|
205
|
+
return t ? `${Number(t[1])}${t[2].toLowerCase()}` : Lt(e);
|
|
206
|
+
}
|
|
207
|
+
function Bt(e, t) {
|
|
208
|
+
return e === "color" ? Rt(t) : e === "dimension" ? zt(t) : Lt(t);
|
|
209
|
+
}
|
|
210
|
+
var Vt = /\/\*[\s\S]*?\*\//g, Ht = /([^{}]*)\{([^{}]*)\}/g, Ut = /(--[A-Za-z0-9_-]+)\s*:\s*([^;]*?)\s*(?:;|$)/g, Wt = /(^|,)\s*(:root|html)\s*(,|$)/, Gt = /^var\(\s*(--[A-Za-z0-9_-]+)\s*\)$/;
|
|
211
|
+
function Kt(e) {
|
|
212
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
213
|
+
for (let r of e.replace(Vt, "").matchAll(Ht)) {
|
|
214
|
+
let e = Wt.test(r[1].trim()) ? t : n;
|
|
215
|
+
for (let t of r[2].matchAll(Ut)) e.set(t[1], t[2]);
|
|
216
|
+
}
|
|
217
|
+
let r = new Map([...n, ...t]);
|
|
218
|
+
for (let [e, t] of r) {
|
|
219
|
+
let n = t, i = /* @__PURE__ */ new Set([e]);
|
|
220
|
+
for (let e = n.match(Gt); e && r.has(e[1]) && !i.has(e[1]); e = n.match(Gt)) i.add(e[1]), n = r.get(e[1]);
|
|
221
|
+
r.set(e, n);
|
|
222
|
+
}
|
|
223
|
+
return r;
|
|
224
|
+
}
|
|
225
|
+
function qt(e, t, n) {
|
|
226
|
+
let r = Bt(e.type, String(e.value)), i = n.get(t);
|
|
227
|
+
if (i === void 0) return {
|
|
228
|
+
path: e.path,
|
|
229
|
+
cssVar: t,
|
|
230
|
+
status: "missing",
|
|
231
|
+
expected: r
|
|
232
|
+
};
|
|
233
|
+
let a = Bt(e.type, i);
|
|
234
|
+
return {
|
|
235
|
+
path: e.path,
|
|
236
|
+
cssVar: t,
|
|
237
|
+
status: a === r ? "ok" : "drift",
|
|
238
|
+
expected: r,
|
|
239
|
+
actual: a
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
var Jt = 1e4;
|
|
243
|
+
function Yt(e) {
|
|
244
|
+
let t = e instanceof Error ? e.message : String(e), n = e instanceof Error ? e.cause : void 0;
|
|
245
|
+
return n instanceof Error && n.message && n.message !== t ? `${t}: ${n.message}` : t;
|
|
246
|
+
}
|
|
247
|
+
async function Xt(e) {
|
|
248
|
+
let t;
|
|
249
|
+
try {
|
|
250
|
+
t = await fetch(e, {
|
|
251
|
+
signal: AbortSignal.timeout(Jt),
|
|
252
|
+
redirect: "follow"
|
|
253
|
+
});
|
|
254
|
+
} catch (t) {
|
|
255
|
+
let n = t instanceof Error && (t.name === "TimeoutError" || t.name === "AbortError");
|
|
256
|
+
throw Error(`could not fetch ${e}: ${n ? `no answer in ${Jt / 1e3} s` : Yt(t)}`, { cause: t });
|
|
257
|
+
}
|
|
258
|
+
if (!t.ok) throw Error(`could not fetch ${e}: ${t.status} ${t.statusText}`.trim());
|
|
259
|
+
let n = [], r = 0;
|
|
260
|
+
try {
|
|
261
|
+
for await (let i of t.body ?? []) {
|
|
262
|
+
if (r += i.byteLength, r > 5242880) throw Error(`${e} is larger than 5 MB`);
|
|
263
|
+
n.push(Buffer.from(i));
|
|
264
|
+
}
|
|
265
|
+
} catch (t) {
|
|
266
|
+
throw t instanceof Error && t.message.endsWith("5 MB") ? t : Error(`could not read ${e}: ${t instanceof Error ? t.message : String(t)}`, { cause: t });
|
|
267
|
+
}
|
|
268
|
+
return Buffer.concat(n);
|
|
269
|
+
}
|
|
270
|
+
async function Zt(e) {
|
|
271
|
+
return (await Xt(e)).toString("utf8");
|
|
272
|
+
}
|
|
273
|
+
function Qt(e, t) {
|
|
274
|
+
let n = [];
|
|
275
|
+
for (let [r] of e.replace(/<!--[\s\S]*?-->/g, "").matchAll(/<link\b[^>]*>/gi)) {
|
|
276
|
+
let e = (e) => r.match(RegExp(`\\s${e}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i")), i = e("rel"), a = e("href");
|
|
277
|
+
if (i && a && (i[1] ?? i[2] ?? i[3] ?? "").toLowerCase().split(/\s+/).includes("stylesheet")) try {
|
|
278
|
+
let e = new URL((a[1] ?? a[2] ?? a[3] ?? "").trim(), t);
|
|
279
|
+
e.protocol !== "http:" && e.protocol !== "https:" || n.includes(e.href) || n.push(e.href);
|
|
280
|
+
} catch {}
|
|
281
|
+
}
|
|
282
|
+
return n;
|
|
283
|
+
}
|
|
284
|
+
async function $t(e) {
|
|
285
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e)) {
|
|
286
|
+
if (!/^https?:\/\//i.test(e)) throw Error(`${e} is not an http(s) address or a file`);
|
|
287
|
+
let t = Qt(await Zt(e), e).slice(0, 20);
|
|
288
|
+
return {
|
|
289
|
+
css: (await Promise.all(t.map(Zt))).join("\n"),
|
|
290
|
+
sources: t
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
let t = O.resolve(e), n;
|
|
294
|
+
try {
|
|
295
|
+
if (k.statSync(t).size > 5242880) throw Error(`${t} is larger than 5 MB`);
|
|
296
|
+
n = k.readFileSync(t, "utf8");
|
|
297
|
+
} catch (e) {
|
|
298
|
+
throw Error(e instanceof Error && e.message.endsWith("5 MB") ? e.message : `could not read ${t}: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
css: n,
|
|
302
|
+
sources: [t]
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
async function en(e) {
|
|
306
|
+
if (!/^https?:\/\//i.test(e)) throw Error(`${e} is not an http(s) address`);
|
|
307
|
+
let t = await Zt(e), n = Qt(t, e).slice(0, 20);
|
|
308
|
+
return {
|
|
309
|
+
html: t,
|
|
310
|
+
css: (await Promise.all(n.map(Zt))).join("\n"),
|
|
311
|
+
sources: n
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
// src/core/init/from-site/tree.ts
|
|
315
|
+
var tn = (e) => typeof e == "object" && !!e && "$value" in e;
|
|
316
|
+
function nn(e) {
|
|
317
|
+
return JSON.parse(k.readFileSync(e, "utf-8"));
|
|
318
|
+
}
|
|
319
|
+
function rn(e, t) {
|
|
320
|
+
k.writeFileSync(e, `${JSON.stringify(t, null, 2)}\n`);
|
|
321
|
+
}
|
|
322
|
+
var an = (e) => ({ "dev.blazon": e });
|
|
323
|
+
function on(e, t = []) {
|
|
324
|
+
let n = [];
|
|
325
|
+
for (let [r, i] of Object.entries(e)) !r.startsWith("$") && typeof i == "object" && i && (tn(i) ? n.push([...t, r].join(".")) : n.push(...on(i, [...t, r])));
|
|
326
|
+
return n;
|
|
327
|
+
}
|
|
328
|
+
var sn = (e, t) => {
|
|
329
|
+
let n = e;
|
|
330
|
+
for (let e of t.split(".")) {
|
|
331
|
+
if (typeof n != "object" || !n) return;
|
|
332
|
+
n = n[e];
|
|
333
|
+
}
|
|
334
|
+
return tn(n) ? n : void 0;
|
|
335
|
+
}, cn = (e) => [...JSON.stringify(e).matchAll(/\{([A-Za-z0-9_.-]+)\}/g)].map((e) => e[1]);
|
|
336
|
+
function ln(e, t) {
|
|
337
|
+
return k.existsSync(e) ? k.readdirSync(e, { withFileTypes: !0 }).flatMap((n) => {
|
|
338
|
+
let r = O.join(e, n.name);
|
|
339
|
+
return n.isDirectory() ? ln(r, t) : t.some((e) => n.name.endsWith(e)) ? [r] : [];
|
|
340
|
+
}) : [];
|
|
341
|
+
}
|
|
342
|
+
function un(e, t) {
|
|
343
|
+
let n = t.split("."), r = [e];
|
|
344
|
+
for (let e of n.slice(0, -1)) r.push(r.at(-1)[e]);
|
|
345
|
+
delete r.at(-1)[n.at(-1)];
|
|
346
|
+
for (let e = r.length - 1; e >= 2 && !Object.keys(r[e]).some((e) => !e.startsWith("$")); e--) delete r[e - 1][n[e - 1]];
|
|
347
|
+
}
|
|
348
|
+
// src/core/init/from-site/clean-colors.ts
|
|
349
|
+
function dn(e) {
|
|
350
|
+
let { tree: t, destDir: n, picks: r, starterColors: i, siteColors: a, note: o, review: s, source: c, result: l } = e, u = (e, n) => {
|
|
351
|
+
let r = sn(t, `${e}.${n}`)?.$value, o = typeof r == "string" ? r.match(/^\{(.+)\}$/)?.[1] : void 0;
|
|
352
|
+
return o && i.has(o) && !a.has(o) ? o : void 0;
|
|
353
|
+
}, d = (e, n, r, i = {}) => {
|
|
354
|
+
let [a, c] = e.split("."), u = sn(t, e), d = String(u.$value);
|
|
355
|
+
t[a][c] = {
|
|
356
|
+
$value: `{${n}}`,
|
|
357
|
+
...typeof u.$description == "string" && { $description: u.$description },
|
|
358
|
+
$extensions: an({
|
|
359
|
+
...i,
|
|
360
|
+
review: r ? {
|
|
361
|
+
...s,
|
|
362
|
+
note: `${o} ${r}`
|
|
363
|
+
} : s
|
|
364
|
+
})
|
|
365
|
+
}, l.repointed.push(`${e} from ${d} to {${n}}${r ? ` (${r.replace(/\.$/, "").replace(/^The /, "the ")})` : ""}`);
|
|
366
|
+
}, f = (e) => `color.${e.segments.join(".")}`, p = (e) => e.map((e) => r.find((t) => (t.segments.at(-1) === "base" ? t.segments.slice(0, -1) : t.segments).join(".") === e.join("."))).find(Boolean);
|
|
367
|
+
for (let [e, t] of [
|
|
368
|
+
["text.primary", [
|
|
369
|
+
["foreground"],
|
|
370
|
+
["text", "primary"],
|
|
371
|
+
["text"]
|
|
372
|
+
]],
|
|
373
|
+
["surface.background", [
|
|
374
|
+
["background"],
|
|
375
|
+
["surface", "background"],
|
|
376
|
+
["surface", "page"],
|
|
377
|
+
["page"]
|
|
378
|
+
]],
|
|
379
|
+
["surface.canvas", [
|
|
380
|
+
["card"],
|
|
381
|
+
["surface", "card"],
|
|
382
|
+
["surface", "canvas"],
|
|
383
|
+
["surface"]
|
|
384
|
+
]]
|
|
385
|
+
]) {
|
|
386
|
+
let [n, r] = e.split("."), i = p(t);
|
|
387
|
+
i && u(n, r) && d(e, f(i), "", { source: c(`:root { ${i.cssVar} }`, i.exact ? i.cssVar : void 0) });
|
|
388
|
+
}
|
|
389
|
+
let m = t.color, { color: h, ...g } = t, _ = new Set(cn(g));
|
|
390
|
+
for (let e of ln(O.join(n, "tokens"), [".json"])) if (O.basename(e) !== "colors.json") for (let t of cn(nn(e))) _.add(t);
|
|
391
|
+
let v = [O.join(n, "blazon.json"), ...ln(O.join(n, "docs"), [".md", ".mdx"])].filter((e) => k.existsSync(e)).map((e) => k.readFileSync(e, "utf-8")).join("\n");
|
|
392
|
+
for (let e of v.matchAll(/(?<![\w.-])color(?:\.[A-Za-z0-9_-]+)+/g)) _.add(e[0]);
|
|
393
|
+
let y = [..._];
|
|
394
|
+
for (; y.length > 0;) {
|
|
395
|
+
let e = sn(t, y.pop());
|
|
396
|
+
for (let t of e ? cn(e.$value) : []) _.has(t) || (_.add(t), y.push(t));
|
|
397
|
+
}
|
|
398
|
+
for (let e of [...i].filter((e) => !a.has(e) && !_.has(e))) sn({ color: m }, e) && (un({ color: m }, e), l.removed.push(`${e} (a starter color nothing uses)`));
|
|
399
|
+
}
|
|
400
|
+
// src/core/init/palette.ts
|
|
401
|
+
var fn = "#ffffff", pn = "#0b1120";
|
|
402
|
+
function mn(e) {
|
|
403
|
+
let t = e.trim().match(/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
404
|
+
if (!t) return;
|
|
405
|
+
let n = t[1].length === 3 ? [...t[1]].map((e) => e + e).join("") : t[1];
|
|
406
|
+
return [
|
|
407
|
+
0,
|
|
408
|
+
2,
|
|
409
|
+
4
|
|
410
|
+
].map((e) => parseInt(n.slice(e, e + 2), 16) / 255);
|
|
411
|
+
}
|
|
412
|
+
var hn = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
|
|
413
|
+
function gn(e) {
|
|
414
|
+
let t = mn(e);
|
|
415
|
+
if (!t) throw Error(`not a hex color: ${e}`);
|
|
416
|
+
return t;
|
|
417
|
+
}
|
|
418
|
+
function _n(e) {
|
|
419
|
+
let [t, n, r] = gn(e).map(hn);
|
|
420
|
+
return .2126 * t + .7152 * n + .0722 * r;
|
|
421
|
+
}
|
|
422
|
+
function z(e, t) {
|
|
423
|
+
let [n, r] = [_n(e), _n(t)];
|
|
424
|
+
return (Math.max(n, r) + .05) / (Math.min(n, r) + .05);
|
|
425
|
+
}
|
|
426
|
+
var vn = (e) => e >= 7 ? "AAA" : e >= 4.5 ? "AA" : e >= 3 ? "AA-large" : "fail";
|
|
427
|
+
function yn(e) {
|
|
428
|
+
let t = z(e, fn), n = z(e, pn);
|
|
429
|
+
return {
|
|
430
|
+
onWhite: {
|
|
431
|
+
ratio: t,
|
|
432
|
+
level: vn(t)
|
|
433
|
+
},
|
|
434
|
+
onNearBlack: {
|
|
435
|
+
ratio: n,
|
|
436
|
+
level: vn(n)
|
|
437
|
+
},
|
|
438
|
+
carriesWhiteText: t >= 4.5
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
var bn = "#1E1F21", xn = "#F2F0EB";
|
|
442
|
+
function Sn(e) {
|
|
443
|
+
let t = z(e, bn), n = z(e, xn);
|
|
444
|
+
return t >= n ? {
|
|
445
|
+
ink: "graphite",
|
|
446
|
+
ratio: t,
|
|
447
|
+
aa: t >= 4.5
|
|
448
|
+
} : {
|
|
449
|
+
ink: "bone",
|
|
450
|
+
ratio: n,
|
|
451
|
+
aa: n >= 4.5
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
// src/core/init/vocabulary.ts
|
|
455
|
+
var Cn = "color.signal.orange", wn = "color.signal.primary", Tn = "color.signal.hazard", En = (e) => typeof e == "object" && !!e && "$value" in e;
|
|
456
|
+
function B(e, t) {
|
|
457
|
+
let n = e;
|
|
458
|
+
for (let e of t.split(".")) {
|
|
459
|
+
if (typeof n != "object" || !n) return;
|
|
460
|
+
n = n[e];
|
|
461
|
+
}
|
|
462
|
+
return En(n) ? n : void 0;
|
|
463
|
+
}
|
|
464
|
+
function Dn(e, t) {
|
|
465
|
+
let n = e.$extensions ??= {}, r = n["dev.blazon"] ??= {};
|
|
466
|
+
r.review === void 0 && (r.review = {
|
|
467
|
+
status: "needs-review",
|
|
468
|
+
note: t
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
function On(e, t) {
|
|
472
|
+
let n = [], r = e.color, i = r?.signal, a = i?.orange;
|
|
473
|
+
if (!i || !En(a)) throw Error(`${Cn} is not in the tokens`);
|
|
474
|
+
let o = {};
|
|
475
|
+
for (let [e, t] of Object.entries(i)) o[e === "orange" ? "primary" : e] = t;
|
|
476
|
+
r.signal = o;
|
|
477
|
+
let s = JSON.parse(JSON.stringify(e).split(`{${Cn}}`).join(`{${wn}}`));
|
|
478
|
+
for (let t of Object.keys(e)) e[t] = s[t];
|
|
479
|
+
let c = B(e, wn);
|
|
480
|
+
c.$value = t, c.$description = "Primary signal color";
|
|
481
|
+
let l = kn(e, t, `{${wn}}`);
|
|
482
|
+
n.push(...l.hints);
|
|
483
|
+
let u = B(e, Tn);
|
|
484
|
+
return u && (Dn(u, "Still blazon's hazard yellow: it was not chosen to go with your primary. Set the brand's own, or remove it."), n.push(`${Tn} is still blazon's hazard yellow and is marked needs-review: set the brand's own or remove it`)), {
|
|
485
|
+
hints: n,
|
|
486
|
+
label: l.label
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
function kn(e, t, n, r = !1) {
|
|
490
|
+
let i = [], a = z(t, bn), o = z(t, xn), s = B(e, "text.onSignal"), c = a < 4.5 && o >= 4.5 && s !== void 0;
|
|
491
|
+
if (c ? (s.$value = "{color.base.bone}", s.$description = "Labels on the brand color are bone", i.push(`Labels on ${t} are bone, because graphite is ${a.toFixed(1)}:1 there; blazon's hazard yellow has no label pair now`)) : a < 4.5 && i.push(`Neither graphite (${a.toFixed(1)}:1) nor bone (${o.toFixed(1)}:1) reaches AA (4.5:1) as a label on ${t}: blazon check will report text.onSignal, so choose a lighter or darker color`), c || r) {
|
|
492
|
+
let t = e.text?.$extensions?.["dev.blazon"];
|
|
493
|
+
for (let e of t?.pairs ?? []) e.bg === "{color.signal.*}" && (e.bg = n);
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
hints: i,
|
|
497
|
+
label: c ? "bone" : "graphite"
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
var An = (e) => JSON.parse(k.readFileSync(e, "utf-8")), jn = (e, t) => k.writeFileSync(e, `${JSON.stringify(t, null, 2)}\n`);
|
|
501
|
+
function Mn(e, t) {
|
|
502
|
+
return [...t, ...Array.isArray(e) ? e.filter((e) => typeof e == "object" && !!e) : []];
|
|
503
|
+
}
|
|
504
|
+
var Nn = ["blazon-graphite", "blazon-bone"], Pn = [...Nn, "blazon-mark"];
|
|
505
|
+
// src/core/init/shared/hex.ts
|
|
506
|
+
function Fn(e) {
|
|
507
|
+
let t = e.trim();
|
|
508
|
+
if (/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)) return {
|
|
509
|
+
hex: Rt(t),
|
|
510
|
+
exact: !0
|
|
511
|
+
};
|
|
512
|
+
let n = t.match(/^rgba?\(\s*([\d.]+)(%?)[\s,]+([\d.]+)%?[\s,]+([\d.]+)%?(?:\s*[,/]\s*([\d.]+)(%?))?\s*\)$/i);
|
|
513
|
+
if (!n) return;
|
|
514
|
+
let r = (e) => Math.max(0, Math.min(255, Math.round(n[2] ? Number(e) * 255 / 100 : Number(e)))), i = (e) => e.toString(16).padStart(2, "0"), a = `#${i(r(n[1]))}${i(r(n[3]))}${i(r(n[4]))}`;
|
|
515
|
+
if (n[5] !== void 0) {
|
|
516
|
+
let e = Math.max(0, Math.min(1, n[6] ? Number(n[5]) / 100 : Number(n[5])));
|
|
517
|
+
e < 1 && (a += i(Math.round(e * 255)));
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
hex: a,
|
|
521
|
+
exact: !1
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
// src/core/init/from-site/colors.ts
|
|
525
|
+
var In = 40, Ln = /brand|primary|secondary|accent|background|foreground|surface/i;
|
|
526
|
+
function Rn(e) {
|
|
527
|
+
let t = [], n = /* @__PURE__ */ new Set();
|
|
528
|
+
for (let [r, i] of e) {
|
|
529
|
+
if (!Ln.test(r)) continue;
|
|
530
|
+
let e = Fn(i);
|
|
531
|
+
if (!e || e.hex.length !== 7) continue;
|
|
532
|
+
let a = r.slice(2).toLowerCase().split(/[-_]+/).filter(Boolean);
|
|
533
|
+
a.length > 1 && (a[0] === "color" || a[0] === "colors") && (a = a.slice(1)), a.length > 1 && a.at(-1) === "foreground" || a.length > 1 && a.at(-2) === "on" && /^(dark|light)$/.test(a.at(-1)) || a.length === 0 || n.has(a.join(".")) || (n.add(a.join(".")), t.push({
|
|
534
|
+
cssVar: r,
|
|
535
|
+
...e,
|
|
536
|
+
segments: a
|
|
537
|
+
}));
|
|
538
|
+
}
|
|
539
|
+
return t.slice(0, In);
|
|
540
|
+
}
|
|
541
|
+
function zn(e, t, n = []) {
|
|
542
|
+
let r = e.filter((e) => e.segments.includes(t)).sort((e, n) => Number(e.segments.at(-1) !== t) - Number(n.segments.at(-1) !== t) || e.segments.length - n.segments.length)[0];
|
|
543
|
+
return r || t !== "secondary" ? r : e.find((e) => !n.includes(e) && e.segments.includes("brand") && !e.segments.some((e) => /light|dark|strong|hero|raised|navy|background|foreground|surface/.test(e)));
|
|
544
|
+
}
|
|
545
|
+
// src/core/init/from-site/context.ts
|
|
546
|
+
var Bn = (...e) => e.join("/");
|
|
547
|
+
// src/core/init/from-site/sections/colors.ts
|
|
548
|
+
function Vn(e, t) {
|
|
549
|
+
let { destDir: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l = Rn(r).filter((e) => !t?.has(e.cssVar));
|
|
550
|
+
if (l.length === 0) i.missing.push("no brand color: no custom property named brand, primary, secondary, accent, background, foreground or surface holds a hex or rgb() color");
|
|
551
|
+
else if (c(Bn("tokens", "colors.json"))) {
|
|
552
|
+
let e = O.join(n, "tokens", "colors.json"), t = nn(e), r = t.color ??= {}, c = new Set(on(r, ["color"])), u = /* @__PURE__ */ new Set(), d = new Set(l.map((e) => e.segments.join(".")));
|
|
553
|
+
for (let e of l) {
|
|
554
|
+
let t = e.segments;
|
|
555
|
+
[...d].some((e) => e.startsWith(`${t.join(".")}.`)) && (t = [...t, "base"]);
|
|
556
|
+
let n = r, a = !1, c = !0;
|
|
557
|
+
for (let [e, r] of t.slice(0, -1).entries()) {
|
|
558
|
+
let t = n[r];
|
|
559
|
+
if (t === void 0) {
|
|
560
|
+
let t = {};
|
|
561
|
+
e === 0 && (t.$extensions = an({ review: o }), a = !0), n[r] = t, n = t;
|
|
562
|
+
} else if (tn(t) || typeof t != "object" || !t) {
|
|
563
|
+
c = !1;
|
|
564
|
+
break;
|
|
565
|
+
} else n = t;
|
|
566
|
+
}
|
|
567
|
+
let l = t.at(-1);
|
|
568
|
+
!c || typeof n[l] == "object" && n[l] !== null && !tn(n[l]) ? i.missing.push(`${e.cssVar} was not written: color.${t.join(".")} clashes with a starter token`) : (n[l] = {
|
|
569
|
+
$value: e.hex,
|
|
570
|
+
$extensions: an({
|
|
571
|
+
source: s(`:root { ${e.cssVar} }`, e.exact ? e.cssVar : void 0),
|
|
572
|
+
...a ? {} : { review: o }
|
|
573
|
+
})
|
|
574
|
+
}, e.segments = t, u.add(e));
|
|
575
|
+
}
|
|
576
|
+
let f = new Set([...u].map((e) => `color.${e.segments.join(".")}`)), p = zn(l, "primary"), m = t.interactive, h = sn(t, "interactive.primary");
|
|
577
|
+
if (!p) i.missing.push("no primary color: interactive.primary keeps the starter's value");
|
|
578
|
+
else if (m && h) {
|
|
579
|
+
let e = `color.${p.segments.join(".")}`;
|
|
580
|
+
m.primary = {
|
|
581
|
+
$value: `{${e}}`,
|
|
582
|
+
...typeof h.$description == "string" && { $description: h.$description },
|
|
583
|
+
$extensions: an({
|
|
584
|
+
source: s(`:root { ${p.cssVar} }`, p.exact ? p.cssVar : void 0),
|
|
585
|
+
review: o
|
|
586
|
+
})
|
|
587
|
+
}, i.repointed.push(`interactive.primary to {${e}}`);
|
|
588
|
+
let n = kn(t, p.hex, `{${e}}`, !0);
|
|
589
|
+
for (let e of n.hints) i.missing.push(e);
|
|
590
|
+
} else i.missing.push("interactive.primary was not found in tokens/colors.json, so the primary color was not set");
|
|
591
|
+
dn({
|
|
592
|
+
tree: t,
|
|
593
|
+
destDir: n,
|
|
594
|
+
picks: [...u],
|
|
595
|
+
starterColors: c,
|
|
596
|
+
siteColors: f,
|
|
597
|
+
note: a,
|
|
598
|
+
review: o,
|
|
599
|
+
source: s,
|
|
600
|
+
result: i
|
|
601
|
+
}), rn(e, t), i.written.push(Bn("tokens", "colors.json"));
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
// src/core/init/from-site/html.ts
|
|
605
|
+
function Hn(e) {
|
|
606
|
+
return e.replace(/&/g, "&").replace(/"/g, "\"").replace(/�?39;|'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " ").replace(/\s+/g, " ").trim().split(/ [|:–—-] /)[0].trim();
|
|
607
|
+
}
|
|
608
|
+
var V = (e, t) => {
|
|
609
|
+
let n = e.match(RegExp(`\\s${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"));
|
|
610
|
+
return n ? n[1] ?? n[2] ?? n[3] : void 0;
|
|
611
|
+
};
|
|
612
|
+
function H(e, t) {
|
|
613
|
+
for (let n of e.match(/<meta\b[^>]*>/gi) ?? []) if ((V(n, "property") ?? V(n, "name"))?.toLowerCase() === t) {
|
|
614
|
+
let e = V(n, "content")?.replace(/&/g, "&").trim();
|
|
615
|
+
if (e) return e;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function Un(e) {
|
|
619
|
+
let t = H(e, "og:site_name") ?? H(e, "application-name");
|
|
620
|
+
if (t) return t;
|
|
621
|
+
let n = e.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
622
|
+
return (n ? Hn(n[1]) : "") || void 0;
|
|
623
|
+
}
|
|
624
|
+
async function Wn(e, t) {
|
|
625
|
+
let n = (e.match(/<link\b[^>]*>/gi) ?? []).find((e) => V(e, "rel")?.toLowerCase() === "manifest"), r = n && V(n, "href");
|
|
626
|
+
if (r) try {
|
|
627
|
+
let e = new URL(r, t);
|
|
628
|
+
if (e.protocol !== "http:" && e.protocol !== "https:") return;
|
|
629
|
+
let n = JSON.parse(await Zt(e.href)), i = typeof n.short_name == "string" ? n.short_name.trim() : "", a = typeof n.name == "string" ? Hn(n.name) : "";
|
|
630
|
+
return i || a || void 0;
|
|
631
|
+
} catch {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
// src/core/init/from-site/sections/config.ts
|
|
636
|
+
async function Gn(e, t, n) {
|
|
637
|
+
let { destDir: r, url: i, page: a, result: o, mayChange: s } = e, { fontUrls: c } = n, l = "blazon.json", u = H(a.html, "og:site_name") ?? H(a.html, "application-name") ?? await Wn(a.html, i) ?? Un(a.html), d = H(a.html, "description");
|
|
638
|
+
u || o.missing.push("no <title> on the page: the config title keeps the folder name");
|
|
639
|
+
let f = !1;
|
|
640
|
+
if ((u || d || t.single || t.onLight || c.length > 0) && s(l)) {
|
|
641
|
+
let e = O.join(r, l), n = An(e);
|
|
642
|
+
u && (n.title = u), d && (n.description = d);
|
|
643
|
+
let i = t.single ?? (t.onLight ? {
|
|
644
|
+
onLight: t.onLight,
|
|
645
|
+
...t.onDark ? { onDark: t.onDark } : {}
|
|
646
|
+
} : void 0);
|
|
647
|
+
i && (n.logo = i), c.length > 0 && (n.fonts = Mn(n.fonts, c)), jn(e, n), o.written.push(l), f = !!i;
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
title: u,
|
|
651
|
+
description: d,
|
|
652
|
+
configLogo: f
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
// src/core/init/from-site/sections/directives.ts
|
|
656
|
+
var Kn = /^[ \t]*<!--\s*blazon:tokens\b([^>]*?)-->[ \t]*\r?\n?/gm;
|
|
657
|
+
function qn(e) {
|
|
658
|
+
let { destDir: t, created: n, result: r } = e, i = O.join(t, "docs");
|
|
659
|
+
if (!k.existsSync(i)) return;
|
|
660
|
+
let a = ne(d(O.join(t, "tokens"), t), "--").items, o = (e) => a.some((t) => t.path === e || t.path.startsWith(`${e}.`));
|
|
661
|
+
for (let e of k.readdirSync(i).filter((e) => e.endsWith(".md"))) {
|
|
662
|
+
let t = `docs/${e}`;
|
|
663
|
+
if (!n.has(t)) continue;
|
|
664
|
+
let a = O.join(i, e), s = k.readFileSync(a, "utf-8"), c = [], l = s.replace(Kn, (e, t) => {
|
|
665
|
+
let n = t.split(/\s+/).filter(Boolean), r = n.filter(o);
|
|
666
|
+
return c.push(...n.filter((e) => !o(e))), r.length === n.length ? e : r.length === 0 ? "" : `<!-- blazon:tokens ${r.join(" ")} -->\n`;
|
|
667
|
+
}).replace(/\n{3,}/g, "\n\n");
|
|
668
|
+
l !== s && (k.writeFileSync(a, l), r.removed.push(`${c.join(", ")} in ${t} (the site has no such token to show)`));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// src/core/init/shared/google-fonts.ts
|
|
672
|
+
var Jn = [
|
|
673
|
+
"Inter",
|
|
674
|
+
"Roboto",
|
|
675
|
+
"Open Sans",
|
|
676
|
+
"Lato",
|
|
677
|
+
"Montserrat",
|
|
678
|
+
"Poppins",
|
|
679
|
+
"Manrope",
|
|
680
|
+
"Mulish",
|
|
681
|
+
"Nunito",
|
|
682
|
+
"Source Sans 3",
|
|
683
|
+
"DM Sans",
|
|
684
|
+
"Work Sans",
|
|
685
|
+
"IBM Plex Sans",
|
|
686
|
+
"Space Grotesk",
|
|
687
|
+
"Playfair Display",
|
|
688
|
+
"JetBrains Mono"
|
|
689
|
+
];
|
|
690
|
+
function Yn(e) {
|
|
691
|
+
let t = Jn.find((t) => t.toLowerCase() === e.toLowerCase());
|
|
692
|
+
return t ? `https://fonts.googleapis.com/css2?family=${t.replace(/ /g, "+")}:wght@400;500;600;700&display=swap` : void 0;
|
|
693
|
+
}
|
|
694
|
+
// src/core/init/from-site/fonts.ts
|
|
695
|
+
var Xn = /* @__PURE__ */ new Set([
|
|
696
|
+
"serif",
|
|
697
|
+
"sans-serif",
|
|
698
|
+
"monospace",
|
|
699
|
+
"cursive",
|
|
700
|
+
"fantasy",
|
|
701
|
+
"system-ui",
|
|
702
|
+
"ui-sans-serif",
|
|
703
|
+
"ui-serif",
|
|
704
|
+
"ui-monospace",
|
|
705
|
+
"ui-rounded",
|
|
706
|
+
"emoji",
|
|
707
|
+
"math",
|
|
708
|
+
"fangsong",
|
|
709
|
+
"inherit",
|
|
710
|
+
"initial",
|
|
711
|
+
"unset",
|
|
712
|
+
"-apple-system",
|
|
713
|
+
"blinkmacsystemfont",
|
|
714
|
+
"segoe ui"
|
|
715
|
+
]), Zn = /* @__PURE__ */ new Set([
|
|
716
|
+
"serif",
|
|
717
|
+
"sans-serif",
|
|
718
|
+
"monospace",
|
|
719
|
+
"cursive",
|
|
720
|
+
"fantasy"
|
|
721
|
+
]);
|
|
722
|
+
function Qn(e) {
|
|
723
|
+
let t = [], n = "", r = "";
|
|
724
|
+
for (let i of e) r ? i === r ? r = "" : n += i : i === "\"" || i === "'" ? r = i : i === "," ? (t.push(n.trim()), n = "") : n += i;
|
|
725
|
+
return t.push(n.trim()), t.filter(Boolean);
|
|
726
|
+
}
|
|
727
|
+
function $n(e, t, n) {
|
|
728
|
+
let r;
|
|
729
|
+
for (let i of e.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]*)\{([^{}]*)\}/g)) {
|
|
730
|
+
let e = i[1].split(",").map((e) => e.trim().toLowerCase()).find((e) => n.test(e));
|
|
731
|
+
if (!e) continue;
|
|
732
|
+
let a = i[2].match(/(?:^|;)\s*font-family\s*:\s*([^;]+)/i);
|
|
733
|
+
if (!a) continue;
|
|
734
|
+
let o = a[1].replace(/!important/i, "").trim(), s, c = o.match(/^var\(\s*(--[A-Za-z0-9_-]+)\s*(?:,\s*(.+))?\)$/);
|
|
735
|
+
if (c) {
|
|
736
|
+
let e = t.get(c[1]);
|
|
737
|
+
o = e ?? c[2] ?? "", e !== void 0 && (s = c[1]);
|
|
738
|
+
}
|
|
739
|
+
let l = Qn(o), u = l.find((e) => !Xn.has(e.toLowerCase()) && !e.startsWith("var("));
|
|
740
|
+
u && (r = {
|
|
741
|
+
family: u,
|
|
742
|
+
stack: l,
|
|
743
|
+
locator: `${e} { font-family }`,
|
|
744
|
+
...s && { cssVar: s }
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
return r;
|
|
748
|
+
}
|
|
749
|
+
function er(e) {
|
|
750
|
+
let t = e.stack.find((e) => Zn.has(e.toLowerCase()));
|
|
751
|
+
return [e.family, (t ?? "sans-serif").toLowerCase()];
|
|
752
|
+
}
|
|
753
|
+
// src/core/init/from-site/sections/fonts.ts
|
|
754
|
+
function tr(e) {
|
|
755
|
+
let { destDir: t, page: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l = $n(n.css, r, /^(body|html)$/), u = $n(n.css, r, /^h[1-6]$/), d = [];
|
|
756
|
+
if (!l && !u) i.missing.push("no font: no body or heading rule in the stylesheets names a font-family");
|
|
757
|
+
else if (c(Bn("tokens", "typography.json"))) {
|
|
758
|
+
let e = O.join(t, "tokens", "typography.json"), n = nn(e), r = (n.font ??= {}).family ??= {}, c = l ?? u, f = [["body", c], ["display", u ?? c]];
|
|
759
|
+
for (let [e, t] of f) {
|
|
760
|
+
let n = Yn(t.family);
|
|
761
|
+
n ? d.includes(n) || d.push(n) : i.missing.push(`the font ${t.family} is not one blazon knows a stylesheet for: add its stylesheet to fonts in blazon.json`), r[e] = {
|
|
762
|
+
$value: er(t),
|
|
763
|
+
$extensions: an({
|
|
764
|
+
source: s(t.cssVar ? `${t.locator}, from ${t.cssVar}` : t.locator),
|
|
765
|
+
review: n ? o : {
|
|
766
|
+
status: "needs-review",
|
|
767
|
+
note: `${a} The font ${t.family} must be added to fonts in blazon.json.`
|
|
768
|
+
}
|
|
769
|
+
})
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
let p = r.mono;
|
|
773
|
+
p && Dn(p, `${a} Still blazon's mono font: the site's stylesheets named no monospace font. Set the brand's own.`), rn(e, n), i.written.push(Bn("tokens", "typography.json"));
|
|
774
|
+
}
|
|
775
|
+
return { fontUrls: d };
|
|
776
|
+
}
|
|
777
|
+
// src/core/init/from-site/sections/intro.ts
|
|
778
|
+
var nr = (e) => e.length === 1 && e[0] === "logo", rr = (e) => e.length < 2 ? e.join("") : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
|
|
779
|
+
function ir(e) {
|
|
780
|
+
let { url: t, date: n, result: r } = e, i = {
|
|
781
|
+
colors: r.written.includes("tokens/colors.json"),
|
|
782
|
+
fonts: r.written.includes("tokens/typography.json"),
|
|
783
|
+
logo: r.written.some((e) => e.startsWith("assets/logos/"))
|
|
784
|
+
}, a = Object.entries(i).filter(([, e]) => e).map(([e]) => e), o = Object.entries(i).filter(([, e]) => !e).map(([e]) => e);
|
|
785
|
+
if (a.length === 0) return `Nothing could be read from ${t} on ${n}: it gave no brand colors, no fonts and no logo. This brand book is still blazon's own starter, so replace its colors, fonts and logo with the brand's.`;
|
|
786
|
+
let s = `The ${rr(a)} in this brand book ${nr(a) ? "was" : "were"} read from ${t} on ${n}. They are what the site shows today, so the brand owner needs to confirm them before anyone relies on them.`;
|
|
787
|
+
return o.length === 0 ? s : `${s} The ${rr(o)} ${nr(o) ? "was" : "were"} not found, so ${nr(o) ? "it is" : "they are"} still blazon's own starter: replace ${nr(o) ? "it" : "them"}.`;
|
|
788
|
+
}
|
|
789
|
+
function ar(e, t, n) {
|
|
790
|
+
let { destDir: r, url: i, created: a, result: o } = e, s = "docs/01-principles.md";
|
|
791
|
+
if (a.has(s) && k.existsSync(O.join(r, s))) {
|
|
792
|
+
let a = t ?? new URL(i).hostname.replace(/^www\./, ""), c = [
|
|
793
|
+
"---",
|
|
794
|
+
"title: Introduction",
|
|
795
|
+
"section: intro",
|
|
796
|
+
"order: 1",
|
|
797
|
+
"group: Foundations",
|
|
798
|
+
`description: ${JSON.stringify(n ?? "Where the values in this brand book came from.")}`,
|
|
799
|
+
"---",
|
|
800
|
+
"",
|
|
801
|
+
`# ${a}`,
|
|
802
|
+
"",
|
|
803
|
+
...n ? [n, ""] : [],
|
|
804
|
+
ir(e),
|
|
805
|
+
""
|
|
806
|
+
];
|
|
807
|
+
k.writeFileSync(O.join(r, s), c.join("\n")), o.written.push(s);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
// src/core/init/shared/svg.ts
|
|
811
|
+
function or(e) {
|
|
812
|
+
let t = e.replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/\son\w+\s*=\s*(?:"[^"]*"|'[^']*')/gi, "").replace(/(href\s*=\s*["'])\s*javascript:[^"']*/gi, "$1#");
|
|
813
|
+
return /<svg\b[^>]*\sxmlns\s*=/i.test(t) || (t = t.replace(/<svg\b/i, "<svg xmlns=\"http://www.w3.org/2000/svg\"")), `${t.trim()}\n`;
|
|
814
|
+
}
|
|
815
|
+
// src/core/init/from-site/logo.ts
|
|
816
|
+
function sr(e, t) {
|
|
817
|
+
let n = e.replace(/<!--[\s\S]*?-->/g, "").match(/<header\b[^>]*>([\s\S]*?)<\/header>/i)?.[1];
|
|
818
|
+
if (!n) return;
|
|
819
|
+
let r = [];
|
|
820
|
+
for (let e of n.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi)) {
|
|
821
|
+
let n = V(`<a${e[1]}>`, "href");
|
|
822
|
+
if (n !== void 0) try {
|
|
823
|
+
let i = new URL(n.trim(), t);
|
|
824
|
+
i.origin === new URL(t).origin && i.pathname === "/" && r.push(e[2]);
|
|
825
|
+
} catch {}
|
|
826
|
+
}
|
|
827
|
+
let i = (e) => e.match(/<svg\b[\s\S]*?<\/svg>/i)?.[0], a = (e) => {
|
|
828
|
+
for (let n of e.matchAll(/<img\b[^>]*>/gi)) {
|
|
829
|
+
let e = V(n[0], "src");
|
|
830
|
+
if (e && /\.svg(?:[?#]|$)/i.test(e)) try {
|
|
831
|
+
let n = new URL(e.trim(), t);
|
|
832
|
+
if (n.protocol === "http:" || n.protocol === "https:") return n.href;
|
|
833
|
+
} catch {}
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
for (let e of r) {
|
|
837
|
+
let t = i(e);
|
|
838
|
+
if (t) return {
|
|
839
|
+
kind: "inline",
|
|
840
|
+
svg: t,
|
|
841
|
+
locator: "header a[href=\"/\"] svg"
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
for (let e of r) {
|
|
845
|
+
let t = a(e);
|
|
846
|
+
if (t) return {
|
|
847
|
+
kind: "url",
|
|
848
|
+
url: t,
|
|
849
|
+
locator: "header a[href=\"/\"] img"
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
let o = i(n);
|
|
853
|
+
if (o) return {
|
|
854
|
+
kind: "inline",
|
|
855
|
+
svg: o,
|
|
856
|
+
locator: "header svg"
|
|
857
|
+
};
|
|
858
|
+
let s = a(n);
|
|
859
|
+
return s ? {
|
|
860
|
+
kind: "url",
|
|
861
|
+
url: s,
|
|
862
|
+
locator: "header img"
|
|
863
|
+
} : void 0;
|
|
864
|
+
}
|
|
865
|
+
function cr(e, t) {
|
|
866
|
+
let n = [];
|
|
867
|
+
for (let [r] of e.replace(/<!--[\s\S]*?-->/g, "").matchAll(/<link\b[^>]*>/gi)) {
|
|
868
|
+
let e = (V(r, "rel") ?? "").toLowerCase().split(/\s+/), i = e.includes("apple-touch-icon") || e.includes("apple-touch-icon-precomposed");
|
|
869
|
+
if (!i && !e.includes("icon")) continue;
|
|
870
|
+
let a = V(r, "href");
|
|
871
|
+
if (a) try {
|
|
872
|
+
let o = new URL(a.trim(), t);
|
|
873
|
+
if (o.protocol !== "http:" && o.protocol !== "https:") continue;
|
|
874
|
+
let s = O.extname(o.pathname).toLowerCase() || (V(r, "type") === "image/svg+xml" ? ".svg" : ".png");
|
|
875
|
+
n.push({
|
|
876
|
+
url: o.href,
|
|
877
|
+
svg: s === ".svg",
|
|
878
|
+
ext: s,
|
|
879
|
+
apple: i,
|
|
880
|
+
locator: `link rel="${e.join(" ")}"`
|
|
881
|
+
});
|
|
882
|
+
} catch {}
|
|
883
|
+
}
|
|
884
|
+
return n.find((e) => e.svg) ?? n.find((e) => e.apple) ?? n[0];
|
|
885
|
+
}
|
|
886
|
+
function lr(e) {
|
|
887
|
+
let t = new URL(e).hostname.replace(/^www\./, "");
|
|
888
|
+
return /^[\d.]+$/.test(t) || t.includes(":") || t.startsWith("[") ? "site" : t.split(".")[0].replace(/[^a-z0-9-]/gi, "-").toLowerCase() || "site";
|
|
889
|
+
}
|
|
890
|
+
// src/core/init/from-site/sections/logo.ts
|
|
891
|
+
async function ur(e) {
|
|
892
|
+
let { destDir: t, url: n, date: r, page: i, result: a, note: o, review: s } = e, c = {}, l = lr(n), u = (e, i, c) => {
|
|
893
|
+
rn(O.join(t, e.replace(/\.[a-z]+$/, ".json")), {
|
|
894
|
+
description: o,
|
|
895
|
+
...c,
|
|
896
|
+
source: {
|
|
897
|
+
doc: `${n} page, read ${r}`,
|
|
898
|
+
locator: i
|
|
899
|
+
},
|
|
900
|
+
review: s
|
|
901
|
+
}), a.written.push(e.replace(/\.[a-z]+$/, ".json"));
|
|
902
|
+
}, d = (e, n) => {
|
|
903
|
+
let r = O.join(t, e), i = [e, e.replace(/\.[a-z]+$/, ".json")].filter((e) => k.existsSync(O.join(t, e)));
|
|
904
|
+
return i.length > 0 ? (a.missing.push(`${i.join(" and ")} already existed, so ${i.length > 1 ? "they were" : "it was"} kept as ${i.length > 1 ? "they were" : "it was"}, and no logo was written to ${e}`), !1) : (k.mkdirSync(O.dirname(r), { recursive: !0 }), k.writeFileSync(r, n), a.written.push(e), !0);
|
|
905
|
+
}, f = sr(i.html, n), p, m = "";
|
|
906
|
+
if (f?.kind === "inline") p = f.svg, m = f.locator;
|
|
907
|
+
else if (f?.kind === "url") {
|
|
908
|
+
try {
|
|
909
|
+
p = (await Xt(f.url)).toString("utf8"), m = `${f.locator} (${f.url})`;
|
|
910
|
+
} catch (e) {
|
|
911
|
+
a.missing.push(`the header logo could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
912
|
+
}
|
|
913
|
+
p !== void 0 && !/<svg\b/i.test(p) && (p = void 0, a.missing.push(`${f.url} is not an SVG`));
|
|
914
|
+
}
|
|
915
|
+
let h;
|
|
916
|
+
if (p === void 0 && (h = cr(i.html, n), h?.svg)) try {
|
|
917
|
+
p = (await Xt(h.url)).toString("utf8"), m = `${h.locator} (${h.url})`, /<svg\b/i.test(p) || (p = void 0);
|
|
918
|
+
} catch (e) {
|
|
919
|
+
a.missing.push(`the icon could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
920
|
+
}
|
|
921
|
+
if (p !== void 0) {
|
|
922
|
+
let e = or(p);
|
|
923
|
+
if (/<use\b/i.test(e) && !/<symbol\b/i.test(e) && a.missing.push("the logo uses <use> to point at a sprite elsewhere on the page, so it may draw nothing: check it"), /currentColor/i.test(e)) {
|
|
924
|
+
let t = `assets/logos/${l}.svg`, n = `assets/logos/${l}-white.svg`;
|
|
925
|
+
d(t, e.replace(/currentColor/gi, "#111111")) && (u(t, m, {
|
|
926
|
+
title: "Logo",
|
|
927
|
+
background: "light",
|
|
928
|
+
ink: "#111111"
|
|
929
|
+
}), c.onLight = `./${t}`), d(n, e.replace(/currentColor/gi, "#ffffff")) && (u(n, m, {
|
|
930
|
+
title: "White logo",
|
|
931
|
+
background: "dark",
|
|
932
|
+
ink: "#ffffff"
|
|
933
|
+
}), c.onDark = `./${n}`);
|
|
934
|
+
} else {
|
|
935
|
+
let t = `assets/logos/${l}.svg`;
|
|
936
|
+
d(t, e) && (u(t, m, { title: "Logo" }), c.single = `./${t}`);
|
|
937
|
+
}
|
|
938
|
+
} else if (h) {
|
|
939
|
+
if (![
|
|
940
|
+
".png",
|
|
941
|
+
".jpg",
|
|
942
|
+
".jpeg",
|
|
943
|
+
".gif",
|
|
944
|
+
".webp",
|
|
945
|
+
".avif"
|
|
946
|
+
].includes(h.ext)) a.missing.push(`only a ${h.ext} icon was found (${h.url}), which blazon cannot show: no logo was written`);
|
|
947
|
+
else try {
|
|
948
|
+
let e = `assets/logos/${l}${h.ext === ".jpeg" ? ".jpg" : h.ext}`;
|
|
949
|
+
d(e, await Xt(h.url)) && (u(e, h.locator, { title: "Site icon" }), c.single = `./${e}`, a.missing.push(`no SVG logo was found: ${e} is the site's raster icon (${h.url}), not a logo, so replace it with the real one`));
|
|
950
|
+
} catch (e) {
|
|
951
|
+
a.missing.push(`the icon could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
952
|
+
}
|
|
953
|
+
} else a.missing.push("no logo: no SVG in the header and no <link rel=\"icon\"> on the page");
|
|
954
|
+
return c;
|
|
955
|
+
}
|
|
956
|
+
// src/core/init/from-site/sections/placeholder.ts
|
|
957
|
+
function dr(e, t, n) {
|
|
958
|
+
let { destDir: r, created: i, result: a } = e, o = t.single ?? t.onLight;
|
|
959
|
+
if (n && o) {
|
|
960
|
+
let e = O.join(r, `assets/logos/${Nn[0]}.json`), t = O.join(r, o.replace(/^\.\//, "").replace(/\.[a-z]+$/, ".json"));
|
|
961
|
+
if (i.has(`assets/logos/${Nn[0]}.json`) && k.existsSync(e) && k.existsSync(t)) {
|
|
962
|
+
let { description: n, background: i, ...a } = nn(e), s = nn(t), c = k.readFileSync(O.join(r, o.replace(/^\.\//, "")), "utf-8").match(/<svg\b[^>]*>/i)?.[0] ?? "", l = c.match(/viewBox\s*=\s*["']\s*[-\d.]+[\s,]+[-\d.]+[\s,]+[\d.]+[\s,]+([\d.]+)/i)?.[1] ?? c.match(/\sheight\s*=\s*["']?([\d.]+)/i)?.[1];
|
|
963
|
+
l && Number(l) > 0 && (a.clearSpace = {
|
|
964
|
+
value: Math.max(1, Math.round(Number(l) * .3 * 100) / 100),
|
|
965
|
+
unit: "px"
|
|
966
|
+
});
|
|
967
|
+
for (let [e, t] of Object.entries(a)) s[e] ??= t;
|
|
968
|
+
s.description = `${String(s.description)} Clear space, minimum size, lockup, placement and partnership are blazon's, not the brand's: set them.`, rn(t, s);
|
|
969
|
+
}
|
|
970
|
+
for (let e of Pn) for (let t of ["svg", "json"]) {
|
|
971
|
+
let n = `assets/logos/${e}.${t}`;
|
|
972
|
+
i.has(n) && (k.rmSync(O.join(r, n), { force: !0 }), a.removed.push(`${n} (blazon's own logo)`));
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
// src/core/init/from-site/apply.ts
|
|
977
|
+
async function fr(e, t, n, r = /* @__PURE__ */ new Date(), i = {}) {
|
|
978
|
+
let a = r.toISOString().slice(0, 10), o = i.page ?? await en(t), s = {
|
|
979
|
+
written: [],
|
|
980
|
+
missing: [],
|
|
981
|
+
removed: [],
|
|
982
|
+
repointed: []
|
|
983
|
+
}, c = `Read from ${t} on ${a}: confirm with the brand owner.`, l = {
|
|
984
|
+
destDir: e,
|
|
985
|
+
url: t,
|
|
986
|
+
date: a,
|
|
987
|
+
created: n,
|
|
988
|
+
page: o,
|
|
989
|
+
vars: Kt(o.css),
|
|
990
|
+
result: s,
|
|
991
|
+
note: c,
|
|
992
|
+
review: {
|
|
993
|
+
status: "needs-review",
|
|
994
|
+
note: c
|
|
995
|
+
},
|
|
996
|
+
source: (e, n) => ({
|
|
997
|
+
doc: `${t} stylesheet, read ${a}`,
|
|
998
|
+
locator: e,
|
|
999
|
+
...n && { cssVar: n }
|
|
1000
|
+
}),
|
|
1001
|
+
mayChange: (e) => n.has(e) ? !0 : (s.missing.push(`${e} already existed, so it was kept as it was`), !1)
|
|
1002
|
+
};
|
|
1003
|
+
Vn(l, i.skipVars);
|
|
1004
|
+
let u = tr(l), d = await ur(l), { title: f, description: p, configLogo: m } = await Gn(l, d, u);
|
|
1005
|
+
return dr(l, d, m), ar(l, f, p), qn(l), s;
|
|
1006
|
+
}
|
|
1007
|
+
// src/core/init/from-site/inspect.ts
|
|
1008
|
+
async function pr(e) {
|
|
1009
|
+
let t = await en(e), n = Kt(t.css), r = Rn(n), i = $n(t.css, n, /^(body|html)$/), a = $n(t.css, n, /^h[1-6]$/), o = [];
|
|
1010
|
+
i && o.push({
|
|
1011
|
+
family: i.family,
|
|
1012
|
+
role: "body",
|
|
1013
|
+
stylesheet: !!Yn(i.family)
|
|
1014
|
+
}), a && a.family.toLowerCase() !== i?.family.toLowerCase() && o.push({
|
|
1015
|
+
family: a.family,
|
|
1016
|
+
role: "headings",
|
|
1017
|
+
stylesheet: !!Yn(a.family)
|
|
1018
|
+
});
|
|
1019
|
+
let s = sr(t.html, e), c = cr(t.html, e), l = s ? `${s.kind === "inline" ? "an inline SVG" : `an SVG image (${s.url})`} in the page header` : c ? `the site icon (${c.url})${c.svg ? "" : `, a ${c.ext} image, not an SVG logo`}` : void 0, u = H(t.html, "og:site_name") ?? H(t.html, "application-name") ?? await Wn(t.html, e) ?? Un(t.html), d = [];
|
|
1020
|
+
return r.length === 0 && d.push("no brand colors: no custom property named brand, primary, secondary, accent, background, foreground or surface holds a hex or rgb() color"), o.length === 0 && d.push("no font: no body or heading rule names a font-family"), l || d.push("no logo: no SVG in the header and no icon link on the page"), u || d.push("no site name: the brand name stays as you typed it"), {
|
|
1021
|
+
page: t,
|
|
1022
|
+
name: u,
|
|
1023
|
+
description: H(t.html, "description"),
|
|
1024
|
+
colors: r.map((e) => ({
|
|
1025
|
+
cssVar: e.cssVar,
|
|
1026
|
+
hex: e.hex
|
|
1027
|
+
})),
|
|
1028
|
+
fonts: o,
|
|
1029
|
+
logo: l,
|
|
1030
|
+
missing: d
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
// src/core/init/answers.ts
|
|
1034
|
+
var mr = [
|
|
1035
|
+
".svg",
|
|
1036
|
+
".png",
|
|
1037
|
+
".jpg",
|
|
1038
|
+
".jpeg",
|
|
1039
|
+
".webp"
|
|
1040
|
+
], hr = (e) => e.trim() ? { value: e.trim() } : { hint: "A name cannot be empty." }, gr = (e) => e.trim().length <= 240 ? { value: e.trim() } : { hint: "Keep the description to one sentence, 240 characters at most." };
|
|
1041
|
+
function _r(e) {
|
|
1042
|
+
let t = e.trim(), n = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t) ? Fn(t.startsWith("#") ? t : `#${t}`) : void 0;
|
|
1043
|
+
return n ? { value: n.hex } : { hint: "Give the color as hex, for example #2563eb or #26e." };
|
|
1044
|
+
}
|
|
1045
|
+
var vr = (e) => /^[A-Za-z0-9][A-Za-z0-9 -]{0,60}$/.test(e.trim()) ? { value: e.trim() } : { hint: "Give a font family name, for example Inter or DM Sans." };
|
|
1046
|
+
function yr(e, t = process.cwd()) {
|
|
1047
|
+
let n = O.resolve(t, e.trim());
|
|
1048
|
+
return mr.includes(O.extname(n).toLowerCase()) ? !k.existsSync(n) || !k.statSync(n).isFile() ? { hint: `There is no file at ${n}. Check the path, or press Enter to skip the logo.` } : { value: n } : { hint: "The logo must be an SVG or PNG file (JPG and WebP also work)." };
|
|
1049
|
+
}
|
|
1050
|
+
function br(e) {
|
|
1051
|
+
let t = k.readFileSync(e), n = O.extname(e).toLowerCase() === ".svg";
|
|
1052
|
+
return {
|
|
1053
|
+
bytes: t.length,
|
|
1054
|
+
svg: n,
|
|
1055
|
+
usesCurrentColor: n && /currentColor/i.test(t.toString("utf8"))
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
var xr = (e) => /^https?:\/\/[^\s/]/i.test(e);
|
|
1059
|
+
function Sr(e, t, n) {
|
|
1060
|
+
let r = {
|
|
1061
|
+
set: [],
|
|
1062
|
+
hints: [],
|
|
1063
|
+
files: []
|
|
1064
|
+
}, i = (e) => r.hints.push(`${e} already existed, so it was kept as it was`), a = O.join(e, "blazon.json"), o = n.has("blazon.json") ? An(a) : void 0, s = o === void 0 ? void 0 : JSON.stringify(o), c = (e) => (o === void 0 && i(`blazon.json (${e} not set)`), o !== void 0);
|
|
1065
|
+
if (t.name !== void 0 && c("name") && (o.title = t.name, r.set.push(`name "${t.name}"`)), t.description && c("description") && (o.description = t.description, r.set.push("description")), t.color !== void 0) {
|
|
1066
|
+
let a = O.join(e, "tokens", "colors.json");
|
|
1067
|
+
if (!n.has("tokens/colors.json")) i("tokens/colors.json");
|
|
1068
|
+
else {
|
|
1069
|
+
let e = JSON.parse(k.readFileSync(a, "utf-8"));
|
|
1070
|
+
if (B(e, "color.signal.orange")) {
|
|
1071
|
+
let n = On(e, t.color);
|
|
1072
|
+
k.writeFileSync(a, `${JSON.stringify(e, null, 2)}\n`), r.files.push("tokens/colors.json"), r.set.push(`primary color ${t.color} (color.signal.primary, which interactive.primary uses)`), r.hints.push(...n.hints);
|
|
1073
|
+
} else r.hints.push("color.signal.orange was not found in tokens/colors.json, so the color was not set");
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (t.font !== void 0) {
|
|
1077
|
+
let a = O.join(e, "tokens", "typography.json");
|
|
1078
|
+
if (!n.has("tokens/typography.json")) i("tokens/typography.json");
|
|
1079
|
+
else {
|
|
1080
|
+
let e = JSON.parse(k.readFileSync(a, "utf-8")), n = B(e, "font.family.display"), i = B(e, "font.family.body");
|
|
1081
|
+
if (n && i) {
|
|
1082
|
+
n.$value = [t.font, "sans-serif"], i.$value = [t.font, "sans-serif"];
|
|
1083
|
+
let s = B(e, "font.family.mono");
|
|
1084
|
+
s && Dn(s, "Still blazon's mono font: it was not chosen to go with your font. Set the brand's own."), k.writeFileSync(a, `${JSON.stringify(e, null, 2)}\n`), r.files.push("tokens/typography.json");
|
|
1085
|
+
let l = Yn(t.font);
|
|
1086
|
+
l && c("font stylesheet") ? (o.fonts = Mn(o.fonts, [l]), r.set.push(`font ${t.font} (font.family.display and font.family.body)`)) : l || (r.set.push(`font ${t.font} (font.family.display and font.family.body)`), r.hints.push(`${t.font} is not a font blazon knows a stylesheet for: add its stylesheet to fonts in blazon.json`)), r.hints.push("font.family.mono and the type scale are still blazon's: set the brand's own");
|
|
1087
|
+
} else r.hints.push("font.family.display and font.family.body were not found in tokens/typography.json, so the font was not set");
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (t.logo !== void 0 && c("logo")) {
|
|
1091
|
+
let a = O.basename(t.logo).replace(/[^A-Za-z0-9._-]/g, "-"), s = a.replace(/\.[^.]+$/, ""), c = O.join(e, "assets", "logos"), l = [a, `${s}.json`].filter((e) => !n.has(`assets/logos/${e}`) && k.existsSync(O.join(c, e)));
|
|
1092
|
+
if (l.length) {
|
|
1093
|
+
for (let e of l) i(`assets/logos/${e}`);
|
|
1094
|
+
r.hints.push(`the logo ${t.logo} was not copied: pick another file name, or remove the existing file`);
|
|
1095
|
+
} else {
|
|
1096
|
+
let e = O.join(c, `${Nn[0]}.json`), i = {};
|
|
1097
|
+
if (n.has(`assets/logos/${Nn[0]}.json`) && k.existsSync(e)) {
|
|
1098
|
+
let { description: t, background: n, ...r } = JSON.parse(k.readFileSync(e, "utf-8"));
|
|
1099
|
+
i = r;
|
|
1100
|
+
}
|
|
1101
|
+
for (let e of Pn) for (let t of ["svg", "json"]) n.has(`assets/logos/${e}.${t}`) && k.rmSync(O.join(c, `${e}.${t}`), { force: !0 });
|
|
1102
|
+
k.mkdirSync(c, { recursive: !0 });
|
|
1103
|
+
let l = k.readFileSync(t.logo);
|
|
1104
|
+
k.writeFileSync(O.join(c, a), a.toLowerCase().endsWith(".svg") ? or(l.toString("utf8")) : l), k.writeFileSync(O.join(c, `${s}.json`), `${JSON.stringify({
|
|
1105
|
+
title: "Logo",
|
|
1106
|
+
description: "The brand's logo. Clear space, minimum size, lockup, placement and partnership are blazon's, not the brand's: set them.",
|
|
1107
|
+
...i
|
|
1108
|
+
}, null, 2)}\n`), o.logo = `./assets/logos/${a}`, r.files.push(`assets/logos/${a}`, `assets/logos/${s}.json`), r.set.push(`logo ${a}`);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return o !== void 0 && JSON.stringify(o) !== s && (jn(a, o), r.files.push("blazon.json")), r;
|
|
1112
|
+
}
|
|
1113
|
+
// src/core/init/prompts.ts
|
|
1114
|
+
var Cr = class extends Error {
|
|
1115
|
+
constructor() {
|
|
1116
|
+
super("cancelled"), this.name = "PromptCancelled";
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
function U(e, t) {
|
|
1120
|
+
return e.split("\n").map((e) => {
|
|
1121
|
+
if (e.length <= t || e.includes("\x1B")) return e;
|
|
1122
|
+
let n = [], r = "";
|
|
1123
|
+
for (let i of e.split(" ")) r && r.length + 1 + i.length > t ? (n.push(r), r = i) : r = r ? `${r} ${i}` : i;
|
|
1124
|
+
return n.push(r), n.join("\n");
|
|
1125
|
+
}).join("\n");
|
|
1126
|
+
}
|
|
1127
|
+
var W = () => Math.max(30, (process.stdout.columns ?? 80) - 6);
|
|
1128
|
+
function wr(e) {
|
|
1129
|
+
if (A.isCancel(e)) throw new Cr();
|
|
1130
|
+
return e;
|
|
1131
|
+
}
|
|
1132
|
+
function Tr() {
|
|
1133
|
+
return {
|
|
1134
|
+
intro: (e) => A.intro(e),
|
|
1135
|
+
outro: (e) => A.outro(e),
|
|
1136
|
+
cancel: (e) => A.cancel(e),
|
|
1137
|
+
text: async (e) => wr(await A.text({
|
|
1138
|
+
message: e.message,
|
|
1139
|
+
placeholder: e.placeholder,
|
|
1140
|
+
defaultValue: e.defaultValue,
|
|
1141
|
+
validate: e.validate && ((t) => e.validate(t ?? ""))
|
|
1142
|
+
})) ?? "",
|
|
1143
|
+
select: async (e) => wr(await A.select({
|
|
1144
|
+
message: e.message,
|
|
1145
|
+
options: e.options,
|
|
1146
|
+
initialValue: e.initialValue
|
|
1147
|
+
})),
|
|
1148
|
+
multiselect: async (e) => wr(await A.multiselect({
|
|
1149
|
+
message: e.message,
|
|
1150
|
+
options: e.options,
|
|
1151
|
+
initialValues: e.initialValues,
|
|
1152
|
+
required: !1
|
|
1153
|
+
})),
|
|
1154
|
+
confirm: async (e) => wr(await A.confirm({
|
|
1155
|
+
message: e.message,
|
|
1156
|
+
initialValue: e.initialValue
|
|
1157
|
+
})),
|
|
1158
|
+
spinner: () => {
|
|
1159
|
+
let e = A.spinner();
|
|
1160
|
+
return {
|
|
1161
|
+
start: (t) => e.start(t),
|
|
1162
|
+
stop: (t) => e.stop(t),
|
|
1163
|
+
error: (t) => e.error(t)
|
|
1164
|
+
};
|
|
1165
|
+
},
|
|
1166
|
+
note: (e, t) => A.note(e, t),
|
|
1167
|
+
log: {
|
|
1168
|
+
message: (e) => A.log.message(U(e, W())),
|
|
1169
|
+
info: (e) => A.log.info(U(e, W())),
|
|
1170
|
+
success: (e) => A.log.success(U(e, W())),
|
|
1171
|
+
warn: (e) => A.log.warn(U(e, W())),
|
|
1172
|
+
error: (e) => A.log.error(U(e, W())),
|
|
1173
|
+
step: (e) => A.log.step(U(e, W()))
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
// src/cli/init-ui.ts
|
|
1178
|
+
function Er(e = process.env, t = !!process.stdout.isTTY) {
|
|
1179
|
+
let n = x(e, t, []);
|
|
1180
|
+
return {
|
|
1181
|
+
color: n,
|
|
1182
|
+
truecolor: n && /^(truecolor|24bit)$/i.test(e.COLORTERM ?? "")
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
function Dr(e, t) {
|
|
1186
|
+
let [n, r, i] = (mn(e) ?? [
|
|
1187
|
+
0,
|
|
1188
|
+
0,
|
|
1189
|
+
0
|
|
1190
|
+
]).map((e) => Math.round(e * 255));
|
|
1191
|
+
if (t.truecolor) return `\x1b[48;2;${n};${r};${i}m`;
|
|
1192
|
+
let a = (e) => Math.round(e / 255 * 5);
|
|
1193
|
+
return `\x1b[48;5;${16 + 36 * a(n) + 6 * a(r) + a(i)}m`;
|
|
1194
|
+
}
|
|
1195
|
+
function Or(e, t, n = 2) {
|
|
1196
|
+
return t.color ? `${Dr(e, t)}${" ".repeat(n)}\x1b[0m` : `[${e}]`;
|
|
1197
|
+
}
|
|
1198
|
+
var kr = {
|
|
1199
|
+
AAA: "AAA",
|
|
1200
|
+
AA: "AA",
|
|
1201
|
+
"AA-large": "AA for large text only",
|
|
1202
|
+
fail: "below AA"
|
|
1203
|
+
}, Ar = (e) => `${e.toFixed(1)}:1`;
|
|
1204
|
+
function jr(e, t, n = yn(e)) {
|
|
1205
|
+
let r = (e) => e === "AAA" || e === "AA" ? "yes" : "no";
|
|
1206
|
+
return [
|
|
1207
|
+
`${Or(e, t, 4)} ${e}`,
|
|
1208
|
+
`AA for text on white: ${r(n.onWhite.level)} (${Ar(n.onWhite.ratio)}, ${kr[n.onWhite.level]})`,
|
|
1209
|
+
`AA for text on near-black: ${r(n.onNearBlack.level)} (${Ar(n.onNearBlack.ratio)}, ${kr[n.onNearBlack.level]})`
|
|
1210
|
+
];
|
|
1211
|
+
}
|
|
1212
|
+
function Mr(e) {
|
|
1213
|
+
let { ink: t, ratio: n, aa: r } = Sn(e);
|
|
1214
|
+
return r ? `Labels on ${e} will be ${t} (${n.toFixed(1)}:1).` : `Neither graphite nor bone reaches AA (4.5:1) as a label on ${e} (best is ${t} at ${n.toFixed(1)}:1). blazon check will report it; a lighter or darker color fixes that.`;
|
|
1215
|
+
}
|
|
1216
|
+
var Nr = (e, t, n) => `${e} of ${t} ${n}`;
|
|
1217
|
+
function Pr(e) {
|
|
1218
|
+
return e < 1024 ? `${e} bytes` : `${(e / 1024).toFixed(1)} KB`;
|
|
1219
|
+
}
|
|
1220
|
+
// src/cli/init-flow.ts
|
|
1221
|
+
var Fr = 4;
|
|
1222
|
+
function G(e, t, r, i) {
|
|
1223
|
+
return e.log.message(i.color ? n.dim(r) : r), t;
|
|
1224
|
+
}
|
|
1225
|
+
function Ir(e) {
|
|
1226
|
+
return (t) => {
|
|
1227
|
+
if (t.trim() === "") return;
|
|
1228
|
+
let n = e(t);
|
|
1229
|
+
return "hint" in n ? n.hint : void 0;
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
var Lr = (e, t) => {
|
|
1233
|
+
let n = t.trim() === "" ? void 0 : e(t);
|
|
1234
|
+
return n && "value" in n ? n.value : void 0;
|
|
1235
|
+
};
|
|
1236
|
+
async function Rr(e) {
|
|
1237
|
+
let { prompter: t, look: r } = e, i = {};
|
|
1238
|
+
t.intro(r.color ? n.bold(`blazon init ${n.dim(e.dir)}`) : `blazon init ${e.dir}`), e.kept && t.log.warn(`${e.kept} starter ${e.kept === 1 ? "file is" : "files are"} already in this folder and ${e.kept === 1 ? "is" : "are"} kept as ${e.kept === 1 ? "it is" : "they are"}. Only missing files are added.`), t.log.step(Nr(1, Fr, "Brand"));
|
|
1239
|
+
let a = (await t.text({
|
|
1240
|
+
message: G(t, "Brand name", "The title of the brand book. Enter keeps the name taken from the folder.", r),
|
|
1241
|
+
placeholder: "from the folder name",
|
|
1242
|
+
validate: () => void 0
|
|
1243
|
+
})).trim();
|
|
1244
|
+
a && (i.name = a);
|
|
1245
|
+
let o = (await t.text({
|
|
1246
|
+
message: G(t, "One-line description", "What the brand is, in a sentence. It goes in the config and opens the intro page. Enter skips it.", r),
|
|
1247
|
+
placeholder: "what the brand is, in one sentence",
|
|
1248
|
+
validate: (e) => "hint" in gr(e) ? "Keep it to one sentence, 240 characters at most." : void 0
|
|
1249
|
+
})).trim();
|
|
1250
|
+
if (o && (i.description = o), await t.select({
|
|
1251
|
+
message: G(t, "Where should the colors, fonts and logo come from?", "Reading a live site fills them in for you to review before anything is written.", r),
|
|
1252
|
+
options: [{
|
|
1253
|
+
value: "manual",
|
|
1254
|
+
label: "I will give them here",
|
|
1255
|
+
hint: "color, font and logo, each optional"
|
|
1256
|
+
}, {
|
|
1257
|
+
value: "site",
|
|
1258
|
+
label: "Read them from my website",
|
|
1259
|
+
hint: "you review what was found first"
|
|
1260
|
+
}]
|
|
1261
|
+
}) === "site") {
|
|
1262
|
+
let n = await zr(e);
|
|
1263
|
+
if (n) return {
|
|
1264
|
+
answers: i,
|
|
1265
|
+
site: n
|
|
1266
|
+
};
|
|
1267
|
+
t.log.info("Nothing from a site will be written. Giving the values here instead.");
|
|
1268
|
+
}
|
|
1269
|
+
t.log.step(Nr(2, Fr, "Colors"));
|
|
1270
|
+
let s = Lr(_r, (await t.text({
|
|
1271
|
+
message: G(t, "Primary color", "Hex, for example #2563eb. Buttons and links use it. Enter keeps the orange it starts with.", r),
|
|
1272
|
+
placeholder: "#2563eb",
|
|
1273
|
+
validate: Ir(_r)
|
|
1274
|
+
})).trim());
|
|
1275
|
+
s && (i.color = s, t.log.info(jr(s, r).join("\n")), t.log.info(Mr(s))), t.log.step(Nr(3, Fr, "Type"));
|
|
1276
|
+
let c = Lr(vr, (await t.text({
|
|
1277
|
+
message: G(t, "Font family", "A Google Fonts name, for example Inter. Enter keeps the fonts it starts with.", r),
|
|
1278
|
+
placeholder: "Inter",
|
|
1279
|
+
validate: Ir(vr)
|
|
1280
|
+
})).trim());
|
|
1281
|
+
c && (i.font = c, Yn(c) ? t.log.success(`${c} is on Google Fonts. Its stylesheet will be added to fonts in blazon.json.`) : t.log.warn(`${c} is not in blazon's short list of Google Fonts, so only the font name is written. Add its stylesheet to fonts in blazon.json.`)), t.log.step(Nr(4, Fr, "Logo"));
|
|
1282
|
+
let l = Lr((e) => yr(e), (await t.text({
|
|
1283
|
+
message: G(t, "Logo file", "The path to an SVG or PNG. Enter skips it and keeps the logo it starts with.", r),
|
|
1284
|
+
placeholder: "./logo.svg",
|
|
1285
|
+
validate: Ir((e) => yr(e))
|
|
1286
|
+
})).trim());
|
|
1287
|
+
if (l) {
|
|
1288
|
+
i.logo = l;
|
|
1289
|
+
let e = br(l), n = O.basename(l);
|
|
1290
|
+
t.log.info([
|
|
1291
|
+
`${n}: ${e.svg ? "SVG" : "raster image"}, ${Pr(e.bytes)}.`,
|
|
1292
|
+
"It will be copied to assets/logos/ and replace the starter's placeholder.",
|
|
1293
|
+
...e.usesCurrentColor ? ["It draws in currentColor, so it takes the text color of the page it is on."] : [],
|
|
1294
|
+
...e.svg ? [] : ["A raster logo cannot be recolored; an SVG is better if you have one."]
|
|
1295
|
+
].join("\n"));
|
|
1296
|
+
}
|
|
1297
|
+
return { answers: i };
|
|
1298
|
+
}
|
|
1299
|
+
async function zr(e) {
|
|
1300
|
+
let { prompter: t, look: n } = e, r = e.inspect ?? pr;
|
|
1301
|
+
for (;;) {
|
|
1302
|
+
let i = (await t.text({
|
|
1303
|
+
message: G(t, "Website address", "Blazon reads its stylesheets and page. It sends no cookies and runs none of the site's scripts.", n),
|
|
1304
|
+
placeholder: "https://example.com (leave empty to enter the values by hand)",
|
|
1305
|
+
validate: (e) => e.trim() === "" || xr(e.trim()) ? void 0 : "Give the full address, starting with http:// or https://, or leave it empty to enter the values by hand."
|
|
1306
|
+
})).trim();
|
|
1307
|
+
if (i === "") {
|
|
1308
|
+
t.log.info("No address given: you can enter the values by hand.");
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
let a = t.spinner();
|
|
1312
|
+
a.start(`Reading ${i}`);
|
|
1313
|
+
let o;
|
|
1314
|
+
try {
|
|
1315
|
+
o = await r(i), a.stop(`Read ${i}`);
|
|
1316
|
+
} catch (e) {
|
|
1317
|
+
a.error(`Could not read ${i}`), t.log.error(`${e instanceof Error ? e.message : String(e)}\nCheck the address and your connection. The starter is in place, so nothing is lost.`);
|
|
1318
|
+
}
|
|
1319
|
+
if (o) {
|
|
1320
|
+
let t = await Br(e, i, o);
|
|
1321
|
+
return t ? {
|
|
1322
|
+
url: i,
|
|
1323
|
+
findings: o,
|
|
1324
|
+
skipVars: t
|
|
1325
|
+
} : void 0;
|
|
1326
|
+
}
|
|
1327
|
+
if (!await t.confirm({
|
|
1328
|
+
message: "Try a different address?",
|
|
1329
|
+
initialValue: !0
|
|
1330
|
+
})) return;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
async function Br(e, t, n) {
|
|
1334
|
+
let { prompter: r, look: i } = e, a = [];
|
|
1335
|
+
n.name && a.push(`Name: ${n.name}`), n.description && a.push(`Description: ${n.description}`);
|
|
1336
|
+
for (let e of n.fonts) a.push(`Font (${e.role}): ${e.family}${e.stylesheet ? ", its Google Fonts stylesheet will be added" : ", not in blazon's short list, so add its stylesheet yourself"}`);
|
|
1337
|
+
n.logo && a.push(`Logo: ${n.logo}`), r.log.info(a.length > 0 ? `Found at ${t}\n${a.join("\n")}` : `Found nothing usable at ${t}`);
|
|
1338
|
+
for (let e of n.missing) r.log.warn(`Not found: ${e}`);
|
|
1339
|
+
let o = /* @__PURE__ */ new Set();
|
|
1340
|
+
if (n.colors.length > 0) {
|
|
1341
|
+
let e = await r.multiselect({
|
|
1342
|
+
message: G(r, "Brand colors found", "Untick any you do not want. Everything written is marked needs-review.", i),
|
|
1343
|
+
options: n.colors.map((e) => ({
|
|
1344
|
+
value: e.cssVar,
|
|
1345
|
+
label: `${Or(e.hex, i)} ${e.hex} ${e.cssVar}`
|
|
1346
|
+
})),
|
|
1347
|
+
initialValues: n.colors.map((e) => e.cssVar)
|
|
1348
|
+
});
|
|
1349
|
+
o = new Set(n.colors.map((e) => e.cssVar).filter((t) => !e.includes(t)));
|
|
1350
|
+
}
|
|
1351
|
+
return await r.confirm({
|
|
1352
|
+
message: "Write these into the brand book?",
|
|
1353
|
+
initialValue: !0
|
|
1354
|
+
}) ? o : void 0;
|
|
1355
|
+
}
|
|
1356
|
+
// src/cli/commands/init.ts
|
|
1357
|
+
var Vr = (e, t, n) => `${e} ${e === 1 ? t : n}`;
|
|
1358
|
+
function Hr(e, t) {
|
|
1359
|
+
let n = t.map((e) => e.split("/").slice(1));
|
|
1360
|
+
if (n.length === 0) return;
|
|
1361
|
+
if (e === "docs") return `${Vr(n.length, "page", "pages")}, ${n[0][0]} to ${n[n.length - 1][0]}`;
|
|
1362
|
+
if (e === "tokens") return `${Vr(n.length, "file", "files")}: ${n.map((e) => e.join("/")).join(", ")}`;
|
|
1363
|
+
let r = [...new Set(n.filter((e) => e.length > 1).map((e) => e[0]))];
|
|
1364
|
+
return r.length > 0 ? `${Vr(n.length, "file", "files")} in ${Vr(r.length, "folder", "folders")}: ${r.join(", ")}` : `${Vr(n.length, "file", "files")}: ${n.map((e) => e[0]).join(", ")}`;
|
|
1365
|
+
}
|
|
1366
|
+
var Ur = /^(brand|book|guidelines|guide)$/i;
|
|
1367
|
+
function Wr(e) {
|
|
1368
|
+
let t = O.basename(e).split(/[-_\s]+/).filter(Boolean), n = t.length > 0;
|
|
1369
|
+
for (; t.length > 0 && Ur.test(t[t.length - 1]);) t = t.slice(0, -1);
|
|
1370
|
+
let r = t.map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ");
|
|
1371
|
+
return r ? `${r} Brand Book` : n ? "Brand Book" : "Blazon Brand Book";
|
|
1372
|
+
}
|
|
1373
|
+
var Gr = [
|
|
1374
|
+
[
|
|
1375
|
+
"--name",
|
|
1376
|
+
"name",
|
|
1377
|
+
hr
|
|
1378
|
+
],
|
|
1379
|
+
[
|
|
1380
|
+
"--description",
|
|
1381
|
+
"description",
|
|
1382
|
+
gr
|
|
1383
|
+
],
|
|
1384
|
+
[
|
|
1385
|
+
"--color",
|
|
1386
|
+
"color",
|
|
1387
|
+
_r
|
|
1388
|
+
],
|
|
1389
|
+
[
|
|
1390
|
+
"--font",
|
|
1391
|
+
"font",
|
|
1392
|
+
vr
|
|
1393
|
+
],
|
|
1394
|
+
[
|
|
1395
|
+
"--logo",
|
|
1396
|
+
"logo",
|
|
1397
|
+
(e) => yr(e)
|
|
1398
|
+
]
|
|
1399
|
+
];
|
|
1400
|
+
async function Kr(e = ".", t = {}) {
|
|
1401
|
+
if (t.from !== void 0 && !/^https?:\/\/[^\s/]/i.test(t.from)) {
|
|
1402
|
+
let e = `--from needs an http(s) address, got ${JSON.stringify(t.from)}`;
|
|
1403
|
+
return console.error(n.red(`blazon init: ${e}`)), t.failure?.({
|
|
1404
|
+
code: "invalid-option-value",
|
|
1405
|
+
message: e
|
|
1406
|
+
}), 2;
|
|
1407
|
+
}
|
|
1408
|
+
let r = {};
|
|
1409
|
+
for (let [e, i, a] of Gr) {
|
|
1410
|
+
let o = t[i];
|
|
1411
|
+
if (o === void 0) continue;
|
|
1412
|
+
let s = a(String(o));
|
|
1413
|
+
if ("hint" in s) return console.error(n.red(`blazon init: ${e}: ${s.hint}`)), t.failure?.({
|
|
1414
|
+
code: "invalid-option-value",
|
|
1415
|
+
message: `${e}: ${s.hint}`
|
|
1416
|
+
}), 2;
|
|
1417
|
+
r[i] = s.value;
|
|
1418
|
+
}
|
|
1419
|
+
let i = O.resolve(process.cwd(), e), a = qe();
|
|
1420
|
+
if (!k.existsSync(a)) throw Error(`Template directory not found at ${a}`);
|
|
1421
|
+
let o = t.tty ?? !!(process.stdin.isTTY && process.stdout.isTTY), s = [
|
|
1422
|
+
t.from,
|
|
1423
|
+
t.name,
|
|
1424
|
+
t.description,
|
|
1425
|
+
t.color,
|
|
1426
|
+
t.font,
|
|
1427
|
+
t.logo
|
|
1428
|
+
].some((e) => e !== void 0), c = o && !s && !t.yes && t.input !== !1, l = c ? t.prompter ?? Tr() : void 0, u = t.look ?? Er(process.env, o);
|
|
1429
|
+
c || console.log(n.cyan(`\n✨ Initializing Blazon Brand Book in ${n.bold(i)}...\n`));
|
|
1430
|
+
let d = O.join(i, "blazon.json"), f = k.existsSync(d), p = fe(i, a), m = p.kept, h = p.written.map((e) => O.relative(i, e).split(O.sep).join("/")).sort(), g = new Set(h);
|
|
1431
|
+
t.report?.({
|
|
1432
|
+
dir: i,
|
|
1433
|
+
created: h,
|
|
1434
|
+
kept: m.map((e) => O.relative(i, e).split(O.sep).join("/")).sort()
|
|
1435
|
+
}), !f && k.existsSync(d) && jn(d, {
|
|
1436
|
+
...An(d),
|
|
1437
|
+
title: Wr(i),
|
|
1438
|
+
description: "Brand guidelines, built from design tokens"
|
|
1439
|
+
});
|
|
1440
|
+
let _ = [];
|
|
1441
|
+
for (let e of [
|
|
1442
|
+
"tokens",
|
|
1443
|
+
"assets",
|
|
1444
|
+
"docs"
|
|
1445
|
+
]) {
|
|
1446
|
+
let t = Hr(e, h.filter((t) => t.startsWith(`${e}/`)));
|
|
1447
|
+
t && _.push(`${e}/ (${t})`);
|
|
1448
|
+
}
|
|
1449
|
+
h.includes("blazon.json") && _.push("blazon.json"), h.includes("blazon.resolver.json") && _.push("blazon.resolver.json");
|
|
1450
|
+
let v = { answers: r };
|
|
1451
|
+
if (l) try {
|
|
1452
|
+
v = await Rr({
|
|
1453
|
+
prompter: l,
|
|
1454
|
+
look: u,
|
|
1455
|
+
dir: i,
|
|
1456
|
+
kept: m.length
|
|
1457
|
+
});
|
|
1458
|
+
} catch (e) {
|
|
1459
|
+
if (e instanceof Cr) return l.cancel("Stopped. The starter was copied as it is, and nothing else was changed."), 130;
|
|
1460
|
+
throw e;
|
|
1461
|
+
}
|
|
1462
|
+
else {
|
|
1463
|
+
for (let e of _) console.log(` ${n.green("✔")} Created ${e}`);
|
|
1464
|
+
m.length > 0 && console.log(` ${n.yellow("!")} ${m.length} starter files were already here and are kept as they are`), console.log();
|
|
1465
|
+
}
|
|
1466
|
+
let y = v.site?.url ?? t.from, b = 0, x, ee = l?.spinner();
|
|
1467
|
+
if (ee?.start("Writing the brand book"), y !== void 0) try {
|
|
1468
|
+
if (x = await fr(i, y, g, /* @__PURE__ */ new Date(), {
|
|
1469
|
+
page: v.site?.findings.page,
|
|
1470
|
+
skipVars: v.site?.skipVars
|
|
1471
|
+
}), !l) {
|
|
1472
|
+
console.log(n.bold(`Read from ${y}:`));
|
|
1473
|
+
for (let e of x.written) console.log(` ${n.green("✔")} Wrote ${e}`);
|
|
1474
|
+
for (let e of x.removed) console.log(` ${n.green("✔")} Removed ${e}`);
|
|
1475
|
+
for (let e of x.repointed) console.log(` ${n.green("✔")} Re-pointed ${e}`);
|
|
1476
|
+
for (let e of x.missing) console.log(` ${n.yellow("!")} ${e}`);
|
|
1477
|
+
console.log(n.dim("\n All of it is marked needs-review: it is a starting point, so confirm it with the brand owner.\n"));
|
|
1478
|
+
}
|
|
1479
|
+
} catch (e) {
|
|
1480
|
+
let r = e instanceof Error ? e.message : String(e);
|
|
1481
|
+
t.failure?.({
|
|
1482
|
+
code: "site-unreadable",
|
|
1483
|
+
message: r
|
|
1484
|
+
}), l ? l.log.error(`Could not read ${y}: ${r}\nThe starter was copied as it is. To start from the site, run blazon init again with --from in a new folder (a folder that already has the starter is kept as it is), or carry on with the starter.`) : (console.error(n.red(`blazon init: ${r}`)), console.error(n.dim(" The starter was copied as it is. To start from the site, run blazon init again with --from in a new folder (a folder that already has the starter is kept as it is), or carry on with the starter.\n"))), b = 2;
|
|
1485
|
+
}
|
|
1486
|
+
let S;
|
|
1487
|
+
try {
|
|
1488
|
+
S = Sr(i, v.answers, g);
|
|
1489
|
+
} catch (e) {
|
|
1490
|
+
throw ee?.error("Could not write the brand book"), e;
|
|
1491
|
+
}
|
|
1492
|
+
ee?.stop("Wrote the brand book");
|
|
1493
|
+
let C = (e) => u.color ? n.cyan(e) : e, w = F(i), te = [
|
|
1494
|
+
`Run ${C(L("dev", w))} to see the book`,
|
|
1495
|
+
`Replace blazon's artwork in ${C(I(w, "assets/"))} and the text in ${C(I(w, "docs/"))}`,
|
|
1496
|
+
`Run ${C(L("check", w))} to see what is left`,
|
|
1497
|
+
`Point a coding agent at ${C(I(w, "AGENTS.md"))}: it is the guide for editing this brand`
|
|
1498
|
+
];
|
|
1499
|
+
x && !x.written.some((e) => e.startsWith("assets/logos/")) && te.splice(1, 0, `Add your logo: the book still shows blazon's own. Put it in ${C(I(w, "assets/logos/"))} and point ${C("logo")} in ${C(I(w, "blazon.json"))} at it`);
|
|
1500
|
+
let ne = C(I(w, "tokens/colors.json")), re = S.set.some((e) => e.startsWith("primary color")) ? `Finish the palette in ${ne}: the primary color is set, the rest is still blazon's` : x?.written.includes("tokens/colors.json") ? `Confirm the colors read from the site in ${ne} with the brand owner` : `Edit ${ne} with your colors`;
|
|
1501
|
+
if (l) {
|
|
1502
|
+
let e = [..._.map((e) => `Created ${e}`)];
|
|
1503
|
+
x && e.push(`Read from ${y}: ${x.written.length} files written, ${x.removed.length} starter files removed`, ...x.missing.map((e) => `Not found: ${e}`));
|
|
1504
|
+
for (let t of S.set) e.push(`Set ${t}`);
|
|
1505
|
+
e.push(...S.hints.map((e) => `Note: ${e}`)), l.note(e.join("\n"), "What was written"), b === 0 && l.note(te.map((e, t) => `${t + 1}. ${e}`).join("\n"), "Next steps");
|
|
1506
|
+
let n;
|
|
1507
|
+
try {
|
|
1508
|
+
n = t.dev ?? await l.confirm({
|
|
1509
|
+
message: "Start the dev server now?",
|
|
1510
|
+
initialValue: !1
|
|
1511
|
+
});
|
|
1512
|
+
} catch (e) {
|
|
1513
|
+
if (!(e instanceof Cr)) throw e;
|
|
1514
|
+
return l.cancel("Stopped. Everything above was written."), b === 0 ? 130 : b;
|
|
1515
|
+
}
|
|
1516
|
+
return l.outro(n ? "Starting blazon dev. Press Ctrl-C to stop it." : `Done. Run ${C(L("dev", w))} when you are ready.`), n && await (t.startDev ?? qr)(i), b;
|
|
1517
|
+
}
|
|
1518
|
+
for (let e of S.hints) console.log(` ${n.yellow("!")} ${e}`);
|
|
1519
|
+
return S.set.length > 0 && console.log(` ${n.green("✔")} Set ${S.set.join(", ")}\n`), b === 0 && (console.log(n.bold("Next steps:")), console.log(` 1. ${re}`), te.forEach((e, t) => console.log(` ${t + 2}. ${e}`))), console.log(), t.dev && await (t.startDev ?? qr)(i), b;
|
|
1520
|
+
}
|
|
1521
|
+
async function qr(e) {
|
|
1522
|
+
let { runDev: t } = await Promise.resolve().then(() => gt);
|
|
1523
|
+
await t(e);
|
|
1524
|
+
}
|
|
1525
|
+
// src/server/preview-guard.ts
|
|
1526
|
+
function Jr(e) {
|
|
1527
|
+
return (t, n, r) => {
|
|
1528
|
+
let i;
|
|
1529
|
+
try {
|
|
1530
|
+
i = decodeURIComponent((t.url ?? "").split("?")[0]);
|
|
1531
|
+
} catch {
|
|
1532
|
+
return r();
|
|
1533
|
+
}
|
|
1534
|
+
if (i.includes("\0")) return r();
|
|
1535
|
+
let a = O.join(e, O.normalize(`/${i}`));
|
|
1536
|
+
if (oe(ie(e), ie(a))) return r();
|
|
1537
|
+
n.statusCode = 403, n.setHeader("Content-Type", "text/plain"), n.end("blazon preview serves only files inside the built site: this path is a link that leaves it");
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
var Yr = (e) => ({
|
|
1541
|
+
name: "blazon-site-link-guard",
|
|
1542
|
+
configurePreviewServer(t) {
|
|
1543
|
+
t.middlewares.use(Jr(e));
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
// src/cli/commands/preview.ts
|
|
1547
|
+
async function Xr(e = process.cwd(), t, r = {}) {
|
|
1548
|
+
mt(e);
|
|
1549
|
+
let i = await ae(e, t ? { port: t } : void 0), a = O.resolve(e, i.outDir);
|
|
1550
|
+
if (!k.existsSync(O.join(a, "index.html"))) throw new M(`no built site at "${a}"`, `Run ${L("build", F(e))} first.`, "no-built-site");
|
|
1551
|
+
let o;
|
|
1552
|
+
try {
|
|
1553
|
+
o = await Qe({
|
|
1554
|
+
plugins: [le(), Yr(a)],
|
|
1555
|
+
build: { outDir: a },
|
|
1556
|
+
preview: {
|
|
1557
|
+
port: i.port,
|
|
1558
|
+
strictPort: r.strictPort ?? !1,
|
|
1559
|
+
host: r.host ?? "localhost",
|
|
1560
|
+
open: !1
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
} catch (e) {
|
|
1564
|
+
throw r.strictPort && e instanceof Error && /already in use/.test(e.message) ? et(i.port) : e;
|
|
1565
|
+
}
|
|
1566
|
+
let s = o.resolvedUrls, c = s?.local[0] || `http://localhost:${i.port}/`;
|
|
1567
|
+
console.log(`\n ${n.bold(n.blue("blazon preview"))}`), console.log(` ${n.dim("➜")} ${n.bold("Local:")} ${n.cyan(c)}`);
|
|
1568
|
+
for (let e of s?.network ?? []) console.log(` ${n.dim("➜")} ${n.bold("Network:")} ${n.cyan(e)}`);
|
|
1569
|
+
return console.log(` ${n.dim("➜")} ${n.bold("Dist:")} ${n.dim(a)}\n`), o;
|
|
1570
|
+
}
|
|
1571
|
+
// src/plugins/roles/check-cases.ts
|
|
1572
|
+
var Zr = "docs/manual/12-plugins.md (\"What a plugin can look at, and where it writes\")";
|
|
1573
|
+
function Qr(e) {
|
|
1574
|
+
let t = O.basename(e), n = ve(t) ?? t.replace(/^blazon-/, "");
|
|
1575
|
+
return ge(n) ? n : void 0;
|
|
1576
|
+
}
|
|
1577
|
+
function $r(e, t) {
|
|
1578
|
+
return k.readdirSync(e, { recursive: !0 }).filter((n) => O.join(e, n) !== t && !O.join(e, n).startsWith(t + O.sep)).sort();
|
|
1579
|
+
}
|
|
1580
|
+
function ei(e) {
|
|
1581
|
+
let t = Qr(e);
|
|
1582
|
+
return async (e, n) => {
|
|
1583
|
+
let i = r(e), o = i.answers.join(" or "), s = i.stdoutLimit ?? 65536, c = [], l = {
|
|
1584
|
+
exit: `a valid request is answered with exit ${o}`,
|
|
1585
|
+
limit: `the answer is at most ${s} bytes`,
|
|
1586
|
+
shape: `the answer is one the ${e} role accepts: a findings list of at most 500, each with the plugin's code, a severity, a path and a message`,
|
|
1587
|
+
folder: "the plugin writes into out_dir and nothing beside it"
|
|
1588
|
+
}, u = JSON.parse(a()[e]), d = k.mkdtempSync(O.join(Ze.tmpdir(), "blazon-plugin-check-")), f = O.join(d, "tokens"), p = O.join(f, t ?? "plugin");
|
|
1589
|
+
try {
|
|
1590
|
+
e === "build" && (k.mkdirSync(O.join(d, "site")), k.mkdirSync(p, { recursive: !0 }), Object.assign(u, {
|
|
1591
|
+
site_dir: O.join(d, "site"),
|
|
1592
|
+
tokens_dir: f,
|
|
1593
|
+
out_dir: p
|
|
1594
|
+
}));
|
|
1595
|
+
let r = await n(Buffer.from(JSON.stringify(u)), s), a = !r.answered && r.breakReason.startsWith("output over the limit");
|
|
1596
|
+
a ? c.push(E(6, l.exit, e, {
|
|
1597
|
+
skipped: !0,
|
|
1598
|
+
detail: "the output went over the limit before the plugin exited (case 7)"
|
|
1599
|
+
})) : r.answered && i.answers.includes(r.code) ? c.push(E(6, l.exit, e, { passed: !0 })) : r.answered && r.code === 1 ? c.push(E(6, l.exit, e, { detail: `got exit 1, and exit 1 is a break in blazon: the ${e} role defines only ${o}, so blazon reports the plugin as failed and counts it toward its breaker. Exit 2 with the reason on the first line when the plugin cannot answer` })) : c.push(E(6, l.exit, e, { detail: r.answered ? `got exit ${r.code}` : `a break: ${r.breakReason}` }));
|
|
1600
|
+
let m = i.stdoutLimit === void 0 ? "the core's limit, which the role does not raise" : `the ${e} role's limit (stdout_limit_bytes)`;
|
|
1601
|
+
if (c.push(a ? E(7, l.limit, e, { detail: `the plugin printed more than ${s} bytes, ${m}` }) : E(7, l.limit, e, { passed: !0 })), !r.answered || r.code !== 0) c.push(E(8, l.shape, e, {
|
|
1602
|
+
skipped: !0,
|
|
1603
|
+
detail: "the plugin did not answer with exit 0"
|
|
1604
|
+
}));
|
|
1605
|
+
else if (t === void 0) c.push(E(8, l.shape, e, {
|
|
1606
|
+
skipped: !0,
|
|
1607
|
+
detail: "the program's file name is not blazon-<plugin name>, so the check does not know the plugin's code prefix"
|
|
1608
|
+
}));
|
|
1609
|
+
else {
|
|
1610
|
+
let n = se(e, t, r.stdout, []);
|
|
1611
|
+
c.push("problem" in n ? E(8, l.shape, e, { detail: n.problem }) : E(8, l.shape, e, { passed: !0 }));
|
|
1612
|
+
}
|
|
1613
|
+
if (e === "build") {
|
|
1614
|
+
let t = $r(f, p);
|
|
1615
|
+
c.push(t.length === 0 ? E(9, l.folder, e, { passed: !0 }) : E(9, l.folder, e, {
|
|
1616
|
+
passed: !0,
|
|
1617
|
+
warning: !0,
|
|
1618
|
+
detail: `it wrote ${t.map((e) => `tokens_dir/${e}`).join(", ")}. Blazon empties only out_dir before a build, so a file beside it is never cleaned and can collide with another plugin's. Blazon has no folder for a plugin's own state yet, so this is a warning; see ${Zr}`
|
|
1619
|
+
}));
|
|
1620
|
+
}
|
|
1621
|
+
} finally {
|
|
1622
|
+
k.rmSync(d, {
|
|
1623
|
+
recursive: !0,
|
|
1624
|
+
force: !0
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
return c;
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
// src/cli/commands/plugin.ts
|
|
1631
|
+
var ti = {
|
|
1632
|
+
plugin: "usage: blazon plugin check <program> [--core] | blazon plugin pin <path> [--name <plugin name>] | blazon plugin profile",
|
|
1633
|
+
check: "usage: blazon plugin check <program> [--core]",
|
|
1634
|
+
pin: "usage: blazon plugin pin <path> [--name <plugin name> [--digest <digest>] [--entry <path>]]"
|
|
1635
|
+
};
|
|
1636
|
+
function ni(e) {
|
|
1637
|
+
let t = e.warning ? n.yellow("warn") : e.passed ? n.green("ok ") : e.skipped ? n.dim("skip") : n.red("FAIL"), r = e.role ? `${e.role}: ` : "", i = e.detail ? ` (${e.detail})` : "";
|
|
1638
|
+
return ` ${t} ${e.case} ${r}${e.name}${i}`;
|
|
1639
|
+
}
|
|
1640
|
+
async function ri(e, t = {}) {
|
|
1641
|
+
if (!e) throw new M(ti.check, void 0, "missing-argument");
|
|
1642
|
+
let r = t.core === !0;
|
|
1643
|
+
t.json || (console.log(`${S.host} plugin check: host ${S.host}, adopts: ${S.adopts.length > 0 ? S.adopts.join(", ") : "none"}`), r && console.log("core cases only (1 to 5): no role cases, no layout line"));
|
|
1644
|
+
let i = await g({
|
|
1645
|
+
...r ? {} : { approvals: await ii(e) },
|
|
1646
|
+
host: S.host,
|
|
1647
|
+
profile: We,
|
|
1648
|
+
program: e,
|
|
1649
|
+
validate: !1,
|
|
1650
|
+
requests: a(),
|
|
1651
|
+
...r ? {} : { roleCases: ei(e) }
|
|
1652
|
+
}), o = i.filter((e) => e.warning).length, s = i.filter((e) => !e.passed && !e.skipped), c = r ? void 0 : Pe(O.resolve(e));
|
|
1653
|
+
if (t.json) {
|
|
1654
|
+
let e = (e) => e.warning ? "warn" : e.passed ? "ok" : e.skipped ? "skip" : "fail", t = i.map((t) => ({
|
|
1655
|
+
case: t.case,
|
|
1656
|
+
name: t.name,
|
|
1657
|
+
role: t.role,
|
|
1658
|
+
status: e(t),
|
|
1659
|
+
detail: t.detail
|
|
1660
|
+
}));
|
|
1661
|
+
return process.stdout.write(`${JSON.stringify({
|
|
1662
|
+
command: "plugin check",
|
|
1663
|
+
passed: s.length === 0 && !c,
|
|
1664
|
+
host: S.host,
|
|
1665
|
+
adopts: S.adopts,
|
|
1666
|
+
...r ? { core: !0 } : {},
|
|
1667
|
+
cases: t,
|
|
1668
|
+
...c ? { layout: c } : {}
|
|
1669
|
+
})}\n`), s.length === 0 && !c ? 0 : 1;
|
|
1670
|
+
}
|
|
1671
|
+
for (let e of i) console.log(ni(e));
|
|
1672
|
+
return c && console.log(` ${n.red("FAIL")} layout: ${c}`), s.length > 0 ? console.log(n.red(`\n${s.length} case${s.length === 1 ? "" : "s"} failed`)) : console.log(c ? n.red("\nFailed: the file name does not follow the layout of a shipped plugin") : n.green(`\nPassed${o > 0 ? `, with ${o} warning${o === 1 ? "" : "s"}` : ""}`)), s.length === 0 && !c ? 0 : 1;
|
|
1673
|
+
}
|
|
1674
|
+
async function ii(e) {
|
|
1675
|
+
let t;
|
|
1676
|
+
try {
|
|
1677
|
+
t = (await R(process.cwd())).plugins ?? [];
|
|
1678
|
+
} catch {
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
let n = O.basename(e), r = ve(n) ?? n.replace(/^blazon-/, "");
|
|
1682
|
+
return t.flatMap((e, t) => e.name === r ? [{
|
|
1683
|
+
key: `plugins[${t}].env`,
|
|
1684
|
+
approved: e.env ?? []
|
|
1685
|
+
}] : []);
|
|
1686
|
+
}
|
|
1687
|
+
function ai(e, t = {}, n = process.cwd()) {
|
|
1688
|
+
if (!e) throw new M(ti.pin, void 0, "missing-argument");
|
|
1689
|
+
if (!t.name && (t.digest || t.entry)) throw new M(`--digest and --entry say what to record, so they need --name; ${ti.pin}`, void 0, "conflicting-options");
|
|
1690
|
+
if (!k.existsSync(e)) return console.error(`blazon plugin pin: there is nothing at ${e}.`), 2;
|
|
1691
|
+
try {
|
|
1692
|
+
if (t.name) {
|
|
1693
|
+
let r = l(n, t.name, e, {
|
|
1694
|
+
digest: t.digest,
|
|
1695
|
+
entry: t.entry
|
|
1696
|
+
});
|
|
1697
|
+
return console.log(`pinned ${t.name}: ${r.digest} (${r.source}) in ${s}`), 0;
|
|
1698
|
+
}
|
|
1699
|
+
let r = k.lstatSync(e);
|
|
1700
|
+
return console.log(r.isDirectory() && !r.isSymbolicLink() ? w(e) : c(e)), 0;
|
|
1701
|
+
} catch (t) {
|
|
1702
|
+
return console.error(t instanceof te ? t.message : `cannot read ${e}: ${t instanceof Error ? t.message : String(t)}`), 1;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
function oi() {
|
|
1706
|
+
return console.log(JSON.stringify(S, null, 2)), 0;
|
|
1707
|
+
}
|
|
1708
|
+
async function si(e, t, n = {}) {
|
|
1709
|
+
if (e === "check") return ri(t, {
|
|
1710
|
+
json: n.json,
|
|
1711
|
+
core: n.core
|
|
1712
|
+
});
|
|
1713
|
+
if (e === "pin") return ai(t, n);
|
|
1714
|
+
if (e === "profile") return oi();
|
|
1715
|
+
throw new M(ti.plugin, void 0, "missing-argument");
|
|
1716
|
+
}
|
|
1717
|
+
// src/cli/commands/pin.ts
|
|
1718
|
+
function ci(e = process.cwd(), t = {}) {
|
|
1719
|
+
mt(e);
|
|
1720
|
+
try {
|
|
1721
|
+
let r = t.identity === void 0 ? xe(e) : xe(e, t.identity);
|
|
1722
|
+
return t.json ? process.stdout.write(`${JSON.stringify({
|
|
1723
|
+
command: "pin",
|
|
1724
|
+
passed: !0,
|
|
1725
|
+
commit: r,
|
|
1726
|
+
file: Fe
|
|
1727
|
+
})}\n`) : console.log(`pinned blazon ${n.bold(r)} in ${Fe}; commit the file with the book`), 0;
|
|
1728
|
+
} catch (e) {
|
|
1729
|
+
if (t.json) throw e;
|
|
1730
|
+
return console.error(e instanceof Error ? e.message : String(e)), 1;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
// src/cli/commands/drift.ts
|
|
1734
|
+
async function li(e, t = {}) {
|
|
1735
|
+
let r = (e, r, i) => (console.error(nt("drift", r, i).replace(/^blazon drift:/, (e) => n.red(e))), t.json && console.log(JSON.stringify({
|
|
1736
|
+
command: "drift",
|
|
1737
|
+
passed: !1,
|
|
1738
|
+
error: { ...st(e, rt(r, i), i) }
|
|
1739
|
+
})), 2);
|
|
1740
|
+
if (!e) return r("missing-argument", "needs the address of a page or the path of a CSS file", "Run blazon drift <url-or-css-file>.");
|
|
1741
|
+
let i = t.cwd ?? process.cwd();
|
|
1742
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(e) && !k.existsSync(O.resolve(e))) return r("no-file", `there is no file "${e}"`, "Give the path of a CSS file, or the http(s) address of a page.");
|
|
1743
|
+
let a, o;
|
|
1744
|
+
try {
|
|
1745
|
+
let n = await R(i, t.tokens ? { tokensDir: t.tokens } : void 0), r = await T(n, i), s = await $t(e);
|
|
1746
|
+
a = s.sources;
|
|
1747
|
+
let c = Kt(s.css);
|
|
1748
|
+
o = r.tokens.items.flatMap((e) => {
|
|
1749
|
+
let t = e.blazon.source?.cssVar;
|
|
1750
|
+
return typeof t == "string" ? [qt(e, t, c)] : [];
|
|
1751
|
+
});
|
|
1752
|
+
} catch (e) {
|
|
1753
|
+
return r(e instanceof j ? e.code : "error", e instanceof Error ? e.message : String(e), e instanceof j ? e.fix : void 0);
|
|
1754
|
+
}
|
|
1755
|
+
if (o.length === 0) return r("error", "no token declares a source.cssVar, so there is nothing to compare", "Name the site's custom property in a token's dev.blazon source.cssVar (manual chapter 2).");
|
|
1756
|
+
let s = (e) => o.filter((t) => t.status === e).length, c = {
|
|
1757
|
+
ok: s("ok"),
|
|
1758
|
+
drift: s("drift"),
|
|
1759
|
+
missing: s("missing")
|
|
1760
|
+
}, l = +(c.drift + c.missing > 0);
|
|
1761
|
+
if (t.json) return console.log(JSON.stringify({
|
|
1762
|
+
target: e,
|
|
1763
|
+
sources: a,
|
|
1764
|
+
summary: c,
|
|
1765
|
+
tokens: o
|
|
1766
|
+
}, null, 2)), l;
|
|
1767
|
+
let u = Math.max(...o.map((e) => e.path.length));
|
|
1768
|
+
for (let e of o) {
|
|
1769
|
+
let t = e.path.padEnd(u);
|
|
1770
|
+
e.status === "ok" ? console.log(`${n.green("ok ")} ${t} ${n.dim(e.cssVar)}`) : e.status === "drift" ? console.log(`${n.red("drift ")} ${t} ${e.cssVar}: token ${e.expected}, site ${e.actual}`) : console.log(`${n.yellow("missing")} ${t} ${e.cssVar} is not declared (token ${e.expected})`);
|
|
1771
|
+
}
|
|
1772
|
+
return console.log(`\n${c.ok} ok, ${c.drift} drifted, ${c.missing} missing`), l;
|
|
1773
|
+
}
|
|
1774
|
+
// src/cli/commands/approvals.ts
|
|
1775
|
+
async function ui(e = process.cwd(), t = {}) {
|
|
1776
|
+
let r = await R(e), i = await T(r, e), a = ee(i.tokens, i.assets.all, {
|
|
1777
|
+
assetsDir: O.resolve(e, r.assetsDir),
|
|
1778
|
+
dirs: Ye(r.assets, e)
|
|
1779
|
+
}), o = (e) => e.review.value === void 0 ? "not recorded" : e.review.value === e.current ? "recorded" : "stale";
|
|
1780
|
+
if (t.json) {
|
|
1781
|
+
let e = a.map((e) => ({
|
|
1782
|
+
path: e.path,
|
|
1783
|
+
fingerprint: e.current ?? null,
|
|
1784
|
+
state: o(e)
|
|
1785
|
+
}));
|
|
1786
|
+
return process.stdout.write(`${JSON.stringify({
|
|
1787
|
+
command: "approvals",
|
|
1788
|
+
passed: !0,
|
|
1789
|
+
approvals: e
|
|
1790
|
+
})}\n`), 0;
|
|
1791
|
+
}
|
|
1792
|
+
if (a.length === 0) return console.log(n.dim("\n No token or asset is marked review.status: ok.\n")), 0;
|
|
1793
|
+
let s = Math.max(...a.map((e) => e.path.length));
|
|
1794
|
+
console.log();
|
|
1795
|
+
for (let e of a) {
|
|
1796
|
+
let t = o(e), r = t === "recorded" ? n.green : t === "stale" ? n.yellow : n.dim;
|
|
1797
|
+
console.log(` ${e.path.padEnd(s)} ${(e.current ?? "(no value)").padEnd(12)} ${r(t)}`);
|
|
1798
|
+
}
|
|
1799
|
+
return console.log(), console.log(n.dim(" Set review.value to the fingerprint once a person has confirmed the value.\n")), 0;
|
|
1800
|
+
}
|
|
1801
|
+
// src/cli/commands/cwd.ts
|
|
1802
|
+
function di(e) {
|
|
1803
|
+
if (e === void 0) return;
|
|
1804
|
+
if (typeof e != "string" || e === "") throw new M("--cwd needs a folder", "Give one, such as blazon --cwd ./my-brand check.");
|
|
1805
|
+
let t = O.resolve(process.cwd(), e);
|
|
1806
|
+
mt(t), process.chdir(t);
|
|
1807
|
+
}
|
|
1808
|
+
function fi(t, n = process.env) {
|
|
1809
|
+
let r = (Array.isArray(t) ? t : t === void 0 ? [] : [t]).map((e) => typeof e == "string" || typeof e == "number" ? String(e) : "");
|
|
1810
|
+
if (r.some((e) => e.trim() === "")) throw new M("--allow-dir needs a folder", "Give one, such as blazon dev --allow-dir ../shared.");
|
|
1811
|
+
e(y(r, n, process.cwd()));
|
|
1812
|
+
}
|
|
1813
|
+
// src/core/read/lookup.ts
|
|
1814
|
+
var K = class extends Error {}, pi = (e) => e.trim().replace(/^\{(.*)\}$/, "$1").trim();
|
|
1815
|
+
function mi(e, t) {
|
|
1816
|
+
let n = pi(t), r = e.tokens.byPath.get(n);
|
|
1817
|
+
if (r) return r;
|
|
1818
|
+
let i = D(n, e.tokens.items.map((e) => e.path));
|
|
1819
|
+
throw new K(e.tokens.items.some((e) => e.path.startsWith(`${n}.`)) ? `"${n}" is a group, not a token; \`blazon rules ${n}\` shows its rules.` : `no token "${n}"${i ? `; did you mean "${i}"?` : "."}`);
|
|
1820
|
+
}
|
|
1821
|
+
// src/core/read/rules.ts
|
|
1822
|
+
var hi = (e) => e.extensions?.["dev.blazon"] ?? {};
|
|
1823
|
+
function gi(e, t, n) {
|
|
1824
|
+
return hi(t)[n] === void 0 ? e.tokens.groupMeta.filter((e) => t.path.startsWith(`${e.path}.`) && e.blazon[n] !== void 0).sort((e, t) => t.path.length - e.path.length)[0]?.path : t.path;
|
|
1825
|
+
}
|
|
1826
|
+
var q = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : void 0;
|
|
1827
|
+
function _i(e, t) {
|
|
1828
|
+
let n = t.blazon.usage, r = gi(e, t, "usage");
|
|
1829
|
+
if (!n || typeof n != "object" || r === void 0) return;
|
|
1830
|
+
let i = q(n.allow), a = q(n.deny);
|
|
1831
|
+
return {
|
|
1832
|
+
...i && { allow: i },
|
|
1833
|
+
...a && { deny: a },
|
|
1834
|
+
from: r
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
function vi(e, t) {
|
|
1838
|
+
let n = t.blazon.logo, r = gi(e, t, "logo"), i = q(n?.deny);
|
|
1839
|
+
if (n && i && r !== void 0) return {
|
|
1840
|
+
deny: i,
|
|
1841
|
+
...typeof n.reason == "string" && { reason: n.reason },
|
|
1842
|
+
from: r
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
function yi(e) {
|
|
1846
|
+
return e.tokens.groupMeta.flatMap((e) => (e.blazon.pairs ?? []).map((t) => ({
|
|
1847
|
+
fg: t.fg,
|
|
1848
|
+
bg: t.bg,
|
|
1849
|
+
min: t.min,
|
|
1850
|
+
from: e.path
|
|
1851
|
+
})));
|
|
1852
|
+
}
|
|
1853
|
+
function bi(e, t) {
|
|
1854
|
+
let n = [];
|
|
1855
|
+
for (let r of yi(e)) m(r.fg, e.tokens.items).some((e) => e.path === t.path) && n.push({
|
|
1856
|
+
...r,
|
|
1857
|
+
as: "fg"
|
|
1858
|
+
}), m(r.bg, e.tokens.items).some((e) => e.path === t.path) && n.push({
|
|
1859
|
+
...r,
|
|
1860
|
+
as: "bg"
|
|
1861
|
+
});
|
|
1862
|
+
return n;
|
|
1863
|
+
}
|
|
1864
|
+
function xi(e, t) {
|
|
1865
|
+
let n = hi(t).review, r = n ? t.path : gi(e, t, "review"), i = n ?? e.tokens.groupMeta.find((e) => e.path === r)?.blazon.review;
|
|
1866
|
+
if (i && r !== void 0) return {
|
|
1867
|
+
status: i.status,
|
|
1868
|
+
...i.note && { note: i.note },
|
|
1869
|
+
...i.by && { by: i.by },
|
|
1870
|
+
...i.at && { at: i.at },
|
|
1871
|
+
from: r
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
function Si(e, t) {
|
|
1875
|
+
let n = _i(e, t), r = vi(e, t), i = xi(e, t), a = t.blazon.role === void 0 ? void 0 : gi(e, t, "role");
|
|
1876
|
+
return {
|
|
1877
|
+
...t.blazon.role !== void 0 && a !== void 0 && { role: {
|
|
1878
|
+
value: t.blazon.role,
|
|
1879
|
+
from: a
|
|
1880
|
+
} },
|
|
1881
|
+
...n && { usage: n },
|
|
1882
|
+
...r && { logo: r },
|
|
1883
|
+
pairs: bi(e, t),
|
|
1884
|
+
...i && { review: i }
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
function Ci(e, t, n) {
|
|
1888
|
+
let r = n.usage && typeof n.usage == "object" ? {
|
|
1889
|
+
...q(n.usage.allow) && { allow: q(n.usage.allow) },
|
|
1890
|
+
...q(n.usage.deny) && { deny: q(n.usage.deny) }
|
|
1891
|
+
} : void 0, i = q(n.logo?.deny), a = {
|
|
1892
|
+
at: e,
|
|
1893
|
+
kind: t,
|
|
1894
|
+
...typeof n.role == "string" && { role: n.role },
|
|
1895
|
+
...r && { usage: r },
|
|
1896
|
+
...i && { logo: {
|
|
1897
|
+
deny: i,
|
|
1898
|
+
...typeof n.logo?.reason == "string" && { reason: n.logo.reason }
|
|
1899
|
+
} },
|
|
1900
|
+
...t === "group" && n.pairs?.length && { pairs: n.pairs.map((e) => ({
|
|
1901
|
+
fg: e.fg,
|
|
1902
|
+
bg: e.bg,
|
|
1903
|
+
min: e.min
|
|
1904
|
+
})) }
|
|
1905
|
+
};
|
|
1906
|
+
return Object.keys(a).length > 2 ? a : void 0;
|
|
1907
|
+
}
|
|
1908
|
+
function wi(e, t) {
|
|
1909
|
+
let n = pi(t), r = (e) => n === "" || e === n || e.startsWith(`${n}.`);
|
|
1910
|
+
if (!(n === "" || e.tokens.items.some((e) => r(e.path)))) {
|
|
1911
|
+
let t = [...new Set(e.tokens.items.flatMap((e) => e.path.split(".").slice(0, -1).map((e, t, n) => n.slice(0, t + 1).join("."))))], r = D(n, [...t, ...e.tokens.items.map((e) => e.path)]);
|
|
1912
|
+
throw new K(`no token or group "${n}"${r ? `; did you mean "${r}"?` : "."}`);
|
|
1913
|
+
}
|
|
1914
|
+
return [
|
|
1915
|
+
...e.tokens.groupMeta.filter((e) => n !== "" && n.startsWith(`${e.path}.`)).map((e) => Ci(e.path, "group", {
|
|
1916
|
+
...e.blazon,
|
|
1917
|
+
pairs: void 0
|
|
1918
|
+
})).map((e) => e && {
|
|
1919
|
+
...e,
|
|
1920
|
+
inherited: !0
|
|
1921
|
+
}),
|
|
1922
|
+
...e.tokens.groupMeta.filter((e) => r(e.path)).map((e) => Ci(e.path, "group", e.blazon)),
|
|
1923
|
+
...e.tokens.items.filter((e) => r(e.path)).map((e) => Ci(e.path, "token", hi(e)))
|
|
1924
|
+
].filter((e) => e !== void 0);
|
|
1925
|
+
}
|
|
1926
|
+
// src/core/read/token.ts
|
|
1927
|
+
function Ti(e, t) {
|
|
1928
|
+
let [n, ...r] = _(t), i = C(t), a = i ? e.tokens.items.find((e) => C(e) === i) : void 0;
|
|
1929
|
+
return {
|
|
1930
|
+
theme: {
|
|
1931
|
+
variable: n,
|
|
1932
|
+
...t.parts && { parts: Object.fromEntries(Object.keys(t.parts).map((e, t) => [e, r[t]])) }
|
|
1933
|
+
},
|
|
1934
|
+
tailwind: i ? {
|
|
1935
|
+
variable: i,
|
|
1936
|
+
...a && a.path !== t.path && { shadowedBy: a.path }
|
|
1937
|
+
} : null,
|
|
1938
|
+
...t.type === "typography" && { typographyClass: f(t.path) }
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
function Ei(e, t) {
|
|
1942
|
+
let n = mi(e, t), r = (e.tokens.contexts ?? []).flatMap((e) => e.tokens.filter((e) => e.path === n.path).map((t) => ({
|
|
1943
|
+
modifier: e.modifier,
|
|
1944
|
+
context: e.context,
|
|
1945
|
+
selector: e.selector,
|
|
1946
|
+
value: t.value
|
|
1947
|
+
})));
|
|
1948
|
+
return {
|
|
1949
|
+
path: n.path,
|
|
1950
|
+
...n.type && { type: n.type },
|
|
1951
|
+
value: n.value,
|
|
1952
|
+
...n.parts && { parts: n.parts },
|
|
1953
|
+
...n.description && { description: n.description },
|
|
1954
|
+
...n.deprecated && { deprecated: n.deprecated },
|
|
1955
|
+
...n.aliasOf && { aliasOf: n.aliasOf },
|
|
1956
|
+
...n.blazon.tier && { tier: n.blazon.tier },
|
|
1957
|
+
names: Ti(e, n),
|
|
1958
|
+
rules: Si(e, n),
|
|
1959
|
+
...r.length > 0 && { contexts: r },
|
|
1960
|
+
sourceFile: n.file.replace(/ \(inline\)$/, "")
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
// src/core/read/list.ts
|
|
1964
|
+
function Di(e) {
|
|
1965
|
+
let t = /* @__PURE__ */ new Set();
|
|
1966
|
+
for (let { path: n } of e.tokens.items) {
|
|
1967
|
+
let e = n.split(".");
|
|
1968
|
+
for (let n = 1; n < e.length; n++) t.add(e.slice(0, n).join("."));
|
|
1969
|
+
}
|
|
1970
|
+
return t;
|
|
1971
|
+
}
|
|
1972
|
+
function Oi(e, t) {
|
|
1973
|
+
let n = pi(t);
|
|
1974
|
+
return !e.tokens.byPath.has(n) && Di(e).has(n);
|
|
1975
|
+
}
|
|
1976
|
+
function ki(e, t = {}) {
|
|
1977
|
+
let n;
|
|
1978
|
+
if (t.type !== void 0 && (n = o.find((e) => e === t.type), !n)) throw new K(`no token type "${t.type}"; the types are ${o.join(", ")}.`);
|
|
1979
|
+
let r;
|
|
1980
|
+
if (t.group !== void 0) {
|
|
1981
|
+
r = pi(t.group);
|
|
1982
|
+
let n = Di(e);
|
|
1983
|
+
if (!n.has(r)) {
|
|
1984
|
+
let e = D(r, [...n]);
|
|
1985
|
+
throw new K(`no group "${r}"${e ? `; did you mean "${e}"?` : "."}`);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
let i = e.tokens.items.filter((e) => (r === void 0 || e.path.startsWith(`${r}.`)) && (n === void 0 || e.type === n)).map((e) => ({
|
|
1989
|
+
path: e.path,
|
|
1990
|
+
...e.type && { type: e.type },
|
|
1991
|
+
value: e.value,
|
|
1992
|
+
...e.aliasOf && { aliasOf: e.aliasOf }
|
|
1993
|
+
}));
|
|
1994
|
+
return {
|
|
1995
|
+
...r !== void 0 && { group: r },
|
|
1996
|
+
...n && { type: n },
|
|
1997
|
+
tokens: i
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
// src/core/read/can.ts
|
|
2001
|
+
var Ai = ["text", "ui"], ji = t["AA-large"], Mi = [
|
|
2002
|
+
"border",
|
|
2003
|
+
"icon",
|
|
2004
|
+
"interactive"
|
|
2005
|
+
], Ni = [
|
|
2006
|
+
"AAA",
|
|
2007
|
+
"AA",
|
|
2008
|
+
"AA-large"
|
|
2009
|
+
];
|
|
2010
|
+
function Pi(e, t) {
|
|
2011
|
+
let n = [];
|
|
2012
|
+
for (let r = t; r && !n.includes(r); r = r.aliasOf ? e.tokens.byPath.get(r.aliasOf) : void 0) n.push(r);
|
|
2013
|
+
return n;
|
|
2014
|
+
}
|
|
2015
|
+
function Fi(e, t, n) {
|
|
2016
|
+
for (let r of Pi(e, t)) {
|
|
2017
|
+
if (Oe(r, n)) continue;
|
|
2018
|
+
let t = _i(e, r), i = t.deny?.includes(n) ? `denies "${n}"` : `allows only ${(t.allow ?? []).map((e) => `"${e}"`).join(", ")}, not "${n}"`;
|
|
2019
|
+
return {
|
|
2020
|
+
rule: "usage",
|
|
2021
|
+
ok: !1,
|
|
2022
|
+
message: `{${r.path}} ${i} (usage on ${t.from})`,
|
|
2023
|
+
from: t.from
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
let r = Pi(e, t).find((t) => _i(e, t));
|
|
2027
|
+
return {
|
|
2028
|
+
rule: "usage",
|
|
2029
|
+
ok: !0,
|
|
2030
|
+
message: r ? `usage rules on {${r.path}} leave "${n}" open` : `{${t.path}} has no usage rule against "${n}"`
|
|
2031
|
+
};
|
|
2032
|
+
}
|
|
2033
|
+
function Ii(e, t) {
|
|
2034
|
+
let n = Mi.map((n) => Fi(e, t, n)), r = Mi.filter((e, t) => n[t].ok);
|
|
2035
|
+
return r.length > 0 ? {
|
|
2036
|
+
rule: "usage",
|
|
2037
|
+
ok: !0,
|
|
2038
|
+
message: `{${t.path}} may be used as ${r.map((e) => `"${e}"`).join(", ")}`
|
|
2039
|
+
} : {
|
|
2040
|
+
rule: "usage",
|
|
2041
|
+
ok: !1,
|
|
2042
|
+
message: `no non-text use is open: ${n.map((e) => e.message).join("; ")}`,
|
|
2043
|
+
from: n[0].from
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
var Li = "theme";
|
|
2047
|
+
function Ri(e, t) {
|
|
2048
|
+
let n = e.tokens.modifiers?.find((e) => e.name === Li);
|
|
2049
|
+
if (!n) throw new K(`no theme "${t}": this brand has no resolver "${Li}" modifier, so it has no themes.`);
|
|
2050
|
+
if (!n.contexts.includes(t)) throw new K(`no theme "${t}". The themes are ${n.contexts.map((e) => `"${e}"`).join(", ")}.`);
|
|
2051
|
+
let r = (e.tokens.contexts ?? []).filter((e) => e.modifier === "theme" && e.context === t), i = ce(e.tokens.items, r);
|
|
2052
|
+
return {
|
|
2053
|
+
...e,
|
|
2054
|
+
tokens: {
|
|
2055
|
+
...e.tokens,
|
|
2056
|
+
items: i,
|
|
2057
|
+
byPath: new Map(i.map((e) => [e.path, e]))
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
}
|
|
2061
|
+
var zi = (e, t) => {
|
|
2062
|
+
let n = e.type === "color" ? v(String(e.value)) : void 0;
|
|
2063
|
+
if (!n) throw new K(`{${e.path}} (${t}) is not a color blazon can read: it is ${e.type ?? "untyped"} with the value ${String(e.value)}.`);
|
|
2064
|
+
return n;
|
|
2065
|
+
};
|
|
2066
|
+
function Bi(e, n, r, i = "text", a) {
|
|
2067
|
+
if (a !== void 0) return {
|
|
2068
|
+
...Bi(Ri(e, a), n, r, i),
|
|
2069
|
+
theme: a
|
|
2070
|
+
};
|
|
2071
|
+
if (!Ai.includes(i)) throw new K(`"${String(i)}" is not a role blazon can judge. Use ${Ai.map((e) => `"${e}"`).join(" or ")}.`);
|
|
2072
|
+
let o = mi(e, n), s = mi(e, r), c = De(zi(o, "foreground"), zi(s, "background")), l = Ni.find((e) => c >= t[e]) ?? "fail", u = `${c.toFixed(2)}:1`, d = Math.round(c * 100) / 100;
|
|
2073
|
+
if (i === "ui") {
|
|
2074
|
+
let t = [
|
|
2075
|
+
Ii(e, o),
|
|
2076
|
+
Fi(e, s, "background"),
|
|
2077
|
+
{
|
|
2078
|
+
rule: "pairs",
|
|
2079
|
+
ok: !0,
|
|
2080
|
+
message: "pairs list text on background, so they do not apply to a non-text element"
|
|
2081
|
+
},
|
|
2082
|
+
{
|
|
2083
|
+
rule: "contrast",
|
|
2084
|
+
ok: c >= ji,
|
|
2085
|
+
message: `non-text contrast needs ${ji}:1, this is ${u}`
|
|
2086
|
+
}
|
|
2087
|
+
], n = t.find((e) => !e.ok), r = n ? n.message : t[t.length - 1].message;
|
|
2088
|
+
return {
|
|
2089
|
+
fg: o.path,
|
|
2090
|
+
bg: s.path,
|
|
2091
|
+
role: i,
|
|
2092
|
+
allowed: n === void 0,
|
|
2093
|
+
reason: r,
|
|
2094
|
+
checks: t,
|
|
2095
|
+
contrast: {
|
|
2096
|
+
ratio: d,
|
|
2097
|
+
level: l,
|
|
2098
|
+
threshold: ji
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
let f = [Fi(e, o, "text"), Fi(e, s, "background")], p = yi(e), m = h(e.tokens.items, p, o.path, s.path);
|
|
2103
|
+
if (m.length > 0) for (let e of m) {
|
|
2104
|
+
let n = t[e.min];
|
|
2105
|
+
f.push({
|
|
2106
|
+
rule: "pairs",
|
|
2107
|
+
ok: c >= n,
|
|
2108
|
+
message: `pairs on ${e.from} list ${e.fg} on ${e.bg}: ${e.min} needs ${n}:1, this is ${u}`,
|
|
2109
|
+
from: e.from
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
else p.length > 0 ? f.push({
|
|
2113
|
+
rule: "pairs",
|
|
2114
|
+
ok: !1,
|
|
2115
|
+
message: `no pair lists {${o.path}} on {${s.path}}; the brand lists ${p.length} pair${p.length === 1 ? "" : "s"} and only those may sit together`
|
|
2116
|
+
}) : f.push({
|
|
2117
|
+
rule: "pairs",
|
|
2118
|
+
ok: !0,
|
|
2119
|
+
message: "the brand lists no pairs, so contrast is the only measure left"
|
|
2120
|
+
});
|
|
2121
|
+
f.push({
|
|
2122
|
+
rule: "contrast",
|
|
2123
|
+
ok: !0,
|
|
2124
|
+
message: `contrast is ${u}${l === "fail" ? ", below every WCAG level" : `, which meets ${l}`} (reported, never a rule of its own)`
|
|
2125
|
+
});
|
|
2126
|
+
let g = f.find((e) => !e.ok && e.rule !== "contrast") ?? void 0, _ = g === void 0, v = g ? g.message : (f.find((e) => e.rule === "pairs" && e.from) ?? f[f.length - 1]).message;
|
|
2127
|
+
return {
|
|
2128
|
+
fg: o.path,
|
|
2129
|
+
bg: s.path,
|
|
2130
|
+
role: i,
|
|
2131
|
+
allowed: _,
|
|
2132
|
+
reason: v,
|
|
2133
|
+
checks: f,
|
|
2134
|
+
contrast: {
|
|
2135
|
+
ratio: d,
|
|
2136
|
+
level: l
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
// src/core/read/fonts.ts
|
|
2141
|
+
function Vi(e, t, n) {
|
|
2142
|
+
let r = t.fonts ?? [], i = me(t.fonts, n), a = /* @__PURE__ */ new Map();
|
|
2143
|
+
for (let t of e.tokens.items) {
|
|
2144
|
+
let e = t.resolvedValue, n = t.type === "fontFamily" ? (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "string") : void 0, r = t.type === "fontFamily" ? Ee(e) : t.type === "typography" && typeof e == "object" && e ? Ee(e.fontFamily) : void 0;
|
|
2145
|
+
if (!r) continue;
|
|
2146
|
+
let o = r.toLowerCase(), s = a.get(o);
|
|
2147
|
+
s ? (s.tokens.push(t.path), !s.stack && n && (s.stack = n)) : a.set(o, {
|
|
2148
|
+
family: r,
|
|
2149
|
+
tokens: [t.path],
|
|
2150
|
+
...n && { stack: n },
|
|
2151
|
+
system: Ie.has(o),
|
|
2152
|
+
loaded: i.families.has(o) ? !0 : i.opaque ? null : !1,
|
|
2153
|
+
...t.blazon.webFont !== void 0 && { webFont: t.blazon.webFont },
|
|
2154
|
+
...t.blazon.font && { font: t.blazon.font }
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
let o = (t) => e.theme[t] || e.themeTokens?.[t] ? {
|
|
2158
|
+
token: e.themeTokens?.[t],
|
|
2159
|
+
value: e.theme[t]
|
|
2160
|
+
} : void 0;
|
|
2161
|
+
return {
|
|
2162
|
+
stylesheets: r.filter((e) => !Re(e)),
|
|
2163
|
+
files: r.filter(Re).map((e) => ({
|
|
2164
|
+
family: e.family,
|
|
2165
|
+
file: e.file,
|
|
2166
|
+
...e.weight !== void 0 && { weight: e.weight },
|
|
2167
|
+
...e.style && { style: e.style }
|
|
2168
|
+
})),
|
|
2169
|
+
roles: {
|
|
2170
|
+
...o("fontDisplay") && { fontDisplay: o("fontDisplay") },
|
|
2171
|
+
...o("fontBody") && { fontBody: o("fontBody") }
|
|
2172
|
+
},
|
|
2173
|
+
families: [...a.values()]
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
function Hi(e, t) {
|
|
2177
|
+
let n = e.stylesheets.map((e) => `/* Stylesheet, not fetched by blazon: ${e.replace(/\*\//g, "*%2F")} */`);
|
|
2178
|
+
for (let r of e.files) {
|
|
2179
|
+
let e = Me(r.file);
|
|
2180
|
+
if (!e) {
|
|
2181
|
+
n.push(`/* ${r.file.replace(/\*\//g, "*%2F")}: not a font file blazon embeds, so no rule */`);
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
let i = t === void 0 ? r.file : `${t.endsWith("/") ? t : `${t}/`}${r.file.split("/").pop()}`;
|
|
2185
|
+
n.push(ue(r, `url("${encodeURI(i).replace(/"/g, "%22")}") format("${e}")`, !0));
|
|
2186
|
+
}
|
|
2187
|
+
return n.length === 0 ? "/* The config lists no fonts. */\n" : `${n.join("\n\n")}\n`;
|
|
2188
|
+
}
|
|
2189
|
+
// src/core/read/logo.ts
|
|
2190
|
+
function Ui(e, t, n) {
|
|
2191
|
+
let r = u(t), i = O.resolve(n, t.assetsDir), a = Ye(t.assets, n), o = (e) => O.relative(n, b(e, i, a)).split(O.sep).join("/"), s = ["onLight", "onDark"].flatMap((t) => {
|
|
2192
|
+
let n = r[t];
|
|
2193
|
+
if (!n) return [];
|
|
2194
|
+
let i = t === "onLight" ? e.logo?.onLightAsset : e.logo?.onDarkAsset, a = t === "onLight" ? e.logo?.onLightInk : e.logo?.onDarkInk;
|
|
2195
|
+
return [{
|
|
2196
|
+
variant: t,
|
|
2197
|
+
file: n,
|
|
2198
|
+
found: !!(t === "onLight" ? e.logo?.onLight : e.logo?.onDark),
|
|
2199
|
+
...i && { asset: i },
|
|
2200
|
+
...a && { ink: a }
|
|
2201
|
+
}];
|
|
2202
|
+
});
|
|
2203
|
+
return {
|
|
2204
|
+
variants: s,
|
|
2205
|
+
assets: e.assets.logos.map((e) => {
|
|
2206
|
+
let t = b(e, i, a);
|
|
2207
|
+
return {
|
|
2208
|
+
id: e.id,
|
|
2209
|
+
file: o(e),
|
|
2210
|
+
variants: s.filter((e) => r[e.variant] ? p(O.resolve(n, r[e.variant]), t) : !1).map((e) => e.variant),
|
|
2211
|
+
rules: e.meta ?? {}
|
|
2212
|
+
};
|
|
2213
|
+
}),
|
|
2214
|
+
forbidden: wi(e, "").flatMap((e) => e.logo ? [{
|
|
2215
|
+
at: e.at,
|
|
2216
|
+
deny: e.logo.deny,
|
|
2217
|
+
...e.logo.reason && { reason: e.logo.reason }
|
|
2218
|
+
}] : [])
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
// src/cli/read.ts
|
|
2222
|
+
async function J(e) {
|
|
2223
|
+
let t = await R(e), r = await T(t, e), { errors: i } = Ge(r.findings);
|
|
2224
|
+
return i.length > 0 && console.error(n.yellow(`blazon: this brand has ${i.length} error(s), so a value below may be wrong; run blazon check.`)), {
|
|
2225
|
+
config: t,
|
|
2226
|
+
data: r
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
function Wi(e) {
|
|
2230
|
+
try {
|
|
2231
|
+
return e();
|
|
2232
|
+
} catch (e) {
|
|
2233
|
+
throw e instanceof K ? new M(e.message, void 0, "unknown-token") : e;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
function Y(e, t, n) {
|
|
2237
|
+
process.stdout.write(`${JSON.stringify({
|
|
2238
|
+
command: e,
|
|
2239
|
+
passed: t,
|
|
2240
|
+
...n
|
|
2241
|
+
}, null, 2)}\n`);
|
|
2242
|
+
}
|
|
2243
|
+
function Gi(e, t = " ") {
|
|
2244
|
+
let r = e.filter((e) => e[1] !== void 0), i = Math.max(0, ...r.map(([e]) => e.length));
|
|
2245
|
+
for (let [e, a] of r) console.log(`${t}${n.dim(e.padEnd(i))} ${a}`);
|
|
2246
|
+
}
|
|
2247
|
+
// src/cli/commands/doctor.ts
|
|
2248
|
+
var Ki = [
|
|
2249
|
+
"blazon.brand-deck",
|
|
2250
|
+
"blazon.favicons",
|
|
2251
|
+
"blazon.logo-geometry",
|
|
2252
|
+
"blazon.logo-kit",
|
|
2253
|
+
"blazon.press-kit",
|
|
2254
|
+
"blazon.print-book",
|
|
2255
|
+
"blazon.social-cards"
|
|
2256
|
+
], qi = (e) => {
|
|
2257
|
+
try {
|
|
2258
|
+
return k.accessSync(e, k.constants.X_OK), k.statSync(e).isFile();
|
|
2259
|
+
} catch {
|
|
2260
|
+
return !1;
|
|
2261
|
+
}
|
|
2262
|
+
};
|
|
2263
|
+
function Ji(e = process.env) {
|
|
2264
|
+
if (e.BLAZON_CHROME) return qi(e.BLAZON_CHROME);
|
|
2265
|
+
let t = [];
|
|
2266
|
+
if (process.platform === "darwin") t.push("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
|
|
2267
|
+
else if (process.platform === "win32") for (let n of [
|
|
2268
|
+
e.PROGRAMFILES,
|
|
2269
|
+
e["PROGRAMFILES(X86)"],
|
|
2270
|
+
e.LOCALAPPDATA
|
|
2271
|
+
]) n && t.push(O.join(n, "Google", "Chrome", "Application", "chrome.exe"));
|
|
2272
|
+
else t.push("/opt/google/chrome/chrome", ...(e.PATH ?? "").split(O.delimiter).filter(Boolean).flatMap((e) => ["google-chrome", "google-chrome-stable"].map((t) => O.join(e, t))));
|
|
2273
|
+
return t.some(qi);
|
|
2274
|
+
}
|
|
2275
|
+
var Yi = () => {
|
|
2276
|
+
let e = JSON.parse(k.readFileSync(O.join(He(), "package.json"), "utf-8"));
|
|
2277
|
+
return {
|
|
2278
|
+
nodeVersion: process.version,
|
|
2279
|
+
engine: e.engines?.node,
|
|
2280
|
+
hostProblem: (e) => re(e, { final: "dir" }),
|
|
2281
|
+
chrome: () => Ji(),
|
|
2282
|
+
identity: je()
|
|
2283
|
+
};
|
|
2284
|
+
};
|
|
2285
|
+
function Xi(e, t) {
|
|
2286
|
+
let n = /^>=\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/.exec(t.trim()), r = /^v?(\d+)\.(\d+)\.(\d+)/.exec(e);
|
|
2287
|
+
if (!n || !r) return;
|
|
2288
|
+
let i = [
|
|
2289
|
+
n[1],
|
|
2290
|
+
n[2] ?? "0",
|
|
2291
|
+
n[3] ?? "0"
|
|
2292
|
+
].map(Number), a = [
|
|
2293
|
+
r[1],
|
|
2294
|
+
r[2],
|
|
2295
|
+
r[3]
|
|
2296
|
+
].map(Number);
|
|
2297
|
+
for (let e = 0; e < 3; e++) if (a[e] !== i[e]) return a[e] > i[e];
|
|
2298
|
+
return !0;
|
|
2299
|
+
}
|
|
2300
|
+
function Zi(e) {
|
|
2301
|
+
if (!e.engine) return {
|
|
2302
|
+
id: "node",
|
|
2303
|
+
status: "warn",
|
|
2304
|
+
message: `Node ${e.nodeVersion}; blazon's package.json names no engines range to compare`,
|
|
2305
|
+
fix: "Reinstall blazon."
|
|
2306
|
+
};
|
|
2307
|
+
let t = Xi(e.nodeVersion, e.engine);
|
|
2308
|
+
return t === void 0 ? {
|
|
2309
|
+
id: "node",
|
|
2310
|
+
status: "warn",
|
|
2311
|
+
message: `Node ${e.nodeVersion}; engines is "${e.engine}", which doctor cannot compare`,
|
|
2312
|
+
fix: `Use a Node that satisfies ${e.engine}.`
|
|
2313
|
+
} : t ? {
|
|
2314
|
+
id: "node",
|
|
2315
|
+
status: "ok",
|
|
2316
|
+
message: `Node ${e.nodeVersion} (blazon needs ${e.engine})`
|
|
2317
|
+
} : {
|
|
2318
|
+
id: "node",
|
|
2319
|
+
status: "fail",
|
|
2320
|
+
message: `Node ${e.nodeVersion} is older than blazon needs (${e.engine})`,
|
|
2321
|
+
fix: `Install Node ${e.engine.replace(/^>=\s*/, "")} or newer, such as with nvm install ${e.engine.replace(/^>=\s*v?(\d+).*$/, "$1")}.`
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
async function Qi(e) {
|
|
2325
|
+
try {
|
|
2326
|
+
let t = await R(e);
|
|
2327
|
+
return {
|
|
2328
|
+
check: {
|
|
2329
|
+
id: "brand",
|
|
2330
|
+
status: "ok",
|
|
2331
|
+
message: `brand folder found: tokens in ${t.tokensDir}, blazon.json loads`
|
|
2332
|
+
},
|
|
2333
|
+
config: t
|
|
2334
|
+
};
|
|
2335
|
+
} catch (e) {
|
|
2336
|
+
return { check: {
|
|
2337
|
+
id: "brand",
|
|
2338
|
+
status: "fail",
|
|
2339
|
+
message: e instanceof Error ? e.message : String(e),
|
|
2340
|
+
fix: e instanceof j && e.fix ? e.fix : "Fix the error in blazon.json, then run blazon doctor again."
|
|
2341
|
+
} };
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
function $i(e, t, n) {
|
|
2345
|
+
let r = t.hostProblem(e);
|
|
2346
|
+
if (!r) return {
|
|
2347
|
+
id: "plugin-host",
|
|
2348
|
+
status: "ok",
|
|
2349
|
+
message: `${e} is a folder blazon will run plugins from`
|
|
2350
|
+
};
|
|
2351
|
+
let i = /written by group or others/.test(r) ? Ue(e) : "Run blazon from a folder under your own home folder that only you can write.";
|
|
2352
|
+
return {
|
|
2353
|
+
id: "plugin-host",
|
|
2354
|
+
status: n > 0 ? "fail" : "warn",
|
|
2355
|
+
message: `${r}, so blazon will refuse to run plugins from it`,
|
|
2356
|
+
fix: i
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
function ea(e, t) {
|
|
2360
|
+
let n = [...new Set((t?.plugins ?? []).map((e) => e.name).filter((e) => Ki.includes(e)))];
|
|
2361
|
+
return n.length === 0 ? {
|
|
2362
|
+
id: "chrome",
|
|
2363
|
+
status: "ok",
|
|
2364
|
+
message: "Google Chrome is not needed: no configured plugin draws in a browser"
|
|
2365
|
+
} : e.chrome() ? {
|
|
2366
|
+
id: "chrome",
|
|
2367
|
+
status: "ok",
|
|
2368
|
+
message: `Google Chrome found, for ${n.join(", ")}`
|
|
2369
|
+
} : {
|
|
2370
|
+
id: "chrome",
|
|
2371
|
+
status: "fail",
|
|
2372
|
+
message: `no Google Chrome found, and ${n.join(", ")} draw${n.length === 1 ? "s" : ""} in one`,
|
|
2373
|
+
fix: "Install Google Chrome, or set BLAZON_CHROME to a Chrome or Chromium program; or take the plugin out of blazon.json."
|
|
2374
|
+
};
|
|
2375
|
+
}
|
|
2376
|
+
function ta(e, t) {
|
|
2377
|
+
if (!k.existsSync(O.join(e, "blazon.lock"))) return {
|
|
2378
|
+
id: "lock",
|
|
2379
|
+
status: "ok",
|
|
2380
|
+
message: "no blazon.lock: this book is not pinned to a blazon build"
|
|
2381
|
+
};
|
|
2382
|
+
let n = we(e, t.identity)[0];
|
|
2383
|
+
return n ? {
|
|
2384
|
+
id: "lock",
|
|
2385
|
+
status: "fail",
|
|
2386
|
+
message: n.message,
|
|
2387
|
+
fix: n.fix ?? Ce[n.code].fix
|
|
2388
|
+
} : {
|
|
2389
|
+
id: "lock",
|
|
2390
|
+
status: "ok",
|
|
2391
|
+
message: "blazon.lock matches the blazon that is running"
|
|
2392
|
+
};
|
|
2393
|
+
}
|
|
2394
|
+
async function na(e, t = Yi()) {
|
|
2395
|
+
let n = await Qi(e);
|
|
2396
|
+
return [
|
|
2397
|
+
Zi(t),
|
|
2398
|
+
n.check,
|
|
2399
|
+
$i(e, t, n.config?.plugins?.length ?? 0),
|
|
2400
|
+
ea(t, n.config),
|
|
2401
|
+
ta(e, t)
|
|
2402
|
+
];
|
|
2403
|
+
}
|
|
2404
|
+
var ra = {
|
|
2405
|
+
ok: n.green,
|
|
2406
|
+
warn: n.yellow,
|
|
2407
|
+
fail: n.red
|
|
2408
|
+
};
|
|
2409
|
+
async function ia(e = process.cwd(), t = {}) {
|
|
2410
|
+
let r = await na(e), i = !r.some((e) => e.status === "fail");
|
|
2411
|
+
if (t.json) return Y("doctor", i, { checks: r }), +!i;
|
|
2412
|
+
console.log();
|
|
2413
|
+
for (let e of r) console.log(` ${ra[e.status](e.status.padEnd(4))} ${e.id.padEnd(11)} ${e.message}`), e.status !== "ok" && e.fix && console.log(n.dim(` fix: ${e.fix}`));
|
|
2414
|
+
return console.log(), +!i;
|
|
2415
|
+
}
|
|
2416
|
+
// src/core/operations/limits.ts
|
|
2417
|
+
var aa = 4e4, X = {
|
|
2418
|
+
readOnlyHint: !0,
|
|
2419
|
+
destructiveHint: !1,
|
|
2420
|
+
idempotentHint: !0,
|
|
2421
|
+
openWorldHint: !1
|
|
2422
|
+
}, oa = {
|
|
2423
|
+
type: "string",
|
|
2424
|
+
description: "The brand folder. Default: the current folder"
|
|
2425
|
+
}, Z = (e, t) => ({
|
|
2426
|
+
type: "object",
|
|
2427
|
+
properties: e,
|
|
2428
|
+
...t.length > 0 && { required: t },
|
|
2429
|
+
additionalProperties: !1
|
|
2430
|
+
}), sa = {
|
|
2431
|
+
warnings: {
|
|
2432
|
+
type: "array",
|
|
2433
|
+
items: { type: "string" },
|
|
2434
|
+
description: "Lines blazon printed on standard error, such as a warning that the brand has errors. Empty when blazon said nothing"
|
|
2435
|
+
},
|
|
2436
|
+
brandHasErrors: {
|
|
2437
|
+
type: "boolean",
|
|
2438
|
+
description: "True when the brand has errors, so values read from it may be wrong. Run check_brand to see them"
|
|
2439
|
+
},
|
|
2440
|
+
truncated: {
|
|
2441
|
+
description: "True when the answer was cut to fit the size limit. `notice` says how to narrow the question",
|
|
2442
|
+
type: "boolean"
|
|
2443
|
+
},
|
|
2444
|
+
notice: {
|
|
2445
|
+
description: "Present when the answer was cut: how much was kept and how to ask a narrower question",
|
|
2446
|
+
type: "string"
|
|
2447
|
+
}
|
|
2448
|
+
}, Q = (e, t) => ({
|
|
2449
|
+
type: "object",
|
|
2450
|
+
properties: {
|
|
2451
|
+
...sa,
|
|
2452
|
+
...e
|
|
2453
|
+
},
|
|
2454
|
+
required: [
|
|
2455
|
+
"warnings",
|
|
2456
|
+
"brandHasErrors",
|
|
2457
|
+
...t
|
|
2458
|
+
],
|
|
2459
|
+
additionalProperties: {}
|
|
2460
|
+
}), ca = [
|
|
2461
|
+
{
|
|
2462
|
+
name: "check_brand",
|
|
2463
|
+
title: "Check the brand",
|
|
2464
|
+
description: "Runs blazon check on the brand, without plugins, and returns its findings and counts. `passed` is false when the brand has errors, and values read from such a brand can be wrong. Returns at most `limit` findings (default 50, at most 500); `counts` stay whole. Not for reading a value: use get_token.",
|
|
2465
|
+
annotations: X,
|
|
2466
|
+
inputSchema: Z({
|
|
2467
|
+
severity: {
|
|
2468
|
+
description: "List only the findings at this level or worse. The counts stay whole",
|
|
2469
|
+
type: "string",
|
|
2470
|
+
enum: [
|
|
2471
|
+
"error",
|
|
2472
|
+
"warning",
|
|
2473
|
+
"info"
|
|
2474
|
+
]
|
|
2475
|
+
},
|
|
2476
|
+
limit: {
|
|
2477
|
+
default: 50,
|
|
2478
|
+
description: "The most findings to return, from 1 to 500; default 50",
|
|
2479
|
+
type: "integer",
|
|
2480
|
+
minimum: 1,
|
|
2481
|
+
maximum: 500
|
|
2482
|
+
}
|
|
2483
|
+
}, []),
|
|
2484
|
+
outputSchema: Q({
|
|
2485
|
+
passed: {
|
|
2486
|
+
type: "boolean",
|
|
2487
|
+
description: "True when the brand has no errors"
|
|
2488
|
+
},
|
|
2489
|
+
counts: {
|
|
2490
|
+
type: "object",
|
|
2491
|
+
properties: {
|
|
2492
|
+
errors: {
|
|
2493
|
+
type: "number",
|
|
2494
|
+
description: "How many findings are errors, whatever `severity` or `limit` asked for"
|
|
2495
|
+
},
|
|
2496
|
+
warnings: {
|
|
2497
|
+
type: "number",
|
|
2498
|
+
description: "How many findings are warnings"
|
|
2499
|
+
},
|
|
2500
|
+
info: {
|
|
2501
|
+
type: "number",
|
|
2502
|
+
description: "How many findings are notes"
|
|
2503
|
+
}
|
|
2504
|
+
},
|
|
2505
|
+
required: [
|
|
2506
|
+
"errors",
|
|
2507
|
+
"warnings",
|
|
2508
|
+
"info"
|
|
2509
|
+
],
|
|
2510
|
+
additionalProperties: {},
|
|
2511
|
+
description: "How many findings the brand has at each level"
|
|
2512
|
+
},
|
|
2513
|
+
findings: {
|
|
2514
|
+
type: "array",
|
|
2515
|
+
items: {
|
|
2516
|
+
type: "object",
|
|
2517
|
+
properties: {
|
|
2518
|
+
code: {
|
|
2519
|
+
type: "string",
|
|
2520
|
+
description: "The finding code, such as starter-logo-unchanged"
|
|
2521
|
+
},
|
|
2522
|
+
severity: {
|
|
2523
|
+
type: "string",
|
|
2524
|
+
description: "error, warning or info"
|
|
2525
|
+
},
|
|
2526
|
+
message: {
|
|
2527
|
+
type: "string",
|
|
2528
|
+
description: "What is wrong and where"
|
|
2529
|
+
}
|
|
2530
|
+
},
|
|
2531
|
+
required: [
|
|
2532
|
+
"code",
|
|
2533
|
+
"severity",
|
|
2534
|
+
"message"
|
|
2535
|
+
],
|
|
2536
|
+
additionalProperties: {}
|
|
2537
|
+
},
|
|
2538
|
+
description: "The findings, cut to `limit`"
|
|
2539
|
+
},
|
|
2540
|
+
findingsTotal: {
|
|
2541
|
+
description: "How many findings there are before `limit` cut the list",
|
|
2542
|
+
type: "number"
|
|
2543
|
+
}
|
|
2544
|
+
}, [
|
|
2545
|
+
"passed",
|
|
2546
|
+
"counts",
|
|
2547
|
+
"findings"
|
|
2548
|
+
]),
|
|
2549
|
+
cli: !1,
|
|
2550
|
+
mcp: {
|
|
2551
|
+
command: ["check"],
|
|
2552
|
+
fixed: ["--no-plugins"],
|
|
2553
|
+
flags: ["severity"],
|
|
2554
|
+
answers: [1],
|
|
2555
|
+
ignoreStderr: !0
|
|
2556
|
+
}
|
|
2557
|
+
},
|
|
2558
|
+
{
|
|
2559
|
+
name: "list_tokens",
|
|
2560
|
+
title: "List the tokens",
|
|
2561
|
+
description: `Lists the design tokens of the brand, or of one group, or of one type, each with its path, type and value, in the order the token files write them. Use it to find a path or to read many values at once. For a token's CSS variable names and rules use get_token; for the brand's usage rules use get_rules. An answer over ${aa} characters is cut to whole tokens, and \`tokensTotal\` says how many matched: narrow with \`group\` or \`type\`.`,
|
|
2562
|
+
annotations: X,
|
|
2563
|
+
inputSchema: Z({
|
|
2564
|
+
group: {
|
|
2565
|
+
type: "string",
|
|
2566
|
+
maxLength: 200,
|
|
2567
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2568
|
+
description: "A group path, for example color or color.brand. Leave out for every token"
|
|
2569
|
+
},
|
|
2570
|
+
type: {
|
|
2571
|
+
description: "A token type, for example color, dimension or fontFamily. Leave out for every type. An unknown type is refused with the list of types",
|
|
2572
|
+
type: "string",
|
|
2573
|
+
maxLength: 40,
|
|
2574
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*$"
|
|
2575
|
+
},
|
|
2576
|
+
dir: {
|
|
2577
|
+
type: "string",
|
|
2578
|
+
description: "The brand folder. Default: the current folder"
|
|
2579
|
+
}
|
|
2580
|
+
}, []),
|
|
2581
|
+
outputSchema: Q({
|
|
2582
|
+
group: {
|
|
2583
|
+
description: "The group asked for, as a clean path. Absent when the whole brand was listed",
|
|
2584
|
+
type: "string"
|
|
2585
|
+
},
|
|
2586
|
+
type: {
|
|
2587
|
+
description: "The type asked for. Absent when every type was listed",
|
|
2588
|
+
type: "string"
|
|
2589
|
+
},
|
|
2590
|
+
tokens: {
|
|
2591
|
+
type: "array",
|
|
2592
|
+
items: {
|
|
2593
|
+
type: "object",
|
|
2594
|
+
properties: {
|
|
2595
|
+
path: {
|
|
2596
|
+
type: "string",
|
|
2597
|
+
description: "The token path, to pass to get_token"
|
|
2598
|
+
},
|
|
2599
|
+
type: {
|
|
2600
|
+
description: "The token type, such as color",
|
|
2601
|
+
type: "string"
|
|
2602
|
+
},
|
|
2603
|
+
value: { description: "The value as CSS needs it, with aliases resolved: a string or a number" },
|
|
2604
|
+
aliasOf: {
|
|
2605
|
+
description: "The token this one is an alias of, when it is one",
|
|
2606
|
+
type: "string"
|
|
2607
|
+
}
|
|
2608
|
+
},
|
|
2609
|
+
required: ["path", "value"],
|
|
2610
|
+
additionalProperties: {}
|
|
2611
|
+
},
|
|
2612
|
+
description: "The tokens, cut to fit the size limit"
|
|
2613
|
+
},
|
|
2614
|
+
tokensTotal: {
|
|
2615
|
+
description: "How many tokens matched before the size limit cut the list",
|
|
2616
|
+
type: "number"
|
|
2617
|
+
}
|
|
2618
|
+
}, ["tokens"]),
|
|
2619
|
+
cli: {
|
|
2620
|
+
rank: 2,
|
|
2621
|
+
command: ["list"],
|
|
2622
|
+
positional: ["group", "dir"],
|
|
2623
|
+
cliOnly: ["dir"],
|
|
2624
|
+
folder: "group",
|
|
2625
|
+
summary: "List the tokens: path, type and value, and the token each aliases. With a group path, only the tokens in that group",
|
|
2626
|
+
options: [{
|
|
2627
|
+
property: "json",
|
|
2628
|
+
description: "Print the list as JSON on standard output"
|
|
2629
|
+
}, {
|
|
2630
|
+
property: "type",
|
|
2631
|
+
value: "type",
|
|
2632
|
+
description: "List only the tokens of one $type (color, dimension, fontFamily, ...)"
|
|
2633
|
+
}]
|
|
2634
|
+
}
|
|
2635
|
+
},
|
|
2636
|
+
{
|
|
2637
|
+
name: "get_token",
|
|
2638
|
+
title: "Read a token",
|
|
2639
|
+
description: "Looks up one design token of the brand: its value, type, the CSS variable names it gets, and the rules that apply to it. Use it for the value of a path you know; a group path is refused. For a path you do not know use list_tokens.",
|
|
2640
|
+
annotations: X,
|
|
2641
|
+
inputSchema: Z({
|
|
2642
|
+
path: {
|
|
2643
|
+
type: "string",
|
|
2644
|
+
maxLength: 200,
|
|
2645
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2646
|
+
description: "The token path, for example color.brand.primary. A path from list_tokens works"
|
|
2647
|
+
},
|
|
2648
|
+
dir: {
|
|
2649
|
+
type: "string",
|
|
2650
|
+
description: "The brand folder. Default: the current folder"
|
|
2651
|
+
}
|
|
2652
|
+
}, ["path"]),
|
|
2653
|
+
outputSchema: Q({ token: {
|
|
2654
|
+
description: "The token, with its CSS variable names, the rules that apply to it and the file that writes it",
|
|
2655
|
+
type: "object",
|
|
2656
|
+
properties: {
|
|
2657
|
+
path: {
|
|
2658
|
+
type: "string",
|
|
2659
|
+
description: "The token path"
|
|
2660
|
+
},
|
|
2661
|
+
type: {
|
|
2662
|
+
description: "The token type, such as color",
|
|
2663
|
+
type: "string"
|
|
2664
|
+
},
|
|
2665
|
+
value: { description: "The value as CSS needs it, with aliases resolved" }
|
|
2666
|
+
},
|
|
2667
|
+
required: ["path", "value"],
|
|
2668
|
+
additionalProperties: {}
|
|
2669
|
+
} }, []),
|
|
2670
|
+
cli: {
|
|
2671
|
+
rank: 1,
|
|
2672
|
+
command: ["get"],
|
|
2673
|
+
positional: ["path", "dir"],
|
|
2674
|
+
cliOnly: ["dir"],
|
|
2675
|
+
summary: "Read one token: its value, type, CSS variable names in theme.css and tailwind.css, its usage, pairs and logo rules, and the file it is in. To find a path, use blazon list",
|
|
2676
|
+
options: [{
|
|
2677
|
+
property: "json",
|
|
2678
|
+
description: "Print the token as JSON on standard output"
|
|
2679
|
+
}]
|
|
2680
|
+
}
|
|
2681
|
+
},
|
|
2682
|
+
{
|
|
2683
|
+
name: "get_rules",
|
|
2684
|
+
title: "Read the brand rules",
|
|
2685
|
+
description: `Lists the brand rules (allowed uses, approved color pairs, logo restrictions) of a token or a group of tokens, or of the whole brand when no path is given. The whole brand can be larger than the size limit (${aa} characters): give a path, or read the resource blazon://rules, which is not cut.`,
|
|
2686
|
+
annotations: X,
|
|
2687
|
+
inputSchema: Z({
|
|
2688
|
+
path: {
|
|
2689
|
+
type: "string",
|
|
2690
|
+
maxLength: 200,
|
|
2691
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2692
|
+
description: "A token or group path, for example color.brand. Leave out for the whole brand"
|
|
2693
|
+
},
|
|
2694
|
+
dir: {
|
|
2695
|
+
type: "string",
|
|
2696
|
+
description: "The brand folder. Default: the current folder"
|
|
2697
|
+
}
|
|
2698
|
+
}, []),
|
|
2699
|
+
outputSchema: Q({
|
|
2700
|
+
kind: {
|
|
2701
|
+
description: "What the rules are for: one token, a group of tokens, or the whole brand",
|
|
2702
|
+
type: "string",
|
|
2703
|
+
enum: [
|
|
2704
|
+
"token",
|
|
2705
|
+
"group",
|
|
2706
|
+
"brand"
|
|
2707
|
+
]
|
|
2708
|
+
},
|
|
2709
|
+
path: {
|
|
2710
|
+
description: "The path the rules are for; empty for the whole brand",
|
|
2711
|
+
type: "string"
|
|
2712
|
+
},
|
|
2713
|
+
entries: {
|
|
2714
|
+
description: "The rules, each with the path it applies to (`at`) and what it says: usage, pairs or logo restrictions",
|
|
2715
|
+
type: "array",
|
|
2716
|
+
items: {}
|
|
2717
|
+
}
|
|
2718
|
+
}, []),
|
|
2719
|
+
cli: {
|
|
2720
|
+
rank: 3,
|
|
2721
|
+
command: ["rules"],
|
|
2722
|
+
positional: ["path", "dir"],
|
|
2723
|
+
cliOnly: ["dir"],
|
|
2724
|
+
folder: "path",
|
|
2725
|
+
summary: "Read the usage, pairs and logo rules of a token or a group, or of the whole brand when no path is given",
|
|
2726
|
+
options: [{
|
|
2727
|
+
property: "json",
|
|
2728
|
+
description: "Print the rules as JSON on standard output"
|
|
2729
|
+
}]
|
|
2730
|
+
}
|
|
2731
|
+
},
|
|
2732
|
+
{
|
|
2733
|
+
name: "can_use",
|
|
2734
|
+
title: "Can this color be used here",
|
|
2735
|
+
description: "Answers whether one color token may be text on another color token, by the brand rules. Set `role` to ui for a focus ring, border or icon stroke: it is judged against the 3:1 non-text contrast and the pairs rules do not apply. A denied answer is a normal result (`allowed` is false, `reason` names the rule), not an error. For a color you have not picked, find one with list_tokens and type color.",
|
|
2736
|
+
annotations: X,
|
|
2737
|
+
inputSchema: Z({
|
|
2738
|
+
fg: {
|
|
2739
|
+
type: "string",
|
|
2740
|
+
maxLength: 200,
|
|
2741
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2742
|
+
description: "The text color token path, for example text.primary"
|
|
2743
|
+
},
|
|
2744
|
+
bg: {
|
|
2745
|
+
type: "string",
|
|
2746
|
+
maxLength: 200,
|
|
2747
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2748
|
+
description: "The background color token path, for example surface.background"
|
|
2749
|
+
},
|
|
2750
|
+
role: {
|
|
2751
|
+
type: "string",
|
|
2752
|
+
enum: ["text", "ui"],
|
|
2753
|
+
default: "text",
|
|
2754
|
+
description: "What the first color is: text (default), judged by the usage, pairs and WCAG text rules, or ui for a focus ring, border or icon stroke, judged by the usage rules and the 3:1 non-text contrast"
|
|
2755
|
+
},
|
|
2756
|
+
theme: {
|
|
2757
|
+
type: "string",
|
|
2758
|
+
maxLength: 200,
|
|
2759
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*$",
|
|
2760
|
+
description: "Judge the pair in this context of the resolver's theme modifier, such as dark. Default: the default tokens"
|
|
2761
|
+
},
|
|
2762
|
+
dir: {
|
|
2763
|
+
type: "string",
|
|
2764
|
+
description: "The brand folder. Default: the current folder"
|
|
2765
|
+
}
|
|
2766
|
+
}, ["fg", "bg"]),
|
|
2767
|
+
outputSchema: Q({
|
|
2768
|
+
allowed: {
|
|
2769
|
+
type: "boolean",
|
|
2770
|
+
description: "True when the brand allows this text color on this background"
|
|
2771
|
+
},
|
|
2772
|
+
reason: {
|
|
2773
|
+
type: "string",
|
|
2774
|
+
description: "The rule that decided the answer"
|
|
2775
|
+
},
|
|
2776
|
+
fg: {
|
|
2777
|
+
description: "The text color token that was asked about",
|
|
2778
|
+
type: "string"
|
|
2779
|
+
},
|
|
2780
|
+
bg: {
|
|
2781
|
+
description: "The background color token that was asked about",
|
|
2782
|
+
type: "string"
|
|
2783
|
+
},
|
|
2784
|
+
role: {
|
|
2785
|
+
description: "What the first color was judged as: text or ui",
|
|
2786
|
+
type: "string",
|
|
2787
|
+
enum: ["text", "ui"]
|
|
2788
|
+
},
|
|
2789
|
+
theme: {
|
|
2790
|
+
description: "The theme context the pair was judged in; absent for the default tokens",
|
|
2791
|
+
type: "string"
|
|
2792
|
+
},
|
|
2793
|
+
contrast: {
|
|
2794
|
+
description: "The contrast ratio of the pair, the strictest WCAG level it meets, and for role ui the threshold it had to reach",
|
|
2795
|
+
type: "object"
|
|
2796
|
+
}
|
|
2797
|
+
}, ["allowed", "reason"]),
|
|
2798
|
+
cli: {
|
|
2799
|
+
rank: 4,
|
|
2800
|
+
command: ["can"],
|
|
2801
|
+
positional: [
|
|
2802
|
+
"fg",
|
|
2803
|
+
"bg",
|
|
2804
|
+
"dir"
|
|
2805
|
+
],
|
|
2806
|
+
cliOnly: ["dir"],
|
|
2807
|
+
summary: "Ask whether the foreground token may be text (or, with --role ui, a border or focus ring) on the background token, by the brand rules; exits 0 allowed, 1 denied, 2 unknown token",
|
|
2808
|
+
options: [
|
|
2809
|
+
{
|
|
2810
|
+
property: "role",
|
|
2811
|
+
value: "text|ui",
|
|
2812
|
+
description: "text (default) or ui: judge a non-text element by the 3:1 rule, with no pairs"
|
|
2813
|
+
},
|
|
2814
|
+
{
|
|
2815
|
+
property: "theme",
|
|
2816
|
+
value: "<name>",
|
|
2817
|
+
description: "judge the pair in this context of the resolver's theme modifier (such as dark); exits 2 for an unknown theme"
|
|
2818
|
+
},
|
|
2819
|
+
{
|
|
2820
|
+
property: "json",
|
|
2821
|
+
description: "Print the answer as JSON on standard output"
|
|
2822
|
+
}
|
|
2823
|
+
]
|
|
2824
|
+
},
|
|
2825
|
+
mcp: { answers: [1] }
|
|
2826
|
+
},
|
|
2827
|
+
{
|
|
2828
|
+
name: "get_fonts",
|
|
2829
|
+
title: "Read the brand fonts",
|
|
2830
|
+
description: "Gets the font stylesheets and font files the brand loads, and for each font family a token names whether the brand loads it. Use it to load the same fonts as the brand instead of typing a font address. For the family a token names, use get_token.",
|
|
2831
|
+
annotations: X,
|
|
2832
|
+
inputSchema: Z({
|
|
2833
|
+
dir: {
|
|
2834
|
+
type: "string",
|
|
2835
|
+
description: "The brand folder. Default: the current folder"
|
|
2836
|
+
},
|
|
2837
|
+
css: {
|
|
2838
|
+
type: "boolean",
|
|
2839
|
+
description: "Print the @font-face rules for the font files, and a comment for each stylesheet"
|
|
2840
|
+
},
|
|
2841
|
+
base: {
|
|
2842
|
+
type: "string",
|
|
2843
|
+
description: "With css: the URL prefix for each font file, in place of its path from the brand folder"
|
|
2844
|
+
}
|
|
2845
|
+
}, []),
|
|
2846
|
+
outputSchema: Q({
|
|
2847
|
+
stylesheets: {
|
|
2848
|
+
description: "Addresses of the font stylesheets to load",
|
|
2849
|
+
type: "array",
|
|
2850
|
+
items: { type: "string" }
|
|
2851
|
+
},
|
|
2852
|
+
files: {
|
|
2853
|
+
description: "Font files the brand ships. Empty when the fonts come from a stylesheet",
|
|
2854
|
+
type: "array",
|
|
2855
|
+
items: {}
|
|
2856
|
+
},
|
|
2857
|
+
families: {
|
|
2858
|
+
description: "Each font family a token names, with the tokens that name it and `loaded`, whether the brand loads it",
|
|
2859
|
+
type: "array",
|
|
2860
|
+
items: {}
|
|
2861
|
+
}
|
|
2862
|
+
}, []),
|
|
2863
|
+
cli: {
|
|
2864
|
+
rank: 5,
|
|
2865
|
+
command: ["fonts"],
|
|
2866
|
+
positional: ["dir"],
|
|
2867
|
+
cliOnly: [
|
|
2868
|
+
"dir",
|
|
2869
|
+
"css",
|
|
2870
|
+
"base"
|
|
2871
|
+
],
|
|
2872
|
+
summary: "Read the fonts the brand loads (stylesheets and font files) and the families its tokens name",
|
|
2873
|
+
options: [
|
|
2874
|
+
{
|
|
2875
|
+
property: "css",
|
|
2876
|
+
description: "Print the @font-face rules for the brand font files (and the stylesheet addresses as comments) instead of the listing"
|
|
2877
|
+
},
|
|
2878
|
+
{
|
|
2879
|
+
property: "base",
|
|
2880
|
+
value: "url-prefix",
|
|
2881
|
+
description: "With --css: serve the files from this prefix, such as /fonts/, instead of their path from the brand folder"
|
|
2882
|
+
},
|
|
2883
|
+
{
|
|
2884
|
+
property: "json",
|
|
2885
|
+
description: "Print the fonts as JSON on standard output"
|
|
2886
|
+
}
|
|
2887
|
+
]
|
|
2888
|
+
}
|
|
2889
|
+
},
|
|
2890
|
+
{
|
|
2891
|
+
name: "get_logo",
|
|
2892
|
+
title: "Read the brand logo",
|
|
2893
|
+
description: "Gets the brand logo variants for light and dark surfaces, their files, and the rules for each logo: clear space, minimum size, lockups, and the backgrounds that forbid it. Use it before placing a logo. For the brand's other rules use get_rules.",
|
|
2894
|
+
annotations: X,
|
|
2895
|
+
inputSchema: Z({ dir: {
|
|
2896
|
+
type: "string",
|
|
2897
|
+
description: "The brand folder. Default: the current folder"
|
|
2898
|
+
} }, []),
|
|
2899
|
+
outputSchema: Q({
|
|
2900
|
+
variants: {
|
|
2901
|
+
description: "The logo variants (onLight, onDark), each with its file and whether the file was found",
|
|
2902
|
+
type: "array",
|
|
2903
|
+
items: {}
|
|
2904
|
+
},
|
|
2905
|
+
assets: {
|
|
2906
|
+
description: "The logo assets, each with its id, file, the variants it serves and its rules: clear space, minimum size, lockups",
|
|
2907
|
+
type: "array",
|
|
2908
|
+
items: {}
|
|
2909
|
+
}
|
|
2910
|
+
}, []),
|
|
2911
|
+
cli: {
|
|
2912
|
+
rank: 6,
|
|
2913
|
+
command: ["logo"],
|
|
2914
|
+
positional: ["dir"],
|
|
2915
|
+
cliOnly: ["dir"],
|
|
2916
|
+
summary: "Read the configured logo variants and the rules each logo sidecar states: clear space, minimum size, lockups, ink",
|
|
2917
|
+
options: [{
|
|
2918
|
+
property: "json",
|
|
2919
|
+
description: "Print the logo as JSON on standard output"
|
|
2920
|
+
}]
|
|
2921
|
+
}
|
|
2922
|
+
},
|
|
2923
|
+
{
|
|
2924
|
+
name: "get_shadcn",
|
|
2925
|
+
title: "Read the shadcn/ui variables",
|
|
2926
|
+
description: "Gets the shadcn/ui variables the brand supplies (theme.shadcn): which token each variable takes, its value, and the variables nothing supplies. Use it when the site uses shadcn/ui. It compiles the brand when called, so it needs no build and is never out of date.",
|
|
2927
|
+
annotations: X,
|
|
2928
|
+
inputSchema: Z({}, []),
|
|
2929
|
+
outputSchema: Q({
|
|
2930
|
+
variables: {
|
|
2931
|
+
description: "Each shadcn variable the brand supplies, by name, with the token it takes, its value and where the pick came from",
|
|
2932
|
+
type: "object",
|
|
2933
|
+
propertyNames: { type: "string" },
|
|
2934
|
+
additionalProperties: {}
|
|
2935
|
+
},
|
|
2936
|
+
unsupplied: {
|
|
2937
|
+
description: "The shadcn variables nothing supplies. They are questions for the brand owner, not for a guess",
|
|
2938
|
+
type: "array",
|
|
2939
|
+
items: {}
|
|
2940
|
+
}
|
|
2941
|
+
}, []),
|
|
2942
|
+
cli: !1,
|
|
2943
|
+
mcp: {
|
|
2944
|
+
command: ["brand"],
|
|
2945
|
+
fixed: ["--key", "theme.shadcn"],
|
|
2946
|
+
json: !1
|
|
2947
|
+
}
|
|
2948
|
+
},
|
|
2949
|
+
{
|
|
2950
|
+
name: "get_brand",
|
|
2951
|
+
title: "Read the whole brand",
|
|
2952
|
+
description: "The brand as brand.json holds it, compiled now and written nowhere. It is the whole document, large for a real brand, so no tool serves it: the CLI prints it, and the resource blazon://brand carries it for an agent. `key` cuts it to one part.",
|
|
2953
|
+
annotations: X,
|
|
2954
|
+
inputSchema: Z({
|
|
2955
|
+
key: {
|
|
2956
|
+
type: "string",
|
|
2957
|
+
description: "Only this part of the document, by its dotted path, such as theme.shadcn"
|
|
2958
|
+
},
|
|
2959
|
+
dir: oa
|
|
2960
|
+
}, []),
|
|
2961
|
+
cli: {
|
|
2962
|
+
rank: 7,
|
|
2963
|
+
command: ["brand"],
|
|
2964
|
+
positional: ["dir"],
|
|
2965
|
+
cliOnly: ["dir"],
|
|
2966
|
+
summary: "Print the brand as brand.json holds it, compiled now and written nowhere; --key prints one part",
|
|
2967
|
+
options: [{
|
|
2968
|
+
property: "key",
|
|
2969
|
+
value: "path",
|
|
2970
|
+
description: "Print only this part of the document, by its dotted path, such as theme.shadcn"
|
|
2971
|
+
}]
|
|
2972
|
+
},
|
|
2973
|
+
mcp: !1
|
|
2974
|
+
}
|
|
2975
|
+
], la = (e) => e.filter((e) => e.mcp !== !1), ua = (e) => e.filter((e) => e.cli !== !1).sort((e, t) => e.cli.rank - t.cli.rank);
|
|
2976
|
+
// src/cli/handlers/rules.ts
|
|
2977
|
+
function da(e) {
|
|
2978
|
+
let t = (e) => n.dim(`(on ${e})`);
|
|
2979
|
+
return [
|
|
2980
|
+
...e.role ? [`role ${e.role.value} ${t(e.role.from)}`] : [],
|
|
2981
|
+
...e.usage ? [`usage ${[e.usage.deny && `deny ${e.usage.deny.join(", ")}`, e.usage.allow && `allow ${e.usage.allow.join(", ")}`].filter(Boolean).join("; ")} ${t(e.usage.from)}`] : [],
|
|
2982
|
+
...e.pairs.map((e) => `pair ${e.fg} on ${e.bg}, ${e.min}, this token is the ${e.as === "fg" ? "text" : "background"} ${t(e.from)}`),
|
|
2983
|
+
...e.logo ? [`logo deny ${e.logo.deny.join(", ")}${e.logo.reason ? `: ${e.logo.reason}` : ""} ${t(e.logo.from)}`] : [],
|
|
2984
|
+
...e.review ? [`review ${e.review.status}${e.review.by ? ` by ${e.review.by}` : ""}${e.review.at ? ` on ${e.review.at}` : ""} ${t(e.review.from)}`] : []
|
|
2985
|
+
];
|
|
2986
|
+
}
|
|
2987
|
+
function fa(e) {
|
|
2988
|
+
return [
|
|
2989
|
+
...e.role ? [`role ${e.role}`] : [],
|
|
2990
|
+
...e.usage ? [`usage ${[e.usage.deny && `deny ${e.usage.deny.join(", ")}`, e.usage.allow && `allow ${e.usage.allow.join(", ")}`].filter(Boolean).join("; ")}`] : [],
|
|
2991
|
+
...(e.pairs ?? []).map((e) => `pair ${e.fg} on ${e.bg}, ${e.min}`),
|
|
2992
|
+
...e.logo ? [`logo deny ${e.logo.deny.join(", ")}${e.logo.reason ? `: ${e.logo.reason}` : ""}`] : []
|
|
2993
|
+
];
|
|
2994
|
+
}
|
|
2995
|
+
var pa = async ({ path: e }, { dir: t }) => {
|
|
2996
|
+
let { data: r } = await J(t), i = pi(e ?? ""), a = i !== "" && r.tokens.byPath.has(i), o = Wi(() => a ? {
|
|
2997
|
+
path: i,
|
|
2998
|
+
kind: "token",
|
|
2999
|
+
rules: Si(r, mi(r, i))
|
|
3000
|
+
} : {
|
|
3001
|
+
path: i,
|
|
3002
|
+
kind: i === "" ? "brand" : "group",
|
|
3003
|
+
entries: wi(r, i)
|
|
3004
|
+
});
|
|
3005
|
+
return {
|
|
3006
|
+
command: "rules",
|
|
3007
|
+
passed: !0,
|
|
3008
|
+
status: 0,
|
|
3009
|
+
body: o,
|
|
3010
|
+
text: () => {
|
|
3011
|
+
if (console.log(), o.kind === "token") {
|
|
3012
|
+
let e = da(o.rules);
|
|
3013
|
+
console.log(` ${n.bold(o.path)}`), e.length === 0 && console.log(n.dim(" no rules apply to this token"));
|
|
3014
|
+
for (let t of e) console.log(` ${t}`);
|
|
3015
|
+
} else {
|
|
3016
|
+
o.entries.length === 0 && console.log(n.dim(` No rules are written ${i === "" ? "in this brand" : `at or under ${i}`}.`));
|
|
3017
|
+
for (let e of o.entries) {
|
|
3018
|
+
console.log(` ${n.bold(e.at)} ${n.dim(e.kind === "group" ? "group" : "token")}${e.inherited ? n.dim(", passes its rules down") : ""}`);
|
|
3019
|
+
for (let t of fa(e)) console.log(` ${t}`);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
console.log();
|
|
3023
|
+
}
|
|
3024
|
+
};
|
|
3025
|
+
}, ma = async ({ path: e }, { dir: t }) => {
|
|
3026
|
+
let { data: n } = await J(t);
|
|
3027
|
+
if (Oi(n, String(e))) throw new M(`"${String(e)}" is a group of tokens, not one token; \`blazon list ${String(e)}\` lists its tokens.`, void 0, "not-a-token");
|
|
3028
|
+
let r = Wi(() => Ei(n, String(e)));
|
|
3029
|
+
return {
|
|
3030
|
+
command: "get",
|
|
3031
|
+
passed: !0,
|
|
3032
|
+
status: 0,
|
|
3033
|
+
body: { token: r },
|
|
3034
|
+
text: () => ha(r)
|
|
3035
|
+
};
|
|
3036
|
+
};
|
|
3037
|
+
function ha(e) {
|
|
3038
|
+
let { names: t } = e;
|
|
3039
|
+
console.log(`\n ${n.bold(e.path)}${e.deprecated ? n.yellow(" deprecated") : ""}`), Gi([
|
|
3040
|
+
["value", String(e.value)],
|
|
3041
|
+
["type", e.type],
|
|
3042
|
+
["alias of", e.aliasOf && `{${e.aliasOf}}`],
|
|
3043
|
+
["tier", e.tier],
|
|
3044
|
+
["about", e.description],
|
|
3045
|
+
["theme.css", [t.theme.variable, ...Object.values(t.theme.parts ?? {})].join(", ")],
|
|
3046
|
+
["tailwind.css", t.tailwind ? `${t.tailwind.variable}${t.tailwind.shadowedBy ? ` (taken by {${t.tailwind.shadowedBy}}, which is written first)` : ""}` : "none: no Tailwind namespace for this token"],
|
|
3047
|
+
["typography.css", t.typographyClass && `.${t.typographyClass}`],
|
|
3048
|
+
["written in", e.sourceFile]
|
|
3049
|
+
]);
|
|
3050
|
+
for (let t of e.contexts ?? []) console.log(` ${n.dim(`${t.modifier}=${t.context}`.padEnd(12))} ${String(t.value)} ${n.dim(t.selector)}`);
|
|
3051
|
+
let r = da(e.rules);
|
|
3052
|
+
console.log(`\n ${n.bold("Rules")}`), r.length === 0 && console.log(n.dim(" none written for this token"));
|
|
3053
|
+
for (let e of r) console.log(` ${e}`);
|
|
3054
|
+
console.log();
|
|
3055
|
+
}
|
|
3056
|
+
// src/cli/handlers/list.ts
|
|
3057
|
+
var ga = async ({ group: e, type: t }, { dir: n }) => {
|
|
3058
|
+
let { data: r } = await J(n), i = Wi(() => ki(r, {
|
|
3059
|
+
group: e,
|
|
3060
|
+
type: t
|
|
3061
|
+
}));
|
|
3062
|
+
return {
|
|
3063
|
+
command: "list",
|
|
3064
|
+
passed: !0,
|
|
3065
|
+
status: 0,
|
|
3066
|
+
body: {
|
|
3067
|
+
...i.group !== void 0 && { group: i.group },
|
|
3068
|
+
...i.type && { type: i.type },
|
|
3069
|
+
tokens: i.tokens
|
|
3070
|
+
},
|
|
3071
|
+
text: () => _a(i)
|
|
3072
|
+
};
|
|
3073
|
+
};
|
|
3074
|
+
function _a(e) {
|
|
3075
|
+
if (e.tokens.length === 0) return console.log(n.dim(`\n no tokens${e.type ? ` of type ${e.type}` : ""}${e.group ? ` in ${e.group}` : ""}\n`));
|
|
3076
|
+
let t = Math.max(...e.tokens.map((e) => e.path.length)), r = Math.max(...e.tokens.map((e) => (e.type ?? "").length)), i;
|
|
3077
|
+
for (let a of e.tokens) {
|
|
3078
|
+
let e = a.path.split(".")[0];
|
|
3079
|
+
e !== i && console.log(`\n ${n.dim(e)}`), i = e;
|
|
3080
|
+
let o = a.aliasOf ? ` ${n.dim(`-> ${a.aliasOf}`)}` : "";
|
|
3081
|
+
console.log(` ${a.path.padEnd(t)} ${n.dim((a.type ?? "").padEnd(r))} ${String(a.value)}${o}`);
|
|
3082
|
+
}
|
|
3083
|
+
console.log(`\n ${n.dim(`${e.tokens.length} token${e.tokens.length === 1 ? "" : "s"}; blazon get <path> shows one in full`)}\n`);
|
|
3084
|
+
}
|
|
3085
|
+
// src/cli/handlers/can.ts
|
|
3086
|
+
var va = async ({ fg: e, bg: t, role: n, theme: r }, { dir: i }) => {
|
|
3087
|
+
let { data: a } = await J(i), o = Wi(() => Bi(a, e, t, n ?? "text", r));
|
|
3088
|
+
return {
|
|
3089
|
+
command: "can",
|
|
3090
|
+
passed: o.allowed,
|
|
3091
|
+
status: +!o.allowed,
|
|
3092
|
+
body: o,
|
|
3093
|
+
text: () => ya(o)
|
|
3094
|
+
};
|
|
3095
|
+
};
|
|
3096
|
+
function ya(e) {
|
|
3097
|
+
if (console.log(`\n ${e.allowed ? n.green("allowed") : n.red("denied")} ${e.fg} as ${e.role === "ui" ? "a non-text element (--role ui)" : "text"} on ${e.bg}${e.theme ? ` (theme ${e.theme})` : ""}`), console.log(` ${e.reason}`), e.checks.length > 1) {
|
|
3098
|
+
console.log();
|
|
3099
|
+
for (let t of e.checks) console.log(` ${t.rule === "contrast" && e.role === "text" ? n.dim("info") : t.ok ? n.green("ok ") : n.red("no ")} ${t.message}`);
|
|
3100
|
+
}
|
|
3101
|
+
console.log();
|
|
3102
|
+
}
|
|
3103
|
+
// src/cli/handlers/fonts.ts
|
|
3104
|
+
var ba = async (e, { dir: t }) => {
|
|
3105
|
+
let { config: n, data: r } = await J(t), i = Vi(r, n, t);
|
|
3106
|
+
if (e.css === !0 || typeof e.base == "string") {
|
|
3107
|
+
if (e.css !== !0) throw new M("blazon fonts: --base goes with --css.", "Add --css, or leave --base out.", "conflicting-options");
|
|
3108
|
+
let t = Hi(i, typeof e.base == "string" ? e.base : void 0);
|
|
3109
|
+
return {
|
|
3110
|
+
command: "fonts",
|
|
3111
|
+
passed: !0,
|
|
3112
|
+
status: 0,
|
|
3113
|
+
body: {
|
|
3114
|
+
...i,
|
|
3115
|
+
fontFace: t
|
|
3116
|
+
},
|
|
3117
|
+
text: () => process.stdout.write(t)
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
return {
|
|
3121
|
+
command: "fonts",
|
|
3122
|
+
passed: !0,
|
|
3123
|
+
status: 0,
|
|
3124
|
+
body: i,
|
|
3125
|
+
text: () => xa(i)
|
|
3126
|
+
};
|
|
3127
|
+
};
|
|
3128
|
+
function xa(e) {
|
|
3129
|
+
console.log(`\n ${n.bold("Loaded")}`), e.stylesheets.length + e.files.length === 0 && console.log(n.dim(" The config lists no fonts."));
|
|
3130
|
+
for (let t of e.stylesheets) console.log(` stylesheet ${t}`);
|
|
3131
|
+
for (let t of e.files) console.log(` file ${t.file} ${t.family}${t.weight === void 0 ? "" : `, weight ${t.weight}`}${t.style ? `, ${t.style}` : ""}`);
|
|
3132
|
+
console.log(`\n ${n.bold("Named by the tokens")}`);
|
|
3133
|
+
for (let [t, r] of Object.entries(e.roles)) console.log(` ${n.dim(t.padEnd(11))} ${r.token ?? ""} ${r.value ?? ""}`);
|
|
3134
|
+
for (let t of e.families) {
|
|
3135
|
+
let e = t.system ? "system font" : t.loaded === !0 ? "loaded" : t.loaded === null ? "maybe loaded by a stylesheet blazon cannot read" : t.webFont === void 0 ? "not loaded" : "not loaded, as the token says";
|
|
3136
|
+
console.log(` ${t.family} ${n.dim(`${e}; ${t.tokens.join(", ")}`)}`), t.stack && t.stack.length > 1 && console.log(n.dim(` stack: ${t.stack.join(", ")}`));
|
|
3137
|
+
}
|
|
3138
|
+
console.log();
|
|
3139
|
+
}
|
|
3140
|
+
// src/cli/handlers/logo.ts
|
|
3141
|
+
var $ = (e) => {
|
|
3142
|
+
if (typeof e != "object" || !e) return String(e);
|
|
3143
|
+
let t = e;
|
|
3144
|
+
return t.units === void 0 ? t.value === void 0 ? [t.width !== void 0 && `width ${$(t.width)}`, t.height !== void 0 && `height ${$(t.height)}`].filter(Boolean).join(", ") : `${t.value}${t.unit}` : `${t.units} unit${t.units === 1 ? "" : "s"}`;
|
|
3145
|
+
}, Sa = async (e, { dir: t }) => {
|
|
3146
|
+
let { config: n, data: r } = await J(t), i = Ui(r, n, t);
|
|
3147
|
+
return {
|
|
3148
|
+
command: "logo",
|
|
3149
|
+
passed: !0,
|
|
3150
|
+
status: 0,
|
|
3151
|
+
body: i,
|
|
3152
|
+
text: () => Ca(i)
|
|
3153
|
+
};
|
|
3154
|
+
};
|
|
3155
|
+
function Ca(e) {
|
|
3156
|
+
console.log(`\n ${n.bold("Variants")}`), e.variants.length === 0 && console.log(n.dim(" No logo is configured."));
|
|
3157
|
+
for (let t of e.variants) console.log(` ${t.variant.padEnd(8)} ${t.file}${t.found ? "" : n.red(" (not found)")}${t.ink ? ` ink ${t.ink}` : ""}${t.asset ? n.dim(` ${t.asset}`) : ""}`);
|
|
3158
|
+
for (let t of e.assets) {
|
|
3159
|
+
let e = t.rules;
|
|
3160
|
+
console.log(`\n ${n.bold(t.id)} ${t.file}${t.variants.length ? n.dim(` used as ${t.variants.join(", ")}`) : ""}`);
|
|
3161
|
+
let r = [
|
|
3162
|
+
["lockup", e.lockup],
|
|
3163
|
+
["ink", e.ink],
|
|
3164
|
+
["background", e.background],
|
|
3165
|
+
["unit", e.unit && $(e.unit)],
|
|
3166
|
+
["clear space", e.clearSpace && $(e.clearSpace)],
|
|
3167
|
+
["min size", e.minSize && $(e.minSize)],
|
|
3168
|
+
["max size", e.maxSize && $(e.maxSize)],
|
|
3169
|
+
["below that", e.replacedBelow && `${$(e.replacedBelow)}: use ${e.replacedBelow.by}`],
|
|
3170
|
+
["placement", e.placement?.join(", ")],
|
|
3171
|
+
["partnership", e.partnership && `gap ${$(e.partnership.gap)}${e.partnership.dividerHeight ? `, divider ${$(e.partnership.dividerHeight)}` : ""}`],
|
|
3172
|
+
["initiative", e.initiative && `${e.initiative.name}, mark ${e.initiative.mark}, gap ${$(e.initiative.gap)}, ${e.initiative.position ?? "beside"}`]
|
|
3173
|
+
];
|
|
3174
|
+
for (let [e, t] of r) t !== void 0 && console.log(` ${n.dim(e.padEnd(12))} ${t}`);
|
|
3175
|
+
for (let t of e.do ?? []) console.log(` ${n.dim("do")} ${t}`);
|
|
3176
|
+
for (let t of e.dont ?? []) console.log(` ${n.dim("do not")} ${t}`);
|
|
3177
|
+
}
|
|
3178
|
+
if (e.forbidden.length > 0) {
|
|
3179
|
+
console.log(`\n ${n.bold("Forbidden on")}`);
|
|
3180
|
+
for (let t of e.forbidden) console.log(` ${t.at} ${t.deny.join(", ")}${t.reason ? ` ${n.dim(t.reason)}` : ""}`);
|
|
3181
|
+
}
|
|
3182
|
+
console.log();
|
|
3183
|
+
}
|
|
3184
|
+
// src/cli/handlers/brand.ts
|
|
3185
|
+
function wa(e, t) {
|
|
3186
|
+
let n = e;
|
|
3187
|
+
for (let e of t.split(".")) {
|
|
3188
|
+
if (typeof n != "object" || !n || !Object.prototype.hasOwnProperty.call(n, e)) return;
|
|
3189
|
+
n = n[e];
|
|
3190
|
+
}
|
|
3191
|
+
return n;
|
|
3192
|
+
}
|
|
3193
|
+
// src/cli/handlers/index.ts
|
|
3194
|
+
var Ta = {
|
|
3195
|
+
get_token: ma,
|
|
3196
|
+
list_tokens: ga,
|
|
3197
|
+
get_rules: pa,
|
|
3198
|
+
can_use: va,
|
|
3199
|
+
get_fonts: ba,
|
|
3200
|
+
get_logo: Sa,
|
|
3201
|
+
get_brand: async ({ key: e }, { dir: t }) => {
|
|
3202
|
+
let { config: n, data: r } = await J(t), i = ze(r, n, t), a = e === void 0 ? i : wa(i, e);
|
|
3203
|
+
if (a === void 0) throw new M(`brand.json has no "${String(e)}". Run blazon brand without --key to see the keys.`, void 0, "unknown-key");
|
|
3204
|
+
return {
|
|
3205
|
+
command: "brand",
|
|
3206
|
+
passed: !0,
|
|
3207
|
+
status: 0,
|
|
3208
|
+
body: {},
|
|
3209
|
+
text: () => void process.stdout.write(`${JSON.stringify(a, null, 2)}\n`)
|
|
3210
|
+
};
|
|
3211
|
+
}
|
|
3212
|
+
}, Ea = (e) => e.cli, Da = (e) => e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), Oa = ua(ca).filter((e) => Ea(e).options.some((e) => e.property === "json")).map((e) => Ea(e).command[0]);
|
|
3213
|
+
function ka(e) {
|
|
3214
|
+
let t = Ea(e), n = new Set(e.inputSchema.required ?? []);
|
|
3215
|
+
return [...t.command, ...t.positional.map((e) => n.has(e) ? `<${e}>` : `[${e}]`)].join(" ");
|
|
3216
|
+
}
|
|
3217
|
+
function Aa(e, t) {
|
|
3218
|
+
return t.property === "json" ? "--json" : e.inputSchema.properties[t.property]?.type === "boolean" ? `--${Da(t.property)}` : `--${Da(t.property)} <${t.value ?? Da(t.property)}>`;
|
|
3219
|
+
}
|
|
3220
|
+
var ja = (e) => typeof e == "string" && /^\.|[\\/]/.test(e) && !!k.statSync(e, { throwIfNoEntry: !1 })?.isDirectory();
|
|
3221
|
+
function Ma(e, t) {
|
|
3222
|
+
for (let n of ua(ca)) {
|
|
3223
|
+
let r = Ea(n), i = Ta[n.name];
|
|
3224
|
+
if (!i) throw Error(`operation ${n.name} has a command and no handler`);
|
|
3225
|
+
let a = e.command(ka(n), r.summary);
|
|
3226
|
+
for (let e of r.options) a.option(Aa(n, e), e.description);
|
|
3227
|
+
a.action(async (...e) => {
|
|
3228
|
+
let n = e.pop() ?? {};
|
|
3229
|
+
try {
|
|
3230
|
+
let t = {};
|
|
3231
|
+
r.positional.forEach((n, r) => t[n] = e[r]);
|
|
3232
|
+
for (let e of r.options) e.property !== "json" && (t[e.property] = n[e.property]);
|
|
3233
|
+
let a = t.dir;
|
|
3234
|
+
r.folder !== void 0 && a === void 0 && ja(t[r.folder]) && (a = t[r.folder], t[r.folder] = void 0), delete t.dir;
|
|
3235
|
+
let o = await i(t, { dir: a ? String(a) : process.cwd() });
|
|
3236
|
+
n.json ? Y(o.command, o.passed, o.body) : o.text(), process.exitCode = o.status;
|
|
3237
|
+
} catch (e) {
|
|
3238
|
+
P(r.command.join(" "), e, t);
|
|
3239
|
+
}
|
|
3240
|
+
});
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
// src/cli/commands/mcp-check.ts
|
|
3244
|
+
var Na = 3e4, Pa = "This check starts blazon-mcp on the brand folder. The server runs blazon with no plugin and a limited environment, and reads the brand files as data. What the brand says reaches your agent as tool results, so check only a brand folder you trust.", Fa = "npm ci && npm run build -w mcp", Ia = () => la(ca).map((e) => e.name);
|
|
3245
|
+
function La(e) {
|
|
3246
|
+
let t = O.join(e, "mcp/dist/index.js");
|
|
3247
|
+
return k.existsSync(t) ? {
|
|
3248
|
+
name: "built",
|
|
3249
|
+
passed: !0,
|
|
3250
|
+
detail: `${t} exists`,
|
|
3251
|
+
entry: t
|
|
3252
|
+
} : {
|
|
3253
|
+
name: "built",
|
|
3254
|
+
passed: !1,
|
|
3255
|
+
detail: `${t} does not exist: blazon-mcp is not built`,
|
|
3256
|
+
fix: `cd ${e} && ${Fa}`,
|
|
3257
|
+
entry: t
|
|
3258
|
+
};
|
|
3259
|
+
}
|
|
3260
|
+
var Ra = (e) => {
|
|
3261
|
+
try {
|
|
3262
|
+
return k.statSync(e).isFile() ? (k.accessSync(e, k.constants.X_OK), !0) : !1;
|
|
3263
|
+
} catch {
|
|
3264
|
+
return !1;
|
|
3265
|
+
}
|
|
3266
|
+
};
|
|
3267
|
+
function za(e, t) {
|
|
3268
|
+
let n = (t.PATH ?? "").split(O.delimiter).filter(Boolean), r = process.platform === "win32" ? ["", ...(t.PATHEXT ?? ".EXE;.CMD").split(";")].map((t) => e + t) : [e];
|
|
3269
|
+
for (let e of n) for (let t of r) if (Ra(O.join(e, t))) return O.join(e, t);
|
|
3270
|
+
}
|
|
3271
|
+
function Ba(e, t, n) {
|
|
3272
|
+
let r = O.join(n, "bin/blazon.js"), i = k.existsSync(r) ? k.existsSync(O.join(n, "dist/cli/index.js")) ? `export BLAZON_BIN=${r}` : `cd ${n} && npm run build && export BLAZON_BIN=${r}` : "put the blazon program on PATH, or export BLAZON_BIN=<path to the blazon executable>", a = e.BLAZON_BIN;
|
|
3273
|
+
if (a) {
|
|
3274
|
+
let n = a.includes("/") || a.includes(O.sep) ? O.resolve(t, a) : za(a, e);
|
|
3275
|
+
return n && Ra(n) ? {
|
|
3276
|
+
name: "blazon",
|
|
3277
|
+
passed: !0,
|
|
3278
|
+
detail: `BLAZON_BIN names ${n}`,
|
|
3279
|
+
source: "BLAZON_BIN",
|
|
3280
|
+
path: n
|
|
3281
|
+
} : {
|
|
3282
|
+
name: "blazon",
|
|
3283
|
+
passed: !1,
|
|
3284
|
+
detail: `BLAZON_BIN is set to "${a}", which is not an executable file`,
|
|
3285
|
+
fix: i,
|
|
3286
|
+
source: "BLAZON_BIN"
|
|
3287
|
+
};
|
|
3288
|
+
}
|
|
3289
|
+
let o = za("blazon", e);
|
|
3290
|
+
return o ? {
|
|
3291
|
+
name: "blazon",
|
|
3292
|
+
passed: !0,
|
|
3293
|
+
detail: `blazon found on PATH at ${o}`,
|
|
3294
|
+
source: "PATH",
|
|
3295
|
+
path: o
|
|
3296
|
+
} : {
|
|
3297
|
+
name: "blazon",
|
|
3298
|
+
passed: !1,
|
|
3299
|
+
detail: "BLAZON_BIN is not set and no blazon program is on PATH",
|
|
3300
|
+
fix: i,
|
|
3301
|
+
source: "none"
|
|
3302
|
+
};
|
|
3303
|
+
}
|
|
3304
|
+
var Va = (e, t = 200) => {
|
|
3305
|
+
let n = e.trim().split("\n").find((e) => e.trim() !== "") ?? "";
|
|
3306
|
+
return n.length > t ? `${n.slice(0, t)}...` : n;
|
|
3307
|
+
};
|
|
3308
|
+
async function Ha(e) {
|
|
3309
|
+
let { entry: t, brand: n, env: r = process.env, timeoutMs: i = Na, expect: a = Ia() } = e, o = process.platform !== "win32", s = Xe(process.execPath, [
|
|
3310
|
+
t,
|
|
3311
|
+
"--brand",
|
|
3312
|
+
n
|
|
3313
|
+
], {
|
|
3314
|
+
stdio: [
|
|
3315
|
+
"pipe",
|
|
3316
|
+
"pipe",
|
|
3317
|
+
"pipe"
|
|
3318
|
+
],
|
|
3319
|
+
env: r,
|
|
3320
|
+
detached: o
|
|
3321
|
+
}), c = "";
|
|
3322
|
+
s.stderr.on("data", (e) => {
|
|
3323
|
+
c.length < 4e3 && (c += e.toString());
|
|
3324
|
+
});
|
|
3325
|
+
let l = new Promise((e) => s.once("close", () => e())), u = new Promise((e, t) => s.once("error", (e) => t(/* @__PURE__ */ Error(`cannot start ${process.execPath}: ${e.message}`)))), d = /* @__PURE__ */ new Map(), f = "";
|
|
3326
|
+
s.stdout.on("data", (e) => {
|
|
3327
|
+
f += e.toString();
|
|
3328
|
+
let t;
|
|
3329
|
+
for (; (t = f.indexOf("\n")) >= 0;) {
|
|
3330
|
+
let e = f.slice(0, t).trim();
|
|
3331
|
+
if (f = f.slice(t + 1), e) try {
|
|
3332
|
+
let t = JSON.parse(e);
|
|
3333
|
+
t.id !== void 0 && d.get(t.id)?.(t);
|
|
3334
|
+
} catch {}
|
|
3335
|
+
}
|
|
3336
|
+
}), s.stdin.on("error", () => void 0);
|
|
3337
|
+
let p = !1, m, h = new Promise((e, t) => {
|
|
3338
|
+
m = setTimeout(() => {
|
|
3339
|
+
p = !0, t(/* @__PURE__ */ Error(`no answer within ${i / 1e3} s`));
|
|
3340
|
+
}, i);
|
|
3341
|
+
}), g = new Promise((e, t) => s.once("close", (e) => t(/* @__PURE__ */ Error(`the server exited (${e ?? "signal"}) before it answered${c ? `: ${Va(c)}` : ""}`))));
|
|
3342
|
+
g.catch(() => void 0), h.catch(() => void 0), u.catch(() => void 0);
|
|
3343
|
+
let _ = 0, v = (e, t) => {
|
|
3344
|
+
let n = ++_, r = new Promise((e) => d.set(n, e));
|
|
3345
|
+
return s.stdin.write(`${JSON.stringify({
|
|
3346
|
+
jsonrpc: "2.0",
|
|
3347
|
+
id: n,
|
|
3348
|
+
method: e,
|
|
3349
|
+
params: t
|
|
3350
|
+
})}\n`), Promise.race([
|
|
3351
|
+
r,
|
|
3352
|
+
h,
|
|
3353
|
+
g,
|
|
3354
|
+
u
|
|
3355
|
+
]);
|
|
3356
|
+
}, y = Date.now();
|
|
3357
|
+
try {
|
|
3358
|
+
let e = await v("initialize", {
|
|
3359
|
+
protocolVersion: "2025-06-18",
|
|
3360
|
+
capabilities: {},
|
|
3361
|
+
clientInfo: {
|
|
3362
|
+
name: "blazon-mcp-check",
|
|
3363
|
+
version: "0"
|
|
3364
|
+
}
|
|
3365
|
+
});
|
|
3366
|
+
if (e.error) throw Error(`initialize was refused: ${Va(e.error.message ?? "")}`);
|
|
3367
|
+
s.stdin.write(`${JSON.stringify({
|
|
3368
|
+
jsonrpc: "2.0",
|
|
3369
|
+
method: "notifications/initialized"
|
|
3370
|
+
})}\n`);
|
|
3371
|
+
let t = await v("tools/list", {}), n = (t.result?.tools ?? []).map((e) => e.name), r = a.filter((e) => !n.includes(e));
|
|
3372
|
+
if (t.error || r.length > 0) return {
|
|
3373
|
+
name: "handshake",
|
|
3374
|
+
passed: !1,
|
|
3375
|
+
detail: t.error ? `tools/list failed: ${Va(t.error.message ?? "")}` : `tools/list answered ${n.length} tool(s); missing ${r.join(", ")}`,
|
|
3376
|
+
fix: `cd ${He()} && ${Fa} (the build is older than this blazon), then run this check again`,
|
|
3377
|
+
tools: n
|
|
3378
|
+
};
|
|
3379
|
+
let i = Date.now(), o = await v("tools/call", {
|
|
3380
|
+
name: "check_brand",
|
|
3381
|
+
arguments: { limit: 1 }
|
|
3382
|
+
}), c = Date.now() - i, l = o.result?.content?.find((e) => e.text)?.text ?? "";
|
|
3383
|
+
if (o.error || o.result?.isError) return {
|
|
3384
|
+
name: "handshake",
|
|
3385
|
+
passed: !1,
|
|
3386
|
+
detail: `check_brand failed: ${Va(o.error?.message ?? l)}`,
|
|
3387
|
+
fix: "run blazon check in the brand folder, and make sure the blazon program and the brand folder are the ones the server uses",
|
|
3388
|
+
tools: n,
|
|
3389
|
+
ms: c
|
|
3390
|
+
};
|
|
3391
|
+
let u = o.result?.structuredContent?.passed;
|
|
3392
|
+
return {
|
|
3393
|
+
name: "handshake",
|
|
3394
|
+
passed: !0,
|
|
3395
|
+
detail: `initialize and tools/list answered (${n.length} tools); check_brand answered in ${(c / 1e3).toFixed(1)} s${u === !1 ? " (the brand itself has errors: run blazon check)" : ""}`,
|
|
3396
|
+
tools: n,
|
|
3397
|
+
ms: c,
|
|
3398
|
+
...u !== void 0 && { brandPassed: u }
|
|
3399
|
+
};
|
|
3400
|
+
} catch (e) {
|
|
3401
|
+
return {
|
|
3402
|
+
name: "handshake",
|
|
3403
|
+
passed: !1,
|
|
3404
|
+
detail: `the handshake did not finish: ${e instanceof Error ? e.message : String(e)}${p ? "; the server was killed" : ""}`,
|
|
3405
|
+
fix: `cd ${He()} && ${Fa}, then run this check again; on a hang, run the server by hand: node ${t} --brand ${n}`,
|
|
3406
|
+
ms: Date.now() - y
|
|
3407
|
+
};
|
|
3408
|
+
} finally {
|
|
3409
|
+
clearTimeout(m), await Ua(s, l, o);
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
async function Ua(e, t, n) {
|
|
3413
|
+
let r = (t) => {
|
|
3414
|
+
try {
|
|
3415
|
+
n && e.pid !== void 0 ? process.kill(-e.pid, t) : e.kill(t);
|
|
3416
|
+
} catch {}
|
|
3417
|
+
};
|
|
3418
|
+
if (e.stdin?.end(), e.exitCode !== null || e.signalCode !== null) {
|
|
3419
|
+
r("SIGKILL");
|
|
3420
|
+
return;
|
|
3421
|
+
}
|
|
3422
|
+
r("SIGTERM");
|
|
3423
|
+
let i;
|
|
3424
|
+
await Promise.race([t, new Promise((e) => i = setTimeout(e, 2e3))]), clearTimeout(i), e.exitCode === null && e.signalCode === null ? (r("SIGKILL"), await t) : r("SIGKILL");
|
|
3425
|
+
}
|
|
3426
|
+
function Wa(e, t, n, r = Ze.homedir()) {
|
|
3427
|
+
let i = Ve(e, t, r, process.platform, process.env.APPDATA), a = [], o = [], s = [];
|
|
3428
|
+
for (let e of i) {
|
|
3429
|
+
let t;
|
|
3430
|
+
try {
|
|
3431
|
+
t = k.readFileSync(e.path, "utf8");
|
|
3432
|
+
} catch {
|
|
3433
|
+
continue;
|
|
3434
|
+
}
|
|
3435
|
+
let n = he(t, e);
|
|
3436
|
+
n === void 0 ? s.push(e.path) : (o.push(e.path), n.includes("blazon") && a.push(e.path));
|
|
3437
|
+
}
|
|
3438
|
+
let c = s.length > 0 ? ` (not valid JSON, skipped: ${s.join(", ")})` : "", l = `blazon mcp --print-config --client ${e} --brand ${n}`;
|
|
3439
|
+
return a.length > 0 ? {
|
|
3440
|
+
name: "registered",
|
|
3441
|
+
passed: !0,
|
|
3442
|
+
advisory: !0,
|
|
3443
|
+
client: e,
|
|
3444
|
+
detail: `${e} has a server named blazon in ${a.join(", ")}${c}`,
|
|
3445
|
+
files: a
|
|
3446
|
+
} : {
|
|
3447
|
+
name: "registered",
|
|
3448
|
+
passed: !1,
|
|
3449
|
+
advisory: !0,
|
|
3450
|
+
client: e,
|
|
3451
|
+
detail: `no server named blazon in ${e}'s config; looked in ${o.length > 0 ? o.join(", ") : "no file that exists"}${c}`,
|
|
3452
|
+
fix: l,
|
|
3453
|
+
files: []
|
|
3454
|
+
};
|
|
3455
|
+
}
|
|
3456
|
+
async function Ga(e) {
|
|
3457
|
+
let { client: t, brand: r, env: i = process.env, cwd: a = process.cwd(), home: o = Ze.homedir() } = e, s = He(), c = La(s), l = Ba(i, r, s), u = c.passed ? await Ha({
|
|
3458
|
+
entry: c.entry,
|
|
3459
|
+
brand: r,
|
|
3460
|
+
env: i,
|
|
3461
|
+
...e.timeoutMs !== void 0 && { timeoutMs: e.timeoutMs }
|
|
3462
|
+
}) : {
|
|
3463
|
+
name: "handshake",
|
|
3464
|
+
passed: !1,
|
|
3465
|
+
detail: "not run: the server is not built",
|
|
3466
|
+
fix: c.fix
|
|
3467
|
+
}, d = Wa(t, [.../* @__PURE__ */ new Set([a, r])], r, o), { entry: f, ...p } = c, m = [
|
|
3468
|
+
p,
|
|
3469
|
+
l,
|
|
3470
|
+
u,
|
|
3471
|
+
d
|
|
3472
|
+
], h = m.filter((e) => !e.advisory).every((e) => e.passed);
|
|
3473
|
+
if (e.json) return Y("mcp", h, {
|
|
3474
|
+
mode: "check",
|
|
3475
|
+
client: t,
|
|
3476
|
+
brand: r,
|
|
3477
|
+
runsPlugins: !1,
|
|
3478
|
+
trust: Pa,
|
|
3479
|
+
registered: d.passed,
|
|
3480
|
+
checks: m
|
|
3481
|
+
}), +!h;
|
|
3482
|
+
console.log(`\n ${n.bold(`blazon-mcp for ${t}, brand ${r}`)}\n ${n.yellow(Pa)}\n`);
|
|
3483
|
+
for (let e of m) {
|
|
3484
|
+
let t = e.passed ? n.green("ok ") : e.advisory ? n.yellow("finding") : n.red("fail ");
|
|
3485
|
+
console.log(` ${t} ${e.name.padEnd(10)} ${e.detail}`), !e.passed && e.fix && console.log(` ${" ".repeat(7)} ${" ".repeat(10)} ${n.dim("fix:")} ${e.fix}`);
|
|
3486
|
+
}
|
|
3487
|
+
return console.log(`\n ${h ? n.green("The server is ready.") : n.red("The server is not ready.")}${d.passed ? "" : " It is not registered in this client yet (a finding, not a failure)."}\n`), +!h;
|
|
3488
|
+
}
|
|
3489
|
+
// src/cli/commands/mcp.ts
|
|
3490
|
+
async function Ka(e = {}) {
|
|
3491
|
+
if (e.printConfig && e.check) throw new M("give --print-config or --check, not both. See blazon mcp --help.", void 0, "conflicting-options");
|
|
3492
|
+
if (!e.printConfig && !e.check) throw new M("give --print-config to print the config that registers blazon-mcp in a client, or --check to test that it works; neither writes a file. See blazon mcp --help.", void 0, "missing-argument");
|
|
3493
|
+
let t = e.client === void 0 ? "claude-code" : e.client;
|
|
3494
|
+
if (e.client !== void 0 && !ke(e.client)) throw new M(`unknown client "${e.client}"; the clients are ${Le.join(", ")}.`, void 0, "invalid-option-value");
|
|
3495
|
+
let r = e.brand === void 0 ? void 0 : O.resolve(process.cwd(), e.brand);
|
|
3496
|
+
if (e.check) {
|
|
3497
|
+
let n = r ?? process.cwd();
|
|
3498
|
+
if (!k.statSync(n, { throwIfNoEntry: !1 })?.isDirectory()) throw new M(`the brand folder ${n} does not exist.`, void 0, "no-folder");
|
|
3499
|
+
return Ga({
|
|
3500
|
+
client: t,
|
|
3501
|
+
brand: n,
|
|
3502
|
+
...e.json && { json: !0 }
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3505
|
+
let i = pe(t, _e(), r);
|
|
3506
|
+
if (e.json) return Y("mcp", !0, {
|
|
3507
|
+
client: t,
|
|
3508
|
+
built: i.built,
|
|
3509
|
+
...r && { brand: r },
|
|
3510
|
+
...i.note && { note: i.note },
|
|
3511
|
+
snippets: i.snippets
|
|
3512
|
+
}), 0;
|
|
3513
|
+
console.log(`\n ${n.bold(i.title)}`);
|
|
3514
|
+
for (let e of i.snippets) console.log(`\n ${n.dim(e.label)}\n\n${e.text.replace(/^/gm, " ")}`);
|
|
3515
|
+
return i.note && console.log(`\n ${n.yellow(i.note)}`), console.log(""), 0;
|
|
3516
|
+
}
|
|
3517
|
+
// src/cli/commands/explain.ts
|
|
3518
|
+
function qa(e) {
|
|
3519
|
+
let t = Ce[e], n = Ae(e);
|
|
3520
|
+
return {
|
|
3521
|
+
code: e,
|
|
3522
|
+
severity: t.severity,
|
|
3523
|
+
summary: t.summary,
|
|
3524
|
+
...n !== void 0 && { fix: n },
|
|
3525
|
+
appliesTo: [...t.appliesTo],
|
|
3526
|
+
rfc: t.rfc,
|
|
3527
|
+
manual: t.manual
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
function Ja(e) {
|
|
3531
|
+
let [t = "", n] = e.split("#");
|
|
3532
|
+
return `RFC ${t.padStart(4, "0")}${n ? `, section ${n}` : ""}`;
|
|
3533
|
+
}
|
|
3534
|
+
function Ya(e) {
|
|
3535
|
+
let t = Object.keys(Ce), n = [];
|
|
3536
|
+
for (let r = 0; r < 3; r++) {
|
|
3537
|
+
let r = D(e, t);
|
|
3538
|
+
if (r === void 0) break;
|
|
3539
|
+
n.push(r), t.splice(t.indexOf(r), 1);
|
|
3540
|
+
}
|
|
3541
|
+
return n;
|
|
3542
|
+
}
|
|
3543
|
+
function Xa(e) {
|
|
3544
|
+
let t = e.severity === "error" ? n.red : e.severity === "warning" ? n.yellow : n.dim;
|
|
3545
|
+
console.log(`\n ${n.bold(e.code)} ${t(e.severity)}\n`), console.log(` ${e.summary}`), e.fix !== void 0 && console.log(`\n ${n.bold("Fix")} ${e.fix}`), console.log(`\n ${n.bold("Read")} docs/manual/${e.manual}.md, ${Ja(e.rfc)}\n`);
|
|
3546
|
+
}
|
|
3547
|
+
function Za(e, t = {}) {
|
|
3548
|
+
if (e === void 0) {
|
|
3549
|
+
let e = Object.keys(Ce).sort().map((e) => qa(e));
|
|
3550
|
+
if (t.json) Y("explain", !0, { codes: e });
|
|
3551
|
+
else {
|
|
3552
|
+
let t = Math.max(...e.map((e) => e.code.length));
|
|
3553
|
+
console.log();
|
|
3554
|
+
for (let n of e) console.log(` ${n.code.padEnd(t)} ${n.severity.padEnd(7)} ${n.summary}`);
|
|
3555
|
+
console.log("\n Run blazon explain <code> for the fix and where to read more.\n");
|
|
3556
|
+
}
|
|
3557
|
+
return 0;
|
|
3558
|
+
}
|
|
3559
|
+
if (!Object.hasOwn(Ce, e)) {
|
|
3560
|
+
let t = Ya(e);
|
|
3561
|
+
throw new M(`unknown code "${e}"`, t.length > 0 ? `Did you mean ${t.map((e) => `"${e}"`).join(", ")}? Run blazon explain to list every code.` : "Run blazon explain to list every code.", "unknown-finding-code");
|
|
3562
|
+
}
|
|
3563
|
+
let n = qa(e);
|
|
3564
|
+
return t.json ? Y("explain", !0, n) : Xa(n), 0;
|
|
3565
|
+
}
|
|
3566
|
+
// src/cli/options.ts
|
|
3567
|
+
var Qa = (e) => {
|
|
3568
|
+
if (e.length === 1) return [`-${e}`];
|
|
3569
|
+
let t = e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
|
|
3570
|
+
return t === e ? [`--${e}`] : [`--${e}`, `--${t}`];
|
|
3571
|
+
};
|
|
3572
|
+
function $a(e, t) {
|
|
3573
|
+
let n = e.matchedCommand;
|
|
3574
|
+
if (!n) return;
|
|
3575
|
+
let r = [...n.options, ...e.globalCommand.options].filter((e) => e.required);
|
|
3576
|
+
for (let i of r) {
|
|
3577
|
+
if (typeof e.options[i.name] == "object") continue;
|
|
3578
|
+
let r = i.names.flatMap(Qa);
|
|
3579
|
+
for (let a = 2; a < t.length; a++) {
|
|
3580
|
+
let o = t[a], s = r.find((e) => o === e || o.startsWith(`${e}=`));
|
|
3581
|
+
if (s === void 0) continue;
|
|
3582
|
+
let c = o === s ? t[a + 1] : o.slice(s.length + 1);
|
|
3583
|
+
if (c !== void 0 && (c === "" && N(`blazon ${n.name}: ${s} needs a value, not an empty one.`, "empty-value", { fix: `Give ${s} a value, or leave it out.` }), i.name !== "port")) for (let t of i.names) t in e.options && (e.options[t] = c);
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
let i = t.slice(2);
|
|
3587
|
+
i.some((e, t) => e === "" && !(i[t - 1] ?? "").startsWith("-")) && N(`blazon ${n.name}: ${n.rawName.includes("[dir]") ? "the folder is an empty name; leave it out to use the current folder" : "an argument is empty"}.`, "empty-value", { fix: "Leave the empty argument out, or give it a value." });
|
|
3588
|
+
}
|
|
3589
|
+
// src/cli/json.ts
|
|
3590
|
+
var eo = [
|
|
3591
|
+
"error",
|
|
3592
|
+
"warning",
|
|
3593
|
+
"info"
|
|
3594
|
+
], to = {
|
|
3595
|
+
error: ["error"],
|
|
3596
|
+
warning: ["error", "warning"],
|
|
3597
|
+
info: [
|
|
3598
|
+
"error",
|
|
3599
|
+
"warning",
|
|
3600
|
+
"info"
|
|
3601
|
+
]
|
|
3602
|
+
};
|
|
3603
|
+
async function no(e, t, n, r = "info") {
|
|
3604
|
+
let i = console.log;
|
|
3605
|
+
console.log = (...e) => console.error(...e);
|
|
3606
|
+
let a;
|
|
3607
|
+
try {
|
|
3608
|
+
a = (await n()).findings;
|
|
3609
|
+
} catch (e) {
|
|
3610
|
+
if (!(e instanceof vt)) throw e;
|
|
3611
|
+
a = e.findings;
|
|
3612
|
+
} finally {
|
|
3613
|
+
console.log = i;
|
|
3614
|
+
}
|
|
3615
|
+
let o = Ge(a, { strict: t }), s = {
|
|
3616
|
+
errors: o.errors.length,
|
|
3617
|
+
warnings: o.warnings.length,
|
|
3618
|
+
info: o.infos.length
|
|
3619
|
+
};
|
|
3620
|
+
process.stdout.write(`${JSON.stringify({
|
|
3621
|
+
command: e,
|
|
3622
|
+
passed: o.passed,
|
|
3623
|
+
strict: t,
|
|
3624
|
+
counts: s,
|
|
3625
|
+
findings: o.all.filter((e) => to[r].includes(e.severity)).map((e) => ({
|
|
3626
|
+
...e,
|
|
3627
|
+
...Se(e) && { fix: Se(e) }
|
|
3628
|
+
}))
|
|
3629
|
+
}, null, 2)}\n`), process.exitCode = +!o.passed;
|
|
3630
|
+
}
|
|
3631
|
+
async function ro(e, t) {
|
|
3632
|
+
let n = console.log;
|
|
3633
|
+
console.log = (...e) => console.error(...e);
|
|
3634
|
+
let r, i, a;
|
|
3635
|
+
try {
|
|
3636
|
+
i = await Kr(e, {
|
|
3637
|
+
...t,
|
|
3638
|
+
input: !1,
|
|
3639
|
+
report: (e) => r = e,
|
|
3640
|
+
failure: (e) => a = e
|
|
3641
|
+
});
|
|
3642
|
+
} finally {
|
|
3643
|
+
console.log = n;
|
|
3644
|
+
}
|
|
3645
|
+
let o = {
|
|
3646
|
+
command: "init",
|
|
3647
|
+
passed: i === 0,
|
|
3648
|
+
...r ?? {},
|
|
3649
|
+
...i !== 0 && { error: a ? st(a.code, a.message) : st("error", `init did not finish (exit status ${i}); the reason is on standard error`) }
|
|
3650
|
+
};
|
|
3651
|
+
return process.stdout.write(`${JSON.stringify(o)}\n`), i;
|
|
3652
|
+
}
|
|
3653
|
+
// src/cli/help.ts
|
|
3654
|
+
var io = " 0 it did what it was asked (for check, no errors)\n 1 the check found errors (or warnings, with --strict), `blazon can` denied the combination, `blazon doctor` found a failing check, or the command failed\n 2 it was used wrongly: an unknown command or option, an unknown token, a bad port, no brand book in the folder. It did nothing, except `blazon init --from`, which copies the starter and then exits 2 when the site cannot be read", ao = " blazon explain <code> what a finding code means, the fix, and where to read more\n blazon explain list every code", oo = " --cwd <dir> sets the folder every command works from, the same as running blazon there. A folder argument is then relative to it:\n `blazon --cwd ./brands check acme` checks ./brands/acme. A --cwd that is not a folder exits 2.\n `blazon doctor` checks the environment (Node, brand folder, plugin folder safety, Chrome, blazon.lock): one line each, ok, warn or fail, with a fix.", so = {
|
|
3655
|
+
check: "blazon plugin check <program> [--core] [--json]\n\nStarts the program the way blazon does and runs the protocol's core cases against it, then blazon's own cases for each role it declares and, for a shipped plugin's layout, the file name rule. Prints one line for each case: ok, skip or FAIL.\nIn a project whose config lists the plugin, case 10 also fails when the entry's env does not approve a variable the manifest lists.\nWith --core, only the core cases (1 to 5) run: no role cases, no case 10 and no layout line. Use it to check a plugin against the protocol alone.\n\nExit status:\n 0 every case passed\n 1 a case failed\n 2 no program was given\n\nExample:\n $ blazon plugin check ./blazon-acme.house-style",
|
|
3656
|
+
pin: "blazon plugin pin <path> [--name <plugin>] [--digest <digest>] [--entry <path>]\n\nPrints the digest that pins a plugin: sha256: for a file, t1: for a directory.\nWith --name, records the pin in blazon.plugins.lock instead. --digest says what the bytes must be, and the pin is refused when they are not. --entry names the program inside a directory when it is not blazon-<plugin>.\n\nExit status:\n 0 printed, or recorded\n 1 the path is one a host must refuse, or the digest does not match\n 2 no path was given, or --digest or --entry without --name\n\nExample:\n $ blazon plugin pin ./blazon-acme.house-style --name acme.house-style",
|
|
3657
|
+
profile: "blazon plugin profile\n\nPrints blazon's profile of the plugin protocol as JSON: the roles it defines and its limits. It is the same for every install.\n\nExit status:\n 0 printed"
|
|
3658
|
+
};
|
|
3659
|
+
function co(e, t, n) {
|
|
3660
|
+
if (t === "plugin" && n !== void 0 && Object.hasOwn(so, n)) return [{ body: so[n] }];
|
|
3661
|
+
let r = e.map((e) => ({
|
|
3662
|
+
...e,
|
|
3663
|
+
body: e.body.replace(/(--no-[a-z-]+[^\n]*?) *\(default: true\)/g, "$1")
|
|
3664
|
+
}));
|
|
3665
|
+
return t === void 0 ? [
|
|
3666
|
+
...r,
|
|
3667
|
+
{
|
|
3668
|
+
title: "Finding codes",
|
|
3669
|
+
body: ao
|
|
3670
|
+
},
|
|
3671
|
+
{
|
|
3672
|
+
title: "Working folder and environment",
|
|
3673
|
+
body: oo
|
|
3674
|
+
},
|
|
3675
|
+
{
|
|
3676
|
+
title: "Exit status",
|
|
3677
|
+
body: io
|
|
3678
|
+
}
|
|
3679
|
+
] : r;
|
|
3680
|
+
}
|
|
3681
|
+
// src/cli/index.ts
|
|
3682
|
+
function lo(e, t) {
|
|
3683
|
+
if (t === void 0) return;
|
|
3684
|
+
let n = String(t), r = /^\d+$/.test(n) ? Number(n) : NaN;
|
|
3685
|
+
return r >= 1 && r <= 65535 || N(`blazon ${e}: the port must be a whole number from 1 to 65535, not "${n}".`, "invalid-port", { fix: "Give a whole number from 1 to 65535." }), r;
|
|
3686
|
+
}
|
|
3687
|
+
var uo = (e) => typeof e == "number" ? String(e) : e;
|
|
3688
|
+
function fo(e, t) {
|
|
3689
|
+
t?.plugins === !1 && t.plugin !== void 0 && N(`blazon ${e}: --no-plugins runs no plugin, so it cannot be used with --plugin.`, "conflicting-options", { fix: "Leave out --no-plugins, or leave out --plugin." });
|
|
3690
|
+
}
|
|
3691
|
+
function po(e, t, n) {
|
|
3692
|
+
if (t !== void 0) return n || N(`blazon ${e}: --severity cuts the list that --json prints; add --json, or leave --severity out.`, "conflicting-options", { fix: "Add --json, or leave --severity out." }), eo.includes(t) || N(`blazon ${e}: --severity must be error, warning or info, not "${String(t)}".`, "invalid-option-value", { fix: "Use --severity error, warning or info." }), t;
|
|
3693
|
+
}
|
|
3694
|
+
var mo = (e) => {
|
|
3695
|
+
let [t, n] = e.slice(2).filter((e, t, n) => !e.startsWith("-") && n[t - 1] !== "--cwd" && n[t - 1] !== "--allow-dir");
|
|
3696
|
+
if (e.includes("--json") && t !== void 0) return t === "plugin" ? n === "check" ? "plugin check" : void 0 : [
|
|
3697
|
+
"check",
|
|
3698
|
+
"build",
|
|
3699
|
+
"tokens",
|
|
3700
|
+
"init",
|
|
3701
|
+
"drift",
|
|
3702
|
+
"approvals",
|
|
3703
|
+
"pin",
|
|
3704
|
+
"explain",
|
|
3705
|
+
"doctor",
|
|
3706
|
+
...Oa,
|
|
3707
|
+
"mcp"
|
|
3708
|
+
].includes(t) ? t : void 0;
|
|
3709
|
+
};
|
|
3710
|
+
function ho(e) {
|
|
3711
|
+
if (e[2] !== "help") return e;
|
|
3712
|
+
let t = e[3];
|
|
3713
|
+
return t !== void 0 && !t.startsWith("-") ? [
|
|
3714
|
+
...e.slice(0, 2),
|
|
3715
|
+
t,
|
|
3716
|
+
"--help",
|
|
3717
|
+
...e.slice(4)
|
|
3718
|
+
] : [...e.slice(0, 2), "--help"];
|
|
3719
|
+
}
|
|
3720
|
+
async function go(e = process.argv) {
|
|
3721
|
+
let t = ho(e), n = t.includes("--debug");
|
|
3722
|
+
at(mo(t));
|
|
3723
|
+
let r = $e("blazon");
|
|
3724
|
+
if (r.option("--debug", "Show the stack of an error"), r.option("--allow-dir <folder>", "Approve a folder outside the project for an asset category dir (repeat for more; or BLAZON_ALLOW_DIRS)"), r.option("--cwd <dir>", "Work from this folder, as if blazon were run there; a folder argument is then relative to it"), r.command("dev [dir]", "Start interactive Brand Book dev server with HMR").option("-p, --port <port>", "Port number to listen on (default: the port in blazon.json, else 3000)").option("--strict-port", "Exit 2 when the port is in use, instead of taking the next free one").option("--host [address]", "Listen on this address, or on every network interface with no address (default: localhost only)").action(async (e, t) => {
|
|
3725
|
+
try {
|
|
3726
|
+
await _t(e || process.cwd(), lo("dev", t?.port), {
|
|
3727
|
+
strictPort: t?.strictPort,
|
|
3728
|
+
host: uo(t?.host)
|
|
3729
|
+
});
|
|
3730
|
+
} catch (e) {
|
|
3731
|
+
P("dev", e, n);
|
|
3732
|
+
}
|
|
3733
|
+
}), r.command("build [dir]", "Build static brand book site and compiled design tokens").option("-o, --outDir <dir>", "Output directory for static site").option("--plugin <program>", "Run a plugin program that the config does not allow or the lock does not pin, once, with a warning (repeat for more)").option("--no-plugins", "Run no plugin at all, whatever the config lists: the tokens and the book only (no browser needed)").option("--json", "Print the findings as JSON on standard output; everything else goes to standard error").option("--severity <level>", "With --json: list only the findings at this level or worse (error, warning or info); the counts stay whole").action(async (e, t) => {
|
|
3734
|
+
try {
|
|
3735
|
+
fo("build", t);
|
|
3736
|
+
let n = po("build", t?.severity, t?.json), r = () => Nt(e || process.cwd(), t?.outDir === void 0 ? void 0 : O.resolve(process.cwd(), t.outDir), t);
|
|
3737
|
+
t?.json ? await no("build", !1, r, n) : await r();
|
|
3738
|
+
} catch (e) {
|
|
3739
|
+
P("build", e, n);
|
|
3740
|
+
}
|
|
3741
|
+
}), r.command("tokens [dir]", "Compile design tokens only (theme.css, tokens.ts, tokens.json)").option("--plugin <program>", "Run a plugin program that the config does not allow or the lock does not pin, once, with a warning (repeat for more)").option("--no-plugins", "Run no plugin at all, whatever the config lists: the tokens and the book only (no browser needed)").option("--json", "Print the findings as JSON on standard output; everything else goes to standard error").option("--severity <level>", "With --json: list only the findings at this level or worse (error, warning or info); the counts stay whole").action(async (e, t) => {
|
|
3742
|
+
try {
|
|
3743
|
+
fo("tokens", t);
|
|
3744
|
+
let n = po("tokens", t?.severity, t?.json), r = () => Pt(e || process.cwd(), t);
|
|
3745
|
+
t?.json ? await no("tokens", !1, r, n) : await r();
|
|
3746
|
+
} catch (e) {
|
|
3747
|
+
P("tokens", e, n);
|
|
3748
|
+
}
|
|
3749
|
+
}), r.command("check [dir]", "Check tokens: aliases, types, usage rules, contrast pairs, duplicates and review flags").option("--strict", "Treat warnings as errors (useful for CI/CD pipelines)").option("--plugin <program>", "Run a plugin program that the config does not allow or the lock does not pin, once, with a warning (repeat for more)").option("--no-plugins", "Run no plugin at all, whatever the config lists: the tokens and the book only (no browser needed)").option("--json", "Print the findings as JSON on standard output; everything else goes to standard error").option("--severity <level>", "With --json: list only the findings at this level or worse (error, warning or info); the counts stay whole").action(async (e, t) => {
|
|
3750
|
+
try {
|
|
3751
|
+
fo("check", t);
|
|
3752
|
+
let n = po("check", t?.severity, t?.json), r = () => Mt(e || process.cwd(), t?.strict, t);
|
|
3753
|
+
t?.json ? await no("check", !!t.strict, r, n) : (await r()).passed || (process.exitCode = 1);
|
|
3754
|
+
} catch (e) {
|
|
3755
|
+
P("check", e, n);
|
|
3756
|
+
}
|
|
3757
|
+
}), Ma(r, n), r.command("mcp", "Set up blazon-mcp, the MCP server for coding agents: --print-config prints what registers it in a client, --check tests that it works; neither writes a file").option("--print-config", "Print the config that registers blazon-mcp (stdio) in a client").option("--check", "Test that the server is built, finds blazon, answers a real MCP handshake and is registered in the client; runs no plugin").option("--client <client>", "With --print-config or --check: claude-code (default), claude-desktop, cursor or vscode").option("--brand <dir>", "The brand folder: with --print-config, written into the config as an absolute path; with --check, the folder the server starts on").option("--json", "Print the config or the check as JSON on standard output").action(async (e) => {
|
|
3758
|
+
try {
|
|
3759
|
+
process.exitCode = await Ka(e);
|
|
3760
|
+
} catch (e) {
|
|
3761
|
+
P("mcp", e, n);
|
|
3762
|
+
}
|
|
3763
|
+
}), r.command("drift [target]", "Find tokens that have drifted from the live site: compare each token that names a source.cssVar with a page (http or https address) or a CSS file").option("--json", "Print the findings as JSON").option("--tokens <dir>", "Read the tokens from this folder instead of the one the config names").action(async (e, t) => {
|
|
3764
|
+
try {
|
|
3765
|
+
process.exitCode = await li(e, t);
|
|
3766
|
+
} catch (e) {
|
|
3767
|
+
P("drift", e, n);
|
|
3768
|
+
}
|
|
3769
|
+
}), r.command("approvals [dir]", "List the tokens and assets marked review ok with the fingerprint of their value today, to record in review.value so `blazon check` sees a later change").option("--json", "Print the list as JSON on standard output").action(async (e, t) => {
|
|
3770
|
+
try {
|
|
3771
|
+
process.exitCode = await ui(e || process.cwd(), { json: t?.json });
|
|
3772
|
+
} catch (e) {
|
|
3773
|
+
P("approvals", e, n);
|
|
3774
|
+
}
|
|
3775
|
+
}), r.command("plugin [action] [target]", "Plugins: `check <program>` checks that a program follows the plugin protocol, `pin <path>` prints the digest that pins it, `profile` prints the profile blazon enforces").option("--name <name>", "With `pin`: record the pin in blazon.plugins.lock under this plugin name").option("--digest <digest>", "With `pin --name`: the digest you vouch for; the bytes must be those").option("--entry <path>", "With `pin --name` on a directory: the program inside it, when it is not blazon-<name>").option("--json", "With `check`: print the cases as JSON on standard output").option("--core", "With `check`: run only the core cases of the protocol (1 to 5), not blazon's role cases or the layout of a shipped plugin").action(async (e, t, r) => {
|
|
3776
|
+
try {
|
|
3777
|
+
if (r?.json && e !== "check" && N("blazon plugin: --json is for `blazon plugin check`; `pin` prints a digest and `profile` prints JSON already.", "conflicting-options", { fix: "Leave out --json, or use it with `blazon plugin check`." }), r?.core && e !== "check" && N("blazon plugin: --core is for `blazon plugin check`; `pin` and `profile` run no cases.", "conflicting-options", { fix: "Leave out --core, or use it with `blazon plugin check`." }), e !== "pin") for (let t of [
|
|
3778
|
+
"name",
|
|
3779
|
+
"digest",
|
|
3780
|
+
"entry"
|
|
3781
|
+
]) r?.[t] !== void 0 && N(`blazon plugin: --${t} is for \`blazon plugin pin\`; \`${e ?? "check"}\` does not take it.`, "conflicting-options", { fix: `Leave out --${t}, or use it with \`blazon plugin pin\`.` });
|
|
3782
|
+
e === "profile" && t !== void 0 && N("blazon plugin: `profile` takes no target.", "conflicting-options", { fix: "Run `blazon plugin profile` on its own." }), process.exitCode = await si(e, t, r);
|
|
3783
|
+
} catch (e) {
|
|
3784
|
+
P("plugin", e, n);
|
|
3785
|
+
}
|
|
3786
|
+
}), r.command("explain [code]", "Explain a finding code: its severity, what it means, the fix and where to read more; with no code, list every code").option("--json", "Print the explanation as JSON on standard output").action((e, t) => {
|
|
3787
|
+
try {
|
|
3788
|
+
process.exitCode = Za(e, { json: t?.json });
|
|
3789
|
+
} catch (e) {
|
|
3790
|
+
P("explain", e, n);
|
|
3791
|
+
}
|
|
3792
|
+
}), r.command("pin [dir]", "Pin the blazon you build with: write blazon.lock with the commit of the blazon that runs this, so check, tokens and build refuse any other").option("--json", "Print the pinned commit as JSON on standard output").action((e, t) => {
|
|
3793
|
+
try {
|
|
3794
|
+
process.exitCode = ci(e || process.cwd(), { json: t?.json });
|
|
3795
|
+
} catch (e) {
|
|
3796
|
+
P("pin", e, n);
|
|
3797
|
+
}
|
|
3798
|
+
}), r.command("init [dir]", "Scaffold a new Blazon brand book and design token structure").option("--from <url>", "Start from a live site: read its stylesheets and page for the brand colors, fonts, logo and title (all marked needs-review)").option("--name <text>", "With `init`: the brand book title, as given").option("--description <text>", "With `init`: one sentence on the brand: the config description").option("--color <hex>", "With `init`: the primary color as hex, with or without the #: #2563eb, 2563eb or #26e").option("--font <family>", "With `init`: the font family, a Google Fonts name").option("--logo <file>", "With `init`: an SVG or PNG file to use as the logo").option("--dev", "With `init`: start `blazon dev` when it is done").option("--json", "Print what init made as JSON on standard output; everything else goes to standard error (never asks)").option("--yes", "With `init`: accept every default and never ask").option("--no-input", "With `init`: same as --yes; implied when stdin or stdout is not a terminal").action(async (e, t) => {
|
|
3799
|
+
try {
|
|
3800
|
+
t?.json ? (t.dev && N("blazon init: --dev starts a server that never ends, so it cannot be used with --json.", "conflicting-options", { fix: "Leave out --dev, or leave out --json." }), process.exitCode = await ro(e || ".", t)) : process.exitCode = await Kr(e || ".", { ...t });
|
|
3801
|
+
} catch (e) {
|
|
3802
|
+
P("init", e, n);
|
|
3803
|
+
}
|
|
3804
|
+
}), r.command("preview [dir]", "Preview the static production brand book build").option("-p, --port <port>", "Port number to listen on (default: the port in blazon.json, else 3000)").option("--strict-port", "Exit 2 when the port is in use, instead of taking the next free one").option("--host [address]", "Listen on this address, or on every network interface with no address (default: localhost only)").action(async (e, t) => {
|
|
3805
|
+
try {
|
|
3806
|
+
await Xr(e || process.cwd(), lo("preview", t?.port), {
|
|
3807
|
+
strictPort: t?.strictPort,
|
|
3808
|
+
host: uo(t?.host)
|
|
3809
|
+
});
|
|
3810
|
+
} catch (e) {
|
|
3811
|
+
P("preview", e, n);
|
|
3812
|
+
}
|
|
3813
|
+
}), r.command("doctor", "Check this machine and folder: Node version, brand folder, plugin folder safety, Chrome (if a plugin needs it) and blazon.lock; writes nothing").option("--json", "Print the checks as JSON on standard output").action(async (e) => {
|
|
3814
|
+
try {
|
|
3815
|
+
process.exitCode = await ia(process.cwd(), { json: e?.json });
|
|
3816
|
+
} catch (e) {
|
|
3817
|
+
P("doctor", e, n);
|
|
3818
|
+
}
|
|
3819
|
+
}), r.example(" $ blazon init my-brand"), r.example(" $ blazon check my-brand --json"), r.example(" $ blazon build my-brand"), r.example(" $ blazon list ./my-brand --type color"), r.example(" $ blazon get color.brand.primary my-brand --json"), r.example(" $ blazon can text.primary surface.canvas my-brand"), r.help((e) => co(e, r.matchedCommand?.name, r.args[0])), r.version(Ke), t.slice(2).length === 0) return r.outputHelp();
|
|
3820
|
+
r.addEventListener("command:*", (e) => {
|
|
3821
|
+
if (r.options.help || r.options.version) return;
|
|
3822
|
+
let t = String(e.detail), n = D(t, r.commands.map((e) => e.name).filter(Boolean));
|
|
3823
|
+
N(`blazon: unknown command "${t}"${n ? `; did you mean "${n}"?` : "."} Run blazon --help for the commands.`, "unknown-command", { fix: n ? `Run blazon ${n}, or blazon --help for the commands.` : "Run blazon --help for the commands." });
|
|
3824
|
+
});
|
|
3825
|
+
try {
|
|
3826
|
+
r.parse(t, { run: !1 }), $a(r, t);
|
|
3827
|
+
try {
|
|
3828
|
+
fi(r.options.allowDir), di(r.options.cwd);
|
|
3829
|
+
} catch (e) {
|
|
3830
|
+
P(r.matchedCommand?.name ?? "", e, n);
|
|
3831
|
+
}
|
|
3832
|
+
await r.runMatchedCommand();
|
|
3833
|
+
} catch (e) {
|
|
3834
|
+
if (!ut(e)) return P("", e, n);
|
|
3835
|
+
let t = r.matchedCommand?.name, i = t ? `blazon ${t}` : "blazon", [, a = "", o] = /^Unknown option `(-{1,2})([^`]+)`$/.exec(e.message) ?? [], s = n ? e.stack : void 0;
|
|
3836
|
+
o !== void 0 && /^\d+$/.test(o) && (t === "dev" || t === "preview") && N(`blazon ${t}: the port must be a whole number from 1 to 65535, not "-${o}".`, "invalid-port", { fix: "Give a whole number from 1 to 65535." }), t === "get" && /^missing required args/i.test(e.message) && N("blazon get: give a token path, such as blazon get color.brand.primary; blazon list shows the token paths.", "missing-argument", {
|
|
3837
|
+
stack: s,
|
|
3838
|
+
fix: "Run blazon list to see the token paths."
|
|
3839
|
+
}), o === void 0 && N(`${i}: ${lt(e.message)}. Run ${i} --help for the options.`, "missing-argument", {
|
|
3840
|
+
stack: s,
|
|
3841
|
+
fix: `Run ${i} --help for the options.`
|
|
3842
|
+
});
|
|
3843
|
+
let c = [...r.matchedCommand?.options ?? [], ...r.globalCommand.options].map((e) => e.name), l = D(o, c);
|
|
3844
|
+
N(`${i}: unknown option "${a}${o}"${l ? `; did you mean "--${l}"?` : "."} Run ${i} --help for the options.`, "unknown-option", {
|
|
3845
|
+
stack: s,
|
|
3846
|
+
fix: l ? `Use --${l}, or run ${i} --help for the options.` : `Run ${i} --help for the options.`
|
|
3847
|
+
});
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
export { go as runCli };
|