@typestyles/cli 0.3.4 → 0.3.5

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/dist/cli.cjs CHANGED
@@ -1,524 +1,77 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var path = require('path');
5
- var fs = require('fs');
6
- var ts = require('typescript');
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 === "hashed" || config.mode === "compact" || config.mode === "atomic" || config.mode === "template") {
42
- return null;
43
- }
44
- const prefix = semanticScopePrefix(config.scopeId);
45
- return `${prefix}${namespace}`;
46
- }
47
- function getStaticObjectKey(name) {
48
- if (ts__default.default.isIdentifier(name)) return name.text;
49
- if (ts__default.default.isStringLiteral(name)) return name.text;
50
- return null;
51
- }
52
- function firstStringArg(args) {
53
- const first = args[0];
54
- if (!first || !ts__default.default.isStringLiteral(first)) return null;
55
- return first.text;
56
- }
57
- function unwrapExpression(expr) {
58
- let current = expr;
59
- while (ts__default.default.isParenthesizedExpression(current) || ts__default.default.isAsExpression(current) || ts__default.default.isSatisfiesExpression(current) || ts__default.default.isTypeAssertionExpression(current) || ts__default.default.isNonNullExpression(current)) {
60
- current = current.expression;
61
- }
62
- return current;
63
- }
64
- function objectExpressionFromConfigArg(arg) {
65
- if (!arg) return null;
66
- const expr = unwrapExpression(arg);
67
- if (ts__default.default.isObjectLiteralExpression(expr)) return expr;
68
- if (ts__default.default.isArrowFunction(expr)) {
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
- } else {
76
- const body = unwrapExpression(expr.body);
77
- if (ts__default.default.isObjectLiteralExpression(body)) return body;
78
- }
79
- }
80
- return null;
81
- }
82
- function literalFromProperty(obj, key) {
83
- for (const prop of obj.properties) {
84
- if (!ts__default.default.isPropertyAssignment(prop)) continue;
85
- const propKey = getStaticObjectKey(prop.name);
86
- if (propKey !== key) continue;
87
- const init = unwrapExpression(prop.initializer);
88
- if (ts__default.default.isStringLiteral(init)) return init.text;
89
- if (ts__default.default.isNoSubstitutionTemplateLiteral(init)) return init.text;
90
- }
91
- return null;
92
- }
93
- function hasObjectKey(obj, key) {
94
- return obj.properties.some((prop) => {
95
- if (!ts__default.default.isPropertyAssignment(prop)) return false;
96
- return getStaticObjectKey(prop.name) === key;
97
- });
98
- }
99
- function slotsArrayFromObject(obj) {
100
- const slotsProp = obj.properties.find((prop) => {
101
- if (!ts__default.default.isPropertyAssignment(prop)) return false;
102
- return getStaticObjectKey(prop.name) === "slots";
103
- });
104
- if (!slotsProp || !ts__default.default.isPropertyAssignment(slotsProp)) return null;
105
- const init = unwrapExpression(slotsProp.initializer);
106
- return ts__default.default.isArrayLiteralExpression(init) ? init : null;
107
- }
108
- function isSchemaRecipeCall(node) {
109
- if (node.arguments.length < 3) return false;
110
- const callback = node.arguments[2];
111
- if (!callback) return false;
112
- const unwrapped = unwrapExpression(callback);
113
- return ts__default.default.isArrowFunction(unwrapped) || ts__default.default.isFunctionExpression(unwrapped);
114
- }
115
- function propertyInit(obj, key) {
116
- for (const prop of obj.properties) {
117
- if (!ts__default.default.isPropertyAssignment(prop)) continue;
118
- if (getStaticObjectKey(prop.name) === key) return prop.initializer;
119
- }
120
- return void 0;
121
- }
122
- function recipeInputFromCall(node) {
123
- const first = node.arguments[0];
124
- if (!first) return null;
125
- const unwrapped = unwrapExpression(first);
126
- if (ts__default.default.isObjectLiteralExpression(unwrapped)) {
127
- const namespace = literalFromProperty(unwrapped, "name");
128
- if (!namespace) return null;
129
- return {
130
- namespace,
131
- styles: objectExpressionFromConfigArg(propertyInit(unwrapped, "styles")),
132
- slots: slotsArrayFromObject(unwrapped)
133
- };
134
- }
135
- return null;
136
- }
137
- function definitionSlots(arg) {
138
- if (!arg) return null;
139
- const def = unwrapExpression(arg);
140
- if (!ts__default.default.isObjectLiteralExpression(def)) return null;
141
- return slotsArrayFromObject(def);
142
- }
143
- function collectClassNamePartsFromConfig(obj, slotsOverride) {
144
- const parts = [];
145
- const hasVariants = hasObjectKey(obj, "variants");
146
- const hasCompound = hasObjectKey(obj, "compoundVariants");
147
- const hasDefaults = hasObjectKey(obj, "defaultVariants");
148
- const slotsNode = slotsOverride ?? slotsArrayFromObject(obj);
149
- const hasSlots = slotsNode !== null;
150
- if (hasSlots && (hasVariants || hasCompound || hasDefaults)) {
151
- const baseObj = obj.properties.find((prop) => {
152
- if (!ts__default.default.isPropertyAssignment(prop)) return false;
153
- return getStaticObjectKey(prop.name) === "base";
154
- });
155
- if (baseObj && ts__default.default.isPropertyAssignment(baseObj) && ts__default.default.isObjectLiteralExpression(baseObj.initializer)) {
156
- for (const slotProp of baseObj.initializer.properties) {
157
- if (!ts__default.default.isPropertyAssignment(slotProp)) continue;
158
- const slot = getStaticObjectKey(slotProp.name);
159
- if (slot) parts.push({ element: slot === "root" ? void 0 : slot });
160
- }
161
- }
162
- const variantsProp = obj.properties.find((prop) => {
163
- if (!ts__default.default.isPropertyAssignment(prop)) return false;
164
- return getStaticObjectKey(prop.name) === "variants";
165
- });
166
- if (variantsProp && ts__default.default.isPropertyAssignment(variantsProp) && ts__default.default.isObjectLiteralExpression(variantsProp.initializer)) {
167
- for (const dimProp of variantsProp.initializer.properties) {
168
- if (!ts__default.default.isPropertyAssignment(dimProp) || !ts__default.default.isObjectLiteralExpression(dimProp.initializer)) {
169
- continue;
170
- }
171
- const dimension = getStaticObjectKey(dimProp.name);
172
- if (!dimension) continue;
173
- for (const optProp of dimProp.initializer.properties) {
174
- if (!ts__default.default.isPropertyAssignment(optProp) || !ts__default.default.isObjectLiteralExpression(optProp.initializer)) {
175
- continue;
176
- }
177
- const option = getStaticObjectKey(optProp.name);
178
- if (!option) continue;
179
- for (const slotProp of optProp.initializer.properties) {
180
- if (!ts__default.default.isPropertyAssignment(slotProp)) continue;
181
- const slot = getStaticObjectKey(slotProp.name);
182
- if (slot) {
183
- parts.push({
184
- element: slot === "root" ? void 0 : slot,
185
- dimension,
186
- modifier: option
187
- });
188
- }
189
- }
190
- }
191
- }
192
- }
193
- return parts;
194
- }
195
- if (hasSlots && !hasVariants && !hasCompound && !hasDefaults) {
196
- if (slotsNode) {
197
- for (const element of slotsNode.elements) {
198
- if (element && ts__default.default.isStringLiteral(element)) {
199
- parts.push({ element: element.text === "root" ? void 0 : element.text });
200
- }
201
- }
202
- }
203
- return parts;
204
- }
205
- if (hasVariants || hasCompound || hasDefaults) {
206
- parts.push({});
207
- const variantsProp = obj.properties.find((prop) => {
208
- if (!ts__default.default.isPropertyAssignment(prop)) return false;
209
- return getStaticObjectKey(prop.name) === "variants";
210
- });
211
- if (variantsProp && ts__default.default.isPropertyAssignment(variantsProp) && ts__default.default.isObjectLiteralExpression(variantsProp.initializer)) {
212
- for (const dimProp of variantsProp.initializer.properties) {
213
- if (!ts__default.default.isPropertyAssignment(dimProp) || !ts__default.default.isObjectLiteralExpression(dimProp.initializer)) {
214
- continue;
215
- }
216
- const dimension = getStaticObjectKey(dimProp.name);
217
- if (!dimension) continue;
218
- for (const optProp of dimProp.initializer.properties) {
219
- if (!ts__default.default.isPropertyAssignment(optProp)) continue;
220
- const option = getStaticObjectKey(optProp.name);
221
- if (option) parts.push({ dimension, modifier: option });
222
- }
223
- }
224
- }
225
- return parts;
226
- }
227
- for (const prop of obj.properties) {
228
- if (!ts__default.default.isPropertyAssignment(prop)) continue;
229
- const key = getStaticObjectKey(prop.name);
230
- if (!key) continue;
231
- if (key === "base") {
232
- parts.push({});
233
- continue;
234
- }
235
- if (RESERVED_COMPONENT_KEYS.has(key)) continue;
236
- parts.push({ modifier: key });
237
- }
238
- return parts;
239
- }
240
- function componentClassName(config, namespace, part) {
241
- if (config.mode === "hashed" || config.mode === "compact" || config.mode === "atomic" || config.mode === "template") {
242
- return null;
243
- }
244
- const prefix = semanticScopePrefix(config.scopeId);
245
- const block = `${prefix}${namespace}${part.element ? `__${part.element}` : ""}`;
246
- if (!part.modifier) return block;
247
- if (config.mode === "attribute" && part.dimension) return block;
248
- if (config.mode === "bem") return `${block}--${part.modifier}`;
249
- return `${block}--${part.dimension ? `${part.dimension}-` : ""}${part.modifier}`;
250
- }
251
- function parseCreateStylesConfig(init) {
252
- const config = { mode: "semantic", scopeId: "" };
253
- let expr = unwrapExpression(init);
254
- if (ts__default.default.isCallExpression(expr)) {
255
- const firstArg = expr.arguments[0];
256
- if (!firstArg) return config;
257
- expr = unwrapExpression(firstArg);
258
- }
259
- if (!ts__default.default.isObjectLiteralExpression(expr)) return config;
260
- const mode = literalFromProperty(expr, "mode");
261
- if (mode === "semantic" || mode === "hashed" || mode === "compact" || mode === "atomic" || mode === "attribute" || mode === "bem" || mode === "template") {
262
- config.mode = mode;
263
- }
264
- const scopeId = literalFromProperty(expr, "scopeId");
265
- if (scopeId != null) config.scopeId = scopeId;
266
- return config;
267
- }
268
- function isCreateStylesCall(expr) {
269
- const unwrapped = unwrapExpression(expr);
270
- if (!ts__default.default.isCallExpression(unwrapped)) return false;
271
- const callee = unwrapped.expression;
272
- if (ts__default.default.isIdentifier(callee) && (callee.text === "createStyles" || callee.text === "createTypeStyles")) {
273
- return true;
274
- }
275
- if (ts__default.default.isPropertyAccessExpression(callee) && ts__default.default.isIdentifier(callee.expression) && callee.expression.text === "typestyles" && (callee.name.text === "createStyles" || callee.name.text === "createTypeStyles")) {
276
- return true;
277
- }
278
- return false;
279
- }
280
- function registerBindingFromCreateCall(bindings, name, init) {
281
- bindings.set(name, parseCreateStylesConfig(init));
282
- }
283
- function collectBindings(sourceFile) {
284
- const bindings = /* @__PURE__ */ new Map();
285
- const visit = (node) => {
286
- if (ts__default.default.isVariableDeclaration(node) && node.initializer && isCreateStylesCall(node.initializer)) {
287
- if (ts__default.default.isIdentifier(node.name)) {
288
- registerBindingFromCreateCall(bindings, node.name.text, node.initializer);
289
- } else if (ts__default.default.isObjectBindingPattern(node.name)) {
290
- const config = parseCreateStylesConfig(node.initializer);
291
- for (const element of node.name.elements) {
292
- if (ts__default.default.isBindingElement(element) && ts__default.default.isIdentifier(element.name)) {
293
- bindings.set(element.name.text, config);
294
- }
295
- }
296
- }
297
- }
298
- ts__default.default.forEachChild(node, visit);
299
- };
300
- visit(sourceFile);
301
- return bindings;
302
- }
303
- function normalizeCalleeMethod(name) {
304
- if (name === "style" || name === "class") return "class";
305
- if (name === "recipe" || name === "component") return "component";
306
- return null;
307
- }
308
- function calleeMethodName(expr) {
309
- if (ts__default.default.isIdentifier(expr)) {
310
- return normalizeCalleeMethod(expr.text);
311
- }
312
- if (!ts__default.default.isPropertyAccessExpression(expr)) return null;
313
- if (ts__default.default.isIdentifier(expr.name)) return normalizeCalleeMethod(expr.name.text);
314
- return null;
315
- }
316
- function lineOf(sourceFile, node) {
317
- const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
318
- return line + 1;
319
- }
320
- function stylesBindingFromCallee(expr, bindings, defaultConfig) {
321
- if (ts__default.default.isPropertyAccessExpression(expr) && ts__default.default.isIdentifier(expr.expression)) {
322
- const binding = bindings.get(expr.expression.text);
323
- if (binding) return binding;
324
- if (expr.expression.text === "styles" && defaultConfig) return defaultConfig;
325
- }
326
- if (ts__default.default.isIdentifier(expr)) {
327
- return bindings.get(expr.text) ?? defaultConfig ?? { mode: "semantic", scopeId: "" };
328
- }
329
- return defaultConfig ?? { mode: "semantic", scopeId: "" };
330
- }
331
- function mergeProjectBindings(sourceFiles) {
332
- const bindings = /* @__PURE__ */ new Map();
333
- const configs = [];
334
- for (const sourceFile of sourceFiles) {
335
- const fileBindings = collectBindings(sourceFile);
336
- for (const [key, value] of fileBindings) {
337
- bindings.set(key, value);
338
- configs.push(value);
339
- }
340
- }
341
- const unique = /* @__PURE__ */ new Map();
342
- for (const config of configs) {
343
- unique.set(`${config.mode}:${config.scopeId}`, config);
344
- }
345
- const defaultConfig = unique.size === 1 ? [...unique.values()][0] : void 0;
346
- return { bindings, defaultConfig };
347
- }
348
- function collectCallsFromSourceFile(sourceFile, relativePath, bindings, defaultConfig) {
349
- const entries = [];
350
- const visit = (node) => {
351
- if (ts__default.default.isCallExpression(node)) {
352
- const method = calleeMethodName(node.expression);
353
- if (method === "class" || method === "component") {
354
- const recipeInput = method === "component" ? recipeInputFromCall(node) : null;
355
- const namespace = recipeInput?.namespace ?? firstStringArg(node.arguments);
356
- if (!namespace) {
357
- ts__default.default.forEachChild(node, visit);
358
- return;
359
- }
360
- const config = stylesBindingFromCallee(node.expression, bindings, defaultConfig);
361
- const line = lineOf(sourceFile, node.arguments[0] ?? node);
362
- if (method === "class") {
363
- const className = semanticClassName(config, namespace);
364
- if (className) {
365
- entries.push({
366
- className,
367
- kind: "class",
368
- namespace,
369
- file: relativePath,
370
- line
371
- });
372
- }
373
- } else {
374
- const schemaCall = recipeInput ? false : isSchemaRecipeCall(node);
375
- const configObj = recipeInput?.styles ?? objectExpressionFromConfigArg(schemaCall ? node.arguments[2] : node.arguments[1]);
376
- const slotsOverride = recipeInput ? recipeInput.slots : schemaCall ? definitionSlots(node.arguments[1]) : void 0;
377
- const parts = configObj ? collectClassNamePartsFromConfig(configObj, slotsOverride) : [{}];
378
- for (const part of parts) {
379
- const className = componentClassName(config, namespace, part);
380
- if (className) {
381
- entries.push({
382
- className,
383
- kind: "component",
384
- namespace,
385
- suffix: part.modifier ? `${part.element ? `${part.element}-` : ""}${part.dimension ? `${part.dimension}-` : ""}${part.modifier}` : part.element ?? "base",
386
- file: relativePath,
387
- line
388
- });
389
- }
390
- }
391
- }
392
- }
393
- }
394
- ts__default.default.forEachChild(node, visit);
395
- };
396
- visit(sourceFile);
397
- return entries;
398
- }
399
- function collectPublicClassNamesFromFiles(filePaths, rootDir) {
400
- const parsed = filePaths.map((filePath) => {
401
- const sourceText = fs__default.default.readFileSync(filePath, "utf8");
402
- const sourceFile = ts__default.default.createSourceFile(
403
- filePath,
404
- sourceText,
405
- ts__default.default.ScriptTarget.Latest,
406
- true,
407
- filePath.endsWith(".tsx") ? ts__default.default.ScriptKind.TSX : ts__default.default.ScriptKind.TS
408
- );
409
- return { filePath, sourceFile, relativePath: path__default.default.relative(rootDir, filePath) };
410
- });
411
- const { bindings, defaultConfig } = mergeProjectBindings(parsed.map((item) => item.sourceFile));
412
- const entries = [];
413
- for (const { sourceFile, relativePath } of parsed) {
414
- entries.push(...collectCallsFromSourceFile(sourceFile, relativePath, bindings, defaultConfig));
415
- }
416
- return dedupeEntries(entries);
417
- }
418
- function dedupeEntries(entries) {
419
- const byClass = /* @__PURE__ */ new Map();
420
- for (const entry of entries) {
421
- if (!byClass.has(entry.className)) {
422
- byClass.set(entry.className, entry);
423
- }
424
- }
425
- return [...byClass.values()].sort((a, b) => a.className.localeCompare(b.className));
426
- }
427
- async function collectPublicClassNames(options = {}) {
428
- const rootDir = path__default.default.resolve(options.rootDir ?? process.cwd());
429
- const include = options.include ?? DEFAULT_INCLUDE;
430
- const exclude = options.exclude ?? DEFAULT_EXCLUDE;
431
- const files = await fg__default.default(include, {
432
- cwd: rootDir,
433
- absolute: true,
434
- ignore: exclude
435
- });
436
- return collectPublicClassNamesFromFiles(files, rootDir);
437
- }
438
- function buildSnapshot(entries) {
439
- const sorted = dedupeEntries(entries);
440
- return {
441
- version: 1,
442
- classNames: sorted.map((entry) => entry.className),
443
- entries: sorted
444
- };
445
- }
446
- function writePublicClassNamesSnapshot(snapshotPath, entries) {
447
- const snapshot = buildSnapshot(entries);
448
- fs__default.default.writeFileSync(snapshotPath, `${JSON.stringify(snapshot, null, 2)}
449
- `, "utf8");
450
- return snapshot;
451
- }
452
-
453
- // src/commands/snapshot.ts
454
- var SNAPSHOT_HELP = `typestyles snapshot [options]
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]
455
7
 
456
8
  Scan TypeScript sources for semantic \`style\` / \`recipe\` (and legacy \`styles.class\` /
457
9
  \`styles.component\`) class names and write or print the public API snapshot used by
458
10
  \`@typestyles/no-removed-public-classname\`.
459
11
 
460
12
  Options:
461
- --write Write ${PUBLIC_CLASSNAMES_SNAPSHOT} in the project root
462
- --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})
463
15
  --root <path> Project root for scanning (default: cwd)
464
16
  --help Show this help
465
17
  `;
