-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-tokens.js
40 lines (35 loc) · 1.08 KB
/
build-tokens.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
const fs = require('fs');
const path = require('path');
const theo = require('theo');
const googleSpreadsheetsTheo = require('google-spreadsheets-theo');
const config = require('./config');
const convert = (name, transform, format, data) =>
theo
.convert({
transform: {
type: transform,
file: `${name}.json`,
data,
},
format: {
type: format,
},
})
.then((contents) => contents)
.catch((error) => console.log(`Something went wrong: ${error}`));
const main = async (config) => {
for ({id, name} of config.worksheets) {
const data = await googleSpreadsheetsTheo(config.spreadsheetUrl, id);
for ({transform, format} of config.formats) {
const tokens = await convert(name, transform, format, data);
const filename = `${config.outputDirectory}${name}.${format}`;
await fs.promises
.mkdir(path.dirname(filename), {recursive: true})
.then(() => {
fs.writeFileSync(filename, tokens);
});
console.log(`✔ Design tokens written to ${filename}`);
}
}
};
main(config);