-
Notifications
You must be signed in to change notification settings - Fork 3
/
figma-comments-to-tsv.js
46 lines (36 loc) · 1.11 KB
/
figma-comments-to-tsv.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
43
44
45
46
const lib = require("./lib");
async function main() {
const {ACCESS_TOKEN, FILE_ID} = getArgs();
const data = await lib.fetchDocumentWithComments({ACCESS_TOKEN, FILE_ID});
const rows = data.comments
.slice()
.sort(lib.byCreated)
.map(toResultRow(data, {FILE_ID}));
console.log(lib.toCSV([headerRow(), ...rows]));
}
main().catch(e => console.error(e));
function getArgs() {
const [ACCESS_TOKEN, FILE_ID] = process.argv.slice(2);
if (!ACCESS_TOKEN || !FILE_ID) throw usage();
return {ACCESS_TOKEN, FILE_ID};
}
function usage() {
return `
Usage:
node figma-comments-to-tsv.js ACCESS_TOKEN FILE_ID > output.tsv
`;
}
function headerRow() {
return ["Comment", "Created", "Frame", "Tags", "Frame Link"];
}
function toResultRow(data, {FILE_ID}) {
return function(comment) {
return [
comment.message,
comment.created_at,
lib.getCommentFrame(comment, data).name,
lib.getCommentTags(comment).join(","),
lib.generateFrameURL(lib.getCommentFrame(comment, data), {FILE_ID})
];
}
}