-
Notifications
You must be signed in to change notification settings - Fork 5
/
tasksEdit.js
64 lines (55 loc) · 2.56 KB
/
tasksEdit.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
/**
* Copyright 2018-2024 bluefox <[email protected]>
*
* MIT License
*
**/
'use strict';
const fs = require('node:fs');
const { deleteFoldersRecursive, npmInstall, buildReact, copyFiles } = require('@iobroker/build-tools');
function copyAllFiles() {
deleteFoldersRecursive(`${__dirname}/admin`, ['chart', 'preview']);
copyFiles([
'src-editor/build/**/*',
'!src-editor/build/vendor/*',
'!src-editor/build/index.html',
'!src-editor/build/static/js/main.*.chunk.js',
'!src-editor/build/static/media/*.svg',
'!src-editor/build/static/media/*.txt',
'!src-editor/build/i18n/**/*',
'!src-editor/build/i18n',
],'admin/');
copyFiles('admin-config/*', 'admin/');
fs.copyFileSync(`${__dirname}/src-editor/build/index.html`, `${__dirname}/admin/tab.html`);
copyFiles('src-editor/build/static/js/main.*.chunk.js', 'admin/static/js/');
}
deleteFoldersRecursive(`${__dirname}/admin`, ['chart']);
deleteFoldersRecursive(`${__dirname}/src-editor/build`);
let installPromise;
if (fs.existsSync(`${__dirname}/src-editor/node_modules`)) {
installPromise = Promise.resolve();
} else {
installPromise = npmInstall(`${__dirname.replace(/\\/g, '/')}/src-editor/`);
}
installPromise
.then(() => {
if (fs.existsSync(`${__dirname}/src-editor/node_modules/@iobroker/adapter-react-v5/build`)) {
fs.copyFileSync(`${__dirname}/src-editor/node_modules/@iobroker/adapter-react-v5/build/index.css`, `${__dirname}/src-editor/node_modules/@iobroker/adapter-react-v5/index.css`);
}
})
.then(() => buildReact(`${__dirname}/src-editor/`, { rootDir: __dirname }))
.then(() => copyAllFiles())
.then(() => {
if (fs.existsSync(`${__dirname}/admin/tab.html`)) {
let code = fs.readFileSync(`${__dirname}/admin/tab.html`).toString('utf8');
code = code.replace(/<script>var script=document\.createElement\("script"\).+?<\/script>/,
`<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`);
fs.writeFileSync(`${__dirname}/admin/tab.html`, code);
}
if (fs.existsSync(`${__dirname}/src-editor/build/index.html`)) {
let code = fs.readFileSync(`${__dirname}/src-editor/build/index.html`).toString('utf8');
code = code.replace(/<script>var script=document\.createElement\("script"\).+?<\/script>/,
`<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`);
fs.writeFileSync(`${__dirname}/src-editor/build/index.html`, code);
}
});