-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
249 lines (230 loc) · 10.9 KB
/
gulpfile.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
/*!
* ioBroker gulpfile
* Date: 2023-02-22
*/
'use strict';
const gulp = require('gulp');
const { copyFileSync, readFileSync, statSync, writeFileSync, existsSync, readdirSync, rmdirSync } = require('node:fs');
const adapterName = require('./package.json').name.replace('iobroker.', '');
const gulpHelper = require('@iobroker/vis-2-widgets-react-dev/gulpHelper');
const { npmInstall, buildReact, deleteFoldersRecursive, patchHtmlFile } = require('@iobroker/build-tools');
function sync2files(src, dst) {
const srcTxt = readFileSync(src).toString('utf8');
const destTxt = readFileSync(dst).toString('utf8');
if (srcTxt !== destTxt) {
const srcs = statSync(src);
const dest = statSync(dst);
if (srcs.mtime > dest.mtime) {
writeFileSync(dst, srcTxt);
} else {
writeFileSync(src, destTxt);
}
}
}
function buildWidgets() {
// sync src and src-widgets
sync2files(
`${__dirname}/src-widgets/src/components/DayNightSwitcher.jsx`,
`${__dirname}/src/src/components/DayNightSwitcher.jsx`,
);
sync2files(
`${__dirname}/src-widgets/src/components/DayOfWeekPanel.jsx`,
`${__dirname}/src/src/components/DayOfWeekPanel.jsx`,
);
sync2files(`${__dirname}/src-widgets/src/components/Interval.jsx`, `${__dirname}/src/src/components/Interval.jsx`);
sync2files(
`${__dirname}/src-widgets/src/components/Intervals.jsx`,
`${__dirname}/src/src/components/Intervals.jsx`,
);
sync2files(
`${__dirname}/src-widgets/src/components/IntervalsContainer.jsx`,
`${__dirname}/src/src/components/IntervalsContainer.jsx`,
);
sync2files(`${__dirname}/src-widgets/src/data/minmax.json`, `${__dirname}/src/src/data/minmax.json`);
return buildReact(`${__dirname}/src-widgets/`, { rootDir: __dirname, craco: true });
}
// TASKS
gulp.task('widget-0-clean', done => {
deleteFoldersRecursive(`${__dirname}/src-widgets/build`);
deleteFoldersRecursive(`${__dirname}/widgets`);
done();
});
gulp.task('widget-1-npm', async () => npmInstall(`${__dirname}/src-widgets/`));
gulp.task('widget-2-compile', async () => buildWidgets());
gulp.task('widget-3-copy', () =>
Promise.all([
gulp.src([`src-widgets/build/*.js`]).pipe(gulp.dest(`widgets/${adapterName}`)),
gulp.src([`src-widgets/build/img/*`]).pipe(gulp.dest(`widgets/${adapterName}/img`)),
gulp.src([`src-widgets/build/*.map`]).pipe(gulp.dest(`widgets/${adapterName}`)),
gulp
.src([`src-widgets/build/static/**/*`, ...gulpHelper.ignoreFiles(`${__dirname}/src-widgets/`)])
.pipe(gulp.dest(`widgets/${adapterName}/static`)),
gulp
.src([...gulpHelper.copyFiles(`${__dirname}/src-widgets/`)])
.pipe(gulp.dest(`widgets/${adapterName}/static/js`)),
gulp.src([`src-widgets/src/i18n/*.json`]).pipe(gulp.dest(`widgets/${adapterName}/i18n`)),
new Promise(resolve =>
setTimeout(() => {
if (
existsSync(`widgets/${adapterName}/static/media`) &&
!readdirSync(`widgets/${adapterName}/static/media`).length
) {
rmdirSync(`widgets/${adapterName}/static/media`);
}
resolve(null);
}, 500),
),
]),
);
gulp.task('widget-build', gulp.series(['widget-0-clean', 'widget-1-npm', 'widget-2-compile', 'widget-3-copy']));
gulp.task('clean', done => {
deleteFoldersRecursive(`${__dirname}/admin`, ['scheduler.png']);
done();
});
gulp.task('2-npm', () => {
if (existsSync(`${__dirname}/src/node_modules`)) {
return Promise.resolve();
}
return npmInstall(`${__dirname}/src/`);
});
gulp.task('2-npm-dep', gulp.series('clean', '2-npm'));
gulp.task('3-build', () => buildReact(`${__dirname}/src`, { vite: true }));
gulp.task('3-build-dep', gulp.series('2-npm-dep', '3-build'));
gulp.task('5-copy', () =>
gulp
.src([
'src/build/*/**',
'src/build/*',
// replace it later with
// ...gulpHelper.ignoreSvgFiles(`${__dirname}/src/`),
`!src/build/index.html`,
`!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`,
])
.pipe(gulp.dest('admin/')),
);
gulp.task('5-copy-dep', gulp.series('3-build-dep', '5-copy'));
gulp.task('6-patch', () =>
patchHtmlFile(`${__dirname}/src/build/index.html`).then(() =>
copyFileSync(`${__dirname}/src/build/index.html`, `${__dirname}/admin/index_m.html`),
),
);
gulp.task('6-patch-dep', gulp.series('5-copy-dep', '6-patch'));
gulp.task('default', gulp.series('6-patch-dep', 'widget-build'));