|
1 | 1 | import type { Action } from 'style-dictionary/types'; |
2 | 2 |
|
3 | | -import { readFile, writeFile, rm } from 'node:fs/promises'; |
4 | | - |
5 | | -import { fileURLToPath } from 'node:url'; |
| 3 | +import { writeFile, rm } from 'node:fs/promises'; |
6 | 4 |
|
7 | 5 | const rel = (path: string) => new URL(path, import.meta.url); |
8 | | -const PACKAGE_JSON_URL = rel('../../package.json'); |
9 | | -const TOKENS_DECL_CONTENT = 'export declare const tokens: Map<`--rh-${string}`, string|number>;'; |
10 | | -const TOKENS_DECL_URLS = [ |
11 | | - rel('../../js/tokens.d.ts'), |
12 | | - rel('../../js/tokens.d.cts'), |
13 | | -]; |
| 6 | + |
| 7 | +const files = new Map([ |
| 8 | + [ |
| 9 | + rel('../../js/tokens.d.ts'), |
| 10 | + 'export declare const tokens: Map<`--rh-${string}`, string|number>;', |
| 11 | + ], |
| 12 | + [ |
| 13 | + rel('../../js/meta.d.ts'), |
| 14 | + `interface DesignToken { |
| 15 | + value?: any; |
| 16 | + $value?: any; |
| 17 | + type?: string; |
| 18 | + $type?: string; |
| 19 | + $description?: string; |
| 20 | + name?: string; |
| 21 | + comment?: string; |
| 22 | + themeable?: boolean; |
| 23 | + attributes?: Record<string, unknown>; |
| 24 | + [key: string]: any; |
| 25 | +} |
| 26 | +
|
| 27 | +export declare const tokens: Map<\`--rh-\${string}\`, DesignToken>; |
| 28 | +`, |
| 29 | + ], |
| 30 | +]); |
14 | 31 |
|
15 | 32 | /** |
16 | 33 | * Write declaration file for JS token map |
17 | 34 | */ |
18 | 35 | export const writeEsMapDeclaration: Action = { |
19 | 36 | name: 'writeEsMapDeclaration', |
20 | 37 | async do() { |
21 | | - for (const url of TOKENS_DECL_URLS) { |
22 | | - await writeFile(url, TOKENS_DECL_CONTENT, 'utf8'); |
| 38 | + for (const [url, content] of files) { |
| 39 | + await writeFile(url, content, 'utf8'); |
23 | 40 | } |
24 | 41 | }, |
25 | 42 | async undo() { |
26 | | - for (const url of TOKENS_DECL_URLS) { |
| 43 | + for (const [url] of files) { |
27 | 44 | await rm(url); |
28 | 45 | } |
29 | 46 | }, |
|
0 commit comments