@multiplatform.one/cli 9.16.1 → 10.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/lib/bin/multiplatformOne.mjs +15 -0
- package/lib/commands/themeKeys.mjs +3 -0
- package/lib/source.json +2 -2
- package/lib/themeKeys-DUM-GCcW.mjs +1003 -0
- package/package.json +3 -3
- package/scripts/scaffold.sh +21 -11
- package/src/bin/multiplatformOne.ts +33 -0
- package/src/commands/themeKeyRenames.json +207 -0
- package/src/commands/themeKeys.spec.ts +403 -0
- package/src/commands/themeKeys.ts +1034 -0
- package/templates/AGENTS.md +78 -15
- package/templates/pieces/gnome/universal/README.md.partial +4 -4
- package/templates/pieces/gnome/universal/apps/__NAME__/gnome/anchor.tsx +5 -4
- package/templates/pieces/gnome/universal/apps/__NAME__/gnome/shims/forms.ts +1 -1
- package/templates/pieces/gnome/universal/apps/__NAME__/gnome/shims/theme.ts +4 -0
- package/templates/pieces/gnome/universal/apps/__NAME__/gnome/tamagui-barrel.ts +6 -6
- package/templates/pieces/gnome/universal/apps/__NAME__/package.json.partial +1 -1
- package/templates/pieces/vscode/universal/apps/__NAME__/package.json.partial +1 -1
- package/templates/pieces/webext/universal/apps/__NAME__/package.json.partial +2 -2
- package/types/bin/multiplatformOne.d.ts.map +1 -1
- package/types/commands/themeKeys.d.ts +77 -0
- package/types/commands/themeKeys.d.ts.map +1 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// mpo-theme-keys: skip-file (these fixtures spell the old keys on purpose)
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
formatThemeKeysReport,
|
|
8
|
+
isStyleValueProp,
|
|
9
|
+
listThemeKeyFiles,
|
|
10
|
+
renameCssVars,
|
|
11
|
+
renameThemeKeysInSource,
|
|
12
|
+
runThemeKeys,
|
|
13
|
+
} from "./themeKeys";
|
|
14
|
+
import themeKeyRenames from "./themeKeyRenames.json";
|
|
15
|
+
|
|
16
|
+
const tsx = (source: string) => renameThemeKeysInSource(source, "fixture.tsx");
|
|
17
|
+
const ts = (source: string) => renameThemeKeysInSource(source, "fixture.ts");
|
|
18
|
+
|
|
19
|
+
describe("the shipped map", () => {
|
|
20
|
+
it("is the 205-key table, kebab-case of the camelCase name", () => {
|
|
21
|
+
const entries = Object.entries(themeKeyRenames);
|
|
22
|
+
expect(entries).toHaveLength(205);
|
|
23
|
+
for (const [from, to] of entries) {
|
|
24
|
+
const kebab = from.replace(/([a-z])([A-Z0-9])/gu, "$1-$2").toLowerCase();
|
|
25
|
+
expect(to).toBe(kebab);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("$-token strings", () => {
|
|
31
|
+
it("renames tokens in props, style objects and plain strings", () => {
|
|
32
|
+
const { output, counts } = tsx(
|
|
33
|
+
[
|
|
34
|
+
`<View borderColor="$borderColorControl" bg="$color2" />;`,
|
|
35
|
+
`const style = { backgroundColor: "$backgroundHover", color: "$color12" };`,
|
|
36
|
+
`const ink = "$accent9";`,
|
|
37
|
+
`const value = getTokenValue("$blue10");`,
|
|
38
|
+
].join("\n"),
|
|
39
|
+
);
|
|
40
|
+
expect(output).toContain(`borderColor="$border-color-control"`);
|
|
41
|
+
expect(output).toContain(`bg="$color-2"`);
|
|
42
|
+
expect(output).toContain(`backgroundColor: "$background-hover"`);
|
|
43
|
+
expect(output).toContain(`color: "$color-12"`);
|
|
44
|
+
expect(output).toContain(`const ink = "$accent-9"`);
|
|
45
|
+
expect(output).toContain(`getTokenValue("$blue-10")`);
|
|
46
|
+
expect(counts.token).toBe(6);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("renames inside template literals and regex literals", () => {
|
|
50
|
+
const { output } = ts(
|
|
51
|
+
["const a = `0 1px 2px $shadowColor`;", "const b = /\\$color12/u;"].join("\n"),
|
|
52
|
+
);
|
|
53
|
+
expect(output).toContain("`0 1px 2px $shadow-color`");
|
|
54
|
+
expect(output).toContain("/\\$color-12/u");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("flat values after Tamagui's codemod", () => {
|
|
59
|
+
it("renames each clause's key and keeps modifiers and other values", () => {
|
|
60
|
+
const { output, counts } = tsx(
|
|
61
|
+
`<View bg="background hover:backgroundHover dark:hover:blue10" p="4 sm:6" />;`,
|
|
62
|
+
);
|
|
63
|
+
expect(output).toContain(`bg="background hover:background-hover dark:hover:blue-10"`);
|
|
64
|
+
expect(output).toContain(`p="4 sm:6"`);
|
|
65
|
+
expect(counts.flat).toBe(2);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("renames bare keys in style props, style objects and conditional values", () => {
|
|
69
|
+
const { output } = tsx(
|
|
70
|
+
[
|
|
71
|
+
`<Text color="color10" />;`,
|
|
72
|
+
`<YStack backgroundColor={\`\${on ? "green5" : "color3"}\`} />;`,
|
|
73
|
+
`<YStack boxShadow="0 8px 24px shadow4, 0 1px 2px shadow1" />;`,
|
|
74
|
+
`const Frame = styled(View, { borderColor: "borderColorField", variants: { muted: { true: { color: "textMuted" } } } });`,
|
|
75
|
+
].join("\n"),
|
|
76
|
+
);
|
|
77
|
+
expect(output).toContain(`<Text color="color-10" />`);
|
|
78
|
+
expect(output).toContain(`on ? "green-5" : "color-3"`);
|
|
79
|
+
expect(output).toContain(`boxShadow="0 8px 24px shadow-4, 0 1px 2px shadow-1"`);
|
|
80
|
+
expect(output).toContain(`borderColor: "border-color-field"`);
|
|
81
|
+
expect(output).toContain(`color: "text-muted"`);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("renames object-form values under a style prop", () => {
|
|
85
|
+
const { output, counts } = tsx(
|
|
86
|
+
`<View bg={{ default: "color2", hover: "color3", "dark:hover": "accentBackground" }} />;`,
|
|
87
|
+
);
|
|
88
|
+
expect(output).toContain(
|
|
89
|
+
`bg={{ default: "color-2", hover: "color-3", "dark:hover": "accent-background" }}`,
|
|
90
|
+
);
|
|
91
|
+
expect(counts.flat).toBe(3);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("reads off useTheme()", () => {
|
|
96
|
+
it("rewrites member reads to bracket reads, keeping optional chaining", () => {
|
|
97
|
+
const { output, counts } = tsx(
|
|
98
|
+
[
|
|
99
|
+
`const theme = useTheme();`,
|
|
100
|
+
`const a = theme.borderColorControl;`,
|
|
101
|
+
`const b = theme.color11?.val;`,
|
|
102
|
+
`const c = theme?.color12;`,
|
|
103
|
+
`const d = useTheme().accentColor;`,
|
|
104
|
+
`const e = theme.background;`,
|
|
105
|
+
].join("\n"),
|
|
106
|
+
);
|
|
107
|
+
expect(output).toContain(`theme["border-color-control"];`);
|
|
108
|
+
expect(output).toContain(`theme["color-11"]?.val;`);
|
|
109
|
+
expect(output).toContain(`theme?.["color-12"];`);
|
|
110
|
+
expect(output).toContain(`useTheme()["accent-color"];`);
|
|
111
|
+
expect(output).toContain(`theme.background;`);
|
|
112
|
+
expect(counts.member).toBe(4);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("follows a theme into locals, records and fallbacks", () => {
|
|
116
|
+
const { output } = ts(
|
|
117
|
+
[
|
|
118
|
+
`const t = useTheme();`,
|
|
119
|
+
`const ink = t.color12;`,
|
|
120
|
+
`const base = themes[scheme] ?? {};`,
|
|
121
|
+
`const muted = base.textMuted;`,
|
|
122
|
+
`const step = config.themes.light_Button.borderColorPress;`,
|
|
123
|
+
].join("\n"),
|
|
124
|
+
);
|
|
125
|
+
expect(output).toContain(`t["color-12"]`);
|
|
126
|
+
expect(output).toContain(`base["text-muted"]`);
|
|
127
|
+
expect(output).toContain(`light_Button["border-color-press"]`);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("renames a literal element read and a destructured read", () => {
|
|
131
|
+
const { output, counts } = ts(
|
|
132
|
+
[
|
|
133
|
+
`const a = theme["color12"];`,
|
|
134
|
+
`const b = theme['borderColorHover'];`,
|
|
135
|
+
`const { color12, accentBackground: fill, background } = useTheme();`,
|
|
136
|
+
].join("\n"),
|
|
137
|
+
);
|
|
138
|
+
expect(output).toContain(`theme["color-12"]`);
|
|
139
|
+
expect(output).toContain(`theme['border-color-hover']`);
|
|
140
|
+
expect(output).toContain(
|
|
141
|
+
`const { "color-12": color12, "accent-background": fill, background } = useTheme();`,
|
|
142
|
+
);
|
|
143
|
+
expect(counts.element).toBe(2);
|
|
144
|
+
expect(counts.destructure).toBe(2);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("renames a ramp step built from its prefix", () => {
|
|
148
|
+
const { output, counts } = ts(
|
|
149
|
+
[
|
|
150
|
+
"const a = theme[`accent${i + 1}`];",
|
|
151
|
+
"const b = `$color${step}`;",
|
|
152
|
+
"type Fill = `$color${number}`;",
|
|
153
|
+
"el.style.setProperty(`--color${i}`, value);",
|
|
154
|
+
].join("\n"),
|
|
155
|
+
);
|
|
156
|
+
expect(output).toContain("theme[`accent-${i + 1}`]");
|
|
157
|
+
expect(output).toContain("`$color-${step}`");
|
|
158
|
+
expect(output).toContain("type Fill = `$color-${number}`");
|
|
159
|
+
expect(output).toContain("`--color-${i}`");
|
|
160
|
+
expect(counts.family).toBe(4);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe("getVariable and getTokenValue arguments", () => {
|
|
165
|
+
it("renames a bare key passed to Tamagui's lookups", () => {
|
|
166
|
+
const { output, counts } = ts(
|
|
167
|
+
[
|
|
168
|
+
`const a = getVariableValue("color12");`,
|
|
169
|
+
`const b = getVariable(theme.selectedColor);`,
|
|
170
|
+
`const c = getTokenValue("$4", "space");`,
|
|
171
|
+
`const d = resolveTokenValue(theme, "color1") ?? resolveTokenValue(theme, "textMuted");`,
|
|
172
|
+
].join("\n"),
|
|
173
|
+
);
|
|
174
|
+
expect(output).toContain(`getVariableValue("color-12")`);
|
|
175
|
+
expect(output).toContain(`getVariable(theme["selected-color"])`);
|
|
176
|
+
expect(output).toContain(`getTokenValue("$4", "space")`);
|
|
177
|
+
expect(output).toContain(
|
|
178
|
+
`resolveTokenValue(theme, "color-1") ?? resolveTokenValue(theme, "text-muted")`,
|
|
179
|
+
);
|
|
180
|
+
expect(counts["call-arg"]).toBe(3);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("CSS variables", () => {
|
|
185
|
+
it("renames var() reads and declarations in strings", () => {
|
|
186
|
+
const { output, counts } = ts(
|
|
187
|
+
[
|
|
188
|
+
"const css = `.x { color: var(--color12); outline: 2px solid var(--outlineColor, var(--c-outlineColor, CanvasText)); }`;",
|
|
189
|
+
`const root = ":root { --color12: white; }";`,
|
|
190
|
+
`expect(declared).toBe("var(--switchTrackOffBorder)");`,
|
|
191
|
+
].join("\n"),
|
|
192
|
+
);
|
|
193
|
+
expect(output).toContain("var(--color-12)");
|
|
194
|
+
expect(output).toContain("var(--outline-color, var(--c-outlineColor, CanvasText))");
|
|
195
|
+
expect(output).toContain(":root { --color-12: white; }");
|
|
196
|
+
expect(output).toContain("var(--switch-track-off-border)");
|
|
197
|
+
expect(counts["css-var"]).toBe(4);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("renames a CSS file's custom properties", () => {
|
|
201
|
+
const { text, count } = renameCssVars(
|
|
202
|
+
".a { color: var(--red9); background: var(--backgroundHover); }",
|
|
203
|
+
);
|
|
204
|
+
expect(text).toBe(".a { color: var(--red-9); background: var(--background-hover); }");
|
|
205
|
+
expect(count).toBe(2);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe("theme definitions MPO builds by key", () => {
|
|
210
|
+
it("renames keys of a theme passed by name, a variable mock and a themes record", () => {
|
|
211
|
+
const { output, counts } = ts(
|
|
212
|
+
[
|
|
213
|
+
`addTheme({ name: "brand", theme: { color12: "#000", borderColorControl: "#111", background: "#fff" } });`,
|
|
214
|
+
`vi.mock("x", () => ({ useTheme: () => ({ color12: { val: "black" }, textMuted: { val: "#888" } }) }));`,
|
|
215
|
+
`const themes = { light: { accent9: "#00f", color1: "#fff" } };`,
|
|
216
|
+
`const lightTheme = { shadowColor: "#000", color2: "#eee" };`,
|
|
217
|
+
].join("\n"),
|
|
218
|
+
);
|
|
219
|
+
expect(output).toContain(
|
|
220
|
+
`theme: { "color-12": "#000", "border-color-control": "#111", background: "#fff" }`,
|
|
221
|
+
);
|
|
222
|
+
expect(output).toContain(`({ "color-12": { val: "black" }, "text-muted": { val: "#888" } })`);
|
|
223
|
+
expect(output).toContain(`light: { "accent-9": "#00f", "color-1": "#fff" }`);
|
|
224
|
+
expect(output).toContain(`{ "shadow-color": "#000", "color-2": "#eee" }`);
|
|
225
|
+
expect(counts.definition).toBe(8);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("renames a theme-named interface and leaves other type members listed", () => {
|
|
229
|
+
const { output, unclassified } = ts(
|
|
230
|
+
[
|
|
231
|
+
`interface MockTheme { color12?: Variable; selectedColor: Variable }`,
|
|
232
|
+
`interface Shadows { shadow1: string }`,
|
|
233
|
+
].join("\n"),
|
|
234
|
+
);
|
|
235
|
+
expect(output).toContain(
|
|
236
|
+
`interface MockTheme { "color-12"?: Variable; "selected-color": Variable }`,
|
|
237
|
+
);
|
|
238
|
+
expect(output).toContain(`interface Shadows { shadow1: string }`);
|
|
239
|
+
expect(unclassified.map((site) => site.key)).toEqual(["shadow1"]);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("key lists", () => {
|
|
244
|
+
it("renames an array or union made only of theme keys", () => {
|
|
245
|
+
const { output, counts } = ts(
|
|
246
|
+
[
|
|
247
|
+
`for (const key of ["color", "color12", "color11"]) read(key);`,
|
|
248
|
+
`type Ink = "color11" | "color12" | "textMuted";`,
|
|
249
|
+
].join("\n"),
|
|
250
|
+
);
|
|
251
|
+
expect(output).toContain(`["color", "color-12", "color-11"]`);
|
|
252
|
+
expect(output).toContain(`type Ink = "color-11" | "color-12" | "text-muted";`);
|
|
253
|
+
expect(counts["key-list"]).toBe(5);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe("leaves alone what is not a theme key", () => {
|
|
258
|
+
it("keeps prop names, non-theme tokens and keys the map does not list", () => {
|
|
259
|
+
const source = [
|
|
260
|
+
`<Text color="red" fontSize="$4" padding="$true" zIndex="$5" borderRadius="$radius.3" />;`,
|
|
261
|
+
`<View bg="$brandAccent" borderColor="$colorBrand" theme="blue" />;`,
|
|
262
|
+
`<View bg="$color-12" borderColor="border-color-control" />;`,
|
|
263
|
+
`const x = "$color12x";`,
|
|
264
|
+
`import data from "./color12";`,
|
|
265
|
+
].join("\n");
|
|
266
|
+
const { output, counts, unclassified } = tsx(source);
|
|
267
|
+
expect(output).toBe(source);
|
|
268
|
+
expect(counts).toEqual({});
|
|
269
|
+
expect(unclassified).toEqual([]);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("keeps style-named keys of style objects and lists, and library palettes", () => {
|
|
273
|
+
const source = [
|
|
274
|
+
`import { gray } from "@tamagui/colors";`,
|
|
275
|
+
`import * as Colors from "@tamagui/colors";`,
|
|
276
|
+
`const red = Colors.red.red9;`,
|
|
277
|
+
`const { blue } = Colors;`,
|
|
278
|
+
`const sky = blue.blue10;`,
|
|
279
|
+
`const style = { borderColor: "red", shadowColor: "#000", outlineColor: knob.outline };`,
|
|
280
|
+
`const edge = knobProps.surface.borderColor;`,
|
|
281
|
+
`const props = ["color", "backgroundColor", "borderColor"] as const;`,
|
|
282
|
+
`const fallback = gray.gray6;`,
|
|
283
|
+
`// a comment about $color12 and theme.color12 stays as written`,
|
|
284
|
+
].join("\n");
|
|
285
|
+
const { output, counts, unclassified } = ts(source);
|
|
286
|
+
expect(output).toBe(source);
|
|
287
|
+
expect(counts).toEqual({});
|
|
288
|
+
expect(unclassified).toEqual([]);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("leaves a key on an unknown receiver alone and lists the site", () => {
|
|
292
|
+
const source = [
|
|
293
|
+
`const step = palette.color12;`,
|
|
294
|
+
`switchOffGround({ background: text(scope.background), color4: text(scope.color4) });`,
|
|
295
|
+
`<Swatch token="gray11" />;`,
|
|
296
|
+
"const label = out[`shadow${i}`];",
|
|
297
|
+
`const defaultLightShadows: Shadows = { shadow1: "rgba(0,0,0,0.04)", shadow2: "rgba(0,0,0,0.08)" };`,
|
|
298
|
+
].join("\n");
|
|
299
|
+
const { output, unclassified } = tsx(source);
|
|
300
|
+
expect(output).toBe(source);
|
|
301
|
+
expect(unclassified.map((site) => [site.line, site.key])).toEqual([
|
|
302
|
+
[1, "color12"],
|
|
303
|
+
[2, "color4"],
|
|
304
|
+
[2, "color4"],
|
|
305
|
+
[3, "gray11"],
|
|
306
|
+
[4, "shadow${n}"],
|
|
307
|
+
[5, "shadow1"],
|
|
308
|
+
[5, "shadow2"],
|
|
309
|
+
]);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe("idempotence", () => {
|
|
314
|
+
const everyForm = [
|
|
315
|
+
`const theme = useTheme();`,
|
|
316
|
+
`const { color12 } = theme;`,
|
|
317
|
+
`const a = theme.borderColorControl ?? theme["color11"] ?? theme[\`accent\${i}\`];`,
|
|
318
|
+
`const b = getVariableValue("color10");`,
|
|
319
|
+
`const c = \`var(--color12) $color\${n}\`;`,
|
|
320
|
+
`const d = ["color11", "color12"];`,
|
|
321
|
+
`addTheme({ name: "x", theme: { color12: "#000" } });`,
|
|
322
|
+
`<View bg="$color2 hover:color3" color="textMuted" borderColor={{ default: "color6" }} />;`,
|
|
323
|
+
].join("\n");
|
|
324
|
+
|
|
325
|
+
it("changes nothing on a second run", () => {
|
|
326
|
+
const first = tsx(everyForm);
|
|
327
|
+
expect(Object.values(first.counts).reduce((sum, n) => sum + (n ?? 0), 0)).toBeGreaterThan(10);
|
|
328
|
+
const second = tsx(first.output);
|
|
329
|
+
expect(second.output).toBe(first.output);
|
|
330
|
+
expect(second.counts).toEqual({});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe("runThemeKeys over a tree", () => {
|
|
335
|
+
const dirs: string[] = [];
|
|
336
|
+
afterEach(async () => {
|
|
337
|
+
for (const dir of dirs.splice(0)) await fs.rm(dir, { recursive: true, force: true });
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
async function fixture() {
|
|
341
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), "mpo-theme-keys-"));
|
|
342
|
+
dirs.push(root);
|
|
343
|
+
const files: Record<string, string> = {
|
|
344
|
+
"src/App.tsx": `export const App = () => <View bg="$color2" color="color12" />;\n`,
|
|
345
|
+
"src/styles.css": `.a { color: var(--color11); }\n`,
|
|
346
|
+
"src/notes.md": `Use $color12 here.\n`,
|
|
347
|
+
"src/gen.generated.ts": `export const a = "$color12";\n`,
|
|
348
|
+
"src/fixture.ts": `// mpo-theme-keys: skip-file\nexport const a = "$color12";\n`,
|
|
349
|
+
"src/banner.ts": `// @generated by a tool\nexport const a = "$color12";\n`,
|
|
350
|
+
"node_modules/pkg/index.js": `export const a = "$color12";\n`,
|
|
351
|
+
"dist/index.js": `export const a = "$color12";\n`,
|
|
352
|
+
"vendor/keep.ts": `export const a = "$color12";\n`,
|
|
353
|
+
};
|
|
354
|
+
for (const [file, text] of Object.entries(files)) {
|
|
355
|
+
await fs.mkdir(path.dirname(path.join(root, file)), { recursive: true });
|
|
356
|
+
await fs.writeFile(path.join(root, file), text);
|
|
357
|
+
}
|
|
358
|
+
return root;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
it("lists source and CSS, skipping node_modules, dist, generated and excluded files", async () => {
|
|
362
|
+
const root = await fixture();
|
|
363
|
+
expect(await listThemeKeyFiles(root, [], ["vendor"])).toEqual([
|
|
364
|
+
"src/App.tsx",
|
|
365
|
+
"src/banner.ts",
|
|
366
|
+
"src/fixture.ts",
|
|
367
|
+
"src/styles.css",
|
|
368
|
+
]);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("writes nothing on a dry run, applies with write, and is a no-op the second time", async () => {
|
|
372
|
+
const root = await fixture();
|
|
373
|
+
const dry = await runThemeKeys(root, { exclude: ["vendor"] });
|
|
374
|
+
expect(dry.files.map((file) => [file.file, file.total])).toEqual([
|
|
375
|
+
["src/App.tsx", 2],
|
|
376
|
+
["src/styles.css", 1],
|
|
377
|
+
]);
|
|
378
|
+
expect(dry.skipped.map((entry) => entry.reason)).toEqual([
|
|
379
|
+
"generated",
|
|
380
|
+
"mpo-theme-keys: skip-file",
|
|
381
|
+
]);
|
|
382
|
+
expect(await fs.readFile(path.join(root, "src/App.tsx"), "utf8")).toContain(`"$color2"`);
|
|
383
|
+
expect(formatThemeKeysReport(dry)).toContain("3 theme keys to rename in 2 of 2 files");
|
|
384
|
+
|
|
385
|
+
await runThemeKeys(root, { exclude: ["vendor"], write: true });
|
|
386
|
+
expect(await fs.readFile(path.join(root, "src/App.tsx"), "utf8")).toBe(
|
|
387
|
+
`export const App = () => <View bg="$color-2" color="color-12" />;\n`,
|
|
388
|
+
);
|
|
389
|
+
expect(await fs.readFile(path.join(root, "src/styles.css"), "utf8")).toBe(
|
|
390
|
+
`.a { color: var(--color-11); }\n`,
|
|
391
|
+
);
|
|
392
|
+
expect(await fs.readFile(path.join(root, "src/notes.md"), "utf8")).toBe(`Use $color12 here.\n`);
|
|
393
|
+
expect(await fs.readFile(path.join(root, "vendor/keep.ts"), "utf8")).toContain(`"$color12"`);
|
|
394
|
+
|
|
395
|
+
const again = await runThemeKeys(root, { exclude: ["vendor"], write: true });
|
|
396
|
+
expect(again.files).toEqual([]);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("names style props by the colour they carry", () => {
|
|
400
|
+
expect(["color", "bg", "borderColor", "boxShadow", "fill"].every(isStyleValueProp)).toBe(true);
|
|
401
|
+
expect(["theme", "name", "testID", "size"].some(isStyleValueProp)).toBe(false);
|
|
402
|
+
});
|
|
403
|
+
});
|