forked from blynkkk/blynk-sketch-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
151 lines (136 loc) · 5.59 KB
/
cli.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict';
var fs = require('fs');
var path = require('path');
var gen = require("./index.js");
var mkdirSync = function (path) {
try {
fs.mkdirSync(path);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}
};
var mkdirpSync = function (dirpath) {
var parts = dirpath.split(path.sep);
for( var i = 1; i <= parts.length; i++ ) {
mkdirSync( path.join.apply(null, parts.slice(0, i)) );
}
};
const cmd = process.argv[2];
if (cmd === "gen") {
var board = process.argv[3];
var shield = process.argv[4];
var example = process.argv[5];
/*
if (!_.has(boards, board)) {
console.error("Board not found");
process.exit(1);
}
if (!_.has(shields, shield)) {
console.error("Shield not found");
process.exit(1);
}
if (!_.has(examples, example)) {
console.error("Example not found");
process.exit(1);
}
*/
console.log(gen.generate(board, shield, example));
} else if (cmd === "list") {
const c = process.argv[3];
if (c === "boards") {
console.log(gen.listBoards());
} else if (c === "shields") {
console.log(gen.listShields());
} else if (c === "examples") {
console.log(gen.listExamples());
}
} else if (cmd === "count") {
const brd = gen.listBoards().length;
const shld = gen.listShields().length;
const xmpl = gen.listExamples().length;
const comb = brd * shld * xmpl;
console.log("boards qty:", brd);
console.log("shields qty:", shld);
console.log("examples qty:", xmpl);
console.log();
console.log("combinations:", comb);
} else if (cmd === "autogen") {
var board = process.argv[3];
var shield = process.argv[4];
gen.listExamples().forEach((k) => {
var ino = k.split(path.sep).slice(-1)[0] + ".ino";
console.log(ino);
mkdirpSync("./examples/" + k);
var sketch = gen.generate(board, shield, k);
fs.writeFileSync("./examples/" + k + "/" + ino, sketch);
});
const boards_presets = {
"Boards_WiFi/Adafruit_Feather_M0_WiFi" : ["", ""],
"Boards_WiFi/Arduino_MKR1000" : ["", ""],
"Boards_WiFi/Arduino_WiFi_Shield" : ["", ""],
"Boards_WiFi/Arduino_WiFi_Shield_101" : ["", ""],
"Boards_WiFi/Arduino_Yun" : ["", ""],
"Boards_WiFi/CC3000" : ["", ""],
"Boards_WiFi/Digistump_Oak" : ["", ""],
"Boards_WiFi/Energia_WiFi" : ["", ""],
"Boards_WiFi/ESP32_WiFi" : ["", ""],
"Boards_WiFi/ESP8266_Shield" : ["", ""],
"Boards_WiFi/ESP8266_Standalone" : ["", ""],
"Boards_WiFi/ESP8266_Standalone_SSL" : ["", ""],
"Boards_WiFi/Fishino" : ["", ""],
"Boards_WiFi/Intel_Edison_WiFi" : ["", ""],
"Boards_WiFi/LinkItONE" : ["", ""],
"Boards_WiFi/RedBear_Duo_WiFi" : ["", ""],
"Boards_WiFi/RN_XV_WiFly" : ["", ""],
"Boards_WiFi/Sparkfun_Blynk_Board" : ["", ""],
"Boards_WiFi/TheAirBoard_WiFly" : ["", ""],
"Boards_WiFi/TinyDuino_WiFi" : ["", ""],
"Boards_WiFi/WildFire_V3" : ["", ""],
"Boards_WiFi/WildFire_V4" : ["", ""],
"Boards_Bluetooth/Adafruit_Bluefruit_LE" : ["", ""],
"Boards_Bluetooth/Adafruit_Feather_32u4_BLE" : ["", ""],
"Boards_Bluetooth/Arduino_101_BLE" : ["", ""],
"Boards_Bluetooth/BBC_MicroBit" : ["", ""],
"Boards_Bluetooth/DFRobot_Bluno_BLE_Link" : ["", ""],
"Boards_Bluetooth/Energia_BLE" : ["", ""],
"Boards_Bluetooth/LightBlue_Bean" : ["", ""],
"Boards_Bluetooth/Microduino_BLE" : ["", ""],
"Boards_Bluetooth/nRF8001" : ["", ""],
"Boards_Bluetooth/RedBear_Duo_BLE" : ["", ""],
"Boards_Bluetooth/RedBearLab_BLE_Mini" : ["", ""],
"Boards_Bluetooth/RedBearLab_BLE_Nano" : ["", ""],
"Boards_Bluetooth/RedBearLab_BlendMicro" : ["", ""],
"Boards_Bluetooth/RFDuino_BLE" : ["", ""],
"Boards_Bluetooth/Serial_HC05_HC06" : ["", ""],
"Boards_Bluetooth/Serial_HM10_HC08" : ["", ""],
"Boards_Bluetooth/Simblee_BLE" : ["", ""],
"Boards_Bluetooth/TheAirBoard_BLE_Link" : ["", ""],
"Boards_GSM/SIM800_SIM900" : ["", ""],
"Boards_Ethernet/Arduino_Ethernet" : ["", ""],
"Boards_Ethernet/Arduino_Ethernet_Manual" : ["", ""],
"Boards_Ethernet/Arduino_Ethernet2" : ["", ""],
"Boards_Ethernet/ENC28J60" : ["", ""],
"Boards_Ethernet/Energia_Ethernet" : ["", ""],
"Boards_Ethernet/Intel_Galileo" : ["", ""],
"Boards_Ethernet/Seeed_EthernetV2_0" : ["", ""],
"Boards_USB_Serial/Arduino_Serial_USB" : ["", ""],
"Boards_USB_Serial/Arduino_SoftwareSerial" : ["", ""],
"Boards_USB_Serial/Arduino_Zero_M0_Serial" : ["", ""],
"Boards_USB_Serial/ATtiny85" : ["", ""],
"Boards_USB_Serial/Blue_Pill_STM32F103C" : ["", ""],
"Boards_USB_Serial/chipKIT_Uno32" : ["", ""],
"Boards_USB_Serial/Digistump_Digispark" : ["", ""],
"Boards_USB_Serial/Energia_Serial_USB" : ["", ""],
"Boards_USB_Serial/Teensy3" : ["", ""]
};
/*
Object.keys(boards_presets).forEach((k) => {
var ino = k.split(path.sep).slice(-1)[0] + ".ino";
console.log(ino);
mkdirpSync("./examples/" + k);
var args = boards_presets[k];
var sketch = gen.generate(...args, "Simple");
fs.writeFileSync("./examples/" + k + "/" + ino, sketch);
});
*/
}