-
Notifications
You must be signed in to change notification settings - Fork 3
/
tasks.js
82 lines (76 loc) · 2.53 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
79
80
81
82
const { existsSync, copyFileSync } = require('node:fs');
const { deleteFoldersRecursive, copyFiles, npmInstall, buildReact, patchHtmlFile } = require('@iobroker/build-tools');
function clean() {
deleteFoldersRecursive(`${__dirname}/admin`, ['matter.png']);
deleteFoldersRecursive(`${__dirname}/src-admin/build`);
}
function copyAllFiles() {
copyFiles(['src-admin/build/**/*', '!src-admin/build/index.html'], 'admin/');
}
function copyI18n() {
copyFiles(['src/lib/i18n/**/*'], 'build/lib/i18n');
}
async function patch() {
await patchHtmlFile(`${__dirname}/src-admin/build/index.html`, '../..');
if (!existsSync(`${__dirname}/src-admin/build/index.html`)) {
console.error('Index.html not found!');
process.exit(2);
}
copyFileSync(`${__dirname}/src-admin/build/index.html`, `${__dirname}/admin/index_m.html`);
copyFileSync(`${__dirname}/src-admin/build/index.html`, `${__dirname}/admin/tab_m.html`);
}
if (process.argv.includes('--0-clean')) {
clean();
} else if (process.argv.includes('--1-npm')) {
npmInstall(`${__dirname}/src-admin`).catch(e => {
console.error(`Cannot install npm: ${e}`);
process.exit(1);
});
} else if (process.argv.includes('--2-build')) {
buildReact(`${__dirname}/src-admin/`, {
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')) {
patch().catch(e => {
console.error(`Cannot patch: ${e}`);
process.exit(1);
});
} else if (process.argv.includes('--build')) {
clean();
npmInstall(`${__dirname}/src-admin`)
.then(() =>
buildReact(`${__dirname}/src-admin/`, {
rootDir: __dirname,
vite: true,
}),
)
.then(() => copyAllFiles())
.then(() => patch())
.catch(e => {
console.error(`Cannot build: ${e}`);
process.exit(1);
});
} else if (process.argv.includes('--copy-i18n')) {
copyI18n();
} else {
clean();
npmInstall(`${__dirname}/src-admin`)
.then(() =>
buildReact(`${__dirname}/src-admin/`, {
rootDir: __dirname,
vite: true,
}),
)
.then(() => copyAllFiles())
.then(() => patch())
.catch(e => {
console.error(`Cannot build admin controls: ${e}`);
process.exit(1);
});
}