@razorwind/core 0.0.20 → 0.0.22
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/dist/{config-niJpQJza.d.cts → config-CBGz3vxV.d.cts} +2 -2
- package/dist/{config-niJpQJza.d.cts.map → config-CBGz3vxV.d.cts.map} +1 -1
- package/dist/{config-BYknAq7g.d.mts → config-CaaK20wo.d.mts} +2 -2
- package/dist/config-CaaK20wo.d.mts.map +1 -0
- package/dist/{index--y-fo2Lr.d.mts → index-BhVvIILv.d.mts} +1 -1
- package/dist/index-BlIc4ofi.d.mts +169 -0
- package/dist/index-BlIc4ofi.d.mts.map +1 -0
- package/dist/index-CKJ5fZxo.d.cts +169 -0
- package/dist/index-CKJ5fZxo.d.cts.map +1 -0
- package/dist/{index-CjW7STaT.d.cts → index-DW51mcvl.d.cts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +19 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +19 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/tokens/index.d.cts +2 -169
- package/dist/lib/tokens/index.d.mts +2 -169
- package/dist/{plugin-CZz4yUV2.d.cts → plugin-C_nK-znA.d.cts} +2 -2
- package/dist/{plugin-CZz4yUV2.d.cts.map → plugin-C_nK-znA.d.cts.map} +1 -1
- package/dist/{plugin-CfYEjsU7.d.mts → plugin-Cbx7QH4X.d.mts} +2 -2
- package/dist/plugin-Cbx7QH4X.d.mts.map +1 -0
- package/dist/plugin.d.cts +2 -2
- package/dist/plugin.d.mts +2 -2
- package/dist/schema/index.cjs +1 -1
- package/dist/schema/index.d.cts +2 -2
- package/dist/schema/index.d.mts +2 -2
- package/dist/schema/index.mjs +1 -1
- package/dist/{schema-BNfl9Tsw.d.cts → schema-C6-umW1r.d.cts} +9 -9
- package/dist/{schema-BNfl9Tsw.d.cts.map → schema-C6-umW1r.d.cts.map} +1 -1
- package/dist/{schema-BNfl9Tsw.d.mts → schema-C6-umW1r.d.mts} +9 -9
- package/dist/schema-C6-umW1r.d.mts.map +1 -0
- package/dist/schema-CzpHs4s7.mjs +2 -0
- package/dist/schema-CzpHs4s7.mjs.map +1 -0
- package/dist/schema-DWEhLYz4.cjs +1 -0
- package/package.json +2 -2
- package/dist/config-BYknAq7g.d.mts.map +0 -1
- package/dist/lib/tokens/index.d.cts.map +0 -1
- package/dist/lib/tokens/index.d.mts.map +0 -1
- package/dist/plugin-CfYEjsU7.d.mts.map +0 -1
- package/dist/schema-BNfl9Tsw.d.mts.map +0 -1
- package/dist/schema-Bxzw_P4l.mjs +0 -2
- package/dist/schema-Bxzw_P4l.mjs.map +0 -1
- package/dist/schema-D7jRSrC_.cjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Components, t as Schema } from "./schema-
|
|
1
|
+
import { a as Components, t as Schema } from "./schema-C6-umW1r.cjs";
|
|
2
2
|
import { PreprocessedTokens } from "style-dictionary";
|
|
3
3
|
import { Tokens } from "@power-plant/dtcg-schema";
|
|
4
4
|
import { EnvPaths } from "@stryke/env";
|
|
@@ -166,4 +166,4 @@ type Config = RequiredKeys<UserConfig, "componentsPath" | "plugins"> & {
|
|
|
166
166
|
};
|
|
167
167
|
//#endregion
|
|
168
168
|
export { UserConfigFn as a, UserConfigParams as c, TokensPreprocessor as d, UserConfigExport as i, Plugin as l, Options as n, UserConfigFnObject as o, UserConfig as r, UserConfigFnPromise as s, Config as t, TokensParser as u };
|
|
169
|
-
//# sourceMappingURL=config-
|
|
169
|
+
//# sourceMappingURL=config-CBGz3vxV.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-
|
|
1
|
+
{"version":3,"file":"config-CBGz3vxV.d.cts","names":[],"sources":["../src/types/plugin.ts","../src/types/config.ts"],"mappings":";;;;;;;;;;;;;;;UAgCiB;EACf;EACA,SAAS;EACT,SAAS,qBAAqB;;;;;;;;;KAUpB;EAEN;EACA,eAAe,YAAY,uBAAuB;MAElD,YAAY,uBAAuB;;;;;;;;;UAUxB;;;;;;;EAOf;;;;;;EAOA,UAAU;;;;;;EAOV,gBAAgB;;;;;;;;EAShB,WAAW,MAAM,QAAQ,QAAQ,WAAW,aAAa;;;;;;;;EASzD,YACE,MAAM,QACN,QAAQ,WACL,aAAa,eAAe;;;;;;;;EASjC,YAAY,MAAM,QAAQ,QAAQ,WAAW;;;;UCvF9B;;;;;;EAMf;;;;EAKA;;;;;;;;EASA;;;;;;EAOA;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BA;;UAGe,mBAAmB;EAClC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS,SAAS,eAAe;EACjC,aAAa;EACb,UAAU;;UAGK;EACf;EACA;;KAGU,sBAAsB,QAAQ,eAAe;KAC7C,uBACV,QAAQ,qBACL,QAAQ,aAAa;KACd,gBACV,QAAQ,qBACL,aAAa,eAAe,QAAQ,aAAa;KAC1C,mBACR,aACA,eACA,QAAQ,aAAa,gBACrB,qBACA,sBACA;KAEQ,SAAS,aAAa;EAChC;EACA,UAAU;IACR"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Components, t as Schema } from "./schema-
|
|
1
|
+
import { a as Components, t as Schema } from "./schema-C6-umW1r.mjs";
|
|
2
2
|
import { GeneratedDocument } from "@power-plant/core";
|
|
3
3
|
import { PreprocessedTokens } from "style-dictionary";
|
|
4
4
|
import { EnvPaths } from "@stryke/env";
|
|
@@ -166,4 +166,4 @@ type Config = RequiredKeys<UserConfig, "componentsPath" | "plugins"> & {
|
|
|
166
166
|
};
|
|
167
167
|
//#endregion
|
|
168
168
|
export { UserConfigFn as a, UserConfigParams as c, TokensPreprocessor as d, UserConfigExport as i, Plugin as l, Options as n, UserConfigFnObject as o, UserConfig as r, UserConfigFnPromise as s, Config as t, TokensParser as u };
|
|
169
|
-
//# sourceMappingURL=config-
|
|
169
|
+
//# sourceMappingURL=config-CaaK20wo.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-CaaK20wo.d.mts","names":[],"sources":["../src/types/plugin.ts","../src/types/config.ts"],"mappings":""}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { t as Schema } from "./schema-C6-umW1r.mjs";
|
|
2
|
+
import "./index-BhVvIILv.mjs";
|
|
3
|
+
import { l as Plugin, t as Config } from "./config-CaaK20wo.mjs";
|
|
4
|
+
import { ExecutionContext } from "@power-plant/core";
|
|
5
|
+
import { Tokens } from "@power-plant/dtcg-schema";
|
|
6
|
+
import { Hooks, Parser, PreprocessedTokens } from "style-dictionary/types";
|
|
7
|
+
//#region src/lib/tokens/constants.d.ts
|
|
8
|
+
/** Style Dictionary parser hook names registered by Razorwind. */
|
|
9
|
+
declare const TOKEN_PARSER_NAMES: readonly ["razorwind-json", "razorwind-yaml", "razorwind-toml", "razorwind-css"];
|
|
10
|
+
type RazorwindParserName = (typeof TOKEN_PARSER_NAMES)[number];
|
|
11
|
+
/** File extensions treated as design-token sources. */
|
|
12
|
+
declare const TOKEN_FILE_EXTENSIONS: readonly ["json", "json5", "jsonc", "yaml", "yml", "toml", "css", "js", "mjs", "cjs", "ts", "mts", "cts"];
|
|
13
|
+
/**
|
|
14
|
+
* Candidate paths checked when `tokensPath` is omitted.
|
|
15
|
+
* First existing file or directory wins.
|
|
16
|
+
*/
|
|
17
|
+
declare const DEFAULT_TOKEN_PATH_CANDIDATES: readonly ["tokens.json", "tokens.json5", "tokens.jsonc", "tokens.yaml", "tokens.yml", "tokens.toml", "tokens.css", "design-tokens.json", "design-tokens.yaml", "design-tokens.yml", "tokens", "design-tokens", "src/tokens", "src/design-tokens", "packages/tokens", "style-dictionary.config.js", "style-dictionary.config.mjs", "style-dictionary.config.ts", "sd.config.js", "sd.config.mjs", "sd.config.ts"];
|
|
18
|
+
/** Glob appended when a tokens directory is resolved. */
|
|
19
|
+
declare const TOKEN_DIRECTORY_GLOB: string;
|
|
20
|
+
/** Theme-like basename patterns used to split multi-file sources into a record. */
|
|
21
|
+
declare const THEME_BASENAME_PATTERN: RegExp;
|
|
22
|
+
/** Path segment hints used when inferring `$type`. */
|
|
23
|
+
declare const TYPE_PATH_HINTS: Record<string, string>;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/lib/tokens/css.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Extract CSS custom properties from stylesheet text into a nested token tree.
|
|
28
|
+
* Handles `:root`, `[data-theme]`, and Tailwind v4 `@theme` blocks alike.
|
|
29
|
+
*/
|
|
30
|
+
declare function parseCssCustomProperties(contents: string): Record<string, unknown>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/lib/tokens/infer.d.ts
|
|
33
|
+
type InferredTokenType = "color" | "dimension" | "duration" | "fontFamily" | "fontWeight" | "number" | "cubicBezier" | "shadow" | "gradient" | "typography" | "strokeStyle" | "border" | "transition";
|
|
34
|
+
/**
|
|
35
|
+
* Infer DTCG `$type` from a path segment chain (e.g. `color.primary`).
|
|
36
|
+
*/
|
|
37
|
+
declare function inferTypeFromPath(path: string[]): InferredTokenType | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Normalize a raw token value into DTCG-friendly shape + optional `$type`.
|
|
40
|
+
*/
|
|
41
|
+
declare function inferValue(raw: unknown, path?: string[]): {
|
|
42
|
+
value: unknown;
|
|
43
|
+
type?: InferredTokenType;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Walk a token tree: promote legacy keys to DTCG and infer `$type` / `$value` shapes.
|
|
47
|
+
*/
|
|
48
|
+
declare function normalizeTokenTree(input: unknown, path?: string[]): unknown;
|
|
49
|
+
/**
|
|
50
|
+
* Nest a flat map of dashed keys into a token tree.
|
|
51
|
+
* `--color-primary-500` / `color-primary-500` → `color.primary.500`.
|
|
52
|
+
*
|
|
53
|
+
* Scalar parents that also have children (e.g. `--radius` + `--radius-lg`) are
|
|
54
|
+
* preserved under `DEFAULT` so neither value is dropped.
|
|
55
|
+
*/
|
|
56
|
+
declare function nestFlatTokens(flat: Record<string, unknown>): Record<string, unknown>;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/lib/tokens/resolve-path.d.ts
|
|
59
|
+
interface ResolveTokensPathOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Working directory used to resolve relative paths.
|
|
62
|
+
*/
|
|
63
|
+
cwd: string;
|
|
64
|
+
/**
|
|
65
|
+
* Explicit tokens file(s) or directory(ies) from config.
|
|
66
|
+
*/
|
|
67
|
+
tokensPath?: string | string[];
|
|
68
|
+
/**
|
|
69
|
+
* Extra fallback paths (e.g. registry `tailwind.css`).
|
|
70
|
+
*/
|
|
71
|
+
fallbackPaths?: Array<string | null | undefined>;
|
|
72
|
+
}
|
|
73
|
+
interface ResolvedTokensSource {
|
|
74
|
+
/**
|
|
75
|
+
* Absolute path to the resolved file or directory (if any).
|
|
76
|
+
*
|
|
77
|
+
* When multiple `tokensPath` entries are provided, this is the first
|
|
78
|
+
* resolved path (or the Style Dictionary config when that is the sole entry).
|
|
79
|
+
*/
|
|
80
|
+
resolvedPath?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Style Dictionary `source` globs.
|
|
83
|
+
*/
|
|
84
|
+
source: string[];
|
|
85
|
+
/**
|
|
86
|
+
* How the path was discovered.
|
|
87
|
+
*/
|
|
88
|
+
origin: "tokensPath" | "default" | "fallback" | "none";
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve Style Dictionary source globs from `tokensPath` or common defaults.
|
|
92
|
+
*
|
|
93
|
+
* When `tokensPath` is an array, each entry is resolved and the resulting
|
|
94
|
+
* source globs are merged. A Style Dictionary config file may only be used as
|
|
95
|
+
* the sole `tokensPath` entry.
|
|
96
|
+
*/
|
|
97
|
+
declare function resolveTokensSource(options: ResolveTokensPathOptions): ResolvedTokensSource;
|
|
98
|
+
/**
|
|
99
|
+
* Detect theme-like basenames for splitting multi-file token sets.
|
|
100
|
+
*/
|
|
101
|
+
declare function themeKeyFromPath(filePath: string): string | undefined;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/lib/tokens/load.d.ts
|
|
104
|
+
interface LoadTokensOptions extends ResolveTokensPathOptions {
|
|
105
|
+
/**
|
|
106
|
+
* When true, split theme-named files into a record keyed by theme.
|
|
107
|
+
*
|
|
108
|
+
* @defaultValue true
|
|
109
|
+
*/
|
|
110
|
+
splitThemes?: boolean;
|
|
111
|
+
}
|
|
112
|
+
type LoadedTokens = Tokens | Record<string, Tokens>;
|
|
113
|
+
/**
|
|
114
|
+
* Load design tokens via Style Dictionary parser hooks.
|
|
115
|
+
*
|
|
116
|
+
* Resolution order:
|
|
117
|
+
* 1. Explicit `tokensPath` (file, directory, array of those, or SD config)
|
|
118
|
+
* 2. Common default paths (`tokens.json`, `tokens/`, …)
|
|
119
|
+
* 3. Fallback paths (e.g. registry Tailwind CSS)
|
|
120
|
+
*/
|
|
121
|
+
declare function loadTokens(context: ExecutionContext<Schema, Config, void>): Promise<LoadedTokens>;
|
|
122
|
+
/**
|
|
123
|
+
* Convenience: load tokens or throw when nothing usable is found.
|
|
124
|
+
*
|
|
125
|
+
* @param config - The configuration object.
|
|
126
|
+
* @param options - The options for loading the tokens.
|
|
127
|
+
* @returns The loaded tokens.
|
|
128
|
+
* @throws An error if no design tokens are found.
|
|
129
|
+
* @throws An error if the tokens are not valid.
|
|
130
|
+
*/
|
|
131
|
+
declare function loadTokensOrThrow(context: ExecutionContext<Schema, Config, void>): Promise<LoadedTokens>;
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/lib/tokens/parsers.d.ts
|
|
134
|
+
/** Preprocessor name applied after all sources merge. */
|
|
135
|
+
declare const RAZORWIND_INFER_PREPROCESSOR = "razorwind-infer";
|
|
136
|
+
/** Target capable of registering Style Dictionary extraction hooks. */
|
|
137
|
+
interface StyleDictionaryRegisterTarget {
|
|
138
|
+
registerParser: (parser: Parser) => unknown;
|
|
139
|
+
registerPreprocessor: (preprocessor: {
|
|
140
|
+
name: string;
|
|
141
|
+
preprocessor: typeof razorwindInferPreprocessor;
|
|
142
|
+
}) => unknown;
|
|
143
|
+
}
|
|
144
|
+
/** Inline `hooks.parsers` map for Style Dictionary config. */
|
|
145
|
+
declare function getRazorwindParserHooks(): NonNullable<Hooks["parsers"]>;
|
|
146
|
+
/**
|
|
147
|
+
* Infer DTCG `$type` / normalize legacy keys after sources merge.
|
|
148
|
+
* Covers JS/TS modules that bypass custom file parsers.
|
|
149
|
+
*/
|
|
150
|
+
declare function razorwindInferPreprocessor(dictionary: PreprocessedTokens): PreprocessedTokens;
|
|
151
|
+
/** Inline `hooks.preprocessors` map for Style Dictionary config. */
|
|
152
|
+
declare function getRazorwindPreprocessorHooks(): NonNullable<Hooks["preprocessors"]>;
|
|
153
|
+
/**
|
|
154
|
+
* Register Razorwind parsers + infer preprocessor on Style Dictionary,
|
|
155
|
+
* then register any extraction hooks contributed by plugins.
|
|
156
|
+
*
|
|
157
|
+
* Platform generation hooks (transforms, formats, …) are registered by
|
|
158
|
+
* `@razorwind/style-dictionary` during generate.
|
|
159
|
+
*
|
|
160
|
+
* @see https://styledictionary.com/reference/api/
|
|
161
|
+
*/
|
|
162
|
+
declare function registerRazorwindHooks(plugins?: Plugin[], target?: StyleDictionaryRegisterTarget): void;
|
|
163
|
+
/**
|
|
164
|
+
* @deprecated Use {@link registerRazorwindHooks} instead.
|
|
165
|
+
*/
|
|
166
|
+
declare const registerRazorwindParsers: typeof registerRazorwindHooks;
|
|
167
|
+
//#endregion
|
|
168
|
+
export { RazorwindParserName as C, TOKEN_PARSER_NAMES as D, TOKEN_FILE_EXTENSIONS as E, TYPE_PATH_HINTS as O, DEFAULT_TOKEN_PATH_CANDIDATES as S, TOKEN_DIRECTORY_GLOB as T, inferTypeFromPath as _, razorwindInferPreprocessor as a, normalizeTokenTree as b, LoadTokensOptions as c, loadTokensOrThrow as d, ResolveTokensPathOptions as f, InferredTokenType as g, themeKeyFromPath as h, getRazorwindPreprocessorHooks as i, LoadedTokens as l, resolveTokensSource as m, StyleDictionaryRegisterTarget as n, registerRazorwindHooks as o, ResolvedTokensSource as p, getRazorwindParserHooks as r, registerRazorwindParsers as s, RAZORWIND_INFER_PREPROCESSOR as t, loadTokens as u, inferValue as v, THEME_BASENAME_PATTERN as w, parseCssCustomProperties as x, nestFlatTokens as y };
|
|
169
|
+
//# sourceMappingURL=index-BlIc4ofi.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BlIc4ofi.d.mts","names":[],"sources":["../src/lib/tokens/constants.ts","../src/lib/tokens/css.ts","../src/lib/tokens/infer.ts","../src/lib/tokens/resolve-path.ts","../src/lib/tokens/load.ts","../src/lib/tokens/parsers.ts"],"mappings":""}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { t as Schema } from "./schema-C6-umW1r.cjs";
|
|
2
|
+
import "./index-DW51mcvl.cjs";
|
|
3
|
+
import { l as Plugin, t as Config } from "./config-CBGz3vxV.cjs";
|
|
4
|
+
import { Tokens } from "@power-plant/dtcg-schema";
|
|
5
|
+
import { ExecutionContext } from "@power-plant/core";
|
|
6
|
+
import { Hooks, Parser, PreprocessedTokens } from "style-dictionary/types";
|
|
7
|
+
//#region src/lib/tokens/constants.d.ts
|
|
8
|
+
/** Style Dictionary parser hook names registered by Razorwind. */
|
|
9
|
+
declare const TOKEN_PARSER_NAMES: readonly ["razorwind-json", "razorwind-yaml", "razorwind-toml", "razorwind-css"];
|
|
10
|
+
type RazorwindParserName = (typeof TOKEN_PARSER_NAMES)[number];
|
|
11
|
+
/** File extensions treated as design-token sources. */
|
|
12
|
+
declare const TOKEN_FILE_EXTENSIONS: readonly ["json", "json5", "jsonc", "yaml", "yml", "toml", "css", "js", "mjs", "cjs", "ts", "mts", "cts"];
|
|
13
|
+
/**
|
|
14
|
+
* Candidate paths checked when `tokensPath` is omitted.
|
|
15
|
+
* First existing file or directory wins.
|
|
16
|
+
*/
|
|
17
|
+
declare const DEFAULT_TOKEN_PATH_CANDIDATES: readonly ["tokens.json", "tokens.json5", "tokens.jsonc", "tokens.yaml", "tokens.yml", "tokens.toml", "tokens.css", "design-tokens.json", "design-tokens.yaml", "design-tokens.yml", "tokens", "design-tokens", "src/tokens", "src/design-tokens", "packages/tokens", "style-dictionary.config.js", "style-dictionary.config.mjs", "style-dictionary.config.ts", "sd.config.js", "sd.config.mjs", "sd.config.ts"];
|
|
18
|
+
/** Glob appended when a tokens directory is resolved. */
|
|
19
|
+
declare const TOKEN_DIRECTORY_GLOB: string;
|
|
20
|
+
/** Theme-like basename patterns used to split multi-file sources into a record. */
|
|
21
|
+
declare const THEME_BASENAME_PATTERN: RegExp;
|
|
22
|
+
/** Path segment hints used when inferring `$type`. */
|
|
23
|
+
declare const TYPE_PATH_HINTS: Record<string, string>;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/lib/tokens/css.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Extract CSS custom properties from stylesheet text into a nested token tree.
|
|
28
|
+
* Handles `:root`, `[data-theme]`, and Tailwind v4 `@theme` blocks alike.
|
|
29
|
+
*/
|
|
30
|
+
declare function parseCssCustomProperties(contents: string): Record<string, unknown>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/lib/tokens/infer.d.ts
|
|
33
|
+
type InferredTokenType = "color" | "dimension" | "duration" | "fontFamily" | "fontWeight" | "number" | "cubicBezier" | "shadow" | "gradient" | "typography" | "strokeStyle" | "border" | "transition";
|
|
34
|
+
/**
|
|
35
|
+
* Infer DTCG `$type` from a path segment chain (e.g. `color.primary`).
|
|
36
|
+
*/
|
|
37
|
+
declare function inferTypeFromPath(path: string[]): InferredTokenType | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Normalize a raw token value into DTCG-friendly shape + optional `$type`.
|
|
40
|
+
*/
|
|
41
|
+
declare function inferValue(raw: unknown, path?: string[]): {
|
|
42
|
+
value: unknown;
|
|
43
|
+
type?: InferredTokenType;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Walk a token tree: promote legacy keys to DTCG and infer `$type` / `$value` shapes.
|
|
47
|
+
*/
|
|
48
|
+
declare function normalizeTokenTree(input: unknown, path?: string[]): unknown;
|
|
49
|
+
/**
|
|
50
|
+
* Nest a flat map of dashed keys into a token tree.
|
|
51
|
+
* `--color-primary-500` / `color-primary-500` → `color.primary.500`.
|
|
52
|
+
*
|
|
53
|
+
* Scalar parents that also have children (e.g. `--radius` + `--radius-lg`) are
|
|
54
|
+
* preserved under `DEFAULT` so neither value is dropped.
|
|
55
|
+
*/
|
|
56
|
+
declare function nestFlatTokens(flat: Record<string, unknown>): Record<string, unknown>;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/lib/tokens/resolve-path.d.ts
|
|
59
|
+
interface ResolveTokensPathOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Working directory used to resolve relative paths.
|
|
62
|
+
*/
|
|
63
|
+
cwd: string;
|
|
64
|
+
/**
|
|
65
|
+
* Explicit tokens file(s) or directory(ies) from config.
|
|
66
|
+
*/
|
|
67
|
+
tokensPath?: string | string[];
|
|
68
|
+
/**
|
|
69
|
+
* Extra fallback paths (e.g. registry `tailwind.css`).
|
|
70
|
+
*/
|
|
71
|
+
fallbackPaths?: Array<string | null | undefined>;
|
|
72
|
+
}
|
|
73
|
+
interface ResolvedTokensSource {
|
|
74
|
+
/**
|
|
75
|
+
* Absolute path to the resolved file or directory (if any).
|
|
76
|
+
*
|
|
77
|
+
* When multiple `tokensPath` entries are provided, this is the first
|
|
78
|
+
* resolved path (or the Style Dictionary config when that is the sole entry).
|
|
79
|
+
*/
|
|
80
|
+
resolvedPath?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Style Dictionary `source` globs.
|
|
83
|
+
*/
|
|
84
|
+
source: string[];
|
|
85
|
+
/**
|
|
86
|
+
* How the path was discovered.
|
|
87
|
+
*/
|
|
88
|
+
origin: "tokensPath" | "default" | "fallback" | "none";
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve Style Dictionary source globs from `tokensPath` or common defaults.
|
|
92
|
+
*
|
|
93
|
+
* When `tokensPath` is an array, each entry is resolved and the resulting
|
|
94
|
+
* source globs are merged. A Style Dictionary config file may only be used as
|
|
95
|
+
* the sole `tokensPath` entry.
|
|
96
|
+
*/
|
|
97
|
+
declare function resolveTokensSource(options: ResolveTokensPathOptions): ResolvedTokensSource;
|
|
98
|
+
/**
|
|
99
|
+
* Detect theme-like basenames for splitting multi-file token sets.
|
|
100
|
+
*/
|
|
101
|
+
declare function themeKeyFromPath(filePath: string): string | undefined;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/lib/tokens/load.d.ts
|
|
104
|
+
interface LoadTokensOptions extends ResolveTokensPathOptions {
|
|
105
|
+
/**
|
|
106
|
+
* When true, split theme-named files into a record keyed by theme.
|
|
107
|
+
*
|
|
108
|
+
* @defaultValue true
|
|
109
|
+
*/
|
|
110
|
+
splitThemes?: boolean;
|
|
111
|
+
}
|
|
112
|
+
type LoadedTokens = Tokens | Record<string, Tokens>;
|
|
113
|
+
/**
|
|
114
|
+
* Load design tokens via Style Dictionary parser hooks.
|
|
115
|
+
*
|
|
116
|
+
* Resolution order:
|
|
117
|
+
* 1. Explicit `tokensPath` (file, directory, array of those, or SD config)
|
|
118
|
+
* 2. Common default paths (`tokens.json`, `tokens/`, …)
|
|
119
|
+
* 3. Fallback paths (e.g. registry Tailwind CSS)
|
|
120
|
+
*/
|
|
121
|
+
declare function loadTokens(context: ExecutionContext<Schema, Config, void>): Promise<LoadedTokens>;
|
|
122
|
+
/**
|
|
123
|
+
* Convenience: load tokens or throw when nothing usable is found.
|
|
124
|
+
*
|
|
125
|
+
* @param config - The configuration object.
|
|
126
|
+
* @param options - The options for loading the tokens.
|
|
127
|
+
* @returns The loaded tokens.
|
|
128
|
+
* @throws An error if no design tokens are found.
|
|
129
|
+
* @throws An error if the tokens are not valid.
|
|
130
|
+
*/
|
|
131
|
+
declare function loadTokensOrThrow(context: ExecutionContext<Schema, Config, void>): Promise<LoadedTokens>;
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/lib/tokens/parsers.d.ts
|
|
134
|
+
/** Preprocessor name applied after all sources merge. */
|
|
135
|
+
declare const RAZORWIND_INFER_PREPROCESSOR = "razorwind-infer";
|
|
136
|
+
/** Target capable of registering Style Dictionary extraction hooks. */
|
|
137
|
+
interface StyleDictionaryRegisterTarget {
|
|
138
|
+
registerParser: (parser: Parser) => unknown;
|
|
139
|
+
registerPreprocessor: (preprocessor: {
|
|
140
|
+
name: string;
|
|
141
|
+
preprocessor: typeof razorwindInferPreprocessor;
|
|
142
|
+
}) => unknown;
|
|
143
|
+
}
|
|
144
|
+
/** Inline `hooks.parsers` map for Style Dictionary config. */
|
|
145
|
+
declare function getRazorwindParserHooks(): NonNullable<Hooks["parsers"]>;
|
|
146
|
+
/**
|
|
147
|
+
* Infer DTCG `$type` / normalize legacy keys after sources merge.
|
|
148
|
+
* Covers JS/TS modules that bypass custom file parsers.
|
|
149
|
+
*/
|
|
150
|
+
declare function razorwindInferPreprocessor(dictionary: PreprocessedTokens): PreprocessedTokens;
|
|
151
|
+
/** Inline `hooks.preprocessors` map for Style Dictionary config. */
|
|
152
|
+
declare function getRazorwindPreprocessorHooks(): NonNullable<Hooks["preprocessors"]>;
|
|
153
|
+
/**
|
|
154
|
+
* Register Razorwind parsers + infer preprocessor on Style Dictionary,
|
|
155
|
+
* then register any extraction hooks contributed by plugins.
|
|
156
|
+
*
|
|
157
|
+
* Platform generation hooks (transforms, formats, …) are registered by
|
|
158
|
+
* `@razorwind/style-dictionary` during generate.
|
|
159
|
+
*
|
|
160
|
+
* @see https://styledictionary.com/reference/api/
|
|
161
|
+
*/
|
|
162
|
+
declare function registerRazorwindHooks(plugins?: Plugin[], target?: StyleDictionaryRegisterTarget): void;
|
|
163
|
+
/**
|
|
164
|
+
* @deprecated Use {@link registerRazorwindHooks} instead.
|
|
165
|
+
*/
|
|
166
|
+
declare const registerRazorwindParsers: typeof registerRazorwindHooks;
|
|
167
|
+
//#endregion
|
|
168
|
+
export { RazorwindParserName as C, TOKEN_PARSER_NAMES as D, TOKEN_FILE_EXTENSIONS as E, TYPE_PATH_HINTS as O, DEFAULT_TOKEN_PATH_CANDIDATES as S, TOKEN_DIRECTORY_GLOB as T, inferTypeFromPath as _, razorwindInferPreprocessor as a, normalizeTokenTree as b, LoadTokensOptions as c, loadTokensOrThrow as d, ResolveTokensPathOptions as f, InferredTokenType as g, themeKeyFromPath as h, getRazorwindPreprocessorHooks as i, LoadedTokens as l, resolveTokensSource as m, StyleDictionaryRegisterTarget as n, registerRazorwindHooks as o, ResolvedTokensSource as p, getRazorwindParserHooks as r, registerRazorwindParsers as s, RAZORWIND_INFER_PREPROCESSOR as t, loadTokens as u, inferValue as v, THEME_BASENAME_PATTERN as w, parseCssCustomProperties as x, nestFlatTokens as y };
|
|
169
|
+
//# sourceMappingURL=index-CKJ5fZxo.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-CKJ5fZxo.d.cts","names":[],"sources":["../src/lib/tokens/constants.ts","../src/lib/tokens/css.ts","../src/lib/tokens/infer.ts","../src/lib/tokens/resolve-path.ts","../src/lib/tokens/load.ts","../src/lib/tokens/parsers.ts"],"mappings":";;;;;;;;cAmBa;KAOD,8BAA8B;;cAG7B;;;;;cAsBA;;cAyBA;;cAGA,wBAAsB;;cAItB,iBAAiB;;;;;;;iBCvDd,yBACd,mBACC;;;KCgCS;;;;iBAmEI,kBACd,iBACC;;;;iBAiBa,WACd,cACA;EACG;EAAgB,OAAO;;;;;iBAsPZ,mBACd,gBACA;;;;;;;;iBA2Cc,eACd,MAAM,0BACL;;;UC9Zc;;;;EAIf;;;;EAKA;;;;EAKA,gBAAgB;;UAGD;;;;;;;EAOf;;;;EAKA;;;;EAKA;;;;;;;;;iBAyFc,oBACd,SAAS,2BACR;;;;iBAqFa,iBAAiB;;;UCzMhB,0BAA0B;;;;;;EAMzC;;KAGU,eAAe,SAAS,eAAe;;;;;;;;;iBA2I7B,WACpB,SAAS,iBAAiB,QAAQ,gBACjC,QAAQ;;;;;;;;;;iBAsCW,kBACpB,SAAS,iBAAiB,QAAQ,gBACjC,QAAQ;;;;cClME;;UAGI;EACf,iBAAiB,QAAQ;EACzB,uBAAuB;IACrB;IACA,qBAAqB;;;;iBAyET,2BAA2B,YAAY;;;;;iBAavC,2BACd,YAAY,qBACX;;iBAKa,iCAAiC,YAC/C;;;;;;;;;;iBAgBc,uBACd,UAAS,UACT,SAAQ;;;;cA6CG,iCAAwB"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./schema-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./schema-DWEhLYz4.cjs"),n=require("./tokens-IRvI2l2K.cjs"),r=require("./plugin.cjs");let i=require("@power-plant/core"),a=require("@stryke/type-checks/is-empty-object"),o=require("defu"),s=require("style-dictionary");s=e.t(s,1);let c=require("@stryke/fs/exists"),l=require("@stryke/fs/is-file"),u=require("@stryke/fs/json"),d=require("@stryke/fs/list-files"),f=require("@stryke/path/append"),p=require("@stryke/path/file-path-fns"),m=require("@stryke/path/join"),h=require("@stryke/string-format/title-case"),g=require("@stryke/type-checks/is-set-object"),_=require("@stryke/type-checks/is-set-string"),v=require("node:fs/promises"),y=require("node:path"),b=require("@stryke/env"),x=require("@stryke/path/find"),S=require("@stryke/path/replace"),C=require("@stryke/type-checks/is-function"),w=require("c12"),T=require("jiti"),E=require("node:fs"),D=require("node:os");D=e.t(D,1);var O=`0.0.22`;const k=t.r.partial(),A=(0,o.createDefu)((e,t,n)=>Array.isArray(n)?(e[t]=n,!0):!1);function j(e,t){return(0,y.isAbsolute)(t)?t:(0,y.resolve)(e,t)}function M(e){return Array.isArray(e)?e.filter(_.isSetString):(0,_.isSetString)(e)?[e]:[]}function N(e){if((0,_.isSetString)(e))return e;if((0,g.isSetObject)(e)&&`url`in e&&(0,_.isSetString)(e.url))return e.url}function P(e){if(!e)return;let n=t.n.safeParse(e);if(n.success)return[n.data];if(!Array.isArray(e))return;let r=[];for(let n of e){let e=t.n.safeParse(n);e.success&&r.push(e.data)}return r.length>0?r:void 0}function F(e){if(!(0,g.isSetObject)(e))return;let t=k.safeParse(e);if(t.success)return Object.keys(t.data).length>0?t.data:void 0}function I(e){return(0,g.isSetObject)(e)&&`path`in e}async function L(e){let t=(0,m.joinPaths)(e,`package.json`);if(!(0,c.existsSync)(t))return;let n;try{n=await(0,u.readJsonFile)(t)}catch{return}let r={};(0,_.isSetString)(n.name)&&(r.name=n.name,r.title=n.name),(0,_.isSetString)(n.description)&&(r.description=n.description),(0,_.isSetString)(n.version)&&(r.version=n.version),(0,_.isSetString)(n.homepage)&&(r.homepage=n.homepage);let i=N(n.repository);if(i&&(r.repository=i),(0,g.isSetObject)(n.dependencies)&&(r.dependencies=n.dependencies),(0,g.isSetObject)(n.devDependencies)&&(r.devDependencies=n.devDependencies),Array.isArray(n.keywords)){let e=n.keywords.filter(_.isSetString);e.length>0&&(r.tags=e)}let a=n.razorwind,o,s;I(a)?s=P(a):(0,g.isSetObject)(a)&&(o=F(a),`files`in a&&(s=P(a.files)));let l=A(o??{},r);return s?.length&&(l.files=s),Object.keys(l).length>0?l:void 0}async function R(e){let t=(0,m.joinPaths)(e,`component.json`);if(!(0,c.existsSync)(t))return;let n;try{n=await(0,u.readJsonFile)(t)}catch{return}if(I(n)||Array.isArray(n)){let e=P(n);if(e)return{files:e}}return F(n)}async function z(e){let n=await L(e),r=await R(e);if(!n&&!r)return;let i=A(r??{},n??{}),a=(0,_.isSetString)(i.name)?i.name:(0,p.findFolderName)(e),o=(0,_.isSetString)(i.title)?i.title:(0,h.titleCase)(a),s=t.r.safeParse({...i,name:a,title:o});if(s.success)return{...s.data,files:await Promise.all((s.data.files??(await(0,d.listFiles)(e)).filter(e=>(0,p.findFileName)(e,{withExtension:!1})===`index`))?.filter(Boolean)?.map(async t=>typeof t==`string`?{type:/[tj]sx$/.test((0,p.findFileExtensionSafe)(t))?`component`:`file`,path:t,content:await(0,v.readFile)((0,f.appendPath)(t,e),`utf8`)}:{type:/[tj]sx$/.test((0,p.findFileExtensionSafe)(t.path))?`component`:`file`,...t,content:t.content?t.content:t.path?await(0,v.readFile)((0,f.appendPath)(t.path,e),`utf8`):void 0,path:(0,f.appendPath)(t.path,e)}))}}async function B(e){let t={},n=M(e.options.componentsPath);for(let r of n){let n=j(e.cwd,r);if(!(!(0,c.existsSync)(n)||!(0,l.isDirectory)(n)))try{let e=await(0,v.readdir)(n,{withFileTypes:!0});for(let r of e){if(!r.isDirectory()||r.name.startsWith(`.`))continue;let e=await z((0,m.joinPaths)(n,r.name));e&&(t[e.name]=e)}}catch{continue}}return t}const V=D.default.homedir();async function H(e,t){let n=t.configFile&&(0,E.existsSync)((0,S.replacePath)(t.configFile,e))?(0,S.replacePath)(t.configFile,e):t.configFile&&(0,E.existsSync)(t.configFile)?t.configFile:(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.${t.mode}.config.ts`))?(0,m.joinPaths)(e,`razorwind.${t.mode}.config.ts`):(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.${t.mode}.config.js`))?(0,m.joinPaths)(e,`razorwind.${t.mode}.config.js`):(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.${t.mode}.config.mts`))?(0,m.joinPaths)(e,`razorwind.${t.mode}.config.mts`):(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.${t.mode}.config.mjs`))?(0,m.joinPaths)(e,`razorwind.${t.mode}.config.mjs`):(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.config.ts`))?(0,m.joinPaths)(e,`razorwind.config.ts`):(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.config.js`))?(0,m.joinPaths)(e,`razorwind.config.js`):(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.config.mts`))?(0,m.joinPaths)(e,`razorwind.config.mts`):(0,E.existsSync)((0,m.joinPaths)(e,`razorwind.config.mjs`))?(0,m.joinPaths)(e,`razorwind.config.mjs`):void 0,r=(0,b.getEnvPaths)({orgId:`storm-software`,appId:`razorwind`,workspaceRoot:e}),i={fsCache:r.cache},a=(0,T.createJiti)(e,i),s={};if(n){let r=await a.import(a.esmResolve(n));if(r?.default){let i={};(0,C.isFunction)(r.default)?i=await Promise.resolve(r.default({cwd:e,mode:t.mode??`development`})):((0,g.isSetObject)(r.default)||Array.isArray(r.default))&&(i=r.default),((0,g.isSetObject)(i)||Array.isArray(i))&&(s={...i,configFile:n})}}let[c,l,u]=await Promise.all([(0,w.loadConfig)({cwd:e,name:`razorwind`,envName:t.mode,globalRc:!0,packageJson:`razorwind`,dotenv:!0,jitiOptions:i}),(0,w.loadConfig)({cwd:r.config,name:`razorwind`,envName:t.mode,dotenv:!0,jitiOptions:i}),(0,w.loadConfig)({cwd:V,name:`razorwind`,envName:t.mode,dotenv:!0,jitiOptions:i})]),d=(0,o.defu)({cwd:e,envPaths:{...r,home:V}},t,s,(0,g.isSetObject)(c?.config)?{...c.config}:{},(0,g.isSetObject)(l?.config)?{...l.config}:{},(0,g.isSetObject)(u?.config)?{...u.config}:{},{componentsPath:e,plugins:[]});if(Array.isArray(d.componentsPath)){let t=d.componentsPath.filter(_.isSetString).map(e=>(0,x.findFilePath)(e));d.componentsPath=t.length>0?t:e}else d.componentsPath=(0,_.isSetString)(d.componentsPath)?(0,x.findFilePath)(d.componentsPath):e;return Array.isArray(d.plugins)||(d.plugins=[]),d}function U(e){return e}const W=(0,i.defineGenerator)({meta:{name:`razorwind`,title:`Razorwind`,description:`A generator that uses Razorwind to generate design system code from design tokens and components.`,version:O,tags:[`razorwind`,`dtcg`]},schema:(0,i.defineSchema)({schema:t.t}),input:async e=>{let t=(0,i.useExecution)();if(t.options=await H(t.cwd,e),t.options.plugins.length===0)throw Error(`Razorwind will not generate any code - no plugins configured. Please add at least one plugin to the configuration.`);n.l(t.options.plugins,s.default);let r=t.options.tokens;(!r||(0,a.isEmptyObject)(r))&&(r=await n.t(t));let c={tokens:r??{},components:(0,o.defu)(t.options.components??{},await B(t)??{})};for(let e of t.options.plugins.filter(e=>e.extract))c=await e.extract(c,t.options);if(!c.tokens||(0,a.isEmptyObject)(c.tokens))throw Error(`Unable to load design tokens for the current workspace. Please ensure that Razorwind is configured correctly and that the tokens are available.`);for(let e of t.options.plugins.filter(e=>e.validate))await e.validate(c,t.options);return c},generator:async e=>{let t=(0,i.useExecution)(),n={};for(let r of t.options.plugins.filter(e=>e.generate)){let i=await r.generate(e,t.options);n=(0,o.defu)(i,n)}return n}});exports.DEFAULT_TOKEN_PATH_CANDIDATES=n.g,exports.RAZORWIND_INFER_PREPROCESSOR=n.a,exports.THEME_BASENAME_PATTERN=n._,exports.TOKEN_DIRECTORY_GLOB=n.v,exports.TOKEN_FILE_EXTENSIONS=n.y,exports.TYPE_PATH_HINTS=n.x,exports.WINDIE_PARSERS=n.b,exports.razorwindParsers=n.b,exports.defineConfig=U,exports.definePlugin=r.definePlugin,exports.generator=W,exports.getRazorwindParserHooks=n.o,exports.getRazorwindPreprocessorHooks=n.s,exports.inferTypeFromPath=n.f,exports.inferValue=n.p,exports.loadComponents=B,exports.loadTokens=n.t,exports.loadTokensOrThrow=n.n,exports.nestFlatTokens=n.m,exports.normalizeTokenTree=n.h,exports.parseCssCustomProperties=n.d,exports.razorwindInferPreprocessor=n.c,exports.registerRazorwindHooks=n.l,exports.registerRazorwindParsers=n.u,exports.resolveConfig=H,exports.resolveTokensSource=n.r,exports.themeKeyFromPath=n.i;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { t as Schema } from "./schema-
|
|
2
|
-
import "./index-
|
|
3
|
-
import { a as UserConfigFn, c as UserConfigParams, d as TokensPreprocessor, i as UserConfigExport, l as Plugin, n as Options, o as UserConfigFnObject, r as UserConfig, s as UserConfigFnPromise, t as Config, u as TokensParser } from "./config-
|
|
4
|
-
import { t as definePlugin } from "./plugin-
|
|
1
|
+
import { a as Components, t as Schema } from "./schema-C6-umW1r.cjs";
|
|
2
|
+
import "./index-DW51mcvl.cjs";
|
|
3
|
+
import { a as UserConfigFn, c as UserConfigParams, d as TokensPreprocessor, i as UserConfigExport, l as Plugin, n as Options, o as UserConfigFnObject, r as UserConfig, s as UserConfigFnPromise, t as Config, u as TokensParser } from "./config-CBGz3vxV.cjs";
|
|
4
|
+
import { t as definePlugin } from "./plugin-C_nK-znA.cjs";
|
|
5
|
+
import { C as RazorwindParserName, D as TOKEN_PARSER_NAMES, E as TOKEN_FILE_EXTENSIONS, O as TYPE_PATH_HINTS, S as DEFAULT_TOKEN_PATH_CANDIDATES, T as TOKEN_DIRECTORY_GLOB, _ as inferTypeFromPath, a as razorwindInferPreprocessor, b as normalizeTokenTree, c as LoadTokensOptions, d as loadTokensOrThrow, f as ResolveTokensPathOptions, g as InferredTokenType, h as themeKeyFromPath, i as getRazorwindPreprocessorHooks, l as LoadedTokens, m as resolveTokensSource, n as StyleDictionaryRegisterTarget, o as registerRazorwindHooks, p as ResolvedTokensSource, r as getRazorwindParserHooks, s as registerRazorwindParsers, t as RAZORWIND_INFER_PREPROCESSOR, u as loadTokens, v as inferValue, w as THEME_BASENAME_PATTERN, x as parseCssCustomProperties, y as nestFlatTokens } from "./index-CKJ5fZxo.cjs";
|
|
5
6
|
import StyleDictionary from "style-dictionary";
|
|
6
|
-
import { GeneratorConfig } from "@power-plant/core";
|
|
7
|
+
import { ExecutionContext, GeneratorConfig } from "@power-plant/core";
|
|
7
8
|
//#region src/lib/resolve-config.d.ts
|
|
8
9
|
/**
|
|
9
10
|
* Loads the user configuration file for the project.
|
|
@@ -44,6 +45,18 @@ declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
|
|
|
44
45
|
declare function defineConfig(config: UserConfigFn): UserConfigFn;
|
|
45
46
|
declare function defineConfig(config: UserConfigExport): UserConfigExport;
|
|
46
47
|
//#endregion
|
|
48
|
+
//#region src/lib/components/load.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* Load components from `componentsPath` directories.
|
|
51
|
+
*
|
|
52
|
+
* For each configured path that is a directory, every direct child directory is inspected for:
|
|
53
|
+
* 1. `package.json` — npm fields and/or a `razorwind` object (including `componentFileSchema` file entries)
|
|
54
|
+
* 2. `component.json` — component metadata or `componentFileSchema` values
|
|
55
|
+
*
|
|
56
|
+
* When both resolve values, `component.json` overlays `package.json`.
|
|
57
|
+
*/
|
|
58
|
+
declare function loadComponents(context: ExecutionContext<Schema, Config, void>): Promise<Components>;
|
|
59
|
+
//#endregion
|
|
47
60
|
//#region src/types/base.d.ts
|
|
48
61
|
type Generator<TOptions extends object = object> = GeneratorConfig<Schema, TOptions> & {
|
|
49
62
|
name: string;
|
|
@@ -70,5 +83,5 @@ declare module "@power-plant/core" {
|
|
|
70
83
|
*/
|
|
71
84
|
declare const generator: import("@power-plant/core").GeneratorConfigObject<Schema, Options, any>;
|
|
72
85
|
//#endregion
|
|
73
|
-
export { type Config, type Generator, type Options, type Plugin, type TokensParser, type TokensPreprocessor, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type UserConfigParams, defineConfig, definePlugin, generator, resolveConfig };
|
|
86
|
+
export { type Config, DEFAULT_TOKEN_PATH_CANDIDATES, type Generator, type InferredTokenType, type LoadTokensOptions, type LoadedTokens, type Options, type Plugin, RAZORWIND_INFER_PREPROCESSOR, type RazorwindParserName, type ResolveTokensPathOptions, type ResolvedTokensSource, type StyleDictionaryRegisterTarget, THEME_BASENAME_PATTERN, TOKEN_DIRECTORY_GLOB, TOKEN_FILE_EXTENSIONS, TYPE_PATH_HINTS, type TokensParser, type TokensPreprocessor, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type UserConfigParams, TOKEN_PARSER_NAMES as WINDIE_PARSERS, TOKEN_PARSER_NAMES as razorwindParsers, defineConfig, definePlugin, generator, getRazorwindParserHooks, getRazorwindPreprocessorHooks, inferTypeFromPath, inferValue, loadComponents, loadTokens, loadTokensOrThrow, nestFlatTokens, normalizeTokenTree, parseCssCustomProperties, razorwindInferPreprocessor, registerRazorwindHooks, registerRazorwindParsers, resolveConfig, resolveTokensSource, themeKeyFromPath };
|
|
74
87
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/lib/resolve-config.ts","../src/config.ts","../src/types/base.ts","../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/lib/resolve-config.ts","../src/config.ts","../src/lib/components/load.ts","../src/types/base.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;;;iBA8CsB,cACpB,aACA,SAAS,UACR,QAAQ;;;;;;;;;;;;;;;;;;;;;;;iBCEK,aAAa,QAAQ,aAAa;iBAClC,aAAa,QAAQ,eAAe;iBACpC,aAAa,QAAQ,QAAQ,cAAc,QAAQ;iBACnD,aACd,QAAQ,QAAQ,gBACf,QAAQ;iBACK,aAAa,QAAQ,qBAAqB;iBAC1C,aAAa,QAAQ,sBAAsB;iBAC3C,aAAa,QAAQ,eAAe;iBACpC,aAAa,QAAQ,mBAAmB;;;;;;;;;;;;iBC0PlC,eACpB,SAAS,iBAAiB,QAAQ,gBACjC,QAAQ;;;KCnSC,UAAU,oCAAoC,gBACxD,QACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;YCGU;IACR,IAAI;;;;;;;;;cAcK,uCAAS,sBAAA,QAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { t as Schema } from "./schema-
|
|
2
|
-
import "./index
|
|
3
|
-
import { a as UserConfigFn, c as UserConfigParams, d as TokensPreprocessor, i as UserConfigExport, l as Plugin, n as Options, o as UserConfigFnObject, r as UserConfig, s as UserConfigFnPromise, t as Config, u as TokensParser } from "./config-
|
|
4
|
-
import { t as definePlugin } from "./plugin-
|
|
5
|
-
import {
|
|
1
|
+
import { a as Components, t as Schema } from "./schema-C6-umW1r.mjs";
|
|
2
|
+
import "./index-BhVvIILv.mjs";
|
|
3
|
+
import { a as UserConfigFn, c as UserConfigParams, d as TokensPreprocessor, i as UserConfigExport, l as Plugin, n as Options, o as UserConfigFnObject, r as UserConfig, s as UserConfigFnPromise, t as Config, u as TokensParser } from "./config-CaaK20wo.mjs";
|
|
4
|
+
import { t as definePlugin } from "./plugin-Cbx7QH4X.mjs";
|
|
5
|
+
import { C as RazorwindParserName, D as TOKEN_PARSER_NAMES, E as TOKEN_FILE_EXTENSIONS, O as TYPE_PATH_HINTS, S as DEFAULT_TOKEN_PATH_CANDIDATES, T as TOKEN_DIRECTORY_GLOB, _ as inferTypeFromPath, a as razorwindInferPreprocessor, b as normalizeTokenTree, c as LoadTokensOptions, d as loadTokensOrThrow, f as ResolveTokensPathOptions, g as InferredTokenType, h as themeKeyFromPath, i as getRazorwindPreprocessorHooks, l as LoadedTokens, m as resolveTokensSource, n as StyleDictionaryRegisterTarget, o as registerRazorwindHooks, p as ResolvedTokensSource, r as getRazorwindParserHooks, s as registerRazorwindParsers, t as RAZORWIND_INFER_PREPROCESSOR, u as loadTokens, v as inferValue, w as THEME_BASENAME_PATTERN, x as parseCssCustomProperties, y as nestFlatTokens } from "./index-BlIc4ofi.mjs";
|
|
6
|
+
import { ExecutionContext, GeneratorConfig } from "@power-plant/core";
|
|
6
7
|
import StyleDictionary from "style-dictionary";
|
|
7
8
|
//#region src/lib/resolve-config.d.ts
|
|
8
9
|
/**
|
|
@@ -44,6 +45,18 @@ declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
|
|
|
44
45
|
declare function defineConfig(config: UserConfigFn): UserConfigFn;
|
|
45
46
|
declare function defineConfig(config: UserConfigExport): UserConfigExport;
|
|
46
47
|
//#endregion
|
|
48
|
+
//#region src/lib/components/load.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* Load components from `componentsPath` directories.
|
|
51
|
+
*
|
|
52
|
+
* For each configured path that is a directory, every direct child directory is inspected for:
|
|
53
|
+
* 1. `package.json` — npm fields and/or a `razorwind` object (including `componentFileSchema` file entries)
|
|
54
|
+
* 2. `component.json` — component metadata or `componentFileSchema` values
|
|
55
|
+
*
|
|
56
|
+
* When both resolve values, `component.json` overlays `package.json`.
|
|
57
|
+
*/
|
|
58
|
+
declare function loadComponents(context: ExecutionContext<Schema, Config, void>): Promise<Components>;
|
|
59
|
+
//#endregion
|
|
47
60
|
//#region src/types/base.d.ts
|
|
48
61
|
type Generator<TOptions extends object = object> = GeneratorConfig<Schema, TOptions> & {
|
|
49
62
|
name: string;
|
|
@@ -70,5 +83,5 @@ declare module "@power-plant/core" {
|
|
|
70
83
|
*/
|
|
71
84
|
declare const generator: import("@power-plant/core").GeneratorConfigObject<Schema, Options, any>;
|
|
72
85
|
//#endregion
|
|
73
|
-
export { type Config, type Generator, type Options, type Plugin, type TokensParser, type TokensPreprocessor, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type UserConfigParams, defineConfig, definePlugin, generator, resolveConfig };
|
|
86
|
+
export { type Config, DEFAULT_TOKEN_PATH_CANDIDATES, type Generator, type InferredTokenType, type LoadTokensOptions, type LoadedTokens, type Options, type Plugin, RAZORWIND_INFER_PREPROCESSOR, type RazorwindParserName, type ResolveTokensPathOptions, type ResolvedTokensSource, type StyleDictionaryRegisterTarget, THEME_BASENAME_PATTERN, TOKEN_DIRECTORY_GLOB, TOKEN_FILE_EXTENSIONS, TYPE_PATH_HINTS, type TokensParser, type TokensPreprocessor, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type UserConfigParams, TOKEN_PARSER_NAMES as WINDIE_PARSERS, TOKEN_PARSER_NAMES as razorwindParsers, defineConfig, definePlugin, generator, getRazorwindParserHooks, getRazorwindPreprocessorHooks, inferTypeFromPath, inferValue, loadComponents, loadTokens, loadTokensOrThrow, nestFlatTokens, normalizeTokenTree, parseCssCustomProperties, razorwindInferPreprocessor, registerRazorwindHooks, registerRazorwindParsers, resolveConfig, resolveTokensSource, themeKeyFromPath };
|
|
74
87
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/resolve-config.ts","../src/config.ts","../src/types/base.ts","../src/index.ts"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/resolve-config.ts","../src/config.ts","../src/lib/components/load.ts","../src/types/base.ts","../src/index.ts"],"mappings":""}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,i as t,r as n}from"./schema-
|
|
1
|
+
import{a as e,i as t,r as n}from"./schema-CzpHs4s7.mjs";import{_ as r,a as i,b as a,c as o,d as s,f as c,g as l,h as u,i as d,l as f,m as ee,n as p,o as te,p as ne,r as re,s as m,t as h,u as g,v as _,x as v,y}from"./tokens-lbmSdrlF.mjs";import{definePlugin as b}from"./plugin.mjs";import{defineGenerator as x,defineSchema as S,useExecution as C}from"@power-plant/core";import{isEmptyObject as w}from"@stryke/type-checks/is-empty-object";import{createDefu as ie,defu as T}from"defu";import ae from"style-dictionary";import{existsSync as E}from"@stryke/fs/exists";import{isDirectory as oe}from"@stryke/fs/is-file";import{readJsonFile as D}from"@stryke/fs/json";import{listFiles as se}from"@stryke/fs/list-files";import{appendPath as O}from"@stryke/path/append";import{findFileExtensionSafe as k,findFileName as A,findFolderName as j}from"@stryke/path/file-path-fns";import{joinPaths as M}from"@stryke/path/join";import{titleCase as N}from"@stryke/string-format/title-case";import{isSetObject as P}from"@stryke/type-checks/is-set-object";import{isSetString as F}from"@stryke/type-checks/is-set-string";import{readFile as I,readdir as L}from"node:fs/promises";import{isAbsolute as R,resolve as z}from"node:path";import{getEnvPaths as B}from"@stryke/env";import{findFilePath as V}from"@stryke/path/find";import{replacePath as H}from"@stryke/path/replace";import{isFunction as U}from"@stryke/type-checks/is-function";import{loadConfig as W}from"c12";import{createJiti as G}from"jiti";import{existsSync as K}from"node:fs";import ce from"node:os";var le=`0.0.22`;const ue=e.partial(),q=ie((e,t,n)=>Array.isArray(n)?(e[t]=n,!0):!1);function de(e,t){return R(t)?t:z(e,t)}function fe(e){return Array.isArray(e)?e.filter(F):F(e)?[e]:[]}function pe(e){if(F(e))return e;if(P(e)&&`url`in e&&F(e.url))return e.url}function J(e){if(!e)return;let n=t.safeParse(e);if(n.success)return[n.data];if(!Array.isArray(e))return;let r=[];for(let n of e){let e=t.safeParse(n);e.success&&r.push(e.data)}return r.length>0?r:void 0}function Y(e){if(!P(e))return;let t=ue.safeParse(e);if(t.success)return Object.keys(t.data).length>0?t.data:void 0}function X(e){return P(e)&&`path`in e}async function me(e){let t=M(e,`package.json`);if(!E(t))return;let n;try{n=await D(t)}catch{return}let r={};F(n.name)&&(r.name=n.name,r.title=n.name),F(n.description)&&(r.description=n.description),F(n.version)&&(r.version=n.version),F(n.homepage)&&(r.homepage=n.homepage);let i=pe(n.repository);if(i&&(r.repository=i),P(n.dependencies)&&(r.dependencies=n.dependencies),P(n.devDependencies)&&(r.devDependencies=n.devDependencies),Array.isArray(n.keywords)){let e=n.keywords.filter(F);e.length>0&&(r.tags=e)}let a=n.razorwind,o,s;X(a)?s=J(a):P(a)&&(o=Y(a),`files`in a&&(s=J(a.files)));let c=q(o??{},r);return s?.length&&(c.files=s),Object.keys(c).length>0?c:void 0}async function he(e){let t=M(e,`component.json`);if(!E(t))return;let n;try{n=await D(t)}catch{return}if(X(n)||Array.isArray(n)){let e=J(n);if(e)return{files:e}}return Y(n)}async function ge(t){let n=await me(t),r=await he(t);if(!n&&!r)return;let i=q(r??{},n??{}),a=F(i.name)?i.name:j(t),o=F(i.title)?i.title:N(a),s=e.safeParse({...i,name:a,title:o});if(s.success)return{...s.data,files:await Promise.all((s.data.files??(await se(t)).filter(e=>A(e,{withExtension:!1})===`index`))?.filter(Boolean)?.map(async e=>typeof e==`string`?{type:/[tj]sx$/.test(k(e))?`component`:`file`,path:e,content:await I(O(e,t),`utf8`)}:{type:/[tj]sx$/.test(k(e.path))?`component`:`file`,...e,content:e.content?e.content:e.path?await I(O(e.path,t),`utf8`):void 0,path:O(e.path,t)}))}}async function Z(e){let t={},n=fe(e.options.componentsPath);for(let r of n){let n=de(e.cwd,r);if(!(!E(n)||!oe(n)))try{let e=await L(n,{withFileTypes:!0});for(let r of e){if(!r.isDirectory()||r.name.startsWith(`.`))continue;let e=await ge(M(n,r.name));e&&(t[e.name]=e)}}catch{continue}}return t}const Q=ce.homedir();async function $(e,t){let n=t.configFile&&K(H(t.configFile,e))?H(t.configFile,e):t.configFile&&K(t.configFile)?t.configFile:K(M(e,`razorwind.${t.mode}.config.ts`))?M(e,`razorwind.${t.mode}.config.ts`):K(M(e,`razorwind.${t.mode}.config.js`))?M(e,`razorwind.${t.mode}.config.js`):K(M(e,`razorwind.${t.mode}.config.mts`))?M(e,`razorwind.${t.mode}.config.mts`):K(M(e,`razorwind.${t.mode}.config.mjs`))?M(e,`razorwind.${t.mode}.config.mjs`):K(M(e,`razorwind.config.ts`))?M(e,`razorwind.config.ts`):K(M(e,`razorwind.config.js`))?M(e,`razorwind.config.js`):K(M(e,`razorwind.config.mts`))?M(e,`razorwind.config.mts`):K(M(e,`razorwind.config.mjs`))?M(e,`razorwind.config.mjs`):void 0,r=B({orgId:`storm-software`,appId:`razorwind`,workspaceRoot:e}),i={fsCache:r.cache},a=G(e,i),o={};if(n){let r=await a.import(a.esmResolve(n));if(r?.default){let i={};U(r.default)?i=await Promise.resolve(r.default({cwd:e,mode:t.mode??`development`})):(P(r.default)||Array.isArray(r.default))&&(i=r.default),(P(i)||Array.isArray(i))&&(o={...i,configFile:n})}}let[s,c,l]=await Promise.all([W({cwd:e,name:`razorwind`,envName:t.mode,globalRc:!0,packageJson:`razorwind`,dotenv:!0,jitiOptions:i}),W({cwd:r.config,name:`razorwind`,envName:t.mode,dotenv:!0,jitiOptions:i}),W({cwd:Q,name:`razorwind`,envName:t.mode,dotenv:!0,jitiOptions:i})]),u=T({cwd:e,envPaths:{...r,home:Q}},t,o,P(s?.config)?{...s.config}:{},P(c?.config)?{...c.config}:{},P(l?.config)?{...l.config}:{},{componentsPath:e,plugins:[]});if(Array.isArray(u.componentsPath)){let t=u.componentsPath.filter(F).map(e=>V(e));u.componentsPath=t.length>0?t:e}else u.componentsPath=F(u.componentsPath)?V(u.componentsPath):e;return Array.isArray(u.plugins)||(u.plugins=[]),u}function _e(e){return e}const ve=x({meta:{name:`razorwind`,title:`Razorwind`,description:`A generator that uses Razorwind to generate design system code from design tokens and components.`,version:le,tags:[`razorwind`,`dtcg`]},schema:S({schema:n}),input:async e=>{let t=C();if(t.options=await $(t.cwd,e),t.options.plugins.length===0)throw Error(`Razorwind will not generate any code - no plugins configured. Please add at least one plugin to the configuration.`);f(t.options.plugins,ae);let n=t.options.tokens;(!n||w(n))&&(n=await h(t));let r={tokens:n??{},components:T(t.options.components??{},await Z(t)??{})};for(let e of t.options.plugins.filter(e=>e.extract))r=await e.extract(r,t.options);if(!r.tokens||w(r.tokens))throw Error(`Unable to load design tokens for the current workspace. Please ensure that Razorwind is configured correctly and that the tokens are available.`);for(let e of t.options.plugins.filter(e=>e.validate))await e.validate(r,t.options);return r},generator:async e=>{let t=C(),n={};for(let r of t.options.plugins.filter(e=>e.generate)){let i=await r.generate(e,t.options);n=T(i,n)}return n}});export{l as DEFAULT_TOKEN_PATH_CANDIDATES,i as RAZORWIND_INFER_PREPROCESSOR,r as THEME_BASENAME_PATTERN,_ as TOKEN_DIRECTORY_GLOB,y as TOKEN_FILE_EXTENSIONS,v as TYPE_PATH_HINTS,a as WINDIE_PARSERS,a as razorwindParsers,_e as defineConfig,b as definePlugin,ve as generator,te as getRazorwindParserHooks,m as getRazorwindPreprocessorHooks,c as inferTypeFromPath,ne as inferValue,Z as loadComponents,h as loadTokens,p as loadTokensOrThrow,ee as nestFlatTokens,u as normalizeTokenTree,s as parseCssCustomProperties,o as razorwindInferPreprocessor,f as registerRazorwindHooks,g as registerRazorwindParsers,$ as resolveConfig,re as resolveTokensSource,d as themeKeyFromPath};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|