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