-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-to-sd.js
42 lines (35 loc) · 1.08 KB
/
convert-to-sd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { createSpecifyClient, parsers } from "@specifyapp/sdk";
import { convertToDTCG } from "style-dictionary/utils";
import fs from "node:fs/promises";
const tokenTree = JSON.parse(await fs.readFile("specify-tokens.json", "utf-8"));
const specifyClient = createSpecifyClient();
const sdtfClient = specifyClient.loadSDTFClient(tokenTree);
const executePipelines = sdtfClient.createParsersPipelines(
parsers.toStyleDictionary({
output: { type: "directory", directoryPath: "tokens" },
})
);
const results = await executePipelines();
// log some information about the SDK run
results.debug();
// convert results files to DTCG format
results.mapFiles((file) => {
return {
...file,
content: {
...file.content,
text: JSON.stringify(
convertToDTCG(
JSON.parse(
/** @type {{type: 'text'; text: string}} */ (file.content).text
)
// Turns off putting $type to the highest common ancestor group
// { applyTypesToGroup: false }
),
null,
"\t"
),
},
};
});
await results.writeToDisk();