466
18
  function parseSnapshotArgs(argv) {
467
- let write = false;
468
- let outPath = PUBLIC_CLASSNAMES_SNAPSHOT;
469
- let rootDir = process.cwd();
470
- let help = false;
471
- for (let i = 0; i < argv.length; i += 1) {
472
- const token = argv[i];
473
- if (token === "--help" || token === "-h") {
474
- help = true;
475
- continue;
476
- }
477
- if (token === "--write") {
478
- write = true;
479
- continue;
480
- }
481
- if (token === "--out" && argv[i + 1]) {
482
- outPath = argv[i + 1];
483
- i += 1;
484
- continue;
485
- }
486
- if (token === "--root" && argv[i + 1]) {
487
- rootDir = path__default.default.resolve(argv[i + 1]);
488
- i += 1;
489
- }
490
- }
491
- return { write, outPath, rootDir, help };
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
+ };
492
49
  }
493
50
  function buildPreview(entries) {
494
- return {
495
- version: 1,
496
- classNames: entries.map((entry) => entry.className),
497
- entries
498
- };
51
+ return {
52
+ version: 1,
53
+ classNames: entries.map((entry) => entry.className),
54
+ entries
55
+ };
499
56
  }
500
57
  async function runSnapshot(argv) {
501
- const { write, outPath, rootDir, help } = parseSnapshotArgs(argv);
502
- if (help) {
503
- process.stdout.write(SNAPSHOT_HELP);
504
- return;
505
- }
506
- const entries = await collectPublicClassNames({ rootDir });
507
- const resolvedOut = path__default.default.resolve(rootDir, outPath);
508
- if (write) {
509
- const snapshot = writePublicClassNamesSnapshot(resolvedOut, entries);
510
- process.stdout.write(
511
- `Wrote ${snapshot.classNames.length} public class name(s) to ${resolvedOut}
512
- `
513
- );
514
- return;
515
- }
516
- process.stdout.write(`${JSON.stringify(buildPreview(entries), null, 2)}
517
- `);
518
- }
519
-
520
- // src/cli.ts
521
- 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]
522
75
 
