@homepages/concrete 1.0.0
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/CHANGELOG.md +59 -0
- package/README.md +174 -0
- package/codemods/manifest.json +9 -0
- package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
- package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
- package/dist/artifact/playground/client/index.html +13 -0
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
- package/dist/artifact/playground/host.mjs +127 -0
- package/dist/asset-modules.d.ts +99 -0
- package/dist/base.css +220 -0
- package/dist/browser/site-config.d.ts +18 -0
- package/dist/browser/site-config.js +56 -0
- package/dist/browser/submit-lead.d.ts +98 -0
- package/dist/browser/submit-lead.js +188 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +4 -0
- package/dist/cli/build/artifact.js +225 -0
- package/dist/cli/build/captures.js +67 -0
- package/dist/cli/build/esbuild.js +127 -0
- package/dist/cli/build/fixtures.js +96 -0
- package/dist/cli/build/icons.js +76 -0
- package/dist/cli/build/index.js +38 -0
- package/dist/cli/build/playground.js +31 -0
- package/dist/cli/build/sections.js +236 -0
- package/dist/cli/build/source.js +62 -0
- package/dist/cli/build/static.js +156 -0
- package/dist/cli/capture/bundle.js +37 -0
- package/dist/cli/capture/capture-browser.js +51 -0
- package/dist/cli/capture/capture.js +121 -0
- package/dist/cli/check/analyze.js +95 -0
- package/dist/cli/check/index.js +19 -0
- package/dist/cli/check/load-workspace.js +119 -0
- package/dist/cli/check/messages.js +16 -0
- package/dist/cli/check/render/class-conflicts.js +39 -0
- package/dist/cli/check/render/html.js +86 -0
- package/dist/cli/check/render/inputs.js +53 -0
- package/dist/cli/check/render/invariants.js +58 -0
- package/dist/cli/check/render/island-frames.js +72 -0
- package/dist/cli/check/render/marker-coverage.js +102 -0
- package/dist/cli/check/render/nav.js +64 -0
- package/dist/cli/check/report.js +73 -0
- package/dist/cli/check/stages/bundles.js +129 -0
- package/dist/cli/check/stages/composition.js +67 -0
- package/dist/cli/check/stages/contracts.js +22 -0
- package/dist/cli/check/stages/dependencies.js +261 -0
- package/dist/cli/check/stages/fixtures.js +74 -0
- package/dist/cli/check/stages/lint.js +41 -0
- package/dist/cli/check/stages/logic.js +63 -0
- package/dist/cli/check/stages/render.js +144 -0
- package/dist/cli/check/stages/sections.js +83 -0
- package/dist/cli/check/stages/stylesheet.js +31 -0
- package/dist/cli/check/stages/typecheck.js +68 -0
- package/dist/cli/check/stages/workspace.js +26 -0
- package/dist/cli/commands.js +342 -0
- package/dist/cli/currency/cache.js +89 -0
- package/dist/cli/currency/decide.js +65 -0
- package/dist/cli/currency/opt-out.js +16 -0
- package/dist/cli/currency/preamble.js +183 -0
- package/dist/cli/currency/prompt.js +28 -0
- package/dist/cli/currency/refresh.js +44 -0
- package/dist/cli/currency/resolve-latest.js +185 -0
- package/dist/cli/currency/version-order.js +38 -0
- package/dist/cli/dev/crop.js +22 -0
- package/dist/cli/dev/hmr.js +26 -0
- package/dist/cli/dev/http.js +129 -0
- package/dist/cli/dev/index.js +70 -0
- package/dist/cli/dev/islands.js +390 -0
- package/dist/cli/dev/load-template.js +46 -0
- package/dist/cli/dev/request-error.js +22 -0
- package/dist/cli/dev/server.js +307 -0
- package/dist/cli/dev/tsconfig-paths.js +95 -0
- package/dist/cli/dev/vite.js +85 -0
- package/dist/cli/dev/workspace-reader.js +274 -0
- package/dist/cli/io.d.ts +14 -0
- package/dist/cli/media/cache.js +125 -0
- package/dist/cli/media/derive.js +252 -0
- package/dist/cli/media/deriver-plugin.js +71 -0
- package/dist/cli/property/index.js +180 -0
- package/dist/cli/property/library.js +137 -0
- package/dist/cli/publish/client.js +119 -0
- package/dist/cli/publish/freshness.js +66 -0
- package/dist/cli/publish/git.js +43 -0
- package/dist/cli/publish/index.js +207 -0
- package/dist/cli/publish/pack.js +78 -0
- package/dist/cli/publish/report.js +98 -0
- package/dist/cli/publish/target.js +87 -0
- package/dist/cli/publish/wire.js +29 -0
- package/dist/cli/tar.js +87 -0
- package/dist/cli/upgrade/codemod.js +56 -0
- package/dist/cli/upgrade/index.js +263 -0
- package/dist/cli/upgrade/manifest.js +72 -0
- package/dist/cli/upgrade/plan.js +68 -0
- package/dist/cli/upgrade/stage.js +71 -0
- package/dist/cli/version.d.ts +12 -0
- package/dist/cli/version.js +15 -0
- package/dist/cli/workspace.js +108 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +94 -0
- package/dist/css/compile.js +77 -0
- package/dist/css/graph.js +109 -0
- package/dist/css/inline.js +132 -0
- package/dist/css/rules.js +65 -0
- package/dist/design-system/format-variants.js +127 -0
- package/dist/eslint/authoring.js +46 -0
- package/dist/eslint/correctness.js +42 -0
- package/dist/eslint/rules/editor-declaration.js +103 -0
- package/dist/eslint/rules/editor-reason.js +135 -0
- package/dist/eslint/rules/island-imports.js +20 -0
- package/dist/eslint/rules/jsx-visitor.js +20 -0
- package/dist/eslint/rules/no-client-runtime.js +88 -0
- package/dist/eslint/rules/no-editor-globals.js +60 -0
- package/dist/eslint/rules/no-hard-coded-color.js +183 -0
- package/dist/eslint/rules/no-inline-style.js +24 -0
- package/dist/eslint/rules/no-marker-literal.js +37 -0
- package/dist/eslint/rules/no-nondeterminism.js +44 -0
- package/dist/eslint/rules/no-px-breakpoint.js +44 -0
- package/dist/eslint/rules/no-raw-values.js +45 -0
- package/dist/eslint/rules/serializable-props.js +95 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +26 -0
- package/dist/fixtures/brand.d.ts +4 -0
- package/dist/fixtures/brand.js +9 -0
- package/dist/fixtures/bundle-rule.js +67 -0
- package/dist/fixtures/canonical.d.ts +149 -0
- package/dist/fixtures/image-dimensions.js +59 -0
- package/dist/fixtures/load.js +154 -0
- package/dist/fixtures/media-plugin.js +141 -0
- package/dist/fixtures/media.js +165 -0
- package/dist/fixtures/property.js +210 -0
- package/dist/fixtures/resolve.js +202 -0
- package/dist/fixtures/rows.js +108 -0
- package/dist/fixtures/synthesize-empties.js +42 -0
- package/dist/fixtures.d.ts +213 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +37 -0
- package/dist/islands/client-module.js +97 -0
- package/dist/islands/marker.d.ts +43 -0
- package/dist/islands/marker.js +44 -0
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
- package/dist/packages/external/concrete/package.js +5 -0
- package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
- package/dist/packages/internal/fill-bake/dist/display.js +9 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -0
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
- package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
- package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
- package/dist/packages/internal/format-geometry/dist/index.js +4 -0
- package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
- package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
- package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
- package/dist/packages/internal/image-ladder/dist/index.js +4 -0
- package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
- package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
- package/dist/packages/internal/island-runtime/dist/index.js +163 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
- package/dist/packages/internal/property-facts/dist/index.js +3 -0
- package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
- package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
- package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
- package/dist/packages/internal/section-contracts/dist/index.js +26 -0
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
- package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
- package/dist/packages/internal/source-resolution/dist/index.js +222 -0
- package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
- package/dist/packages/internal/template-artifact/dist/index.js +7 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
- package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
- package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
- package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
- package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
- package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
- package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
- package/dist/playground/host/page-state.js +12 -0
- package/dist/playground/host/paths.js +9 -0
- package/dist/playground/layout.js +24 -0
- package/dist/playground/wire.js +36 -0
- package/dist/playground-island-runtime.d.ts +3 -0
- package/dist/playground-island-runtime.js +4 -0
- package/dist/primitives/FrameShell.d.ts +29 -0
- package/dist/primitives/FrameShell.js +34 -0
- package/dist/primitives/Image.d.ts +119 -0
- package/dist/primitives/Image.js +173 -0
- package/dist/primitives/Section.d.ts +22 -0
- package/dist/primitives/Section.js +26 -0
- package/dist/primitives/Tour.d.ts +43 -0
- package/dist/primitives/Tour.js +72 -0
- package/dist/primitives/Video.d.ts +57 -0
- package/dist/primitives/Video.js +116 -0
- package/dist/primitives/embed-playback.js +50 -0
- package/dist/primitives/index.d.ts +11 -0
- package/dist/primitives/marker-attrs.js +44 -0
- package/dist/primitives/object-fit.js +11 -0
- package/dist/primitives/picture-sources.d.ts +24 -0
- package/dist/primitives/picture-sources.js +52 -0
- package/dist/primitives/probe-context.js +24 -0
- package/dist/primitives/slot-bindings.d.ts +96 -0
- package/dist/primitives/slot-bindings.js +226 -0
- package/dist/primitives/slot-document.d.ts +35 -0
- package/dist/primitives/slot-document.js +37 -0
- package/dist/primitives/slot-group.d.ts +40 -0
- package/dist/primitives/slot-group.js +45 -0
- package/dist/primitives/slot-list.d.ts +21 -0
- package/dist/primitives/slot-list.js +23 -0
- package/dist/primitives/slot-media.d.ts +71 -0
- package/dist/primitives/slot-media.js +98 -0
- package/dist/primitives/slot-scalar.d.ts +53 -0
- package/dist/primitives/slot-scalar.js +98 -0
- package/dist/primitives/slot.d.ts +26 -0
- package/dist/primitives/slot.js +28 -0
- package/dist/rules/registry.js +479 -0
- package/dist/schema/compute.d.ts +22 -0
- package/dist/schema/compute.js +30 -0
- package/dist/schema/define-schema.d.ts +27 -0
- package/dist/schema/define-schema.js +73 -0
- package/dist/schema/extract-fill-spec.js +246 -0
- package/dist/schema/extract-used-facts.js +176 -0
- package/dist/schema/fact.d.ts +65 -0
- package/dist/schema/fact.js +33 -0
- package/dist/schema/fill-builders.d.ts +387 -0
- package/dist/schema/fill-builders.js +263 -0
- package/dist/schema/fill-declaration.d.ts +76 -0
- package/dist/schema/fill-declaration.js +43 -0
- package/dist/schema/fill-spec.d.ts +18 -0
- package/dist/schema/fill-spec.js +170 -0
- package/dist/schema/format-presets.d.ts +27 -0
- package/dist/schema/format-presets.js +76 -0
- package/dist/schema/format.d.ts +22 -0
- package/dist/schema/format.js +40 -0
- package/dist/schema/formats.d.ts +6 -0
- package/dist/schema/formats.js +7 -0
- package/dist/schema/layout.d.ts +32 -0
- package/dist/schema/layout.js +30 -0
- package/dist/schema/manifest.js +300 -0
- package/dist/schema/property-facts.d.ts +83 -0
- package/dist/schema/runtime-values.d.ts +88 -0
- package/dist/schema/section-nav.d.ts +38 -0
- package/dist/schema/section-nav.js +29 -0
- package/dist/schema/section-props.d.ts +98 -0
- package/dist/schema/section-schema.d.ts +53 -0
- package/dist/schema/section-schema.js +54 -0
- package/dist/schema/slot-builders.d.ts +497 -0
- package/dist/schema/slot-builders.js +331 -0
- package/dist/schema/slot-types.d.ts +110 -0
- package/dist/schema/slot-types.js +187 -0
- package/dist/section/declare.d.ts +44 -0
- package/dist/section/declare.js +27 -0
- package/dist/section/discovery.js +76 -0
- package/dist/section/groups.js +74 -0
- package/dist/section/materialize.js +28 -0
- package/dist/section/placements.js +28 -0
- package/dist/section/section.d.ts +69 -0
- package/dist/section/section.js +101 -0
- package/dist/site-analytics.d.ts +1 -0
- package/dist/site-analytics.js +15 -0
- package/dist/site-runtime/analytics.js +97 -0
- package/dist/site-runtime/site-integrations.js +97 -0
- package/dist/styles.css +60 -0
- package/dist/template/define-template.d.ts +139 -0
- package/dist/template/define-template.js +98 -0
- package/dist/template/logic-build.js +191 -0
- package/dist/template/logic-shim.d.ts +43 -0
- package/dist/template/logic-shim.js +52 -0
- package/dist/template/logic-transform.js +92 -0
- package/dist/template/materialize.js +107 -0
- package/dist/template/reconcile.d.ts +67 -0
- package/dist/template/reconcile.js +25 -0
- package/dist/template/running-copy.js +58 -0
- package/guide/reference/cli/INDEX.md +79 -0
- package/guide/reference/cli/build.md +48 -0
- package/guide/reference/cli/check.md +49 -0
- package/guide/reference/cli/dev.md +46 -0
- package/guide/reference/cli/property-add.md +53 -0
- package/guide/reference/cli/property-list.md +46 -0
- package/guide/reference/cli/publish.md +54 -0
- package/guide/reference/cli/upgrade.md +48 -0
- package/guide/reference/rules/INDEX.md +190 -0
- package/package.json +137 -0
- package/tsconfig.base.json +16 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { declaringModule } from "../../../section/section.js";
|
|
2
|
+
import { fillSpecFromSchema } from "../../../schema/extract-fill-spec.js";
|
|
3
|
+
import { TEMPLATE_FILE, workspacePath } from "../load-workspace.js";
|
|
4
|
+
import { describeError } from "../messages.js";
|
|
5
|
+
import { renderInstanceSlots } from "../../../fixtures/media.js";
|
|
6
|
+
import { FillSpec } from "../../../schema/fill-spec.js";
|
|
7
|
+
import { SectionSchema } from "../../../schema/section-schema.js";
|
|
8
|
+
import { GroupDerivationError } from "../../../section/groups.js";
|
|
9
|
+
import { materializeSection } from "../../../section/materialize.js";
|
|
10
|
+
import { isAbsolute } from "node:path";
|
|
11
|
+
|
|
12
|
+
//#region src/cli/check/stages/sections.ts
|
|
13
|
+
const GROUP_RULE = {
|
|
14
|
+
"slot-in-two-groups": "groups/slot-in-two-groups",
|
|
15
|
+
"label-conflict": "groups/label-conflict",
|
|
16
|
+
empty: "groups/empty"
|
|
17
|
+
};
|
|
18
|
+
/** The flat serialized shape every contract and consumer reads: `meta`'s anchor, groups and display lifted to the root. */
|
|
19
|
+
function flatten(parsed, key) {
|
|
20
|
+
const { meta, ...rest } = parsed;
|
|
21
|
+
return {
|
|
22
|
+
...rest,
|
|
23
|
+
anchor: meta.anchor ?? key,
|
|
24
|
+
...meta.display ? { display: meta.display } : {},
|
|
25
|
+
...meta.groups ? { groups: meta.groups } : {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function sectionsStage(ctx) {
|
|
29
|
+
const { workspace, discovered, composition } = ctx;
|
|
30
|
+
if (workspace === void 0 || discovered === void 0 || composition === void 0) return Promise.resolve({ skipped: "the composition stage could not derive the placed sections" });
|
|
31
|
+
const corpus = ctx.corpus ?? [];
|
|
32
|
+
const fileOf = (section) => {
|
|
33
|
+
const exported = discovered.find((entry) => entry.section === section);
|
|
34
|
+
if (exported !== void 0) return exported.module;
|
|
35
|
+
const at = declaringModule(section);
|
|
36
|
+
return at !== void 0 && isAbsolute(at) && at.startsWith(workspace.root) ? workspacePath(workspace.root, at) : TEMPLATE_FILE;
|
|
37
|
+
};
|
|
38
|
+
const violations = [];
|
|
39
|
+
const sections = [];
|
|
40
|
+
for (const [key, section] of composition.sections) {
|
|
41
|
+
const file = fileOf(section);
|
|
42
|
+
const states = corpus.flatMap(({ fixture }) => fixture.contentDoc.instances.filter((instance) => instance.section_key === key).map((instance) => renderInstanceSlots(instance, section, fixture.media)));
|
|
43
|
+
let materialized;
|
|
44
|
+
try {
|
|
45
|
+
materialized = materializeSection(section, states);
|
|
46
|
+
} catch (cause) {
|
|
47
|
+
violations.push(cause instanceof GroupDerivationError ? {
|
|
48
|
+
rule: GROUP_RULE[cause.fault],
|
|
49
|
+
file,
|
|
50
|
+
message: cause.message
|
|
51
|
+
} : {
|
|
52
|
+
rule: "groups/probe-failed",
|
|
53
|
+
file,
|
|
54
|
+
message: `Section "${key}" throws under the groups probe: ${describeError(cause)}`
|
|
55
|
+
});
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const parsed = SectionSchema.parse(materialized);
|
|
60
|
+
parsed.slot_order = Object.keys(parsed.slots);
|
|
61
|
+
for (const slot of Object.values(parsed.slots)) if (slot.type === "list" && slot.fields) slot.item_order = slot.layout ? slot.layout.flatMap((row) => typeof row === "string" ? [row] : [...row]) : Object.keys(slot.fields);
|
|
62
|
+
const fillSpec = FillSpec.parse(fillSpecFromSchema(materialized));
|
|
63
|
+
sections.push({
|
|
64
|
+
key,
|
|
65
|
+
section,
|
|
66
|
+
file,
|
|
67
|
+
schema: flatten(parsed, key),
|
|
68
|
+
fillSpec
|
|
69
|
+
});
|
|
70
|
+
} catch (cause) {
|
|
71
|
+
violations.push({
|
|
72
|
+
rule: "sections/schema-invalid",
|
|
73
|
+
file,
|
|
74
|
+
message: `Section "${key}": ${describeError(cause)}`
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
ctx.sections = sections;
|
|
79
|
+
return Promise.resolve({ violations });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { sectionsStage };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compileTemplateCss } from "../../../css/compile.js";
|
|
2
|
+
import { TEMPLATE_FILE } from "../load-workspace.js";
|
|
3
|
+
import { describeError } from "../messages.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/check/stages/stylesheet.ts
|
|
7
|
+
async function stylesheetStage(ctx) {
|
|
8
|
+
const template = ctx.workspace?.template ?? null;
|
|
9
|
+
if (template === null) return { skipped: "the workspace stage could not load template.ts" };
|
|
10
|
+
try {
|
|
11
|
+
const { violations } = await compileTemplateCss({
|
|
12
|
+
root: ctx.root,
|
|
13
|
+
templateFile: join(ctx.root, TEMPLATE_FILE),
|
|
14
|
+
template: {
|
|
15
|
+
key: template.key,
|
|
16
|
+
output: template.output,
|
|
17
|
+
formats: template.formats
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return { violations };
|
|
21
|
+
} catch (cause) {
|
|
22
|
+
return { violations: [{
|
|
23
|
+
rule: "css/compile-failed",
|
|
24
|
+
file: TEMPLATE_FILE,
|
|
25
|
+
message: `The stylesheet reachable from ${TEMPLATE_FILE} could not be resolved or compiled: ${describeError(cause)}`
|
|
26
|
+
}] };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { stylesheetStage };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { workspacePath } from "../load-workspace.js";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join, sep } from "node:path";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/check/stages/typecheck.ts
|
|
7
|
+
const TSCONFIG = "tsconfig.json";
|
|
8
|
+
function relativize(text, root) {
|
|
9
|
+
const prefix = root.endsWith(sep) ? root : root + sep;
|
|
10
|
+
return text.split(prefix).join("");
|
|
11
|
+
}
|
|
12
|
+
function typecheckStage(ctx) {
|
|
13
|
+
const { root } = ctx;
|
|
14
|
+
const configPath = join(root, TSCONFIG);
|
|
15
|
+
if (!existsSync(configPath)) return Promise.resolve({ violations: [{
|
|
16
|
+
rule: "typecheck/error",
|
|
17
|
+
file: TSCONFIG,
|
|
18
|
+
message: `The workspace has no ${TSCONFIG}. Extend the framework's compiler options: { "extends": "@homepages/concrete/tsconfig" }.`
|
|
19
|
+
}] });
|
|
20
|
+
const violations = [];
|
|
21
|
+
const text = (diagnostic) => relativize(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), root);
|
|
22
|
+
const configFile = ts.readConfigFile(configPath, (file) => ts.sys.readFile(file));
|
|
23
|
+
if (configFile.error !== void 0) return Promise.resolve({ violations: [{
|
|
24
|
+
rule: "typecheck/error",
|
|
25
|
+
file: TSCONFIG,
|
|
26
|
+
message: text(configFile.error)
|
|
27
|
+
}] });
|
|
28
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, root, void 0, configPath);
|
|
29
|
+
for (const error of parsed.errors) violations.push({
|
|
30
|
+
rule: "typecheck/error",
|
|
31
|
+
file: TSCONFIG,
|
|
32
|
+
message: text(error)
|
|
33
|
+
});
|
|
34
|
+
const program = ts.createProgram({
|
|
35
|
+
rootNames: parsed.fileNames,
|
|
36
|
+
options: {
|
|
37
|
+
...parsed.options,
|
|
38
|
+
noEmit: true
|
|
39
|
+
},
|
|
40
|
+
configFileParsingDiagnostics: parsed.errors
|
|
41
|
+
});
|
|
42
|
+
const inside = root.endsWith(sep) ? root : root + sep;
|
|
43
|
+
for (const diagnostic of ts.getPreEmitDiagnostics(program)) {
|
|
44
|
+
if (parsed.errors.includes(diagnostic)) continue;
|
|
45
|
+
if (diagnostic.category !== ts.DiagnosticCategory.Error) continue;
|
|
46
|
+
const file = diagnostic.file;
|
|
47
|
+
if (file === void 0) {
|
|
48
|
+
violations.push({
|
|
49
|
+
rule: "typecheck/error",
|
|
50
|
+
file: TSCONFIG,
|
|
51
|
+
message: text(diagnostic)
|
|
52
|
+
});
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const path = file.fileName.split("/").join(sep);
|
|
56
|
+
if (!path.startsWith(inside) || path.includes(`${sep}node_modules${sep}`)) continue;
|
|
57
|
+
violations.push({
|
|
58
|
+
rule: "typecheck/error",
|
|
59
|
+
file: workspacePath(root, path),
|
|
60
|
+
...diagnostic.start === void 0 ? {} : { line: file.getLineAndCharacterOfPosition(diagnostic.start).line + 1 },
|
|
61
|
+
message: `TS${String(diagnostic.code)}: ${text(diagnostic)}`
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve({ violations });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { typecheckStage };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DuplicateSectionKeyError, discoverSections } from "../../../section/discovery.js";
|
|
2
|
+
import { loadWorkspace } from "../load-workspace.js";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/check/stages/workspace.ts
|
|
5
|
+
async function workspaceStage(ctx) {
|
|
6
|
+
const workspace = await loadWorkspace(ctx.root);
|
|
7
|
+
ctx.workspace = workspace;
|
|
8
|
+
const violations = [...workspace.violations];
|
|
9
|
+
if (workspace.template !== null) try {
|
|
10
|
+
ctx.discovered = await discoverSections({
|
|
11
|
+
root: ctx.root,
|
|
12
|
+
importModule: (file) => Promise.resolve(workspace.modules.get(file) ?? {})
|
|
13
|
+
});
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
if (!(cause instanceof DuplicateSectionKeyError)) throw cause;
|
|
16
|
+
violations.push({
|
|
17
|
+
rule: "workspace/duplicate-section-key",
|
|
18
|
+
file: cause.second.module,
|
|
19
|
+
message: cause.message
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return { violations };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { workspaceStage };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
//#region src/cli/commands.ts
|
|
2
|
+
/**
|
|
3
|
+
* The escape hatch for the package-currency preamble, which runs in front of every
|
|
4
|
+
* author command. Declared once and attached to all of them below rather than repeated
|
|
5
|
+
* per command: the same predicate decides who runs the preamble and who documents the
|
|
6
|
+
* flag that turns it off, so the two cannot drift into a command that refreshes
|
|
7
|
+
* without saying it can be told not to.
|
|
8
|
+
*/
|
|
9
|
+
const NO_AUTO_UPDATE = {
|
|
10
|
+
name: "no-auto-update",
|
|
11
|
+
type: "boolean",
|
|
12
|
+
default: false,
|
|
13
|
+
summary: "Skip the package refresh this command runs first when the workspace is behind the published release"
|
|
14
|
+
};
|
|
15
|
+
/** Where `build` writes when `--out` is absent. Gitignored by the scaffold. */
|
|
16
|
+
const DEFAULT_BUILD_DIR = ".concrete/build";
|
|
17
|
+
const DECLARED_COMMANDS = [
|
|
18
|
+
{
|
|
19
|
+
name: "dev",
|
|
20
|
+
summary: "Serve this workspace's template in the local editor",
|
|
21
|
+
flags: [{
|
|
22
|
+
name: "port",
|
|
23
|
+
type: "string",
|
|
24
|
+
valueLabel: "<n>",
|
|
25
|
+
default: 5180,
|
|
26
|
+
summary: "Port to serve on. A non-integer or non-positive value falls back to the default"
|
|
27
|
+
}],
|
|
28
|
+
exits: [{
|
|
29
|
+
code: 0,
|
|
30
|
+
when: "the server is interrupted (Ctrl-C, SIGTERM) and shuts down cleanly"
|
|
31
|
+
}, {
|
|
32
|
+
code: 1,
|
|
33
|
+
when: "the server cannot start"
|
|
34
|
+
}],
|
|
35
|
+
constraints: ["Runs until interrupted — it is a server, not a one-shot command.", "Serves this one workspace: its template over its fixtures, in the platform's own editor."]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "check",
|
|
39
|
+
summary: "Grade the template against every requirement the platform accepts it on",
|
|
40
|
+
flags: [{
|
|
41
|
+
name: "json",
|
|
42
|
+
type: "boolean",
|
|
43
|
+
default: false,
|
|
44
|
+
summary: "Print one machine-readable report on stdout instead of human output"
|
|
45
|
+
}],
|
|
46
|
+
exits: [{
|
|
47
|
+
code: 0,
|
|
48
|
+
when: "the template and the workspace pass every rule that could be measured"
|
|
49
|
+
}, {
|
|
50
|
+
code: 1,
|
|
51
|
+
when: "any rule reports a finding, or the run cannot proceed at all"
|
|
52
|
+
}],
|
|
53
|
+
constraints: [
|
|
54
|
+
"Under `--json` the report is the only thing written to stdout; every notice goes to stderr.",
|
|
55
|
+
"Grades with the toolchain this package ships — TypeScript, ESLint, esbuild — never with a version the workspace declares.",
|
|
56
|
+
"Every threshold is a platform acceptance criterion, not a preference. No flag or config file raises one.",
|
|
57
|
+
"Every run reports what each placed section's built bundles weigh: the renderer, each island chunk and each asset, in the human output and as `weights` under `--json`.",
|
|
58
|
+
"`build` runs this first and refuses on red: an artifact exists only because check passed."
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "build",
|
|
63
|
+
summary: "Run check, then write the template's artifact",
|
|
64
|
+
flags: [{
|
|
65
|
+
name: "out",
|
|
66
|
+
type: "string",
|
|
67
|
+
valueLabel: "<dir>",
|
|
68
|
+
default: DEFAULT_BUILD_DIR,
|
|
69
|
+
summary: "Directory to write the artifact into, relative to the workspace root"
|
|
70
|
+
}],
|
|
71
|
+
exits: [{
|
|
72
|
+
code: 0,
|
|
73
|
+
when: "the artifact was written"
|
|
74
|
+
}, {
|
|
75
|
+
code: 1,
|
|
76
|
+
when: "`check` is not green, a capture failed, or the artifact cannot be written"
|
|
77
|
+
}],
|
|
78
|
+
constraints: [
|
|
79
|
+
"The only producer of an artifact. Nothing else — no bare bundler — writes one.",
|
|
80
|
+
"Deterministic: the same tree builds to the same artifact hash.",
|
|
81
|
+
"An image or document template also carries `captures/`: every authored fixture at every declared format, taken exactly as `dev`'s *Download fixture render* takes it — the enabled pages and their zip, or the PDF. Captures sit outside the artifact hash, and need Playwright: without it, build refuses with the install line.",
|
|
82
|
+
`The default output directory, \`${DEFAULT_BUILD_DIR}/\`, is gitignored by the scaffold.`
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "upgrade",
|
|
87
|
+
summary: "Move the workspace to a newer @homepages/concrete and run its codemods",
|
|
88
|
+
flags: [{
|
|
89
|
+
name: "dry-run",
|
|
90
|
+
type: "boolean",
|
|
91
|
+
default: false,
|
|
92
|
+
summary: "Print the plan and change nothing"
|
|
93
|
+
}, {
|
|
94
|
+
name: "to",
|
|
95
|
+
type: "string",
|
|
96
|
+
valueLabel: "<version>",
|
|
97
|
+
summary: "Move to this exact version instead of the published latest"
|
|
98
|
+
}],
|
|
99
|
+
exits: [{
|
|
100
|
+
code: 0,
|
|
101
|
+
when: "the workspace was moved and every codemod ran, it was already on the target, or it says why nothing could be changed (no lockfile, nothing installed, an unreachable registry)"
|
|
102
|
+
}, {
|
|
103
|
+
code: 1,
|
|
104
|
+
when: "the install fails, a codemod fails, `--to` names a version the registry does not carry, or it runs outside a workspace"
|
|
105
|
+
}],
|
|
106
|
+
constraints: [
|
|
107
|
+
"Installs the target first, then runs every codemod the installed release lists above the version the workspace was on, oldest release first.",
|
|
108
|
+
"Prints each codemod as it runs, with every file it rewrote and every file it could not rewrite and why.",
|
|
109
|
+
"A file no codemod could rewrite, and a step no codemod could take, is printed for you to do by hand; the upgrade still exits 0.",
|
|
110
|
+
"A codemod that fails stops the chain: the ones after it do not run.",
|
|
111
|
+
"Codemods run forward only. Moving to an older version moves the package and runs none.",
|
|
112
|
+
"`--dry-run` reads the target's codemods out of its published tarball without installing anything.",
|
|
113
|
+
"Reads the registry fresh, never the currency preamble's cache.",
|
|
114
|
+
"A release version is stamped as a caret; a prerelease is pinned exactly.",
|
|
115
|
+
"Needs no terminal — it runs the same in CI, down a pipe, and in a container.",
|
|
116
|
+
"A failed install puts package.json back the way it was, and no codemod runs."
|
|
117
|
+
],
|
|
118
|
+
ownsPackageVersion: true
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "property list",
|
|
122
|
+
summary: "List the sample properties a workspace can copy in",
|
|
123
|
+
flags: [],
|
|
124
|
+
exits: [{
|
|
125
|
+
code: 0,
|
|
126
|
+
when: "the listing was printed"
|
|
127
|
+
}, {
|
|
128
|
+
code: 1,
|
|
129
|
+
when: "the library cannot be read from the registry and no earlier copy of it is cached"
|
|
130
|
+
}],
|
|
131
|
+
constraints: [
|
|
132
|
+
"Prints one line per property on stdout: its slug, its description, then its property type, listing intent and non-zero counts.",
|
|
133
|
+
"Reads the latest @homepages/sample-properties from the registry the workspace installs from, and caches each version per user under `XDG_CACHE_HOME`, else `~/.cache`.",
|
|
134
|
+
"When the registry cannot be read, lists the newest cached version and says so on stderr."
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "property add",
|
|
139
|
+
summary: "Copy a sample property into this workspace's fixtures/properties/",
|
|
140
|
+
args: [{
|
|
141
|
+
name: "slug",
|
|
142
|
+
summary: "The property to copy, as `concrete property list` names it"
|
|
143
|
+
}],
|
|
144
|
+
flags: [],
|
|
145
|
+
exits: [{
|
|
146
|
+
code: 0,
|
|
147
|
+
when: "the folder was copied"
|
|
148
|
+
}, {
|
|
149
|
+
code: 1,
|
|
150
|
+
when: "the folder already exists, the library has no property by that slug, the library cannot be read, or it runs outside a workspace"
|
|
151
|
+
}],
|
|
152
|
+
constraints: [
|
|
153
|
+
"Copies the whole folder — property.ts, media/, README.md, sources.json — to `fixtures/properties/<slug>/`. From then on it is the workspace's to edit.",
|
|
154
|
+
"Never overwrites: an existing `fixtures/properties/<slug>/` is refused and named, and nothing is copied.",
|
|
155
|
+
"The workspace never depends on the library: nothing is added to package.json, so no later release of it can change a copied property.",
|
|
156
|
+
"Reads the library the way `property list` does, through the same per-user cache."
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "publish",
|
|
161
|
+
summary: "Publish the template to HomePages",
|
|
162
|
+
flags: [
|
|
163
|
+
{
|
|
164
|
+
name: "rebuild",
|
|
165
|
+
type: "boolean",
|
|
166
|
+
default: false,
|
|
167
|
+
summary: "Build the artifact again even when the tree still matches the one on disk"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: "dry-run",
|
|
171
|
+
type: "boolean",
|
|
172
|
+
default: false,
|
|
173
|
+
summary: "Upload and verify the artifact, report what publishing would change, and write nothing"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "json",
|
|
177
|
+
type: "boolean",
|
|
178
|
+
default: false,
|
|
179
|
+
summary: "Print the settled publication record on stdout instead of the summary"
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
exits: [
|
|
183
|
+
{
|
|
184
|
+
code: 0,
|
|
185
|
+
when: "the template was published, the environment already held it as current, or a dry run passed verification"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
code: 1,
|
|
189
|
+
when: "`check` is not green, or the platform refuses the publication, fails its verification or cannot finish it"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
code: 2,
|
|
193
|
+
when: "no publisher key is set, the key is malformed or not accepted, the endpoint cannot be reached, or it runs outside a workspace"
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
constraints: [
|
|
197
|
+
"The key is the environment: `CONCRETE_TOKEN` names production, staging or dev in its prefix (`cpt_prod_…`), and publish goes where it points. There is no environment flag.",
|
|
198
|
+
"Reads `CONCRETE_TOKEN` from the environment, then from the workspace's `.env`. `CONCRETE_API_URL` replaces the endpoint the key's prefix names.",
|
|
199
|
+
`Builds first when it matters: the artifact in \`${DEFAULT_BUILD_DIR}/\` is reused while the workspace's files match the ones it was built from, and rebuilt — check included — when they do not.`,
|
|
200
|
+
"Prints one line per stage on stderr as it settles: target, build, upload, verify, write, adopt.",
|
|
201
|
+
"Publishing a tree the environment already holds as current changes nothing, says so, and exits 0. Rolling back is publishing the older tree.",
|
|
202
|
+
"Under `--json` the publication record is the only thing written to stdout; every stage line goes to stderr.",
|
|
203
|
+
"Never prompts, in any environment."
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
];
|
|
207
|
+
/** One predicate, applied to a definition rather than a name — see the exported form. */
|
|
208
|
+
const precededByPreamble = (command) => command.ownsPackageVersion !== true && command.reserved === void 0;
|
|
209
|
+
const COMMANDS = DECLARED_COMMANDS.map((command) => precededByPreamble(command) ? {
|
|
210
|
+
...command,
|
|
211
|
+
flags: [...command.flags, NO_AUTO_UPDATE]
|
|
212
|
+
} : command);
|
|
213
|
+
/**
|
|
214
|
+
* Whether the currency preamble runs in front of `name`.
|
|
215
|
+
*
|
|
216
|
+
* An author's command against their own workspace, except the one that moves the
|
|
217
|
+
* package's version itself and a reserved name with no body to run. The two global
|
|
218
|
+
* flags, which are not commands at all, are outside it deliberately: they must keep
|
|
219
|
+
* working when everything else about the workspace is broken.
|
|
220
|
+
*/
|
|
221
|
+
function runsCurrencyPreamble(name) {
|
|
222
|
+
return COMMANDS.some((command) => command.name === name && precededByPreamble(command));
|
|
223
|
+
}
|
|
224
|
+
/** Whether this invocation asked for the currency preamble to stay out of the way. */
|
|
225
|
+
function hasNoAutoUpdateFlag(argv) {
|
|
226
|
+
return argv.includes(`--${NO_AUTO_UPDATE.name}`);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* `argv` without the currency escape hatch.
|
|
230
|
+
*
|
|
231
|
+
* The dispatcher consumes that flag and no command parses it: it is read before the
|
|
232
|
+
* command's module is even imported, and stripping it there is what keeps every
|
|
233
|
+
* command's own parse a parse of the flags it declared.
|
|
234
|
+
*/
|
|
235
|
+
function withoutNoAutoUpdateFlag(argv) {
|
|
236
|
+
return argv.filter((arg) => arg !== `--${NO_AUTO_UPDATE.name}`);
|
|
237
|
+
}
|
|
238
|
+
const GLOBAL_FLAGS = [{
|
|
239
|
+
name: "version",
|
|
240
|
+
spellings: [
|
|
241
|
+
"--version",
|
|
242
|
+
"-v",
|
|
243
|
+
"-V"
|
|
244
|
+
],
|
|
245
|
+
summary: "Print the installed version"
|
|
246
|
+
}, {
|
|
247
|
+
name: "help",
|
|
248
|
+
spellings: ["--help", "-h"],
|
|
249
|
+
summary: "Print this message"
|
|
250
|
+
}];
|
|
251
|
+
/** Every spelling of a global flag, so the dispatcher spells none of them. */
|
|
252
|
+
function globalFlagSpellings(name) {
|
|
253
|
+
const flag = GLOBAL_FLAGS.find((f) => f.name === name);
|
|
254
|
+
if (flag === void 0) throw new Error(`no global flag '${name}'`);
|
|
255
|
+
return flag.spellings;
|
|
256
|
+
}
|
|
257
|
+
/** The members of the group `word` names, in table order; empty when it names no group. */
|
|
258
|
+
function groupMembers(word) {
|
|
259
|
+
return COMMANDS.filter((command) => command.name.startsWith(`${word} `));
|
|
260
|
+
}
|
|
261
|
+
function findCommand(name) {
|
|
262
|
+
const found = COMMANDS.find((command) => command.name === name);
|
|
263
|
+
if (found === void 0) throw new Error(`no command definition for '${name}'`);
|
|
264
|
+
return found;
|
|
265
|
+
}
|
|
266
|
+
/** `--<name>`, so no entry point spells a flag as a string literal of its own. */
|
|
267
|
+
function flagName(command, flag) {
|
|
268
|
+
const found = command.flags.find((f) => f.name === flag);
|
|
269
|
+
if (found === void 0) throw new Error(`'${command.name}' declares no flag '${flag}'`);
|
|
270
|
+
return `--${found.name}`;
|
|
271
|
+
}
|
|
272
|
+
function flagDefault(command, flag) {
|
|
273
|
+
const found = command.flags.find((f) => f.name === flag);
|
|
274
|
+
if (found === void 0) throw new Error(`'${command.name}' declares no flag '${flag}'`);
|
|
275
|
+
return found.default;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The `options` object a command hands `node:util`'s `parseArgs`.
|
|
279
|
+
*
|
|
280
|
+
* Deriving it rather than writing it beside the definition is what makes the
|
|
281
|
+
* definition load-bearing: an undeclared flag is not merely undocumented, it is
|
|
282
|
+
* unparsed, so the two cannot drift apart in the direction that matters.
|
|
283
|
+
*
|
|
284
|
+
* A numeric default (only `dev --port`) is omitted rather than stringified — that
|
|
285
|
+
* command validates and coerces its own value, and handing `parseArgs` a coerced
|
|
286
|
+
* copy would make the definition's number and the parser's string two spellings of
|
|
287
|
+
* one default.
|
|
288
|
+
*/
|
|
289
|
+
function parseSpec(name) {
|
|
290
|
+
const options = {};
|
|
291
|
+
for (const flag of findCommand(name).flags) options[flag.name] = typeof flag.default === "boolean" || typeof flag.default === "string" ? {
|
|
292
|
+
type: flag.type,
|
|
293
|
+
default: flag.default
|
|
294
|
+
} : { type: flag.type };
|
|
295
|
+
return { options };
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Read one parsed flag back off `parseArgs`'s `values`.
|
|
299
|
+
*
|
|
300
|
+
* Deriving the options object from data costs its literal type, so `values` comes
|
|
301
|
+
* back loosely typed. These two narrow it at the point of use — legible, and honest
|
|
302
|
+
* about the runtime shape — rather than reaching for a generic that reconstructs the
|
|
303
|
+
* literal type from `COMMANDS`.
|
|
304
|
+
*/
|
|
305
|
+
function booleanFlag(values, name) {
|
|
306
|
+
return values[name] === true;
|
|
307
|
+
}
|
|
308
|
+
function stringFlag(values, name) {
|
|
309
|
+
const value = values[name];
|
|
310
|
+
return typeof value === "string" ? value : null;
|
|
311
|
+
}
|
|
312
|
+
/** `property add <slug>`: the name and its positionals, as help's command column prints it. */
|
|
313
|
+
function commandLabel(command) {
|
|
314
|
+
return [command.name, ...(command.args ?? []).map((arg) => `<${arg.name}>`)].join(" ");
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The `--help` message, built from the same definitions the pages are.
|
|
318
|
+
*
|
|
319
|
+
* `header` is passed in rather than read here so this module stays import-free.
|
|
320
|
+
*/
|
|
321
|
+
function renderUsage(header) {
|
|
322
|
+
const spelling = (f) => [...f.spellings].reverse().join(", ");
|
|
323
|
+
const commandColumn = Math.max(...COMMANDS.map((c) => commandLabel(c).length)) + 2;
|
|
324
|
+
const optionColumn = Math.max(...GLOBAL_FLAGS.map((f) => spelling(f).length)) + 3;
|
|
325
|
+
const commands = COMMANDS.map((c) => ` ${commandLabel(c).padEnd(commandColumn)}${c.summary}${c.reserved === void 0 ? "" : " (not yet available)"}`);
|
|
326
|
+
const options = GLOBAL_FLAGS.map((f) => ` ${spelling(f).padEnd(optionColumn)}${f.summary}`);
|
|
327
|
+
return [
|
|
328
|
+
header,
|
|
329
|
+
"",
|
|
330
|
+
"Usage: concrete <command> [options]",
|
|
331
|
+
"",
|
|
332
|
+
"Commands:",
|
|
333
|
+
...commands,
|
|
334
|
+
"",
|
|
335
|
+
"Options:",
|
|
336
|
+
...options,
|
|
337
|
+
""
|
|
338
|
+
].join("\n");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
export { COMMANDS, DEFAULT_BUILD_DIR, GLOBAL_FLAGS, booleanFlag, commandLabel, findCommand, flagDefault, flagName, globalFlagSpellings, groupMembers, hasNoAutoUpdateFlag, parseSpec, renderUsage, runsCurrencyPreamble, stringFlag, withoutNoAutoUpdateFlag };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/currency/cache.ts
|
|
7
|
+
/** Below the injected root, so `XDG_CACHE_HOME` and a test fixture behave identically. */
|
|
8
|
+
const CACHE_FILE_RELATIVE = join("homepages", "concrete-currency.json");
|
|
9
|
+
const HIT_TTL_MS = 3600 * 1e3;
|
|
10
|
+
const MISS_TTL_MS = 600 * 1e3;
|
|
11
|
+
const CACHE_SCHEMA = z.object({
|
|
12
|
+
latest: z.object({
|
|
13
|
+
value: z.string().nullable(),
|
|
14
|
+
checkedAt: z.number()
|
|
15
|
+
}).optional(),
|
|
16
|
+
/** version -> when it was declined. Bounded by the number of majors ever published. */
|
|
17
|
+
declined: z.record(z.string(), z.number()).default({})
|
|
18
|
+
});
|
|
19
|
+
const EMPTY = { declined: {} };
|
|
20
|
+
/**
|
|
21
|
+
* The default root: `XDG_CACHE_HOME`, else `~/.cache`.
|
|
22
|
+
*
|
|
23
|
+
* The environment arrives as an argument even here, so the one place that reads an
|
|
24
|
+
* ambient value is a caller's explicit choice to pass `process.env`.
|
|
25
|
+
*/
|
|
26
|
+
function defaultCacheRoot(env) {
|
|
27
|
+
const xdg = env.XDG_CACHE_HOME;
|
|
28
|
+
return xdg !== void 0 && xdg !== "" ? xdg : join(homedir(), ".cache");
|
|
29
|
+
}
|
|
30
|
+
function openCurrencyCache(options) {
|
|
31
|
+
const file = join(options.root, CACHE_FILE_RELATIVE);
|
|
32
|
+
const read = async () => {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
raw = await readFile(file, "utf8");
|
|
36
|
+
} catch {
|
|
37
|
+
return EMPTY;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
return CACHE_SCHEMA.parse(JSON.parse(raw));
|
|
41
|
+
} catch {
|
|
42
|
+
return EMPTY;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const write = async (next) => {
|
|
46
|
+
const temporary = `${file}.${String(process.pid)}.tmp`;
|
|
47
|
+
try {
|
|
48
|
+
await mkdir(dirname(file), { recursive: true });
|
|
49
|
+
await writeFile(temporary, `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
|
50
|
+
await rename(temporary, file);
|
|
51
|
+
} catch {}
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
async readLatest() {
|
|
55
|
+
const { latest } = await read();
|
|
56
|
+
if (latest === void 0) return void 0;
|
|
57
|
+
const ttl = latest.value === null ? MISS_TTL_MS : HIT_TTL_MS;
|
|
58
|
+
const age = options.now() - latest.checkedAt;
|
|
59
|
+
if (age < 0 || age >= ttl) return void 0;
|
|
60
|
+
return { value: latest.value };
|
|
61
|
+
},
|
|
62
|
+
async writeLatest(value) {
|
|
63
|
+
const current = await read();
|
|
64
|
+
await write({
|
|
65
|
+
...current,
|
|
66
|
+
latest: {
|
|
67
|
+
value,
|
|
68
|
+
checkedAt: options.now()
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async declinedVersions() {
|
|
73
|
+
return Object.keys((await read()).declined);
|
|
74
|
+
},
|
|
75
|
+
async decline(version) {
|
|
76
|
+
const current = await read();
|
|
77
|
+
await write({
|
|
78
|
+
...current,
|
|
79
|
+
declined: {
|
|
80
|
+
...current.declined,
|
|
81
|
+
[version]: options.now()
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { CACHE_FILE_RELATIVE, HIT_TTL_MS, MISS_TTL_MS, defaultCacheRoot, openCurrencyCache };
|