@iobroker/adapter-react-v5 7.1.0 → 7.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AdminConnection.js +0 -2
- package/Components/ComplexCron.js +16 -2
- package/Components/TabContainer.js +1 -1
- package/Dialogs/ComplexCron.d.ts +3 -1
- package/Dialogs/ComplexCron.js +28 -1
- package/README.md +1437 -1403
- package/assets/lamp_ceiling.svg +8 -8
- package/assets/lamp_table.svg +7 -7
- package/assets/no_icon.svg +9 -9
- package/i18n/de.json +439 -435
- package/i18n/en.json +439 -435
- package/i18n/es.json +439 -435
- package/i18n/fr.json +439 -435
- package/i18n/it.json +439 -435
- package/i18n/nl.json +439 -435
- package/i18n/pl.json +439 -435
- package/i18n/pt.json +439 -435
- package/i18n/ru.json +439 -435
- package/i18n/uk.json +439 -435
- package/i18n/zh-cn.json +439 -435
- package/index.js +1 -3
- package/package.json +6 -6
- package/src/Components/ComplexCron.tsx +561 -544
- package/src/Components/TabContainer.tsx +57 -57
- package/src/Dialogs/ComplexCron.tsx +163 -123
- package/tasks.js +91 -91
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const styles: Record<string, React.CSSProperties> = {
|
|
6
|
-
root: {
|
|
7
|
-
width: '100%',
|
|
8
|
-
height: '100%',
|
|
9
|
-
},
|
|
10
|
-
overflowHidden: {
|
|
11
|
-
overflow: 'hidden',
|
|
12
|
-
},
|
|
13
|
-
container: {
|
|
14
|
-
height: '100%',
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
interface TabContainerProps {
|
|
19
|
-
/* The elevation of the tab container. */
|
|
20
|
-
elevation?: number;
|
|
21
|
-
/* Set to 'visible' show the overflow. */
|
|
22
|
-
overflow?: string;
|
|
23
|
-
styles?: {
|
|
24
|
-
root?: React.CSSProperties;
|
|
25
|
-
container?: React.CSSProperties;
|
|
26
|
-
};
|
|
27
|
-
onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
28
|
-
tabIndex?: number;
|
|
29
|
-
/** The content of the component. */
|
|
30
|
-
children: React.ReactNode;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function TabContainer(props: TabContainerProps): React.JSX.Element {
|
|
34
|
-
return (
|
|
35
|
-
<Paper
|
|
36
|
-
elevation={!Number.isNaN(props.elevation) ? props.elevation : 1}
|
|
37
|
-
style={{
|
|
38
|
-
...styles.root,
|
|
39
|
-
...(props.styles?.root || undefined),
|
|
40
|
-
...(props.overflow !== 'visible' ? styles.overflowHidden : undefined),
|
|
41
|
-
}}
|
|
42
|
-
onKeyDown={props.onKeyDown}
|
|
43
|
-
tabIndex={props.tabIndex}
|
|
44
|
-
>
|
|
45
|
-
<
|
|
46
|
-
container
|
|
47
|
-
direction="column"
|
|
48
|
-
wrap="nowrap"
|
|
49
|
-
sx={styles.container}
|
|
50
|
-
>
|
|
51
|
-
{props.children}
|
|
52
|
-
</
|
|
53
|
-
</Paper>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default TabContainer;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Grid2, Paper } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
const styles: Record<string, React.CSSProperties> = {
|
|
6
|
+
root: {
|
|
7
|
+
width: '100%',
|
|
8
|
+
height: '100%',
|
|
9
|
+
},
|
|
10
|
+
overflowHidden: {
|
|
11
|
+
overflow: 'hidden',
|
|
12
|
+
},
|
|
13
|
+
container: {
|
|
14
|
+
height: '100%',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface TabContainerProps {
|
|
19
|
+
/* The elevation of the tab container. */
|
|
20
|
+
elevation?: number;
|
|
21
|
+
/* Set to 'visible' show the overflow. */
|
|
22
|
+
overflow?: string;
|
|
23
|
+
styles?: {
|
|
24
|
+
root?: React.CSSProperties;
|
|
25
|
+
container?: React.CSSProperties;
|
|
26
|
+
};
|
|
27
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
28
|
+
tabIndex?: number;
|
|
29
|
+
/** The content of the component. */
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function TabContainer(props: TabContainerProps): React.JSX.Element {
|
|
34
|
+
return (
|
|
35
|
+
<Paper
|
|
36
|
+
elevation={!Number.isNaN(props.elevation) ? props.elevation : 1}
|
|
37
|
+
style={{
|
|
38
|
+
...styles.root,
|
|
39
|
+
...(props.styles?.root || undefined),
|
|
40
|
+
...(props.overflow !== 'visible' ? styles.overflowHidden : undefined),
|
|
41
|
+
}}
|
|
42
|
+
onKeyDown={props.onKeyDown}
|
|
43
|
+
tabIndex={props.tabIndex}
|
|
44
|
+
>
|
|
45
|
+
<Grid2
|
|
46
|
+
container
|
|
47
|
+
direction="column"
|
|
48
|
+
wrap="nowrap"
|
|
49
|
+
sx={styles.container}
|
|
50
|
+
>
|
|
51
|
+
{props.children}
|
|
52
|
+
</Grid2>
|
|
53
|
+
</Paper>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default TabContainer;
|
|
@@ -1,123 +1,163 @@
|
|
|
1
|
-
import React, { type JSX } from 'react';
|
|
2
|
-
|
|
3
|
-
import { Button, DialogTitle, DialogContent, DialogActions, Dialog } from '@mui/material';
|
|
4
|
-
|
|
5
|
-
import { Check as IconOk, Cancel as IconCancel, Delete as IconClear } from '@mui/icons-material';
|
|
6
|
-
|
|
7
|
-
import ComplexCron from '../Components/ComplexCron';
|
|
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
|
-
cron = this.props.cron
|
|
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
|
-
|
|
1
|
+
import React, { type JSX } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Button, DialogTitle, DialogContent, DialogActions, Dialog } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
import { Check as IconOk, Cancel as IconCancel, Delete as IconClear } from '@mui/icons-material';
|
|
6
|
+
|
|
7
|
+
import ComplexCron from '../Components/ComplexCron';
|
|
8
|
+
import ConfirmDialog from '../Dialogs/Confirm';
|
|
9
|
+
|
|
10
|
+
import I18n from '../i18n';
|
|
11
|
+
|
|
12
|
+
// Generate cron expression
|
|
13
|
+
const styles: Record<string, React.CSSProperties> = {
|
|
14
|
+
headerID: {
|
|
15
|
+
fontWeight: 'bold',
|
|
16
|
+
fontStyle: 'italic',
|
|
17
|
+
},
|
|
18
|
+
radio: {
|
|
19
|
+
display: 'inline-block',
|
|
20
|
+
},
|
|
21
|
+
dialogPaper: {
|
|
22
|
+
height: 'calc(100% - 96px)',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
interface DialogCronProps {
|
|
27
|
+
onClose: () => void;
|
|
28
|
+
onOk: (cron: string | false) => void;
|
|
29
|
+
title?: string;
|
|
30
|
+
cron?: string;
|
|
31
|
+
cancel?: string;
|
|
32
|
+
ok?: string;
|
|
33
|
+
clear?: string;
|
|
34
|
+
clearButton?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface DialogCronState {
|
|
38
|
+
cron: string;
|
|
39
|
+
showWarning: '' | 'everySecond' | 'everyMinute';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class DialogComplexCron extends React.Component<DialogCronProps, DialogCronState> {
|
|
43
|
+
constructor(props: DialogCronProps) {
|
|
44
|
+
super(props);
|
|
45
|
+
let cron;
|
|
46
|
+
if (this.props.cron && typeof this.props.cron === 'string' && this.props.cron.replace(/^["']/, '')[0] !== '{') {
|
|
47
|
+
cron = this.props.cron.replace(/['"]/g, '').trim();
|
|
48
|
+
} else {
|
|
49
|
+
cron = this.props.cron || '{}';
|
|
50
|
+
if (typeof cron === 'string') {
|
|
51
|
+
cron = cron.replace(/^["']/, '').replace(/["']\n?$/, '');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.state = {
|
|
56
|
+
showWarning: '',
|
|
57
|
+
cron,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
handleCancel(): void {
|
|
62
|
+
this.props.onClose();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
handleOk(ignoreCheck?: boolean): void {
|
|
66
|
+
if (!ignoreCheck) {
|
|
67
|
+
// Check if the CRON will be executed every second or every minute and warn about it
|
|
68
|
+
const cron = ComplexCron.cron2state(this.state.cron);
|
|
69
|
+
if (cron.seconds === '*' || cron.seconds === '*/1') {
|
|
70
|
+
this.setState({ showWarning: 'everySecond' });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (cron.minutes === '*' || cron.minutes === '*/1') {
|
|
74
|
+
this.setState({ showWarning: 'everyMinute' });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.props.onOk(this.state.cron);
|
|
80
|
+
this.props.onClose();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
renderWarningDialog(): JSX.Element | null {
|
|
84
|
+
if (!this.state.showWarning) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return (
|
|
88
|
+
<ConfirmDialog
|
|
89
|
+
title={I18n.t('ra_Please confirm')}
|
|
90
|
+
text={I18n.t(
|
|
91
|
+
this.state.showWarning === 'everySecond'
|
|
92
|
+
? 'ra_The schedule will be executed every second. Are you sure?'
|
|
93
|
+
: 'ra_The schedule will be executed every minute. Are you sure?',
|
|
94
|
+
)}
|
|
95
|
+
onClose={(ok: boolean) =>
|
|
96
|
+
this.setState({ showWarning: '' }, () => {
|
|
97
|
+
if (ok) {
|
|
98
|
+
this.handleOk(true);
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
handleClear(): void {
|
|
107
|
+
this.props.onOk(false);
|
|
108
|
+
this.props.onClose();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
render(): JSX.Element {
|
|
112
|
+
return (
|
|
113
|
+
<Dialog
|
|
114
|
+
onClose={() => {}}
|
|
115
|
+
maxWidth="md"
|
|
116
|
+
fullWidth
|
|
117
|
+
sx={{ '& .MuiDialog-paper': styles.dialogPaper }}
|
|
118
|
+
open={!0}
|
|
119
|
+
aria-labelledby="cron-dialog-title"
|
|
120
|
+
>
|
|
121
|
+
{this.renderWarningDialog()}
|
|
122
|
+
<DialogTitle id="cron-dialog-title">{this.props.title || I18n.t('ra_Define schedule...')}</DialogTitle>
|
|
123
|
+
<DialogContent style={{ height: '100%', overflow: 'hidden' }}>
|
|
124
|
+
<ComplexCron
|
|
125
|
+
cronExpression={this.state.cron}
|
|
126
|
+
onChange={cron => this.setState({ cron })}
|
|
127
|
+
language={I18n.getLanguage()}
|
|
128
|
+
/>
|
|
129
|
+
</DialogContent>
|
|
130
|
+
<DialogActions>
|
|
131
|
+
{!!this.props.clearButton && (
|
|
132
|
+
<Button
|
|
133
|
+
color="grey"
|
|
134
|
+
variant="contained"
|
|
135
|
+
onClick={() => this.handleClear()}
|
|
136
|
+
startIcon={<IconClear />}
|
|
137
|
+
>
|
|
138
|
+
{this.props.clear || I18n.t('ra_Clear')}
|
|
139
|
+
</Button>
|
|
140
|
+
)}
|
|
141
|
+
<Button
|
|
142
|
+
variant="contained"
|
|
143
|
+
onClick={() => this.handleOk()}
|
|
144
|
+
color="primary"
|
|
145
|
+
startIcon={<IconOk />}
|
|
146
|
+
>
|
|
147
|
+
{this.props.ok || I18n.t('ra_Ok')}
|
|
148
|
+
</Button>
|
|
149
|
+
<Button
|
|
150
|
+
color="grey"
|
|
151
|
+
variant="contained"
|
|
152
|
+
onClick={() => this.handleCancel()}
|
|
153
|
+
startIcon={<IconCancel />}
|
|
154
|
+
>
|
|
155
|
+
{this.props.cancel || I18n.t('ra_Cancel')}
|
|
156
|
+
</Button>
|
|
157
|
+
</DialogActions>
|
|
158
|
+
</Dialog>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default DialogComplexCron;
|
package/tasks.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2024 bluefox <dogafox@gmail.com>
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
const fs = require('node:fs');
|
|
10
|
-
const { deleteFoldersRecursive, npmInstall, buildReact, copyFiles } = require('@iobroker/build-tools');
|
|
11
|
-
|
|
12
|
-
const SRC = 'src';
|
|
13
|
-
|
|
14
|
-
function copyAllFiles() {
|
|
15
|
-
deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
|
|
16
|
-
|
|
17
|
-
copyFiles(
|
|
18
|
-
[
|
|
19
|
-
`${SRC}/build/*`,
|
|
20
|
-
`!${SRC}/build/index.html`,
|
|
21
|
-
`!${SRC}/build/static/js/main.*.chunk.js`,
|
|
22
|
-
`!${SRC}/build/static/media/*.svg`,
|
|
23
|
-
`!${SRC}/build/static/media/*.txt`,
|
|
24
|
-
`!${SRC}/build/i18n/*`,
|
|
25
|
-
`!${SRC}/build/i18n`,
|
|
26
|
-
],
|
|
27
|
-
'admin',
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
copyFiles(`${SRC}/build/index.html`, 'admin');
|
|
31
|
-
|
|
32
|
-
copyFiles(`${SRC}/build/static/js/main.*.chunk.js`, 'admin/static/js');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function clean() {
|
|
36
|
-
deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
|
|
37
|
-
deleteFoldersRecursive(`${SRC}/build`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function installNpmLocal() {
|
|
41
|
-
if (fs.existsSync(`${SRC}/node_modules`)) {
|
|
42
|
-
return Promise.resolve();
|
|
43
|
-
}
|
|
44
|
-
return npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function patchFiles() {
|
|
48
|
-
if (fs.existsSync(`${__dirname}/admin/index.html`)) {
|
|
49
|
-
let code = fs.readFileSync(`${__dirname}/admin/index.html`).toString('utf8');
|
|
50
|
-
code = code.replace(
|
|
51
|
-
/<script>var script=document\.createElement\("script"\).+?<\/script>/,
|
|
52
|
-
`<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
fs.writeFileSync(`${__dirname}/admin/index.html`, code);
|
|
56
|
-
}
|
|
57
|
-
if (fs.existsSync(`${__dirname}/${SRC}/build/index.html`)) {
|
|
58
|
-
let code = fs.readFileSync(`${__dirname}/${SRC}/build/index.html`).toString('utf8');
|
|
59
|
-
code = code.replace(
|
|
60
|
-
/<script>var script=document\.createElement\("script"\).+?<\/script>/,
|
|
61
|
-
`<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
fs.writeFileSync(`${SRC}/build/index.html`, code);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (process.argv.find(arg => arg === '--0-clean')) {
|
|
69
|
-
clean();
|
|
70
|
-
} else if (process.argv.find(arg => arg === '--1-npm')) {
|
|
71
|
-
npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`).catch(e => {
|
|
72
|
-
console.error(`Cannot install: ${e}`);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
});
|
|
75
|
-
} else if (process.argv.find(arg => arg === '--2-build')) {
|
|
76
|
-
buildReact(SRC, { rootDir: __dirname }).catch(e => {
|
|
77
|
-
console.error(`Cannot build: ${e}`);
|
|
78
|
-
process.exit(1);
|
|
79
|
-
});
|
|
80
|
-
} else if (process.argv.find(arg => arg === '--3-copy')) {
|
|
81
|
-
copyAllFiles();
|
|
82
|
-
} else if (process.argv.find(arg => arg === '--4-patch')) {
|
|
83
|
-
patchFiles();
|
|
84
|
-
} else {
|
|
85
|
-
clean();
|
|
86
|
-
|
|
87
|
-
installNpmLocal()
|
|
88
|
-
.then(() => buildReact(SRC, { rootDir: __dirname }))
|
|
89
|
-
.then(() => copyAllFiles())
|
|
90
|
-
.then(() => patchFiles());
|
|
91
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 bluefox <dogafox@gmail.com>
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const fs = require('node:fs');
|
|
10
|
+
const { deleteFoldersRecursive, npmInstall, buildReact, copyFiles } = require('@iobroker/build-tools');
|
|
11
|
+
|
|
12
|
+
const SRC = 'src';
|
|
13
|
+
|
|
14
|
+
function copyAllFiles() {
|
|
15
|
+
deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
|
|
16
|
+
|
|
17
|
+
copyFiles(
|
|
18
|
+
[
|
|
19
|
+
`${SRC}/build/*`,
|
|
20
|
+
`!${SRC}/build/index.html`,
|
|
21
|
+
`!${SRC}/build/static/js/main.*.chunk.js`,
|
|
22
|
+
`!${SRC}/build/static/media/*.svg`,
|
|
23
|
+
`!${SRC}/build/static/media/*.txt`,
|
|
24
|
+
`!${SRC}/build/i18n/*`,
|
|
25
|
+
`!${SRC}/build/i18n`,
|
|
26
|
+
],
|
|
27
|
+
'admin',
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
copyFiles(`${SRC}/build/index.html`, 'admin');
|
|
31
|
+
|
|
32
|
+
copyFiles(`${SRC}/build/static/js/main.*.chunk.js`, 'admin/static/js');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function clean() {
|
|
36
|
+
deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
|
|
37
|
+
deleteFoldersRecursive(`${SRC}/build`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function installNpmLocal() {
|
|
41
|
+
if (fs.existsSync(`${SRC}/node_modules`)) {
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
return npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function patchFiles() {
|
|
48
|
+
if (fs.existsSync(`${__dirname}/admin/index.html`)) {
|
|
49
|
+
let code = fs.readFileSync(`${__dirname}/admin/index.html`).toString('utf8');
|
|
50
|
+
code = code.replace(
|
|
51
|
+
/<script>var script=document\.createElement\("script"\).+?<\/script>/,
|
|
52
|
+
`<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
fs.writeFileSync(`${__dirname}/admin/index.html`, code);
|
|
56
|
+
}
|
|
57
|
+
if (fs.existsSync(`${__dirname}/${SRC}/build/index.html`)) {
|
|
58
|
+
let code = fs.readFileSync(`${__dirname}/${SRC}/build/index.html`).toString('utf8');
|
|
59
|
+
code = code.replace(
|
|
60
|
+
/<script>var script=document\.createElement\("script"\).+?<\/script>/,
|
|
61
|
+
`<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
fs.writeFileSync(`${SRC}/build/index.html`, code);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (process.argv.find(arg => arg === '--0-clean')) {
|
|
69
|
+
clean();
|
|
70
|
+
} else if (process.argv.find(arg => arg === '--1-npm')) {
|
|
71
|
+
npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`).catch(e => {
|
|
72
|
+
console.error(`Cannot install: ${e}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
|
75
|
+
} else if (process.argv.find(arg => arg === '--2-build')) {
|
|
76
|
+
buildReact(SRC, { rootDir: __dirname }).catch(e => {
|
|
77
|
+
console.error(`Cannot build: ${e}`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
});
|
|
80
|
+
} else if (process.argv.find(arg => arg === '--3-copy')) {
|
|
81
|
+
copyAllFiles();
|
|
82
|
+
} else if (process.argv.find(arg => arg === '--4-patch')) {
|
|
83
|
+
patchFiles();
|
|
84
|
+
} else {
|
|
85
|
+
clean();
|
|
86
|
+
|
|
87
|
+
installNpmLocal()
|
|
88
|
+
.then(() => buildReact(SRC, { rootDir: __dirname }))
|
|
89
|
+
.then(() => copyAllFiles())
|
|
90
|
+
.then(() => patchFiles());
|
|
91
|
+
}
|