-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
42 lines (34 loc) · 1.01 KB
/
app.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
require("dotenv").config();
const fs = require("fs");
const md5 = require("md5");
const Extractor = require("figma-extractor");
const DATA_FILE = "data.json";
const DATA_PATH = "data";
const FIGMA_TOKEN = process.env.FIGMA_TOKEN;
const FIGMA_FILE = process.env.FIGMA_FILE;
const PAGES = process.env.PAGES && process.env.PAGES.split(",");
const FILE_FORMAT = process.env.FILE_FORMAT || "jpg";
const OPTIONS = {
format: FILE_FORMAT,
use_pages_as_folders: true,
get_background_color: true,
get_comments: true,
};
fs.rmSync(DATA_PATH, { recursive: true, force: true });
const extractor = new Extractor(FIGMA_TOKEN, FIGMA_FILE, OPTIONS);
extractor
.extract(DATA_PATH)
.then((files) => {
if (PAGES) {
files = files.filter((file) => PAGES.includes(file.page));
}
const data = JSON.stringify({ md5: md5(files), path: DATA_PATH, files });
fs.writeFile(DATA_FILE, data, (error, _content) => {
if (error) {
console.error(e);
}
});
})
.catch((e) => {
console.error(e);
});