forked from cboard-org/cboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-obf.js
73 lines (62 loc) · 1.74 KB
/
format-obf.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const fs = require('fs');
const shortid = require('shortid');
const boards = JSON.parse(fs.readFileSync('./src/api/boards.json', 'utf8'));
const colors = {
folder: 'rgb(187, 222, 251)',
symbol: 'rgb(255, 241, 118)'
};
const boardMeta = {
format: 'open-board-0.1',
license: {
type: 'CC-By',
copyright_notice_url: 'http://creativecommons.org/licenses/by',
source_url: 'https://github.com/shayc/cboard',
author_name: 'Shay Cojocaru',
author_url: 'https://github.com/shayc',
author_email: '[email protected]'
}
};
function formatOBF(boards) {
return boards.map(board => {
const { id, buttons } = board;
const name = id;
return formatBoard(id, name, buttons);
});
}
function formatBoard(id, name, buttons) {
let buttonsAndImages = formatButtonsAndImages(buttons);
return { id, name, ...boardMeta, ...buttonsAndImages };
}
function formatButtonsAndImages(symbols) {
const images = [];
const buttons = symbols.map(symbol => {
const button = {
id: symbol.id,
label: symbol.label,
background_color: symbol.loadBoard ? colors.folder : colors.symbol
};
if (symbol.loadBoard) {
button.load_board = {
id: symbol.loadBoard
};
}
if (symbol.img) {
const imageId = shortid.generate();
const filename = symbol.img.replace('images/mulberry-symbols/', '');
const image = {
id: imageId,
content_type: 'image/svg+xml',
symbol: {
set: 'mulberry',
filename
}
};
button.image_id = imageId;
images.push(image);
}
return button;
});
return { buttons, images };
}
const formattedOBF = JSON.stringify(formatOBF(boards.advanced));
fs.writeFile(`./src/api/boards.obf.json`, formattedOBF);