@typestyles/cli 0.0.0-unstable.fb509f91ba06 → 0.0.0-unstable.ff74983e3aa5

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