-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtasks.js
127 lines (116 loc) · 4.63 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Copyright 2018-2025 bluefox <[email protected]>
*
* MIT License
*
**/
'use strict';
const fs = require('fs');
const adapterName = require('./package.json').name.replace('iobroker.', '');
const buildHelper = require('@iobroker/vis-2-widgets-react-dev/buildHelper');
const { deleteFoldersRecursive, buildReact, npmInstall, copyFiles, patchHtmlFile } = require('@iobroker/build-tools');
const { copyFileSync } = require('node:fs');
async function copyAllFiles() {
deleteFoldersRecursive(`${__dirname}/admin`);
copyFiles(['src-admin/build/**/*', '!src-admin/build/index.html', 'admin-config/*'], 'admin/');
await patchHtmlFile(`${__dirname}/src-admin/build/index.html`);
copyFileSync(`${__dirname}/src-admin/build/index.html`, `${__dirname}/admin/index_m.html`);
}
function clean() {
deleteFoldersRecursive(`${__dirname}/admin`);
deleteFoldersRecursive(`${__dirname}/src-admin/build`);
}
function widgetsClean() {
deleteFoldersRecursive(`${__dirname}/src-widgets/build`);
deleteFoldersRecursive(`${__dirname}/widgets`);
}
async function widgetsCopyAllFiles() {
copyFiles([`${__dirname}/src-widgets/build/*.js`], `widgets/${adapterName}`);
copyFiles([`${__dirname}/src-widgets/build/img/*`], `widgets/${adapterName}/img`);
copyFiles([`${__dirname}/src-widgets/build/*.map`], `widgets/${adapterName}`);
const ignore = buildHelper.ignoreFiles(`${__dirname}/src-widgets/`);
const copy = buildHelper.copyFiles(`${__dirname}/src-widgets/`);
copyFiles([
`${__dirname}/src-widgets/build/static/**/*`,
...ignore,
], `widgets/${adapterName}/static`);
//copyFiles(copy, `widgets/${adapterName}/static/js`);
copyFiles([`${__dirname}/src-widgets/src/i18n/*.json`], `widgets/${adapterName}/i18n`);
await new Promise(resolve =>
setTimeout(() => {
if (
fs.existsSync(`widgets/${adapterName}/static/media`) &&
!fs.readdirSync(`widgets/${adapterName}/static/media`).length
) {
fs.rmdirSync(`widgets/${adapterName}/static/media`);
}
resolve(null);
}, 500),
);
}
if (process.argv.includes('--0-clean')) {
clean();
} else if (process.argv.includes('--1-npm')) {
if (!fs.existsSync(`${__dirname}/src-admin/node_modules`)) {
npmInstall('src-admin').catch(e => {
console.error(`Cannot run npm: ${e}`);
process.exit(2);
});
}
} else if (process.argv.includes('--2-build')) {
buildReact('src-admin', { rootDir: 'src-admin', tsc: true, vite: true }).catch(e => {
console.error(`Cannot build: ${e}`);
process.exit(2);
});
} else if (process.argv.includes('--3-copy')) {
copyAllFiles().catch(e => {
console.error(`Cannot copy: ${e}`);
process.exit(2);
});
} else if (process.argv.includes('--build-admin')) {
clean();
npmInstall('src-admin')
.then(() => buildReact('src-admin', { rootDir: 'src-admin', tsc: true, vite: true }))
.then(() => copyAllFiles());
} else if (process.argv.includes('--widget-0-clean')) {
widgetsClean();
} else if (process.argv.includes('--widget-1-npm')) {
if (!fs.existsSync(`${__dirname}/src-widgets/node_modules`)) {
npmInstall('src-widgets').catch(e => {
console.error(`Cannot run npm: ${e}`);
process.exit(2);
});
}
} else if (process.argv.includes('--widget-2-build')) {
buildReact(`${__dirname}/src-widgets`, { rootDir: `${__dirname}/src-widgets`, craco: true }).catch(e => {
console.error(`Cannot build: ${e}`);
process.exit(2);
});
} else if (process.argv.includes('--widget-3-copy')) {
widgetsCopyAllFiles().catch(e => {
console.error(`Cannot copy: ${e}`);
process.exit(2);
});
} else if (process.argv.includes('--widget-build')) {
widgetsClean();
npmInstall('src-widgets')
.then(() => buildReact(`${__dirname}/src-widgets`, { rootDir: `${__dirname}/src-widgets`, craco: true }))
.then(() => widgetsCopyAllFiles())
.catch(e => {
console.error(`Cannot build: ${e}`);
process.exit(2);
});
} else {
clean();
npmInstall('src-admin')
.then(() => buildReact('src-admin', { rootDir: 'src-admin', tsc: true, vite: true }))
.then(() => copyAllFiles())
.then(() => widgetsClean())
.then(() => npmInstall('src-widgets'))
.then(() => buildReact(`${__dirname}/src-widgets`, { rootDir: `${__dirname}/src-widgets`, craco: true }))
.then(() => widgetsCopyAllFiles())
.catch(e => {
console.error(`Cannot build: ${e}`);
process.exit(2);
});
}