Skip to content

Commit 4e448fd

Browse files
authored
chore: update module documentation (#3)
1 parent 36954e3 commit 4e448fd

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

.changeset/tiny-hats-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hebilicious/cssforge": patch
3+
---
4+
5+
chore: update module documentation

src/cli.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
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+
*/
18
import { defineCommand, runMain } from "citty";
29
import chokidar from "chokidar";
310
import 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+
*/
1525
export 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+
*/
2343
export 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+
*/
6790
export 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+
*/
71100
export 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+
*/
171202
export default mainCommand as CommandDef;

src/generator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ type ForgeValue = {
1919
[key: string]: ForgeValue | CssValue;
2020
};
2121

22+
/**
23+
* Creates a nested object structure of design tokens from a configuration.
24+
* @param config The CSSForge configuration.
25+
* @returns A nested object representing the design tokens.
26+
*/
2227
export function createForgeValues(config: Partial<CSSForgeConfig>) {
2328
type Input = readonly [string, CssValue];
2429

src/lib.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
/**
2+
* A map where keys are dot-separated paths and values are objects
3+
* containing the CSS variable key, its value, and the full variable declaration.
4+
*/
15
export type ResolveMap = Map<
26
string,
37
{ key: string; value: string; variable: string }
48
>;
59

10+
/**
11+
* Represents the output of a processing function, containing the generated
12+
* CSS and a resolve map.
13+
*/
614
export interface Output {
15+
/** The generated CSS string. */
716
css: string;
17+
/** A map for resolving variable paths. */
818
resolveMap: ResolveMap;
919
}
1020

src/mod.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* This module provides the core functionalities of CSSForge, a tool for generating
3+
* CSS variables from a configuration file. It exports functions for processing
4+
* different aspects of a design system, such as colors, typography, and spacing,
5+
* as well as the main function to generate the final CSS.
6+
*
7+
* @module
8+
*/
19
import { generateCSS } from "./generator.ts";
210
import { defineConfig } from "./config.ts";
311
import { processColors } from "./modules/colors.ts";
@@ -6,13 +14,46 @@ import { processPrimitives } from "./modules/primitive.ts";
614
import { processSpacing } from "./modules/spacing.ts";
715

816
import type { CSSForgeConfig } from "./config.ts";
17+
/**
18+
* The main configuration object for CSSForge.
19+
*/
920
export type { CSSForgeConfig };
1021

1122
export {
23+
/**
24+
* A helper function to define the CSSForge configuration with type inference.
25+
* @param config The CSSForge configuration.
26+
* @returns The configuration object.
27+
*/
1228
defineConfig,
29+
/**
30+
* Generates the CSS string from a CSSForge configuration.
31+
* @param config The CSSForge configuration.
32+
* @returns The generated CSS string.
33+
*/
1334
generateCSS,
35+
/**
36+
* Processes the colors section of the configuration.
37+
* @param colors The colors configuration.
38+
* @returns A map of CSS variables for colors.
39+
*/
1440
processColors,
41+
/**
42+
* Processes the primitives section of the configuration.
43+
* @param primitives The primitives configuration.
44+
* @returns A map of CSS variables for primitives.
45+
*/
1546
processPrimitives,
47+
/**
48+
* Processes the spacing section of the configuration.
49+
* @param spacing The spacing configuration.
50+
* @returns A map of CSS variables for spacing.
51+
*/
1652
processSpacing,
53+
/**
54+
* Processes the typography section of the configuration.
55+
* @param typography The typography configuration.
56+
* @returns A map of CSS variables for typography.
57+
*/
1758
processTypography,
1859
};

0 commit comments

Comments
 (0)