-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
66 lines (51 loc) · 1.65 KB
/
index.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
const path = require('path');
const fs = require('fs');
let category = '';
function loadJSONSettings(definition, json, parentKey = null) {
for (const key of Object.keys(json)) {
const setting = json[key];
if (setting.type === 'mainCategory') {
// pass
} else if (setting.type === 'category') {
category = key;
} else {
definition.settings[key] = {
label: setting.label,
category: category,
childKey: [],
};
if (parentKey) {
definition.settings[parentKey].childKey.push(key);
}
}
if (setting.children && setting.visible !== 'false') {
loadJSONSettings(
definition,
setting.children,
['mainCategory', 'category'].includes(setting.type) ? null : key,
);
}
}
}
function loadJSON(definition, json) {
if (json.definitionId) {
definition.definitionId = json.definitionId;
}
if (json.metadata) {
definition.metadata = json.metadata;
}
if (json.settings) {
definition.settings = {};
loadJSONSettings(definition, json.settings);
}
}
function main() {
const printSettingsDir = path.resolve(__dirname, '../../packages/luban-print-settings');
const configPath = path.join(printSettingsDir, 'resources', 'printing', 'snapmaker_modify_0.def.json');
const data = fs.readFileSync(configPath, 'utf8');
const json = JSON.parse(data);
const definition = {};
loadJSON(definition, json);
console.log('definition =', definition);
}
main();