@dsai-io/tools 0.0.1

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.
@@ -0,0 +1,432 @@
1
+ import { Command } from 'commander';
2
+
3
+ /**
4
+ * CLI type definitions
5
+ *
6
+ * @packageDocumentation
7
+ * @module @dsai-io/tools/cli/types
8
+ */
9
+ /**
10
+ * Exit codes for CLI commands
11
+ *
12
+ * Follows common conventions:
13
+ * - 0: Success
14
+ * - 1: General error
15
+ * - 2+: Specific error types
16
+ */
17
+ declare const ExitCode: {
18
+ /** Successful execution */
19
+ readonly Success: 0;
20
+ /** General/unknown error */
21
+ readonly GeneralError: 1;
22
+ /** Configuration loading or validation error */
23
+ readonly ConfigError: 2;
24
+ /** Token or schema validation error */
25
+ readonly ValidationError: 3;
26
+ /** Build process error */
27
+ readonly BuildError: 4;
28
+ /** File system I/O error */
29
+ readonly IOError: 5;
30
+ };
31
+ /**
32
+ * Global CLI options available to all commands
33
+ */
34
+ interface GlobalOptions {
35
+ /** Custom config file path */
36
+ config?: string;
37
+ /** Working directory */
38
+ cwd?: string;
39
+ /** Enable debug mode - verbose output and stack traces */
40
+ debug?: boolean;
41
+ /** Quiet mode - no spinners or colors */
42
+ quiet?: boolean;
43
+ /** Dry run - preview changes without writing files */
44
+ dryRun?: boolean;
45
+ }
46
+ /**
47
+ * Token build command options
48
+ */
49
+ interface TokensBuildOptions extends GlobalOptions {
50
+ /** Platforms to build (comma-separated or 'all') */
51
+ platforms?: string;
52
+ /** Watch mode - rebuild on file changes */
53
+ watch?: boolean;
54
+ /** Clean output directory before build */
55
+ clean?: boolean;
56
+ }
57
+ /**
58
+ * Token validate command options
59
+ */
60
+ interface TokensValidateOptions extends GlobalOptions {
61
+ /** Attempt to fix issues automatically */
62
+ fix?: boolean;
63
+ /** Strict validation mode */
64
+ strict?: boolean;
65
+ }
66
+ /**
67
+ * Token sync command options
68
+ */
69
+ interface TokensSyncOptions extends GlobalOptions {
70
+ /** Output format for sync */
71
+ format?: 'flat' | 'nested';
72
+ }
73
+ /**
74
+ * Icons build command options
75
+ */
76
+ interface IconsBuildOptions extends GlobalOptions {
77
+ /** Output format for icons */
78
+ format?: 'svg' | 'react' | 'vue';
79
+ /** Optimize SVGs */
80
+ optimize?: boolean;
81
+ }
82
+ /**
83
+ * Init command options
84
+ */
85
+ interface InitOptions extends GlobalOptions {
86
+ /** Skip prompts, use defaults */
87
+ yes?: boolean;
88
+ /** Template to use */
89
+ template?: 'minimal' | 'full' | 'enterprise';
90
+ }
91
+ /**
92
+ * Logger interface for CLI output
93
+ */
94
+ interface Logger {
95
+ /** Log a general message */
96
+ log(message: string): void;
97
+ /** Log an info message with icon */
98
+ info(message: string): void;
99
+ /** Log a success message with icon */
100
+ success(message: string): void;
101
+ /** Log a warning message with icon */
102
+ warn(message: string): void;
103
+ /** Log an error message with icon */
104
+ error(message: string): void;
105
+ /** Log a debug message (only in debug mode) */
106
+ debug(message: string): void;
107
+ }
108
+ /**
109
+ * Spinner interface for progress indication
110
+ */
111
+ interface Spinner {
112
+ /** Start spinner with text */
113
+ start(text: string): void;
114
+ /** Stop spinner (optionally update text) */
115
+ stop(text?: string): void;
116
+ /** Stop with success state */
117
+ succeed(text?: string): void;
118
+ /** Stop with failure state */
119
+ fail(text?: string): void;
120
+ /** Stop with warning state */
121
+ warn(text?: string): void;
122
+ /** Stop with info state */
123
+ info(text?: string): void;
124
+ }
125
+ /**
126
+ * CLI context passed to commands
127
+ *
128
+ * Contains resolved values and utility instances
129
+ */
130
+ interface CLIContext {
131
+ /** Resolved working directory (absolute path) */
132
+ cwd: string;
133
+ /** Package version */
134
+ version: string;
135
+ /** Debug mode enabled */
136
+ debug: boolean;
137
+ /** Quiet mode enabled */
138
+ quiet: boolean;
139
+ /** Logger instance */
140
+ logger: Logger;
141
+ /** Spinner instance */
142
+ spinner: Spinner;
143
+ }
144
+ /**
145
+ * Generic command handler function
146
+ */
147
+ type CommandHandler<T extends GlobalOptions = GlobalOptions> = (options: T, context: CLIContext) => Promise<void>;
148
+ /**
149
+ * Build result from token operations
150
+ */
151
+ interface BuildResult {
152
+ /** Whether build succeeded */
153
+ success: boolean;
154
+ /** Number of files written */
155
+ filesWritten: number;
156
+ /** List of output files */
157
+ files?: Array<{
158
+ path: string;
159
+ size?: number;
160
+ }>;
161
+ /** Any errors encountered */
162
+ errors?: Array<{
163
+ message: string;
164
+ file?: string;
165
+ }>;
166
+ }
167
+ /**
168
+ * Validation result from token validation
169
+ */
170
+ interface ValidationResult {
171
+ /** Total number of tokens validated */
172
+ totalTokens: number;
173
+ /** Validation errors */
174
+ errors: Array<{
175
+ path: string;
176
+ message: string;
177
+ }>;
178
+ /** Validation warnings */
179
+ warnings: Array<{
180
+ path: string;
181
+ message: string;
182
+ }>;
183
+ /** Issues that were automatically fixed */
184
+ fixed: Array<{
185
+ path: string;
186
+ message: string;
187
+ }>;
188
+ }
189
+ /**
190
+ * Sync result from token sync
191
+ */
192
+ interface SyncResult {
193
+ /** Whether sync succeeded */
194
+ success: boolean;
195
+ /** Number of tokens synced */
196
+ tokenCount: number;
197
+ /** Output file path */
198
+ outputPath: string;
199
+ /** Error message if failed */
200
+ error?: string;
201
+ }
202
+
203
+ /**
204
+ * Color utilities for CLI output
205
+ *
206
+ * Wraps picocolors with NO_COLOR environment variable support.
207
+ *
208
+ * @packageDocumentation
209
+ * @module @dsai-io/tools/cli/ui/colors
210
+ */
211
+ /**
212
+ * Color utilities with NO_COLOR support
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * import { colors } from './colors.js';
217
+ *
218
+ * console.log(colors.success('Build complete!'));
219
+ * console.log(colors.error('Something went wrong'));
220
+ * console.log(colors.path('./dist/tokens.css'));
221
+ * ```
222
+ */
223
+ declare const colors: {
224
+ /** Red text */
225
+ red: (text: string) => string;
226
+ /** Green text */
227
+ green: (text: string) => string;
228
+ /** Yellow text */
229
+ yellow: (text: string) => string;
230
+ /** Blue text */
231
+ blue: (text: string) => string;
232
+ /** Magenta text */
233
+ magenta: (text: string) => string;
234
+ /** Cyan text */
235
+ cyan: (text: string) => string;
236
+ /** Gray/dim text */
237
+ gray: (text: string) => string;
238
+ /** White text */
239
+ white: (text: string) => string;
240
+ /** Bold text */
241
+ bold: (text: string) => string;
242
+ /** Dim text */
243
+ dim: (text: string) => string;
244
+ /** Italic text */
245
+ italic: (text: string) => string;
246
+ /** Underlined text */
247
+ underline: (text: string) => string;
248
+ /** Red background */
249
+ bgRed: (text: string) => string;
250
+ /** Green background */
251
+ bgGreen: (text: string) => string;
252
+ /** Yellow background */
253
+ bgYellow: (text: string) => string;
254
+ /** Blue background */
255
+ bgBlue: (text: string) => string;
256
+ /** Error messages - red */
257
+ error: (text: string) => string;
258
+ /** Success messages - green */
259
+ success: (text: string) => string;
260
+ /** Warning messages - yellow */
261
+ warning: (text: string) => string;
262
+ /** Info messages - blue */
263
+ info: (text: string) => string;
264
+ /** Muted/secondary text - gray */
265
+ muted: (text: string) => string;
266
+ /** Labels - bold cyan */
267
+ label: (text: string) => string;
268
+ /** Values - yellow */
269
+ value: (text: string) => string;
270
+ /** File paths - underlined cyan */
271
+ path: (text: string) => string;
272
+ /** Commands - bold green */
273
+ command: (text: string) => string;
274
+ /** Code snippets - dim */
275
+ code: (text: string) => string;
276
+ /** Highlight - bold yellow */
277
+ highlight: (text: string) => string;
278
+ };
279
+
280
+ /**
281
+ * Spinner utilities for CLI progress indication
282
+ *
283
+ * Wraps ora for consistent spinner behavior with quiet mode support.
284
+ *
285
+ * @packageDocumentation
286
+ * @module @dsai-io/tools/cli/ui/spinner
287
+ */
288
+
289
+ /**
290
+ * Create a spinner instance
291
+ *
292
+ * In quiet mode, returns a no-op spinner that does nothing.
293
+ *
294
+ * @param quiet - If true, spinner is disabled (no-op)
295
+ * @returns Spinner instance
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * const spinner = createSpinner(false);
300
+ * spinner.start('Loading configuration...');
301
+ * // ... do work
302
+ * spinner.succeed('Configuration loaded!');
303
+ * ```
304
+ */
305
+ declare function createSpinner(quiet?: boolean): Spinner;
306
+
307
+ /**
308
+ * Logger utilities for CLI output
309
+ *
310
+ * Provides consistent logging with icons, colors, and quiet/debug mode support.
311
+ *
312
+ * @packageDocumentation
313
+ * @module @dsai-io/tools/cli/ui/logger
314
+ */
315
+
316
+ /**
317
+ * Logger creation options
318
+ */
319
+ interface LoggerOptions {
320
+ /** Quiet mode - minimal output */
321
+ quiet?: boolean;
322
+ /** Debug mode - verbose output */
323
+ debug?: boolean;
324
+ /** Custom prefix for messages */
325
+ prefix?: string;
326
+ }
327
+ /**
328
+ * Create a logger instance
329
+ *
330
+ * @param options - Logger options
331
+ * @returns Logger instance
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * const logger = createLogger({ debug: true });
336
+ * logger.info('Starting build...');
337
+ * logger.success('Build complete!');
338
+ * logger.debug('Token count: 123'); // Only shown in debug mode
339
+ * ```
340
+ */
341
+ declare function createLogger(options?: LoggerOptions): Logger;
342
+ /**
343
+ * Format a duration in milliseconds to human-readable string
344
+ *
345
+ * @param ms - Duration in milliseconds
346
+ * @returns Formatted duration string
347
+ *
348
+ * @example
349
+ * ```typescript
350
+ * formatDuration(500); // '500ms'
351
+ * formatDuration(2500); // '2.50s'
352
+ * formatDuration(65000); // '1m 5s'
353
+ * ```
354
+ */
355
+ declare function formatDuration(ms: number): string;
356
+ /**
357
+ * Format bytes to human-readable string
358
+ *
359
+ * @param bytes - Number of bytes
360
+ * @returns Formatted size string
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * formatBytes(0); // '0 B'
365
+ * formatBytes(1024); // '1 KB'
366
+ * formatBytes(1536000); // '1.46 MB'
367
+ * ```
368
+ */
369
+ declare function formatBytes(bytes: number): string;
370
+ /**
371
+ * Format a count with singular/plural label
372
+ *
373
+ * @param count - The count
374
+ * @param singular - Singular form
375
+ * @param plural - Plural form (defaults to singular + 's')
376
+ * @returns Formatted string
377
+ *
378
+ * @example
379
+ * ```typescript
380
+ * formatCount(1, 'file'); // '1 file'
381
+ * formatCount(5, 'file'); // '5 files'
382
+ * formatCount(1, 'entry', 'entries'); // '1 entry'
383
+ * ```
384
+ */
385
+ declare function formatCount(count: number, singular: string, plural?: string): string;
386
+
387
+ /**
388
+ * CLI module for @dsai-io/tools
389
+ *
390
+ * Provides the command-line interface for the dsai-tools package.
391
+ * Uses Commander.js for command parsing, with spinners and colored output.
392
+ *
393
+ * Commands:
394
+ * - tokens: Build, validate, and sync design tokens
395
+ * - icons: Generate icon components from SVG files
396
+ * - init: Initialize configuration in a project
397
+ * - config: Display resolved configuration
398
+ *
399
+ * @example
400
+ * ```bash
401
+ * # Build tokens
402
+ * dsai tokens build
403
+ *
404
+ * # Validate tokens
405
+ * dsai tokens validate
406
+ *
407
+ * # Initialize a new project
408
+ * dsai init --template full
409
+ *
410
+ * # Show configuration
411
+ * dsai config --json
412
+ * ```
413
+ */
414
+
415
+ /**
416
+ * Configure and run the CLI
417
+ *
418
+ * Sets up the Commander program with all commands and parses arguments.
419
+ *
420
+ * @param args - Command line arguments (defaults to process.argv)
421
+ */
422
+ declare function run(args?: string[]): Promise<void>;
423
+ /**
424
+ * Get the CLI program instance
425
+ *
426
+ * Used for testing to access the configured Commander program.
427
+ *
428
+ * @returns The Commander program instance
429
+ */
430
+ declare function getProgram(): Command;
431
+
432
+ export { type BuildResult, type CLIContext, type CommandHandler, ExitCode, type GlobalOptions, type IconsBuildOptions, type InitOptions, type Logger, type Spinner, type SyncResult, type TokensBuildOptions, type TokensSyncOptions, type TokensValidateOptions, type ValidationResult, colors, createLogger, createSpinner, formatBytes, formatCount, formatDuration, getProgram, run };