@typestyles/cli 0.0.0-unstable.4fcd3d395821 → 0.0.0-unstable.55791d918743

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