-
Notifications
You must be signed in to change notification settings - Fork 3
/
tasks.js
53 lines (49 loc) · 2.06 KB
/
tasks.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
/*!
* ioBroker gulpfile
* Date: 2024-07-16
*/
const { deleteFoldersRecursive, npmInstall, buildReact, copyFiles } = require('@iobroker/build-tools');
const { existsSync } = require('node:fs');
const srcAdmin = `${__dirname}/src-admin/`;
function clean() {
deleteFoldersRecursive(`${__dirname}/admin`, ['kisshome-research.png', 'jsonConfig.json', 'i18n']);
deleteFoldersRecursive(`${__dirname}/src-admin/build`);
}
function copyAllFiles() {
if (!existsSync('./src-admin/build/customComponents.js')) {
console.error(`[${new Date().toISOString()}] Invalid build: customComponents.js not found!`);
process.exit(2);
}
copyFiles(['src-admin/build/static/js/*.js', '!src-admin/build/static/js/vendors*.js'], 'admin/custom/static/js');
copyFiles(['src-admin/build/static/js/*.map', '!src-admin/build/static/js/vendors*.map'], 'admin/custom/static/js');
copyFiles(['src-admin/build/customComponents.js'], 'admin/custom');
copyFiles(['src-admin/build/customComponents.js.map'], 'admin/custom');
copyFiles(['src-admin/src/i18n/*.json'], 'admin/custom/i18n');
}
if (process.argv.includes('--0-clean')) {
clean();
process.exit();
} else if (process.argv.includes('--1-npm')) {
if (!existsSync(`${__dirname}/src-admin/node_modules`)) {
npmInstall(srcAdmin).catch(e => {
console.error(`[${new Date().toISOString()}] Cannot install admin dependencies: ${e}`);
process.exit(1);
});
}
} else if (process.argv.includes('--2-compile')) {
buildReact(srcAdmin, { rootDir: __dirname, craco: true, exec: true }).catch(e => {
console.error(`[${new Date().toISOString()}] Cannot build: ${e}`);
process.exit(1);
});
} else if (process.argv.includes('--3-copy')) {
copyAllFiles();
} else {
clean();
npmInstall(srcAdmin)
.then(() => buildReact(srcAdmin, { rootDir: __dirname, craco: true }))
.then(() => copyAllFiles())
.catch(e => {
console.error(`[${new Date().toISOString()}] Cannot build all: ${e}`);
process.exit(1);
});
}