@typestyles/cli 0.0.0-unstable.9cf89f1ce486 → 0.0.0-unstable.9ddc7a7c75fd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cli.cjs +86 -494
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +83 -84
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +12 -460
- package/dist/index.d.cts +31 -29
- package/dist/index.d.ts +31 -29
- package/dist/index.js +1 -3
- package/dist/snapshot-classnames-BVrvtE-T.cjs +515 -0
- package/dist/snapshot-classnames-BVrvtE-T.cjs.map +1 -0
- package/dist/snapshot-classnames-Blbh1QKS.js +424 -0
- package/dist/snapshot-classnames-Blbh1QKS.js.map +1 -0
- package/package.json +8 -10
- package/dist/chunk-HWFK4DEK.js +0 -442
- package/dist/chunk-HWFK4DEK.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @typestyles/cli
|
|
2
2
|
|
|
3
|
-
Command-line tools for [typestyles](https://github.com/
|
|
3
|
+
Command-line tools for [typestyles](https://github.com/phthalo-dev/typestyles).
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ pnpm add -D @typestyles/cli
|
|
|
12
12
|
|
|
13
13
|
### `typestyles snapshot`
|
|
14
14
|
|
|
15
|
-
Snapshot semantic class names from `styles.class
|
|
15
|
+
Snapshot semantic class names from `style()` / `recipe()` call sites (and legacy `styles.class` / `styles.component` on `createStyles()` instances).
|
|
16
16
|
Use with `@typestyles/no-removed-public-classname` to guard breaking renames in
|
|
17
17
|
publishable packages.
|
|
18
18
|
|
package/dist/cli.cjs
CHANGED
|
@@ -1,481 +1,77 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
const require_snapshot_classnames = require("./snapshot-classnames-BVrvtE-T.cjs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_snapshot_classnames.__toESM(node_path, 1);
|
|
5
|
+
//#region src/commands/snapshot.ts
|
|
6
|
+
const SNAPSHOT_HELP = `typestyles snapshot [options]
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var fg = require('fast-glob');
|
|
8
|
-
|
|
9
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
13
|
-
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
14
|
-
var fg__default = /*#__PURE__*/_interopDefault(fg);
|
|
15
|
-
|
|
16
|
-
function sanitizeClassSegment(label) {
|
|
17
|
-
const normalized = label.trim().toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
18
|
-
return normalized.replace(/-+/g, "-").replace(/^-|-$/g, "") || "style";
|
|
19
|
-
}
|
|
20
|
-
var RESERVED_COMPONENT_KEYS = /* @__PURE__ */ new Set([
|
|
21
|
-
"base",
|
|
22
|
-
"variants",
|
|
23
|
-
"compoundVariants",
|
|
24
|
-
"defaultVariants",
|
|
25
|
-
"slots"
|
|
26
|
-
]);
|
|
27
|
-
var PUBLIC_CLASSNAMES_SNAPSHOT = ".typestyles-public-classnames.json";
|
|
28
|
-
var DEFAULT_INCLUDE = ["**/*.{ts,tsx}"];
|
|
29
|
-
var DEFAULT_EXCLUDE = [
|
|
30
|
-
"**/node_modules/**",
|
|
31
|
-
"**/dist/**",
|
|
32
|
-
"**/*.d.ts",
|
|
33
|
-
"**/*.test.{ts,tsx}",
|
|
34
|
-
"**/*.spec.{ts,tsx}"
|
|
35
|
-
];
|
|
36
|
-
function semanticScopePrefix(scopeId) {
|
|
37
|
-
if (!scopeId.trim()) return "";
|
|
38
|
-
return `${sanitizeClassSegment(scopeId)}-`;
|
|
39
|
-
}
|
|
40
|
-
function semanticClassName(config, namespace, suffix) {
|
|
41
|
-
if (config.mode !== "semantic") return null;
|
|
42
|
-
const prefix = semanticScopePrefix(config.scopeId);
|
|
43
|
-
if (suffix === void 0) return `${prefix}${namespace}`;
|
|
44
|
-
return `${prefix}${namespace}-${suffix}`;
|
|
45
|
-
}
|
|
46
|
-
function getStaticObjectKey(name) {
|
|
47
|
-
if (ts__default.default.isIdentifier(name)) return name.text;
|
|
48
|
-
if (ts__default.default.isStringLiteral(name)) return name.text;
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
function firstStringArg(args) {
|
|
52
|
-
const first = args[0];
|
|
53
|
-
if (!first || !ts__default.default.isStringLiteral(first)) return null;
|
|
54
|
-
return first.text;
|
|
55
|
-
}
|
|
56
|
-
function unwrapExpression(expr) {
|
|
57
|
-
let current = expr;
|
|
58
|
-
while (ts__default.default.isParenthesizedExpression(current)) {
|
|
59
|
-
current = current.expression;
|
|
60
|
-
}
|
|
61
|
-
return current;
|
|
62
|
-
}
|
|
63
|
-
function objectExpressionFromConfigArg(arg) {
|
|
64
|
-
if (!arg) return null;
|
|
65
|
-
const expr = unwrapExpression(arg);
|
|
66
|
-
if (ts__default.default.isObjectLiteralExpression(expr)) return expr;
|
|
67
|
-
if (ts__default.default.isArrowFunction(expr)) {
|
|
68
|
-
if (ts__default.default.isObjectLiteralExpression(expr.body)) return expr.body;
|
|
69
|
-
if (ts__default.default.isBlock(expr.body)) {
|
|
70
|
-
for (const stmt of expr.body.statements) {
|
|
71
|
-
if (ts__default.default.isReturnStatement(stmt) && stmt.expression && ts__default.default.isObjectLiteralExpression(unwrapExpression(stmt.expression))) {
|
|
72
|
-
return unwrapExpression(stmt.expression);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
function literalFromProperty(obj, key) {
|
|
80
|
-
for (const prop of obj.properties) {
|
|
81
|
-
if (!ts__default.default.isPropertyAssignment(prop)) continue;
|
|
82
|
-
const propKey = getStaticObjectKey(prop.name);
|
|
83
|
-
if (propKey !== key) continue;
|
|
84
|
-
const init = unwrapExpression(prop.initializer);
|
|
85
|
-
if (ts__default.default.isStringLiteral(init)) return init.text;
|
|
86
|
-
if (ts__default.default.isNoSubstitutionTemplateLiteral(init)) return init.text;
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
function hasObjectKey(obj, key) {
|
|
91
|
-
return obj.properties.some((prop) => {
|
|
92
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
93
|
-
return getStaticObjectKey(prop.name) === key;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
function collectSuffixesFromConfig(obj) {
|
|
97
|
-
const suffixes = [];
|
|
98
|
-
const hasVariants = hasObjectKey(obj, "variants");
|
|
99
|
-
const hasCompound = hasObjectKey(obj, "compoundVariants");
|
|
100
|
-
const hasDefaults = hasObjectKey(obj, "defaultVariants");
|
|
101
|
-
const hasSlots = hasObjectKey(obj, "slots");
|
|
102
|
-
if (hasSlots && (hasVariants || hasCompound || hasDefaults)) {
|
|
103
|
-
const baseObj = obj.properties.find((prop) => {
|
|
104
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
105
|
-
return getStaticObjectKey(prop.name) === "base";
|
|
106
|
-
});
|
|
107
|
-
if (baseObj && ts__default.default.isPropertyAssignment(baseObj) && ts__default.default.isObjectLiteralExpression(baseObj.initializer)) {
|
|
108
|
-
for (const slotProp of baseObj.initializer.properties) {
|
|
109
|
-
if (!ts__default.default.isPropertyAssignment(slotProp)) continue;
|
|
110
|
-
const slot = getStaticObjectKey(slotProp.name);
|
|
111
|
-
if (slot) suffixes.push(slot);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
const variantsProp = obj.properties.find((prop) => {
|
|
115
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
116
|
-
return getStaticObjectKey(prop.name) === "variants";
|
|
117
|
-
});
|
|
118
|
-
if (variantsProp && ts__default.default.isPropertyAssignment(variantsProp) && ts__default.default.isObjectLiteralExpression(variantsProp.initializer)) {
|
|
119
|
-
for (const dimProp of variantsProp.initializer.properties) {
|
|
120
|
-
if (!ts__default.default.isPropertyAssignment(dimProp) || !ts__default.default.isObjectLiteralExpression(dimProp.initializer)) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
const dimension = getStaticObjectKey(dimProp.name);
|
|
124
|
-
if (!dimension) continue;
|
|
125
|
-
for (const optProp of dimProp.initializer.properties) {
|
|
126
|
-
if (!ts__default.default.isPropertyAssignment(optProp) || !ts__default.default.isObjectLiteralExpression(optProp.initializer)) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const option = getStaticObjectKey(optProp.name);
|
|
130
|
-
if (!option) continue;
|
|
131
|
-
for (const slotProp of optProp.initializer.properties) {
|
|
132
|
-
if (!ts__default.default.isPropertyAssignment(slotProp)) continue;
|
|
133
|
-
const slot = getStaticObjectKey(slotProp.name);
|
|
134
|
-
if (slot) suffixes.push(`${slot}-${dimension}-${option}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const compoundProp = obj.properties.find((prop) => {
|
|
140
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
141
|
-
return getStaticObjectKey(prop.name) === "compoundVariants";
|
|
142
|
-
});
|
|
143
|
-
if (compoundProp && ts__default.default.isPropertyAssignment(compoundProp) && ts__default.default.isArrayLiteralExpression(compoundProp.initializer)) {
|
|
144
|
-
compoundProp.initializer.elements.forEach((element, index) => {
|
|
145
|
-
if (!element || !ts__default.default.isObjectLiteralExpression(element)) return;
|
|
146
|
-
const styleProp = element.properties.find((prop) => {
|
|
147
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
148
|
-
return getStaticObjectKey(prop.name) === "style";
|
|
149
|
-
});
|
|
150
|
-
if (styleProp && ts__default.default.isPropertyAssignment(styleProp) && ts__default.default.isObjectLiteralExpression(styleProp.initializer)) {
|
|
151
|
-
for (const slotProp of styleProp.initializer.properties) {
|
|
152
|
-
if (!ts__default.default.isPropertyAssignment(slotProp)) continue;
|
|
153
|
-
const slot = getStaticObjectKey(slotProp.name);
|
|
154
|
-
if (slot) suffixes.push(`${slot}-compound-${index}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
return suffixes;
|
|
160
|
-
}
|
|
161
|
-
if (hasSlots && !hasVariants && !hasCompound && !hasDefaults) {
|
|
162
|
-
const slotsProp = obj.properties.find((prop) => {
|
|
163
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
164
|
-
return getStaticObjectKey(prop.name) === "slots";
|
|
165
|
-
});
|
|
166
|
-
if (slotsProp && ts__default.default.isPropertyAssignment(slotsProp) && ts__default.default.isArrayLiteralExpression(slotsProp.initializer)) {
|
|
167
|
-
for (const element of slotsProp.initializer.elements) {
|
|
168
|
-
if (element && ts__default.default.isStringLiteral(element)) {
|
|
169
|
-
suffixes.push(element.text);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
for (const prop of obj.properties) {
|
|
174
|
-
if (!ts__default.default.isPropertyAssignment(prop)) continue;
|
|
175
|
-
const key = getStaticObjectKey(prop.name);
|
|
176
|
-
if (!key || key === "slots") continue;
|
|
177
|
-
suffixes.push(key);
|
|
178
|
-
}
|
|
179
|
-
return suffixes;
|
|
180
|
-
}
|
|
181
|
-
if (hasVariants || hasCompound || hasDefaults) {
|
|
182
|
-
if (hasObjectKey(obj, "base")) suffixes.push("base");
|
|
183
|
-
const variantsProp = obj.properties.find((prop) => {
|
|
184
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
185
|
-
return getStaticObjectKey(prop.name) === "variants";
|
|
186
|
-
});
|
|
187
|
-
if (variantsProp && ts__default.default.isPropertyAssignment(variantsProp) && ts__default.default.isObjectLiteralExpression(variantsProp.initializer)) {
|
|
188
|
-
for (const dimProp of variantsProp.initializer.properties) {
|
|
189
|
-
if (!ts__default.default.isPropertyAssignment(dimProp) || !ts__default.default.isObjectLiteralExpression(dimProp.initializer)) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
const dimension = getStaticObjectKey(dimProp.name);
|
|
193
|
-
if (!dimension) continue;
|
|
194
|
-
for (const optProp of dimProp.initializer.properties) {
|
|
195
|
-
if (!ts__default.default.isPropertyAssignment(optProp)) continue;
|
|
196
|
-
const option = getStaticObjectKey(optProp.name);
|
|
197
|
-
if (option) suffixes.push(`${dimension}-${option}`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const compoundProp = obj.properties.find((prop) => {
|
|
202
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
203
|
-
return getStaticObjectKey(prop.name) === "compoundVariants";
|
|
204
|
-
});
|
|
205
|
-
if (compoundProp && ts__default.default.isPropertyAssignment(compoundProp) && ts__default.default.isArrayLiteralExpression(compoundProp.initializer)) {
|
|
206
|
-
compoundProp.initializer.elements.forEach((_, index) => {
|
|
207
|
-
suffixes.push(`compound-${index}`);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
return suffixes;
|
|
211
|
-
}
|
|
212
|
-
for (const prop of obj.properties) {
|
|
213
|
-
if (!ts__default.default.isPropertyAssignment(prop)) continue;
|
|
214
|
-
const key = getStaticObjectKey(prop.name);
|
|
215
|
-
if (!key || RESERVED_COMPONENT_KEYS.has(key)) continue;
|
|
216
|
-
suffixes.push(key);
|
|
217
|
-
}
|
|
218
|
-
return suffixes;
|
|
219
|
-
}
|
|
220
|
-
function parseCreateStylesConfig(init) {
|
|
221
|
-
const config = { mode: "semantic", scopeId: "" };
|
|
222
|
-
let expr = unwrapExpression(init);
|
|
223
|
-
if (ts__default.default.isCallExpression(expr)) {
|
|
224
|
-
const firstArg = expr.arguments[0];
|
|
225
|
-
if (!firstArg) return config;
|
|
226
|
-
expr = unwrapExpression(firstArg);
|
|
227
|
-
}
|
|
228
|
-
if (!ts__default.default.isObjectLiteralExpression(expr)) return config;
|
|
229
|
-
const mode = literalFromProperty(expr, "mode");
|
|
230
|
-
if (mode === "semantic" || mode === "hashed" || mode === "compact" || mode === "atomic") {
|
|
231
|
-
config.mode = mode;
|
|
232
|
-
}
|
|
233
|
-
const scopeId = literalFromProperty(expr, "scopeId");
|
|
234
|
-
if (scopeId != null) config.scopeId = scopeId;
|
|
235
|
-
return config;
|
|
236
|
-
}
|
|
237
|
-
function isCreateStylesCall(expr) {
|
|
238
|
-
const unwrapped = unwrapExpression(expr);
|
|
239
|
-
if (!ts__default.default.isCallExpression(unwrapped)) return false;
|
|
240
|
-
const callee = unwrapped.expression;
|
|
241
|
-
if (ts__default.default.isIdentifier(callee) && (callee.text === "createStyles" || callee.text === "createTypeStyles")) {
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
if (ts__default.default.isPropertyAccessExpression(callee) && ts__default.default.isIdentifier(callee.expression) && callee.expression.text === "typestyles" && (callee.name.text === "createStyles" || callee.name.text === "createTypeStyles")) {
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
function registerBindingFromCreateCall(bindings, name, init) {
|
|
250
|
-
bindings.set(name, parseCreateStylesConfig(init));
|
|
251
|
-
}
|
|
252
|
-
function collectBindings(sourceFile) {
|
|
253
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
254
|
-
const visit = (node) => {
|
|
255
|
-
if (ts__default.default.isVariableDeclaration(node) && node.initializer && isCreateStylesCall(node.initializer)) {
|
|
256
|
-
if (ts__default.default.isIdentifier(node.name)) {
|
|
257
|
-
registerBindingFromCreateCall(bindings, node.name.text, node.initializer);
|
|
258
|
-
} else if (ts__default.default.isObjectBindingPattern(node.name)) {
|
|
259
|
-
const config = parseCreateStylesConfig(node.initializer);
|
|
260
|
-
for (const element of node.name.elements) {
|
|
261
|
-
if (ts__default.default.isBindingElement(element) && ts__default.default.isIdentifier(element.name)) {
|
|
262
|
-
bindings.set(element.name.text, config);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
ts__default.default.forEachChild(node, visit);
|
|
268
|
-
};
|
|
269
|
-
visit(sourceFile);
|
|
270
|
-
return bindings;
|
|
271
|
-
}
|
|
272
|
-
function calleeMethodName(expr) {
|
|
273
|
-
if (!ts__default.default.isPropertyAccessExpression(expr)) return null;
|
|
274
|
-
if (ts__default.default.isIdentifier(expr.name)) return expr.name.text;
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
function lineOf(sourceFile, node) {
|
|
278
|
-
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
279
|
-
return line + 1;
|
|
280
|
-
}
|
|
281
|
-
function stylesBindingFromCallee(expr, bindings, defaultConfig) {
|
|
282
|
-
if (ts__default.default.isPropertyAccessExpression(expr) && ts__default.default.isIdentifier(expr.expression)) {
|
|
283
|
-
const binding = bindings.get(expr.expression.text);
|
|
284
|
-
if (binding) return binding;
|
|
285
|
-
if (expr.expression.text === "styles" && defaultConfig) return defaultConfig;
|
|
286
|
-
}
|
|
287
|
-
if (ts__default.default.isIdentifier(expr) && expr.text === "styles") {
|
|
288
|
-
return bindings.get("styles") ?? defaultConfig ?? { mode: "semantic", scopeId: "" };
|
|
289
|
-
}
|
|
290
|
-
return defaultConfig ?? { mode: "semantic", scopeId: "" };
|
|
291
|
-
}
|
|
292
|
-
function mergeProjectBindings(sourceFiles) {
|
|
293
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
294
|
-
const configs = [];
|
|
295
|
-
for (const sourceFile of sourceFiles) {
|
|
296
|
-
const fileBindings = collectBindings(sourceFile);
|
|
297
|
-
for (const [key, value] of fileBindings) {
|
|
298
|
-
bindings.set(key, value);
|
|
299
|
-
configs.push(value);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
const unique = /* @__PURE__ */ new Map();
|
|
303
|
-
for (const config of configs) {
|
|
304
|
-
unique.set(`${config.mode}:${config.scopeId}`, config);
|
|
305
|
-
}
|
|
306
|
-
const defaultConfig = unique.size === 1 ? [...unique.values()][0] : void 0;
|
|
307
|
-
return { bindings, defaultConfig };
|
|
308
|
-
}
|
|
309
|
-
function collectCallsFromSourceFile(sourceFile, relativePath, bindings, defaultConfig) {
|
|
310
|
-
const entries = [];
|
|
311
|
-
const visit = (node) => {
|
|
312
|
-
if (ts__default.default.isCallExpression(node)) {
|
|
313
|
-
const method = calleeMethodName(node.expression);
|
|
314
|
-
if (method === "class" || method === "component") {
|
|
315
|
-
const namespace = firstStringArg(node.arguments);
|
|
316
|
-
if (!namespace) {
|
|
317
|
-
ts__default.default.forEachChild(node, visit);
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
const config = stylesBindingFromCallee(node.expression, bindings, defaultConfig);
|
|
321
|
-
const line = lineOf(sourceFile, node.arguments[0] ?? node);
|
|
322
|
-
if (method === "class") {
|
|
323
|
-
const className = semanticClassName(config, namespace);
|
|
324
|
-
if (className) {
|
|
325
|
-
entries.push({
|
|
326
|
-
className,
|
|
327
|
-
kind: "class",
|
|
328
|
-
namespace,
|
|
329
|
-
file: relativePath,
|
|
330
|
-
line
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
} else {
|
|
334
|
-
const configObj = objectExpressionFromConfigArg(node.arguments[1]);
|
|
335
|
-
const suffixes = configObj ? collectSuffixesFromConfig(configObj) : ["base"];
|
|
336
|
-
for (const suffix of suffixes) {
|
|
337
|
-
const className = semanticClassName(config, namespace, suffix);
|
|
338
|
-
if (className) {
|
|
339
|
-
entries.push({
|
|
340
|
-
className,
|
|
341
|
-
kind: "component",
|
|
342
|
-
namespace,
|
|
343
|
-
suffix,
|
|
344
|
-
file: relativePath,
|
|
345
|
-
line
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
ts__default.default.forEachChild(node, visit);
|
|
353
|
-
};
|
|
354
|
-
visit(sourceFile);
|
|
355
|
-
return entries;
|
|
356
|
-
}
|
|
357
|
-
function collectPublicClassNamesFromFiles(filePaths, rootDir) {
|
|
358
|
-
const parsed = filePaths.map((filePath) => {
|
|
359
|
-
const sourceText = fs__default.default.readFileSync(filePath, "utf8");
|
|
360
|
-
const sourceFile = ts__default.default.createSourceFile(
|
|
361
|
-
filePath,
|
|
362
|
-
sourceText,
|
|
363
|
-
ts__default.default.ScriptTarget.Latest,
|
|
364
|
-
true,
|
|
365
|
-
filePath.endsWith(".tsx") ? ts__default.default.ScriptKind.TSX : ts__default.default.ScriptKind.TS
|
|
366
|
-
);
|
|
367
|
-
return { filePath, sourceFile, relativePath: path__default.default.relative(rootDir, filePath) };
|
|
368
|
-
});
|
|
369
|
-
const { bindings, defaultConfig } = mergeProjectBindings(parsed.map((item) => item.sourceFile));
|
|
370
|
-
const entries = [];
|
|
371
|
-
for (const { sourceFile, relativePath } of parsed) {
|
|
372
|
-
entries.push(...collectCallsFromSourceFile(sourceFile, relativePath, bindings, defaultConfig));
|
|
373
|
-
}
|
|
374
|
-
return dedupeEntries(entries);
|
|
375
|
-
}
|
|
376
|
-
function dedupeEntries(entries) {
|
|
377
|
-
const byClass = /* @__PURE__ */ new Map();
|
|
378
|
-
for (const entry of entries) {
|
|
379
|
-
if (!byClass.has(entry.className)) {
|
|
380
|
-
byClass.set(entry.className, entry);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
return [...byClass.values()].sort((a, b) => a.className.localeCompare(b.className));
|
|
384
|
-
}
|
|
385
|
-
async function collectPublicClassNames(options = {}) {
|
|
386
|
-
const rootDir = path__default.default.resolve(options.rootDir ?? process.cwd());
|
|
387
|
-
const include = options.include ?? DEFAULT_INCLUDE;
|
|
388
|
-
const exclude = options.exclude ?? DEFAULT_EXCLUDE;
|
|
389
|
-
const files = await fg__default.default(include, {
|
|
390
|
-
cwd: rootDir,
|
|
391
|
-
absolute: true,
|
|
392
|
-
ignore: exclude
|
|
393
|
-
});
|
|
394
|
-
return collectPublicClassNamesFromFiles(files, rootDir);
|
|
395
|
-
}
|
|
396
|
-
function buildSnapshot(entries) {
|
|
397
|
-
const sorted = dedupeEntries(entries);
|
|
398
|
-
return {
|
|
399
|
-
version: 1,
|
|
400
|
-
classNames: sorted.map((entry) => entry.className),
|
|
401
|
-
entries: sorted
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function writePublicClassNamesSnapshot(snapshotPath, entries) {
|
|
405
|
-
const snapshot = buildSnapshot(entries);
|
|
406
|
-
fs__default.default.writeFileSync(snapshotPath, `${JSON.stringify(snapshot, null, 2)}
|
|
407
|
-
`, "utf8");
|
|
408
|
-
return snapshot;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// src/commands/snapshot.ts
|
|
412
|
-
var SNAPSHOT_HELP = `typestyles snapshot [options]
|
|
413
|
-
|
|
414
|
-
Scan TypeScript sources for semantic \`styles.class\` / \`styles.component\` class names
|
|
415
|
-
and write or print the public API snapshot used by \`@typestyles/no-removed-public-classname\`.
|
|
8
|
+
Scan TypeScript sources for semantic \`style\` / \`recipe\` (and legacy \`styles.class\` /
|
|
9
|
+
\`styles.component\`) class names and write or print the public API snapshot used by
|
|
10
|
+
\`@typestyles/no-removed-public-classname\`.
|
|
416
11
|
|
|
417
12
|
Options:
|
|
418
|
-
--write Write ${PUBLIC_CLASSNAMES_SNAPSHOT} in the project root
|
|
419
|
-
--out <path> Snapshot output path (default: ./${PUBLIC_CLASSNAMES_SNAPSHOT})
|
|
13
|
+
--write Write ${require_snapshot_classnames.PUBLIC_CLASSNAMES_SNAPSHOT} in the project root
|
|
14
|
+
--out <path> Snapshot output path (default: ./${require_snapshot_classnames.PUBLIC_CLASSNAMES_SNAPSHOT})
|
|
420
15
|
--root <path> Project root for scanning (default: cwd)
|
|
421
16
|
--help Show this help
|
|
422
17
|
`;
|
|
423
18
|
function parseSnapshotArgs(argv) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
19
|
+
let write = false;
|
|
20
|
+
let outPath = require_snapshot_classnames.PUBLIC_CLASSNAMES_SNAPSHOT;
|
|
21
|
+
let rootDir = process.cwd();
|
|
22
|
+
let help = false;
|
|
23
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
24
|
+
const token = argv[i];
|
|
25
|
+
if (token === "--help" || token === "-h") {
|
|
26
|
+
help = true;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (token === "--write") {
|
|
30
|
+
write = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (token === "--out" && argv[i + 1]) {
|
|
34
|
+
outPath = argv[i + 1];
|
|
35
|
+
i += 1;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (token === "--root" && argv[i + 1]) {
|
|
39
|
+
rootDir = node_path.default.resolve(argv[i + 1]);
|
|
40
|
+
i += 1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
write,
|
|
45
|
+
outPath,
|
|
46
|
+
rootDir,
|
|
47
|
+
help
|
|
48
|
+
};
|
|
449
49
|
}
|
|
450
50
|
function buildPreview(entries) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
51
|
+
return {
|
|
52
|
+
version: 1,
|
|
53
|
+
classNames: entries.map((entry) => entry.className),
|
|
54
|
+
entries
|
|
55
|
+
};
|
|
456
56
|
}
|
|
457
57
|
async function runSnapshot(argv) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
`
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// src/cli.ts
|
|
478
|
-
var ROOT_HELP = `typestyles <command> [options]
|
|
58
|
+
const { write, outPath, rootDir, help } = parseSnapshotArgs(argv);
|
|
59
|
+
if (help) {
|
|
60
|
+
process.stdout.write(SNAPSHOT_HELP);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const entries = await require_snapshot_classnames.collectPublicClassNames({ rootDir });
|
|
64
|
+
const resolvedOut = node_path.default.resolve(rootDir, outPath);
|
|
65
|
+
if (write) {
|
|
66
|
+
const snapshot = require_snapshot_classnames.writePublicClassNamesSnapshot(resolvedOut, entries);
|
|
67
|
+
process.stdout.write(`Wrote ${snapshot.classNames.length} public class name(s) to ${resolvedOut}\n`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
process.stdout.write(`${JSON.stringify(buildPreview(entries), null, 2)}\n`);
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/cli.ts
|
|
74
|
+
const ROOT_HELP = `typestyles <command> [options]
|
|
479
75
|
|
|
480
76
|
TypeStyles command-line tools.
|
|
481
77
|
|
|
@@ -484,38 +80,34 @@ Commands:
|
|
|
484
80
|
|
|
485
81
|
Run \`typestyles <command> --help\` for command-specific options.
|
|
486
82
|
`;
|
|
487
|
-
|
|
488
|
-
snapshot: runSnapshot
|
|
489
|
-
};
|
|
83
|
+
const COMMANDS = { snapshot: runSnapshot };
|
|
490
84
|
function isCommandName(value) {
|
|
491
|
-
|
|
85
|
+
return value in COMMANDS;
|
|
492
86
|
}
|
|
493
87
|
async function main() {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
await COMMANDS[command](rest);
|
|
88
|
+
const argv = process.argv.slice(2);
|
|
89
|
+
if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
|
|
90
|
+
process.stdout.write(ROOT_HELP);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const [command, ...rest] = argv;
|
|
94
|
+
if (!isCommandName(command)) {
|
|
95
|
+
process.stderr.write(`[typestyles] Unknown command \`${command}\`.\n\n${ROOT_HELP}`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
if (rest[0] === "--help" || rest[0] === "-h") {
|
|
99
|
+
if (command === "snapshot") {
|
|
100
|
+
process.stdout.write(SNAPSHOT_HELP);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
await COMMANDS[command](rest);
|
|
513
105
|
}
|
|
514
106
|
main().catch((error) => {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
process.exit(1);
|
|
107
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
+
process.stderr.write(`[typestyles] ${message}\n`);
|
|
109
|
+
process.exit(1);
|
|
519
110
|
});
|
|
520
|
-
//#
|
|
111
|
+
//#endregion
|
|
112
|
+
|
|
521
113
|
//# sourceMappingURL=cli.cjs.map
|