-
Notifications
You must be signed in to change notification settings - Fork 24
/
tasks.js
108 lines (104 loc) · 4.54 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
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
/*!
* ioBroker tasks file for tasks like build, clean, etc.
* Date: 2024-09-16
*/
'use strict';
const { existsSync, renameSync } = require('node:fs');
const { buildReact, copyFiles, deleteFoldersRecursive, npmInstall, patchHtmlFile } = require('@iobroker/build-tools');
function cleanRules() {
deleteFoldersRecursive(`${__dirname}/admin/rules`);
deleteFoldersRecursive(`${__dirname}/src-rules/build`);
}
function copyRules() {
copyFiles(['src-rules/build/*.js'], 'admin/rules');
copyFiles(['src-rules/build/*.map'], 'admin/rules');
copyFiles(['src-rules/build/asset-manifest.json'], 'admin/rules');
copyFiles(
[
'src-rules/build/static/**/*',
'!src-rules/build/static/media/*.svg',
'!src-rules/build/static/media/*.txt',
'!src-rules/build/static/js/vendors*.js',
'!src-rules/build/static/js/vendors*.map',
],
'admin/rules/static',
);
copyFiles(['src-rules/src/i18n/*.json'], 'admin/rules/i18n');
}
function clean() {
deleteFoldersRecursive(`${__dirname}/admin`, ['actions.js', 'alexalogo.png', 'blockly.js', 'iot.png', 'rules']);
}
if (process.argv.find(arg => arg === '--rules-0-clean')) {
cleanRules();
} else if (process.argv.find(arg => arg === '--rules-1-npm')) {
npmInstall('./src-rules/').catch(error => console.error(error));
} else if (process.argv.find(arg => arg === '--rules-2-compile')) {
buildReact(`${__dirname}/src-rules/`, { rootDir: __dirname, craco: true }).catch(error => console.error(error));
} else if (process.argv.find(arg => arg === '--rules-3-copy')) {
copyRules();
} else if (process.argv.find(arg => arg === '--rules-build')) {
cleanRules();
npmInstall('./src-rules/')
.then(() => buildReact(`${__dirname}/src-rules/`, { rootDir: __dirname, craco: true }))
.then(() => copyRules())
.catch(error => console.error(error));
} else if (process.argv.find(arg => arg === '--0-clean')) {
clean();
} else if (process.argv.find(arg => arg === '--1-npm')) {
if (!existsSync(`${__dirname}/src/node_modules`)) {
npmInstall('./src/').catch(error => console.error(error));
}
} else if (process.argv.find(arg => arg === '--2-build')) {
buildReact(`${__dirname}/src/`, { rootDir: __dirname, vite: true }).catch(error => console.error(error));
} else if (process.argv.find(arg => arg === '--3-copy')) {
copyFiles(['src/build/*/**', 'src/build/*'], 'admin/');
} else if (process.argv.find(arg => arg === '--4-patch')) {
patchHtmlFile(`${__dirname}/admin/index.html`).then(() =>
patchHtmlFile(`${__dirname}/src/build/index.html`)
.then(() => {
if (existsSync(`${__dirname}/admin/index.html`)) {
renameSync(`${__dirname}/admin/index.html`, `${__dirname}/admin/index_m.html`);
}
})
.catch(error => console.error(error)),
);
} else if (process.argv.find(arg => arg === '--build-admin')) {
clean();
let npmPromise;
if (!existsSync(`${__dirname}/src/node_modules`)) {
npmPromise = npmInstall('./src/').catch(error => console.error(error));
} else {
npmPromise = Promise.resolve();
}
npmPromise
.then(() => buildReact(`${__dirname}/src/`, { rootDir: __dirname, vite: true }))
.then(() => copyFiles(['src/build/*/**', 'src/build/*'], 'admin/'))
.then(() => patchHtmlFile(`${__dirname}/admin/index.html`))
.then(() => {
if (existsSync(`${__dirname}/admin/index.html`)) {
renameSync(`${__dirname}/admin/index.html`, `${__dirname}/admin/index_m.html`);
}
})
.catch(error => console.error(error));
} else {
clean();
let installPromise;
if (!existsSync(`${__dirname}/src/node_modules`)) {
installPromise = npmInstall('./src/').catch(error => console.error(error));
} else {
installPromise = Promise.resolve();
}
installPromise
.then(() => buildReact(`${__dirname}/src/`, { rootDir: __dirname, vite: true }))
.then(() => copyFiles(['src/build/*/**', 'src/build/*'], 'admin/'))
.then(() => patchHtmlFile(`${__dirname}/admin/index.html`))
.then(() => {
if (existsSync(`${__dirname}/admin/index.html`)) {
renameSync(`${__dirname}/admin/index.html`, `${__dirname}/admin/index_m.html`);
}
})
.then(() => cleanRules())
.then(() => npmInstall('./src-rules/'))
.then(() => buildReact(`${__dirname}/src-rules/`, { rootDir: __dirname, craco: true }))
.then(() => copyRules());
}