1+ /**
2+ * This module provides the command-line interface (CLI) for CSSForge.
3+ * It allows generating CSS variables from a configuration file, with options
4+ * to watch for changes and specify output formats.
5+ *
6+ * @module
7+ */
18import { defineCommand , runMain } from "citty" ;
29import chokidar from "chokidar" ;
310import fs from "node:fs/promises" ;
@@ -12,14 +19,27 @@ const writeFileRecursive = (path: string, data: string) =>
1219 fs . writeFile ( path , data )
1320 ) ;
1421
22+ /**
23+ * Defines the options for the build command.
24+ */
1525export interface BuildOptions {
26+ /** Path to the configuration file. */
1627 config : string ;
28+ /** The output mode. */
1729 mode : "css" | "json" | "ts" | "all" ;
30+ /** Path for the CSS output file. */
1831 cssOutput : string ;
32+ /** Path for the JSON output file. */
1933 jsonOutput : string ;
34+ /** Path for the TypeScript output file. */
2035 tsOutput : string ;
2136}
2237
38+ /**
39+ * Builds the CSS, JSON, and/or TypeScript files based on the configuration.
40+ * @param options The build options.
41+ * @returns A promise that resolves to an object indicating success or failure.
42+ */
2343export async function build (
2444 { config, tsOutput, cssOutput, jsonOutput, mode } : BuildOptions ,
2545) : Promise < { success : boolean ; error ?: unknown } > {
@@ -64,10 +84,19 @@ export async function build(
6484 }
6585}
6686
87+ /**
88+ * Defines the options for the watch command.
89+ */
6790export interface WatchOptions extends BuildOptions {
91+ /** A callback function to execute on rebuild. */
6892 onRebuild ?: ( ) => void ;
6993}
7094
95+ /**
96+ * Watches the configuration file for changes and rebuilds on modification.
97+ * @param options The watch options.
98+ * @returns A promise that resolves to a function to stop watching.
99+ */
71100export async function watch (
72101 { onRebuild, ...buildOptions } : WatchOptions ,
73102) : Promise < ( ) => void > {
@@ -167,5 +196,7 @@ if (import.meta.main) {
167196 runMain ( mainCommand ) ;
168197}
169198
170- // Export for programmatic usage
199+ /**
200+ * The main command definition for the CSSForge CLI.
201+ */
171202export default mainCommand as CommandDef ;
0 commit comments