-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildHelper.js
292 lines (272 loc) · 11.9 KB
/
buildHelper.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
const fs = require('node:fs');
const cp = require('node:child_process');
function ignoreSvgFiles(src) {
src = src || './src-widgets/';
if (!src.endsWith('/')) {
src += '/';
}
return [
`!${src}build/static/media/Alarm Systems.*.svg`,
`!${src}build/static/media/Amplifier.*.svg`,
`!${src}build/static/media/Anteroom.*.svg`,
`!${src}build/static/media/Attic.*.svg`,
`!${src}build/static/media/Awnings.*.svg`,
`!${src}build/static/media/Balcony.*.svg`,
`!${src}build/static/media/Barn.*.svg`,
`!${src}build/static/media/Basement.*.svg`,
`!${src}build/static/media/Bathroom.*.svg`,
`!${src}build/static/media/Battery Status.*.svg`,
`!${src}build/static/media/Bedroom.*.svg`,
`!${src}build/static/media/Boiler Room.*.svg`,
`!${src}build/static/media/Carport.*.svg`,
`!${src}build/static/media/Ceiling Spotlights.*.svg`,
`!${src}build/static/media/Cellar.*.svg`,
`!${src}build/static/media/Chamber.*.svg`,
`!${src}build/static/media/Chandelier.*.svg`,
`!${src}build/static/media/Climate.*.svg`,
`!${src}build/static/media/Coffee Makers.*.svg`,
`!${src}build/static/media/Cold Water.*.svg`,
`!${src}build/static/media/Computer.*.svg`,
`!${src}build/static/media/Consumption.*.svg`,
`!${src}build/static/media/Corridor.*.svg`,
`!${src}build/static/media/Curtains.*.svg`,
`!${src}build/static/media/Dining Area.*.svg`,
`!${src}build/static/media/Dining Room.*.svg`,
`!${src}build/static/media/Dining.*.svg`,
`!${src}build/static/media/Dishwashers.*.svg`,
`!${src}build/static/media/Doors.*.svg`,
`!${src}build/static/media/Doorstep.*.svg`,
`!${src}build/static/media/Dressing Room.*.svg`,
`!${src}build/static/media/Driveway.*.svg`,
`!${src}build/static/media/Dryer.*.svg`,
`!${src}build/static/media/Entrance.*.svg`,
`!${src}build/static/media/Equipment Room.*.svg`,
`!${src}build/static/media/Fan.*.svg`,
`!${src}build/static/media/Floor Lamps.*.svg`,
`!${src}build/static/media/Front Yard.*.svg`,
`!${src}build/static/media/Gallery.*.svg`,
`!${src}build/static/media/Garage Doors.*.svg`,
`!${src}build/static/media/Garage.*.svg`,
`!${src}build/static/media/Garden.*.svg`,
`!${src}build/static/media/Gates.*.svg`,
`!${src}build/static/media/Ground Floor.*.svg`,
`!${src}build/static/media/Guest Bathroom.*.svg`,
`!${src}build/static/media/Guest Room.*.svg`,
`!${src}build/static/media/Gym.*.svg`,
`!${src}build/static/media/Hairdryer.*.svg`,
`!${src}build/static/media/Hall.*.svg`,
`!${src}build/static/media/Handle.*.svg`,
`!${src}build/static/media/Hanging Lamps.*.svg`,
`!${src}build/static/media/Heater.*.svg`,
`!${src}build/static/media/Home Theater.*.svg`,
`!${src}build/static/media/Hoods.*.svg`,
`!${src}build/static/media/Hot Water.*.svg`,
`!${src}build/static/media/Humidity.*.svg`,
`!${src}build/static/media/Iron.*.svg`,
`!${src}build/static/media/Irrigation.*.svg`,
`!${src}build/static/media/Kitchen.*.svg`,
`!${src}build/static/media/Laundry Room.*.svg`,
`!${src}build/static/media/Led Strip.*.svg`,
`!${src}build/static/media/Light.*.svg`,
`!${src}build/static/media/Lightings.*.svg`,
`!${src}build/static/media/Living Area.*.svg`,
`!${src}build/static/media/Living Room.*.svg`,
`!${src}build/static/media/Lock.*.svg`,
`!${src}build/static/media/Locker Room.*.svg`,
`!${src}build/static/media/Louvre.*.svg`,
`!${src}build/static/media/Mowing Machine.*.svg`,
`!${src}build/static/media/Music.*.svg`,
`!${src}build/static/media/names.*.txt`,
`!${src}build/static/media/Nursery.*.svg`,
`!${src}build/static/media/Office.*.svg`,
`!${src}build/static/media/Outdoor Blinds.*.svg`,
`!${src}build/static/media/Outdoors.*.svg`,
`!${src}build/static/media/People.*.svg`,
`!${src}build/static/media/Playroom.*.svg`,
`!${src}build/static/media/Pool.*.svg`,
`!${src}build/static/media/Power Consumption.*.svg`,
`!${src}build/static/media/Printer.*.svg`,
`!${src}build/static/media/Pump.*.svg`,
`!${src}build/static/media/Rear Wall.*.svg`,
`!${src}build/static/media/Receiver.*.svg`,
`!${src}build/static/media/Sconces.*.svg`,
`!${src}build/static/media/Second Floor.*.svg`,
`!${src}build/static/media/Security.*.svg`,
`!${src}build/static/media/Shading.*.svg`,
`!${src}build/static/media/Shed.*.svg`,
`!${src}build/static/media/Shutters.*.svg`,
`!${src}build/static/media/Sleeping Area.*.svg`,
`!${src}build/static/media/SmokeDetector.*.svg`,
`!${src}build/static/media/Sockets.*.svg`,
`!${src}build/static/media/Speaker.*.svg`,
`!${src}build/static/media/Stairway.*.svg`,
`!${src}build/static/media/Stairwell.*.svg`,
`!${src}build/static/media/Storeroom.*.svg`,
`!${src}build/static/media/Stove.*.svg`,
`!${src}build/static/media/Summer House.*.svg`,
`!${src}build/static/media/Swimming Pool.*.svg`,
`!${src}build/static/media/Table Lamps.*.svg`,
`!${src}build/static/media/Temperature Sensors.*.svg`,
`!${src}build/static/media/Terrace.*.svg`,
`!${src}build/static/media/Toilet.*.svg`,
`!${src}build/static/media/Tv.*.svg`,
`!${src}build/static/media/Upstairs.*.svg`,
`!${src}build/static/media/Vacuum Cleaner.*.svg`,
`!${src}build/static/media/Ventilation.*.svg`,
`!${src}build/static/media/Wardrobe.*.svg`,
`!${src}build/static/media/Washing Machines.*.svg`,
`!${src}build/static/media/Washroom.*.svg`,
`!${src}build/static/media/Water Consumption.*.svg`,
`!${src}build/static/media/Water Heater.*.svg`,
`!${src}build/static/media/Water.*.svg`,
`!${src}build/static/media/Wc.*.svg`,
`!${src}build/static/media/Weather.*.svg`,
`!${src}build/static/media/Window.*.svg`,
`!${src}build/static/media/Windscreen.*.svg`,
`!${src}build/static/media/Workshop.*.svg`,
`!${src}build/static/media/Workspace.*.svg`,
];
}
function ignoreFiles(src, doNotIgnoreSvg, doNotIgnoreMap) {
src = src || './src-widgets/';
if (!src.endsWith('/')) {
src += '/';
}
let list = [
`!${src}build/static/js/node_modules*.*`,
`!${src}build/static/js/vendors-node_modules*.*`,
`!${src}build/static/js/main*.*`,
`!${src}build/static/js/src_bootstrap*.*`,
];
if (!doNotIgnoreMap) {
list = list.concat([
`!${src}build/static/*.map`,
`!${src}build/static/**/*.map`,
]);
}
if (!doNotIgnoreSvg) {
list = list.concat(ignoreSvgFiles(src));
}
return list;
}
function copyFiles(src) {
src = src || './src-widgets/';
if (!src.endsWith('/')) {
src += '/';
}
return [
`${src}build/static/js/*fast-xml*.*`,
`${src}build/static/js/*react-swipeable*.*`,
`${src}build/static/js/*moment_*.*`,
`${src}build/static/js/*react-beautiful-dnd*.*`,
`${src}build/static/js/*vis-2-widgets-react-dev_index_jsx*.*`,
`${src}build/static/js/*vis-2-widgets-react-dev_node_modules_babel_runtime_helpers*.*`,
`${src}build/static/js/*runtime_helpers_asyncToGenerator*.*`,
`${src}build/static/js/*modules_color*.*`,
`${src}build/static/js/*echarts-for-react_lib_core_js-node_modules_echarts_core_js-*.chunk.*`,
`${src}build/static/js/*echarts_lib*.*`,
`${src}build/static/js/*vis-2-widgets-react-dev_node_modules_babel_runtime_helpers*.*`,
`${src}build/static/js/*leaflet*.*`,
`${src}build/static/js/*react-circular*.*`,
`${src}build/static/js/*d3-array_src_index_js-node_modules_d3-collection_src_index_js-*.*`,
`${src}build/static/js/*d3-dispatch_*.*`,
`${src}build/static/js/*lodash_*.*`,
`${src}build/static/js/*react-battery-gauge_dist_react-battery-gauge*.*`,
`${src}build/static/js/*react-gauge-chart*.*`,
`${src}build/static/js/*react-liquid-gauge*.*`,
`${src}build/static/js/*helpers_esm_asyncToGener*.*`,
`${src}build/static/js/*emotion_styled_dist*.*`,
`${src}build/static/js/*mui_system_colorManipulator*.*`,
];
}
function deleteFoldersRecursive(path, exceptions) {
if (fs.existsSync(path)) {
const files = fs.readdirSync(path);
for (const file of files) {
const curPath = `${path}/${file}`;
if (exceptions && exceptions.find(e => curPath.endsWith(e))) {
continue;
}
const stat = fs.statSync(curPath);
if (stat.isDirectory()) {
deleteFoldersRecursive(curPath, exceptions);
if (exceptions?.length) {
// check if the directory is empty
const files = fs.readdirSync(curPath).filter(file => file !== '.' && file !== '..');
if (files.length) {
continue;
}
}
fs.rmdirSync(curPath);
} else {
fs.unlinkSync(curPath);
}
}
}
}
function npmInstall(src) {
src = src || './src-widgets/';
return new Promise((resolve, reject) => {
// Install node modules
const cwd = src.replace(/\\/g, '/');
const cmd = `npm install -f`;
console.log(`"${cmd} in ${cwd}`);
// System call used for update of js-controller itself,
// because during an installation the npm packet will be deleted too, but some files must be loaded even during the installation process.
const exec = cp.exec;
const child = exec(cmd, {cwd});
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
child.on('exit', (code /* , signal */) => {
// code 1 is a strange error that cannot be explained. Everything is installed but error :(
if (code && code !== 1) {
reject(`Cannot install: ${code}`);
} else {
console.log(`"${cmd} in ${cwd} finished.`);
// command succeeded
resolve();
}
});
});
}
function buildWidgets(root, src) {
if (root.endsWith('/')) {
root = root.substring(0, root.length - 1);
}
src = src || `${root}/src-widgets/`;
const version = JSON.parse(fs.readFileSync(`${root}/package.json`).toString('utf8')).version;
const data = JSON.parse(fs.readFileSync(`${src}package.json`).toString('utf8'));
data.version = version;
fs.writeFileSync(`${src}package.json`, JSON.stringify(data, null, 4));
return new Promise((resolve, reject) => {
const options = {
stdio: 'pipe',
cwd: src,
};
console.log(options.cwd);
let script = `${src}node_modules/@craco/craco/dist/bin/craco.js`;
if (!fs.existsSync(script)) {
script = `${root}/node_modules/@craco/craco/dist/bin/craco.js`;
}
if (!fs.existsSync(script)) {
console.error(`Cannot find execution file: ${script}`);
reject(`Cannot find execution file: ${script}`);
} else {
const child = cp.fork(script, ['build'], options);
child.stdout.on('data', data => console.log(data.toString()));
child.stderr.on('data', data => console.log(data.toString()));
child.on('close', code => {
console.log(`child process exited with code ${code}`);
code ? reject(`Exit code: ${code}`) : resolve();
});
}
});
}
module.exports = {
ignoreSvgFiles,
ignoreFiles,
copyFiles,
buildWidgets,
npmInstall,
deleteFoldersRecursive,
};