This repository has been archived by the owner on Apr 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
eiscp-commands-convert.js
executable file
·87 lines (77 loc) · 3.13 KB
/
eiscp-commands-convert.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*jslint node:true nomen:true*/
'use strict';
/*
Script that converts eiscp-commands.yaml to eiscp-commands.json
*/
require('js-yaml');
var fs = require('fs'),
command_mappings = {},
value_mappings = {},
command,
value,
doc,
zone,
name,
n,
i,
result = { 'commands': {} };
try {
doc = require('./eiscp-commands.yaml');
result.modelsets = doc.modelsets;
delete doc.modelsets;
for (zone in doc) {
result.commands[zone] = doc[zone];
if (typeof command_mappings[zone] === 'undefined') {
command_mappings[zone] = {};
value_mappings[zone] = {};
}
for (command in doc[zone]) {
name = doc[zone][command].name;
if (name instanceof Array) {
for (n = 0; n < name.length; n += 1) {
command_mappings[zone][name[n]] = command;
}
} else {
command_mappings[zone][name] = command;
}
if (typeof value_mappings[zone][command] === 'undefined') {
value_mappings[zone][command] = {};
}
for (value in doc[zone][command].values) {
name = doc[zone][command].values[value].name;
if (/[BT]\{xx\}/.exec(value) && /[bt]-xx/.exec(name)) {
// It's not yet supported
console.log('Not yet supported: (command: ' + command + ') (value: ' + value + ') ( ' + doc[zone][command].values[value].description + ' )');
} else if (typeof name !== 'undefined') {
if (name instanceof Array) {
for (n = 0; n < name.length; n += 1) {
value_mappings[zone][command][name[n]] = {value: value, models: doc[zone][command].values[value].models};
}
} else {
value_mappings[zone][command][name] = {value: value, models: doc[zone][command].values[value].models};
}
} else {
// Special values don't have names so we can handle them here
if (value.indexOf(',') !== -1) {
// It's a range
if (typeof value_mappings[zone][command].INTRANGES === 'undefined') {
value_mappings[zone][command].INTRANGES = [];
}
value_mappings[zone][command].INTRANGES.push({range: value, models: doc[zone][command].values[value].models});
} else {
// It's not yet supported
console.log('Not yet supported: (command: ' + command + ') (value: ' + value + ') ( ' + doc[zone][command].values[value].description + ' )');
}
}
}
}
}
result.command_mappings = command_mappings;
result.value_mappings = value_mappings;
fs.writeFile('eiscp-commands.json', JSON.stringify(result), function (err) {
if (err) { return console.log(err); }
console.log('eiscp-commands.json created!');
});
} catch (e) {
console.log(e);
}