523
76
  TypeStyles command-line tools.
524
77
 
@@ -527,38 +80,34 @@ Commands:
527
80
 
528
81
  Run \`typestyles <command> --help\` for command-specific options.
529
82
  `;
530
- var COMMANDS = {
531
- snapshot: runSnapshot
532
- };
83
+ const COMMANDS = { snapshot: runSnapshot };
533
84
  function isCommandName(value) {
534
- return value in COMMANDS;
85
+ return value in COMMANDS;
535
86
  }
536
87
  async function main() {
537
- const argv = process.argv.slice(2);
538
- if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
539
- process.stdout.write(ROOT_HELP);
540
- return;
541
- }
542
- const [command, ...rest] = argv;
543
- if (!isCommandName(command)) {
544
- process.stderr.write(`[typestyles] Unknown command \`${command}\`.
545
-
546
- ${ROOT_HELP}`);
547
- process.exit(1);
548
- }
549
- if (rest[0] === "--help" || rest[0] === "-h") {
550
- if (command === "snapshot") {
551
- process.stdout.write(SNAPSHOT_HELP);
552
- return;
553
- }
554
- }
555
- 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);
556
105
  }
557
106
  main().catch((error) => {
558
- const message = error instanceof Error ? error.message : String(error);
559
- process.stderr.write(`[typestyles] ${message}
560
- `);
561
- process.exit(1);
107
+ const message = error instanceof Error ? error.message : String(error);
108
+ process.stderr.write(`[typestyles] ${message}\n`);
109
+ process.exit(1);
562
110
  });
563
- //# sourceMappingURL=cli.cjs.map
111
+ //#endregion
112
+
564
113
  //# sourceMappingURL=cli.cjs.map