-
Notifications
You must be signed in to change notification settings - Fork 28
/
tasks.js
78 lines (73 loc) · 2.28 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
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
const { renameSync } = require('node:fs');
const { deleteFoldersRecursive, copyFiles, npmInstall, buildReact, patchHtmlFile } = require('@iobroker/build-tools');
function clean() {
deleteFoldersRecursive(`${__dirname}/admin`, ['modbus.png']);
}
function copyAllFiles() {
copyFiles(
['src/build/*/**', 'src/build/*', '!src/build/static/media/*.svg', '!src/build/static/media/*.txt'],
'admin/',
);
}
function patch() {
return patchHtmlFile(`${__dirname}/admin/index.html`).then(() => {
renameSync(`${__dirname}/admin/index.html`, `${__dirname}/admin/index_m.html`);
});
}
if (process.argv.includes('--0-clean')) {
clean();
} else if (process.argv.includes('--1-npm')) {
npmInstall(`${__dirname}/src`).catch(e => {
console.error(`Cannot install npm: ${e}`);
process.exit(1);
});
} else if (process.argv.includes('--2-build')) {
buildReact(`${__dirname}/src/`, {
rootDir: __dirname,
vite: true,
}).catch(e => {
console.error(`Cannot build react: ${e}`);
process.exit(1);
});
} else if (process.argv.includes('--3-copy')) {
copyAllFiles();
} else if (process.argv.includes('--4-patch')) {
patchHtmlFile(`${__dirname}/admin/index.html`)
.then(() => {
renameSync(`${__dirname}/admin/index.html`, `${__dirname}/admin/index_m.html`);
})
.catch(e => {
console.error(`Cannot patch: ${e}`);
process.exit(1);
});
} else if (process.argv.includes('--build')) {
clean();
npmInstall(`${__dirname}/src`)
.then(() =>
buildReact(`${__dirname}/src/`, {
rootDir: __dirname,
vite: true,
}),
)
.then(() => copyAllFiles())
.then(() => patch())
.catch(e => {
console.error(`Cannot build: ${e}`);
process.exit(1);
});
} else {
clean();
npmInstall(`${__dirname}/src`)
.then(() =>
buildReact(`${__dirname}/src/`, {
rootDir: __dirname,
vite: true,
}),
)
.then(() => copyAllFiles())
.then(() => patch())
.catch(e => {
console.error(`Cannot build admin controls: ${e}`);
process.exit(1);
});
}