@homepages/concrete 10.0.0 → 11.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 +29 -0
- package/codemods/manifest.json +5 -158
- package/dist/artifact/playground/client/assets/index-ByeGGedv.js +1259 -0
- package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +1 -0
- package/dist/artifact/playground/client/index.html +2 -2
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
- package/dist/artifact/playground/host.mjs +26 -26
- package/dist/base.css +1 -8
- package/dist/cli/build/artifact.js +1 -1
- package/dist/cli/build/fixtures.js +3 -2
- package/dist/cli/check/stages/sections.js +1 -1
- package/dist/cli/dev/workspace-reader.js +3 -2
- package/dist/css/compile.js +3 -6
- package/dist/css/rules.js +1 -51
- package/dist/design-system/format-variants.js +1 -1
- package/dist/fixtures/resolve.js +5 -1
- package/dist/fixtures/rows.js +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/holder.js +3 -14
- package/dist/packages/internal/media-resolution/dist/document.js +3 -3
- package/dist/packages/internal/media-resolution/dist/image.js +3 -3
- package/dist/packages/internal/media-resolution/dist/tour.js +6 -6
- package/dist/packages/internal/media-resolution/dist/video.js +9 -9
- package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +1 -3
- package/dist/packages/internal/section-contracts/dist/source-contract.js +3 -3
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +0 -2
- package/dist/packages/internal/template-artifact/dist/index.js +2 -2
- package/dist/packages/internal/template-artifact/dist/layout.js +11 -11
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +13 -17
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +3 -5
- package/dist/packages/internal/template-contracts/dist/fill-builders.js +2 -6
- package/dist/packages/internal/template-contracts/dist/fill-spec-schema.js +4 -1
- package/dist/packages/internal/template-contracts/dist/list.js +0 -14
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +1 -1
- package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +6 -7
- package/dist/packages/internal/template-contracts/dist/slot-builders.js +0 -2
- package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +6 -1
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +2 -4
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +3 -4
- package/dist/primitives/Image.d.ts +2 -2
- package/dist/primitives/Tour.d.ts +2 -2
- package/dist/primitives/Video.d.ts +2 -2
- package/dist/primitives/slot-bindings.js +6 -13
- package/dist/primitives/slot-document.d.ts +1 -1
- package/dist/primitives/slot-download.d.ts +3 -1
- package/dist/primitives/slot-media.d.ts +5 -2
- package/dist/primitives/slot-media.js +1 -1
- package/dist/rules/registry.js +0 -6
- package/dist/schema/format-presets.d.ts +1 -1
- package/dist/schema/section-schema.d.ts +5 -5
- package/dist/styles.css +4 -4
- package/dist/template/define-template.js +0 -1
- package/guide/reference/cli/INDEX.md +2 -2
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +1 -1
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +1 -1
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +1 -2
- package/package.json +2 -2
- package/codemods/fill-is-a-source.mjs +0 -533
- package/codemods/framework-namespace.mjs +0 -107
- package/codemods/list-grammar.mjs +0 -923
- package/codemods/object-form-only.mjs +0 -39
- package/codemods/platform-namespace.mjs +0 -83
- package/codemods/process-builders.mjs +0 -198
- package/codemods/reads-replace-reconcile.mjs +0 -285
- package/codemods/registry-keys-only.mjs +0 -113
- package/codemods/slot-object.mjs +0 -1097
- package/codemods/steps/content-object-fields.mjs +0 -324
- package/codemods/steps/list-object-form.mjs +0 -686
- package/codemods/steps/registry-key-reads.mjs +0 -276
- package/codemods/steps/select-object-form.mjs +0 -210
- package/codemods/table-rows.mjs +0 -568
- package/codemods/theme-collapse.mjs +0 -396
- package/codemods/unlayer-author-css.mjs +0 -194
- package/codemods/unwrap-object-fields.mjs +0 -310
- package/codemods/viewer-slot-document.mjs +0 -131
- package/codemods/write-property-as-facts-document.mjs +0 -716
- package/codemods/write-the-address-line.mjs +0 -255
- package/codemods/write-the-registry-members.mjs +0 -653
- package/codemods/write-the-select-from.mjs +0 -141
- package/codemods/write-the-sole-from.mjs +0 -369
- package/codemods/write-the-table-from.mjs +0 -267
- package/codemods/write-the-whole-item.mjs +0 -512
- package/codemods/writeback-drop.mjs +0 -168
- package/codemods/written-contact-address.mjs +0 -162
- package/codemods/written-media-category.mjs +0 -227
- package/codemods/written-ref-kinds-name-the-layer.mjs +0 -172
- package/codemods/written-uploads-replace-pool-reads.mjs +0 -454
- package/codemods/written-uploads-sort-into-lists.mjs +0 -405
- package/codemods/written-uploads-stated-in-sorted-lists.mjs +0 -295
- package/codemods/written-video-sources-drop.mjs +0 -144
- package/codemods/written-without-pick-none.mjs +0 -146
- package/codemods/written-without-retired-knowledge.mjs +0 -223
- package/codemods/written-without-the-media-key.mjs +0 -202
- package/codemods/written-without-the-property-type.mjs +0 -249
- package/dist/artifact/playground/client/assets/index-BFNHB7VM.css +0 -1
- package/dist/artifact/playground/client/assets/index-Div1yo6s.js +0 -1259
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homepages/concrete",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "Concrete, the HomePages template framework: the authoring API, the contract primitives, the styles, the lint preset and the `concrete` command in one package that owns its whole toolchain.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"optionalDependencies": {
|
|
89
89
|
"sharp": "^0.35.3"
|
|
90
90
|
},
|
|
91
|
-
"$comment:devDependencies": "Every `@homepages/*` entry is a private workspace package compiled INTO dist by tsdown, which externalizes only dependencies, peerDependencies and optionalDependencies: nothing about them survives into a consumer's dependency graph, and the packed tarball declares no `workspace:*` edge in any block a consumer installs (src/package-boundary.test.ts). The set is every internal package
|
|
91
|
+
"$comment:devDependencies": "Every `@homepages/*` entry is a private workspace package compiled INTO dist by tsdown, which externalizes only dependencies, peerDependencies and optionalDependencies: nothing about them survives into a consumer's dependency graph, and the packed tarball declares no `workspace:*` edge in any block a consumer installs (src/package-boundary.test.ts). The set is every internal package Concrete inlines, declared here once so the command, check, dev and build modules that follow reach them without a manifest change; a module the shipped entries do not reach today is simply not in dist yet. One entry is never inlined: `@homepages/portability-lint` is imported by eslint.config.mjs alone, the lint rules that grade this package's own source.",
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
94
94
|
"@eslint/js": "^10.0.1",
|
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
// 6.0.0 — one `fill()`, declared as a kind of `source:`.
|
|
2
|
-
//
|
|
3
|
-
// Before this release a slot's fill was one of eleven builders (`textBlock`, `listFill`,
|
|
4
|
-
// `imageAssign`, `videoAssign`, `tourAssign`, `documentAssign`, `contactAssign`,
|
|
5
|
-
// `chooseFrom`, `nameRows`) under its own `fill:` key, its instruction split across up
|
|
6
|
-
// to six prose keys (`voice`, `content`, `pick`, `structureHint`, and the two enums
|
|
7
|
-
// `structure` and `perspective`). Now a slot declares its origin once, in `source:`, and
|
|
8
|
-
// a fill is `fill({ brief, none?, count?, cap?, reads? })`: what the model DOES is the
|
|
9
|
-
// slot's own fact, the one prose key is `brief`, and `none` is the switch `true`.
|
|
10
|
-
//
|
|
11
|
-
// What this codemod does, in every `.ts` and `.tsx` under the workspace:
|
|
12
|
-
//
|
|
13
|
-
// - Rewrites each builder call whose argument is an object literal to `fill({…})`: the
|
|
14
|
-
// prose keys merge into `brief` exactly as the platform merges a stored decision's, one
|
|
15
|
-
// paragraph each — `content` (else `pick`), `Voice: <voice>`, `Form: <structureHint>`,
|
|
16
|
-
// then each enum as the canonical sentence below (`third` is the default and is
|
|
17
|
-
// dropped), then the `none` bar as `Produce nothing when: <none>`. A ported fill and
|
|
18
|
-
// one published before this release read the same. `none` becomes `true` (a blank
|
|
19
|
-
// one, which never switched anything on, is dropped); `cap` and `reads` carry over;
|
|
20
|
-
// `count` carries over, with a `min: 0` dropped (zero is reachable only through
|
|
21
|
-
// `none`).
|
|
22
|
-
// - Renames a slot builder's `fill:` option to `source:`.
|
|
23
|
-
// - Gives every decision that used to read the platform's standing slice of property
|
|
24
|
-
// facts that slice as an explicit `reads`: a fill now sees exactly its own `reads`, so
|
|
25
|
-
// a migrated one sees what it saw. The eight refs are hoisted once, into
|
|
26
|
-
// `fill-reads.ts` at the workspace root, as `PROPERTY` — yours to prune per decision.
|
|
27
|
-
// - Rewrites the imports: the old builder names out, `fill` and `PROPERTY` in.
|
|
28
|
-
//
|
|
29
|
-
// What it leaves to you, reported per file:
|
|
30
|
-
//
|
|
31
|
-
// - Each `none` bar it folded into a brief, by line: the joined paragraph restates the
|
|
32
|
-
// brief's own exclusion more often than not, so rewrite it as the brief's last
|
|
33
|
-
// sentence saying when producing nothing is right.
|
|
34
|
-
// - `order: "walkthrough"` is dropped. A walkthrough seated EVERY photo; a pick keeps
|
|
35
|
-
// what its brief admits, so add a clause dropping anything that is not a photograph
|
|
36
|
-
// of the property (a logo, a flyer).
|
|
37
|
-
// - `fallback` is dropped: a pick that abstains now lands empty. Re-author the chain as
|
|
38
|
-
// a `none` pick plus a contact-bound slot and a `compute()` over the pick.
|
|
39
|
-
// - `contactAssign` has no replacement: bind the contact's field with
|
|
40
|
-
// `source: fact.contact.*`, or write the choice as a text fill reading the contacts.
|
|
41
|
-
// - A brief interpolating `${facts.…}`: declare the fact in `reads` and refer to it by
|
|
42
|
-
// name instead.
|
|
43
|
-
// - A builder call whose argument is not an object literal (a hoisted options object, a
|
|
44
|
-
// spread) — the prose keys cannot be merged without seeing them.
|
|
45
|
-
|
|
46
|
-
import { readdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
47
|
-
import { dirname, join, relative, sep } from "node:path";
|
|
48
|
-
|
|
49
|
-
import ts from "typescript";
|
|
50
|
-
|
|
51
|
-
const CONCRETE = "@homepages/concrete";
|
|
52
|
-
|
|
53
|
-
/** The builders `fill()` replaced. */
|
|
54
|
-
const BUILDERS = new Set([
|
|
55
|
-
"textBlock",
|
|
56
|
-
"listFill",
|
|
57
|
-
"imageAssign",
|
|
58
|
-
"videoAssign",
|
|
59
|
-
"tourAssign",
|
|
60
|
-
"documentAssign",
|
|
61
|
-
"contactAssign",
|
|
62
|
-
"chooseFrom",
|
|
63
|
-
"nameRows",
|
|
64
|
-
]);
|
|
65
|
-
|
|
66
|
-
/** The types that went with them. */
|
|
67
|
-
const RETIRED_TYPES = new Set(["BuiltDecision", "ChosenRows", "DecisionKind", "DisplayChoice", "NamedRows", "RowOrigination", "TextStructure"]);
|
|
68
|
-
|
|
69
|
-
/** The builders whose executor read the standing slice — the ones a migrated fill gives `reads: PROPERTY`. */
|
|
70
|
-
const SLICE_READERS = new Set(["textBlock", "listFill", "chooseFrom", "nameRows"]);
|
|
71
|
-
|
|
72
|
-
/** The slot builders whose options object carries the origin. */
|
|
73
|
-
const SLOT_BUILDERS = new Set(["text.short", "text.medium", "text.long", "image", "video", "tour", "document", "list.of", "select", "select.of", "number", "url"]);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The canonical sentence each enum value becomes — the platform's own merge of a
|
|
77
|
-
* stored decision's prose keys uses the same words in the same order, so a template
|
|
78
|
-
* ported here and a section published before this release send the model the same
|
|
79
|
-
* brief. `third` is the default person and has no sentence.
|
|
80
|
-
*/
|
|
81
|
-
const STRUCTURE_SENTENCE = {
|
|
82
|
-
single_sentence: "Write one sentence.",
|
|
83
|
-
paragraph: "Write one paragraph.",
|
|
84
|
-
bullet_list: "Write a bulleted list.",
|
|
85
|
-
value: "Answer with the bare value alone, never a sentence.",
|
|
86
|
-
};
|
|
87
|
-
const PERSPECTIVE_SENTENCE = {
|
|
88
|
-
first: "Write in the first person.",
|
|
89
|
-
second: "Write in the second person, addressing the reader.",
|
|
90
|
-
third: null,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/** The standing slice, as refs. */
|
|
94
|
-
const PROPERTY_REFS = [
|
|
95
|
-
"fact.property.address",
|
|
96
|
-
"fact.property.latitude",
|
|
97
|
-
"fact.property.longitude",
|
|
98
|
-
"fact.property.property_type",
|
|
99
|
-
"fact.property.listing_intent",
|
|
100
|
-
"fact.property.units",
|
|
101
|
-
"fact.description",
|
|
102
|
-
"fact.document_notes",
|
|
103
|
-
];
|
|
104
|
-
|
|
105
|
-
const READS_MODULE = "fill-reads.ts";
|
|
106
|
-
const READS_CONST = "PROPERTY";
|
|
107
|
-
|
|
108
|
-
const READS_SOURCE = `// The property facts every fill was shown before \`fill()\` read exactly its own
|
|
109
|
-
// \`reads\`: the platform's standing slice, hoisted here once by the 6.0.0 upgrade so
|
|
110
|
-
// each migrated fill still sees what it saw. It is yours: drop from a fill's \`reads\`
|
|
111
|
-
// whatever its brief does not use, and delete this file once nothing imports it.
|
|
112
|
-
import { fact } from "${CONCRETE}";
|
|
113
|
-
|
|
114
|
-
export const ${READS_CONST} = [
|
|
115
|
-
${PROPERTY_REFS.map((ref) => ` ${ref},`).join("\n")}
|
|
116
|
-
] as const;
|
|
117
|
-
`;
|
|
118
|
-
|
|
119
|
-
/** The column a rewritten `fill({…})` must end by to stay on one line. */
|
|
120
|
-
const LINE_WIDTH = 140;
|
|
121
|
-
|
|
122
|
-
const EXTENSIONS = [".ts", ".tsx"];
|
|
123
|
-
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
124
|
-
|
|
125
|
-
async function sourceFiles(root) {
|
|
126
|
-
const found = [];
|
|
127
|
-
async function walk(dir) {
|
|
128
|
-
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
129
|
-
if (entry.isDirectory()) {
|
|
130
|
-
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
131
|
-
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
132
|
-
found.push(join(dir, entry.name));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
await walk(root);
|
|
137
|
-
return found.sort();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function exists(path) {
|
|
141
|
-
try {
|
|
142
|
-
await stat(path);
|
|
143
|
-
return true;
|
|
144
|
-
} catch {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// ----- prose ---------------------------------------------------------------
|
|
150
|
-
|
|
151
|
-
/** One piece of the brief: literal text, or an expression the author computed. */
|
|
152
|
-
function prosePart(node, sf) {
|
|
153
|
-
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return { text: node.text };
|
|
154
|
-
if (ts.isTemplateExpression(node)) return { template: node.getText(sf).slice(1, -1) };
|
|
155
|
-
return { expr: node.getText(sf) };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* The label the `none` bar is folded into the brief under. The platform folds a stored
|
|
160
|
-
* decision's bar the same way, so a ported fill and a published one read the same.
|
|
161
|
-
*/
|
|
162
|
-
const NONE_LABEL = "Produce nothing when: ";
|
|
163
|
-
|
|
164
|
-
const escapeTemplate = (text) => text.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
165
|
-
|
|
166
|
-
/** Each piece becomes one paragraph of the brief, as the platform's own merge joins them. */
|
|
167
|
-
const PARAGRAPH = "\n\n";
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* The merged brief as source text, and its literal content for the interpolation scan.
|
|
171
|
-
* A piece carries an optional `label` (`Voice: `, `Form: `) the merge prefixes it with.
|
|
172
|
-
*/
|
|
173
|
-
function briefSource(parts) {
|
|
174
|
-
const kept = parts.filter((p) => p.text === undefined || p.text.trim() !== "");
|
|
175
|
-
const label = (p) => p.label ?? "";
|
|
176
|
-
if (kept.every((p) => p.text !== undefined)) {
|
|
177
|
-
const text = kept.map((p) => `${label(p)}${p.text.trim()}`).join(PARAGRAPH);
|
|
178
|
-
return { source: JSON.stringify(text), scanned: text };
|
|
179
|
-
}
|
|
180
|
-
const pieces = kept.map((p) => {
|
|
181
|
-
if (p.text !== undefined) return escapeTemplate(`${label(p)}${p.text.trim()}`);
|
|
182
|
-
if (p.template !== undefined) return `${escapeTemplate(label(p))}${p.template}`;
|
|
183
|
-
return `${escapeTemplate(label(p))}\${${p.expr}}`;
|
|
184
|
-
});
|
|
185
|
-
const scanned = kept.map((p) => `${label(p)}${p.text ?? p.template ?? ""}`).join(PARAGRAPH);
|
|
186
|
-
return { source: `\`${pieces.join("\\n\\n")}\``, scanned };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ----- one builder call ------------------------------------------------------
|
|
190
|
-
|
|
191
|
-
/** The object literal's members by name, or why the call cannot be read. */
|
|
192
|
-
function membersOf(arg, sf) {
|
|
193
|
-
if (arg === undefined) return { members: new Map() };
|
|
194
|
-
if (!ts.isObjectLiteralExpression(arg)) return { refused: "its options are not an object literal, so the prose keys cannot be merged" };
|
|
195
|
-
const members = new Map();
|
|
196
|
-
const properties = new Map();
|
|
197
|
-
for (const property of arg.properties) {
|
|
198
|
-
if (ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name))) {
|
|
199
|
-
members.set(property.name.text, property.initializer);
|
|
200
|
-
properties.set(property.name.text, property);
|
|
201
|
-
} else if (ts.isShorthandPropertyAssignment(property)) {
|
|
202
|
-
members.set(property.name.text, property.name);
|
|
203
|
-
properties.set(property.name.text, property);
|
|
204
|
-
} else {
|
|
205
|
-
return { refused: `its options carry \`${property.getText(sf).slice(0, 40)}\`, which cannot be merged without seeing it` };
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return { members, properties };
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* The comments an author wrote inside a builder's options, by the key each sits above,
|
|
213
|
-
* so the port can carry them to the entry that key became. Those after the last key are
|
|
214
|
-
* filed under `""`.
|
|
215
|
-
*/
|
|
216
|
-
function commentsOf(arg, properties, sf) {
|
|
217
|
-
const byKey = new Map();
|
|
218
|
-
if (arg === undefined || !ts.isObjectLiteralExpression(arg)) return byKey;
|
|
219
|
-
const grab = (pos) => (ts.getLeadingCommentRanges(sf.text, pos) ?? []).map((range) => sf.text.slice(range.pos, range.end));
|
|
220
|
-
for (const [key, property] of properties) {
|
|
221
|
-
const found = grab(property.getFullStart());
|
|
222
|
-
if (found.length > 0) byKey.set(key, found);
|
|
223
|
-
}
|
|
224
|
-
const last = arg.properties.at(-1);
|
|
225
|
-
if (last !== undefined) {
|
|
226
|
-
const after = arg.properties.hasTrailingComma ? sf.text.indexOf(",", last.getEnd()) + 1 : last.getEnd();
|
|
227
|
-
const found = grab(after);
|
|
228
|
-
if (found.length > 0) byKey.set("", found);
|
|
229
|
-
}
|
|
230
|
-
return byKey;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** `{ min: 0, max: N }` → `{ max: N }`; everything else as written. */
|
|
234
|
-
function countSource(node, sf, yours) {
|
|
235
|
-
if (!ts.isObjectLiteralExpression(node)) return node.getText(sf);
|
|
236
|
-
const { members, refused } = membersOf(node, sf);
|
|
237
|
-
if (refused !== undefined) return node.getText(sf);
|
|
238
|
-
const min = members.get("min");
|
|
239
|
-
const max = members.get("max");
|
|
240
|
-
if (max === undefined) {
|
|
241
|
-
yours.push("a `count` with no `max` — a count is `N`, `{ max }` or `{ min, max }`; state the ceiling");
|
|
242
|
-
return node.getText(sf);
|
|
243
|
-
}
|
|
244
|
-
if (min === undefined || (ts.isNumericLiteral(min) && Number(min.text) === 0)) return `{ max: ${max.getText(sf)} }`;
|
|
245
|
-
return `{ min: ${min.getText(sf)}, max: ${max.getText(sf)} }`;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* The `fill({…})` text one builder call becomes, or `refused` with the reason. `yours`
|
|
250
|
-
* collects what the port leaves to the author.
|
|
251
|
-
*/
|
|
252
|
-
function fillCall(name, call, sf, yours) {
|
|
253
|
-
const indent = lineIndent(sf, call.getStart(sf));
|
|
254
|
-
const column = sf.getLineAndCharacterOfPosition(call.getStart(sf)).character;
|
|
255
|
-
if (name === "contactAssign") {
|
|
256
|
-
return { refused: "`contactAssign` has no replacement — bind the contact's field with `source: fact.contact.*`, or write the choice as a text fill reading the contacts" };
|
|
257
|
-
}
|
|
258
|
-
if (call.arguments.length > 1) return { refused: `\`${name}\` takes one options object` };
|
|
259
|
-
const { members, properties, refused } = membersOf(call.arguments[0], sf);
|
|
260
|
-
if (refused !== undefined) return { refused: `\`${name}(…)\`: ${refused}` };
|
|
261
|
-
|
|
262
|
-
const part = (key) => (members.has(key) ? prosePart(members.get(key), sf) : undefined);
|
|
263
|
-
const enumSentence = (key, table) => {
|
|
264
|
-
const node = members.get(key);
|
|
265
|
-
if (node === undefined) return undefined;
|
|
266
|
-
if (!ts.isStringLiteral(node)) return prosePart(node, sf);
|
|
267
|
-
const sentence = table[node.text];
|
|
268
|
-
return sentence === null || sentence === undefined ? undefined : { text: sentence };
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
// The platform's own merge, piece for piece: `content ?? pick` (one brief under two
|
|
272
|
-
// names — an executor always read them as one), then the voice, the form, the
|
|
273
|
-
// structure's sentence and the person's.
|
|
274
|
-
const content = part("content");
|
|
275
|
-
const body = content !== undefined && (content.text === undefined || content.text.trim() !== "") ? content : part("pick");
|
|
276
|
-
const labelled = (key, label) => {
|
|
277
|
-
const piece = part(key);
|
|
278
|
-
return piece === undefined ? undefined : { ...piece, label };
|
|
279
|
-
};
|
|
280
|
-
// `none` was a second brief; it is a switch now, and its bar joins the one brief. A
|
|
281
|
-
// blank one never switched abstention on, so it folds nothing and is dropped.
|
|
282
|
-
const bar = labelled("none", NONE_LABEL);
|
|
283
|
-
const abstains = bar !== undefined && (bar.text === undefined || bar.text.trim() !== "");
|
|
284
|
-
const parts = [
|
|
285
|
-
body,
|
|
286
|
-
labelled("voice", "Voice: "),
|
|
287
|
-
labelled("structureHint", "Form: "),
|
|
288
|
-
enumSentence("structure", STRUCTURE_SENTENCE),
|
|
289
|
-
enumSentence("perspective", PERSPECTIVE_SENTENCE),
|
|
290
|
-
].filter((p) => p !== undefined);
|
|
291
|
-
if (parts.length === 0) return { refused: `\`${name}(…)\` states no prose at all — write its \`brief\`` };
|
|
292
|
-
if (abstains) {
|
|
293
|
-
parts.push(bar);
|
|
294
|
-
const line = sf.getLineAndCharacterOfPosition(members.get("none").getStart(sf)).line + 1;
|
|
295
|
-
yours.push(
|
|
296
|
-
`\`none\` is \`true\` now, and its bar is the brief's last paragraph (\`${NONE_LABEL.trim()} …\`) — rewrite it as the brief's own sentence saying when producing nothing is right, at line ${line}`,
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
const brief = briefSource(parts);
|
|
300
|
-
if (/\$\{\s*facts\./.test(brief.scanned)) {
|
|
301
|
-
yours.push("a brief interpolates `${facts.…}` — declare that fact in `reads` and refer to it by name");
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (members.has("order")) {
|
|
305
|
-
yours.push(
|
|
306
|
-
"`order: \"walkthrough\"` is gone and a pick keeps only what its brief admits — say to keep and order every photograph, and to drop anything that is not a photograph of the property",
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
if (members.has("fallback")) {
|
|
310
|
-
yours.push(
|
|
311
|
-
"`fallback` is gone — a pick that abstains lands empty. Keep the `none` pick, bind the fallback's slot with `source: fact.contact.*`, and choose between them with `compute({ reads: [pick] }, …)`",
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// Each entry keeps the comments written above the key(s) it came from — the prose
|
|
316
|
-
// keys' and the dropped keys' above the brief — so nothing the author wrote is lost.
|
|
317
|
-
const comments = commentsOf(call.arguments[0], properties, sf);
|
|
318
|
-
const entries = [];
|
|
319
|
-
const entry = (text, ...keys) => entries.push({ text, comments: keys.flatMap((key) => comments.get(key) ?? []) });
|
|
320
|
-
if (SLICE_READERS.has(name)) {
|
|
321
|
-
const declared = members.get("reads");
|
|
322
|
-
if (declared === undefined) entry(`reads: ${READS_CONST}`);
|
|
323
|
-
else if (ts.isArrayLiteralExpression(declared)) {
|
|
324
|
-
const items = declared.elements.map((e) => e.getText(sf));
|
|
325
|
-
entry(`reads: [...${READS_CONST}${items.length === 0 ? "" : `, ${items.join(", ")}`}]`, "reads");
|
|
326
|
-
} else entry(`reads: [...${READS_CONST}, ...${declared.getText(sf)}]`, "reads");
|
|
327
|
-
} else if (members.has("reads")) {
|
|
328
|
-
entry(`reads: ${members.get("reads").getText(sf)}`, "reads");
|
|
329
|
-
}
|
|
330
|
-
const carried = new Set(["reads", "count", "cap", ...(abstains ? ["none"] : [])]);
|
|
331
|
-
entry(`brief: ${brief.source}`, ...[...members.keys()].filter((key) => !carried.has(key)));
|
|
332
|
-
if (abstains) entry("none: true", "none");
|
|
333
|
-
if (members.has("count")) entry(`count: ${countSource(members.get("count"), sf, yours)}`, "count");
|
|
334
|
-
if (members.has("cap")) entry(`cap: ${members.get("cap").getText(sf)}`, "cap");
|
|
335
|
-
const trailing = comments.get("") ?? [];
|
|
336
|
-
|
|
337
|
-
const inner = `${indent} `;
|
|
338
|
-
const place = (comment) => `${inner}${comment}`;
|
|
339
|
-
const commented = trailing.length > 0 || entries.some((e) => e.comments.length > 0);
|
|
340
|
-
const oneLine = `fill({ ${entries.map((e) => e.text).join(", ")} })`;
|
|
341
|
-
const text =
|
|
342
|
-
!commented && column + oneLine.length <= LINE_WIDTH && !oneLine.includes("\n")
|
|
343
|
-
? oneLine
|
|
344
|
-
: `fill({\n${[...entries.flatMap((e) => [...e.comments.map(place), `${inner}${e.text},`]), ...trailing.map(place)].join("\n")}\n${indent}})`;
|
|
345
|
-
return { text, readsSlice: SLICE_READERS.has(name) };
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// ----- one file --------------------------------------------------------------
|
|
349
|
-
|
|
350
|
-
/** The dotted callee name of a call: `text.medium`, `list.of`, `image`. */
|
|
351
|
-
function calleeName(call) {
|
|
352
|
-
const callee = call.expression;
|
|
353
|
-
if (ts.isIdentifier(callee)) return callee.text;
|
|
354
|
-
if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) return `${callee.expression.text}.${callee.name.text}`;
|
|
355
|
-
return undefined;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function lineIndent(sf, pos) {
|
|
359
|
-
const { line } = sf.getLineAndCharacterOfPosition(pos);
|
|
360
|
-
const start = sf.getPositionOfLineAndCharacter(line, 0);
|
|
361
|
-
return /^[ \t]*/.exec(sf.text.slice(start))[0];
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// Where `fill` joins an import list: its sorted place when the author kept the list
|
|
365
|
-
// sorted, else where the first builder it replaces stood.
|
|
366
|
-
function insertionIndex(kept, fillAt) {
|
|
367
|
-
const key = (specifier) => specifier.replace(/^type\s+/, "").toLowerCase();
|
|
368
|
-
const sorted = kept.every((k, i) => i === 0 || key(kept[i - 1]) <= key(k));
|
|
369
|
-
if (!sorted) return fillAt ?? kept.length;
|
|
370
|
-
const at = kept.findIndex((k) => key(k) > "fill");
|
|
371
|
-
return at === -1 ? kept.length : at;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/** Rewrites one file's text, or returns `null` when nothing in it is this codemod's. */
|
|
375
|
-
function rewrite(text, fileName, readsImport) {
|
|
376
|
-
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
377
|
-
|
|
378
|
-
// The builder names this file imports from the framework — a local function that
|
|
379
|
-
// happens to share one is not ours to touch.
|
|
380
|
-
const imported = new Map();
|
|
381
|
-
const importDecls = [];
|
|
382
|
-
for (const statement of sf.statements) {
|
|
383
|
-
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
384
|
-
if (statement.moduleSpecifier.text !== CONCRETE) continue;
|
|
385
|
-
const bindings = statement.importClause?.namedBindings;
|
|
386
|
-
if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
|
|
387
|
-
importDecls.push(statement);
|
|
388
|
-
for (const element of bindings.elements) imported.set(element.name.text, (element.propertyName ?? element.name).text);
|
|
389
|
-
}
|
|
390
|
-
const builderOf = (identifier) => {
|
|
391
|
-
const original = imported.get(identifier);
|
|
392
|
-
return original !== undefined && BUILDERS.has(original) ? original : undefined;
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
const edits = [];
|
|
396
|
-
const yours = [];
|
|
397
|
-
const refusedNames = new Set();
|
|
398
|
-
let usesFill = false;
|
|
399
|
-
let usesReads = false;
|
|
400
|
-
|
|
401
|
-
function visit(node) {
|
|
402
|
-
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
403
|
-
const builder = builderOf(node.expression.text);
|
|
404
|
-
if (builder !== undefined) {
|
|
405
|
-
const result = fillCall(builder, node, sf, yours);
|
|
406
|
-
if (result.refused !== undefined) {
|
|
407
|
-
yours.push(result.refused);
|
|
408
|
-
refusedNames.add(node.expression.text);
|
|
409
|
-
ts.forEachChild(node, visit);
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
edits.push({ start: node.getStart(sf), end: node.getEnd(), text: result.text });
|
|
413
|
-
usesFill = true;
|
|
414
|
-
if (result.readsSlice) usesReads = true;
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
// A slot builder's `fill:` option is its `source:` now.
|
|
419
|
-
if (ts.isCallExpression(node) && SLOT_BUILDERS.has(calleeName(node) ?? "")) {
|
|
420
|
-
for (const arg of node.arguments) {
|
|
421
|
-
if (!ts.isObjectLiteralExpression(arg)) continue;
|
|
422
|
-
const hasSource = arg.properties.some((p) => p.name !== undefined && ts.isIdentifier(p.name) && p.name.text === "source");
|
|
423
|
-
for (const property of arg.properties) {
|
|
424
|
-
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name) || property.name.text !== "fill") continue;
|
|
425
|
-
if (hasSource) {
|
|
426
|
-
yours.push("a slot declares both `source:` and `fill:` — keep the one origin it has");
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
edits.push({ start: property.name.getStart(sf), end: property.name.getEnd(), text: "source" });
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
ts.forEachChild(node, visit);
|
|
434
|
-
}
|
|
435
|
-
visit(sf);
|
|
436
|
-
|
|
437
|
-
// The imports: the builders that were rewritten and the retired types out of every
|
|
438
|
-
// framework import, `fill` into the first that imports values — never an
|
|
439
|
-
// `import type`, where it would type-check as nothing and the call would not bind.
|
|
440
|
-
const importYours = [];
|
|
441
|
-
if (importDecls.length > 0) {
|
|
442
|
-
const fillHost = importDecls.find((decl) => !decl.importClause.isTypeOnly);
|
|
443
|
-
const alreadyFill = importDecls.some(
|
|
444
|
-
(decl) => !decl.importClause.isTypeOnly && decl.importClause.namedBindings.elements.some((e) => !e.isTypeOnly && e.name.text === "fill"),
|
|
445
|
-
);
|
|
446
|
-
for (const decl of importDecls) {
|
|
447
|
-
const bindings = decl.importClause.namedBindings;
|
|
448
|
-
const kept = [];
|
|
449
|
-
let fillAt;
|
|
450
|
-
for (const element of bindings.elements) {
|
|
451
|
-
const original = (element.propertyName ?? element.name).text;
|
|
452
|
-
if (BUILDERS.has(original) && !refusedNames.has(element.name.text)) {
|
|
453
|
-
fillAt ??= kept.length;
|
|
454
|
-
continue;
|
|
455
|
-
}
|
|
456
|
-
if (RETIRED_TYPES.has(original)) {
|
|
457
|
-
importYours.push(`\`${original}\` is gone — a fill is typed \`FillBinding\`, and nothing else from the old builders survives`);
|
|
458
|
-
fillAt ??= kept.length;
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
kept.push(element.getText(sf));
|
|
462
|
-
}
|
|
463
|
-
if (decl === fillHost && usesFill && !alreadyFill) kept.splice(insertionIndex(kept, fillAt), 0, "fill");
|
|
464
|
-
const changed = kept.length !== bindings.elements.length || kept.some((k, i) => k !== bindings.elements[i].getText(sf));
|
|
465
|
-
if (!changed) continue;
|
|
466
|
-
if (kept.length === 0) {
|
|
467
|
-
edits.push({ start: decl.getFullStart(), end: decl.getEnd(), text: "" });
|
|
468
|
-
continue;
|
|
469
|
-
}
|
|
470
|
-
const multiline = bindings.getText(sf).includes("\n");
|
|
471
|
-
const indent = lineIndent(sf, bindings.elements[0]?.getStart(sf) ?? bindings.getStart(sf));
|
|
472
|
-
const clause = multiline ? `{\n${kept.map((k) => `${indent}${k},`).join("\n")}\n}` : `{ ${kept.join(", ")} }`;
|
|
473
|
-
edits.push({ start: bindings.getStart(sf), end: bindings.getEnd(), text: clause });
|
|
474
|
-
}
|
|
475
|
-
const lastDecl = importDecls.at(-1);
|
|
476
|
-
const added = [];
|
|
477
|
-
if (usesFill && !alreadyFill && fillHost === undefined) added.push(`\nimport { fill } from "${CONCRETE}";`);
|
|
478
|
-
// A file a first run already ported in part (a call it could not see, fixed by hand
|
|
479
|
-
// and run again) already imports the hoisted reads.
|
|
480
|
-
const importsReads = sf.statements.some(
|
|
481
|
-
(s) =>
|
|
482
|
-
ts.isImportDeclaration(s) &&
|
|
483
|
-
s.importClause?.namedBindings !== undefined &&
|
|
484
|
-
ts.isNamedImports(s.importClause.namedBindings) &&
|
|
485
|
-
s.importClause.namedBindings.elements.some((e) => e.name.text === READS_CONST),
|
|
486
|
-
);
|
|
487
|
-
if (usesReads && readsImport !== undefined && !importsReads) added.push(`\nimport { ${READS_CONST} } from "${readsImport}";`);
|
|
488
|
-
if (added.length > 0) edits.push({ start: lastDecl.getEnd(), end: lastDecl.getEnd(), text: added.join("") });
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (edits.length === 0 && yours.length === 0 && importYours.length === 0) return null;
|
|
492
|
-
edits.sort((a, b) => b.start - a.start);
|
|
493
|
-
let out = text;
|
|
494
|
-
for (const edit of edits) out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
495
|
-
return { text: edits.length === 0 ? null : out, yours: [...new Set([...yours, ...importYours])], usesReads };
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/** The extensionless relative specifier from `file` to the hoisted reads module. */
|
|
499
|
-
function readsSpecifier(root, file) {
|
|
500
|
-
const target = join(root, READS_MODULE.replace(/\.ts$/, ""));
|
|
501
|
-
let rel = relative(dirname(file), target).split(sep).join("/");
|
|
502
|
-
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
503
|
-
return rel;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
507
|
-
export default async function fillIsASource(root) {
|
|
508
|
-
const rewritten = [];
|
|
509
|
-
const notRewritten = [];
|
|
510
|
-
const readsFile = join(root, READS_MODULE);
|
|
511
|
-
let needsReads = false;
|
|
512
|
-
const name = (file) => relative(root, file).split(sep).join("/");
|
|
513
|
-
|
|
514
|
-
for (const file of await sourceFiles(root)) {
|
|
515
|
-
if (file === readsFile) continue;
|
|
516
|
-
const text = await readFile(file, "utf8");
|
|
517
|
-
if (![...BUILDERS, ...RETIRED_TYPES].some((b) => text.includes(b)) && !/\bfill\s*:/.test(text)) continue;
|
|
518
|
-
const result = rewrite(text, file, readsSpecifier(root, file));
|
|
519
|
-
if (result === null) continue;
|
|
520
|
-
if (result.text !== null && result.text !== text) {
|
|
521
|
-
await writeFile(file, result.text, "utf8");
|
|
522
|
-
rewritten.push(name(file));
|
|
523
|
-
if (result.usesReads) needsReads = true;
|
|
524
|
-
}
|
|
525
|
-
for (const reason of result.yours) notRewritten.push({ file: name(file), reason: `by hand: ${reason}` });
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
if (needsReads && !(await exists(readsFile))) {
|
|
529
|
-
await writeFile(readsFile, READS_SOURCE, "utf8");
|
|
530
|
-
rewritten.push(READS_MODULE);
|
|
531
|
-
}
|
|
532
|
-
return { rewritten, notRewritten };
|
|
533
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// 3.0.0 — the framework's own CSS names spell `concrete-`.
|
|
2
|
-
//
|
|
3
|
-
// `base.css` used to declare its tokens under `--tr-` and emit its classes as `.tr-*`, a
|
|
4
|
-
// prefix inherited from the old kit. Templates ported from that kit spell their OWN
|
|
5
|
-
// tokens with it too, so one prefix had two owners and nothing told them apart. After
|
|
6
|
-
// this break a name is the framework's if and only if it reads `concrete-`, and
|
|
7
|
-
// `base.css` declares no `--tr-*` and emits no `.tr-*` at all — so a stylesheet still
|
|
8
|
-
// reading `var(--tr-duration-fast)` or selecting `.tr-section` matches nothing and
|
|
9
|
-
// renders a missing value.
|
|
10
|
-
//
|
|
11
|
-
// This codemod applies exactly that map, and only it: the sixteen names concrete itself
|
|
12
|
-
// emits, in every `.css`, `.ts` and `.tsx` under the workspace, in declarations, `var()`
|
|
13
|
-
// reads, selectors, `className` strings and comments alike. Everything else keeps its
|
|
14
|
-
// spelling, which is the point — `--tr-color-ink` in the same file is YOUR token, and
|
|
15
|
-
// `theme-collapse` is what moves it.
|
|
16
|
-
//
|
|
17
|
-
// THREE `tr-` NAMES ARE DELIBERATELY UNTOUCHED: `.tr-frame`, `.tr-root` and
|
|
18
|
-
// `#tr-site-config`. They are the platform's, stamped onto every rendered artifact by
|
|
19
|
-
// the publish and capture surfaces, not derived by concrete — `base.css` only styles
|
|
20
|
-
// them. They rename together in a release of their own, so that an artifact and the page
|
|
21
|
-
// that previewed it never disagree about the class they share. A workspace selecting
|
|
22
|
-
// `.tr-frame` keeps working here; `platform-namespace`, in 4.0.0, is what moves it.
|
|
23
|
-
//
|
|
24
|
-
// Nothing is ever reported as yours: the map is total and mechanical, so whatever this
|
|
25
|
-
// rewrote is not yours to touch.
|
|
26
|
-
|
|
27
|
-
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
28
|
-
import { join, relative } from "node:path";
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The §4.1 map, whole. A custom property carries its `--`; a class, id or counter name
|
|
32
|
-
* does not, which is also what keeps `--tr-image-frame-bg` and the `.tr-image-frame`
|
|
33
|
-
* class two entries rather than one prefix match.
|
|
34
|
-
*/
|
|
35
|
-
const RENAMES = new Map([
|
|
36
|
-
// Declared in base.css, read by templates.
|
|
37
|
-
["--tr-window-h", "--concrete-window-h"],
|
|
38
|
-
["--tr-ease", "--concrete-ease"],
|
|
39
|
-
["--tr-duration-fast", "--concrete-duration-fast"],
|
|
40
|
-
["--tr-duration-base", "--concrete-duration-base"],
|
|
41
|
-
// The one name in the set a template DECLARES rather than only reads.
|
|
42
|
-
["--tr-image-frame-bg", "--concrete-image-frame-bg"],
|
|
43
|
-
// base.css's frame witness, private to it: its properties and its counters.
|
|
44
|
-
["--tr-frame-window-w", "--concrete-frame-window-w"],
|
|
45
|
-
["--tr-frame-window-h", "--concrete-frame-window-h"],
|
|
46
|
-
["--tr-frame-window-mismatch", "--concrete-frame-window-mismatch"],
|
|
47
|
-
["tr-frame-owed-w", "concrete-frame-owed-w"],
|
|
48
|
-
["tr-frame-owed-h", "concrete-frame-owed-h"],
|
|
49
|
-
["tr-frame-got-w", "concrete-frame-got-w"],
|
|
50
|
-
["tr-frame-got-h", "concrete-frame-got-h"],
|
|
51
|
-
// Classes the primitives emit, and the dev canvas's own style element.
|
|
52
|
-
["tr-section", "concrete-section"],
|
|
53
|
-
["tr-image-block", "concrete-image-block"],
|
|
54
|
-
["tr-image-frame", "concrete-image-frame"],
|
|
55
|
-
["tr-canvas-shield-style", "concrete-canvas-shield-style"],
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
const escaped = (name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* One name from the map, bounded.
|
|
62
|
-
*
|
|
63
|
-
* Longest alternative first, so `--tr-frame-window-w` is never read as the untouched
|
|
64
|
-
* `tr-frame` plus a suffix. The two boundaries are what make `.tr-frame` and
|
|
65
|
-
* `.tr-image-frame-bg` miss `tr-image-frame`, and what keeps `--tr-ease` clear of a
|
|
66
|
-
* template's own `--tr-ease-out`.
|
|
67
|
-
*/
|
|
68
|
-
const NAME = new RegExp(
|
|
69
|
-
`(?<![\\w-])(?:${[...RENAMES.keys()]
|
|
70
|
-
.sort((a, b) => b.length - a.length)
|
|
71
|
-
.map(escaped)
|
|
72
|
-
.join("|")})(?![\\w-])`,
|
|
73
|
-
"g",
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
/** The file kinds a workspace spells these names in. */
|
|
77
|
-
const EXTENSIONS = [".css", ".ts", ".tsx"];
|
|
78
|
-
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
79
|
-
|
|
80
|
-
/** Every source file under `root`, absolute, skipping build output and dependencies. */
|
|
81
|
-
async function sourceFiles(root) {
|
|
82
|
-
const found = [];
|
|
83
|
-
async function walk(dir) {
|
|
84
|
-
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
85
|
-
if (entry.isDirectory()) {
|
|
86
|
-
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
87
|
-
} else if (EXTENSIONS.some((extension) => entry.name.endsWith(extension))) {
|
|
88
|
-
found.push(join(dir, entry.name));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
await walk(root);
|
|
93
|
-
return found.sort();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
97
|
-
export default async function frameworkNamespace(root) {
|
|
98
|
-
const rewritten = [];
|
|
99
|
-
for (const file of await sourceFiles(root)) {
|
|
100
|
-
const before = await readFile(file, "utf8");
|
|
101
|
-
const after = before.replace(NAME, (name) => RENAMES.get(name) ?? name);
|
|
102
|
-
if (after === before) continue;
|
|
103
|
-
await writeFile(file, after);
|
|
104
|
-
rewritten.push(relative(root, file).split("\\").join("/"));
|
|
105
|
-
}
|
|
106
|
-
return { rewritten, notRewritten: [] };
|
|
107
|
-
}
|