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 | const dbx_github_url = {
|
32 | v12: "https://raw.githubusercontent.com/chrisemunt/mg-dbx/master/bin/winx64/node12/mg-dbx.node",
|
33 | v14: "https://raw.githubusercontent.com/chrisemunt/mg-dbx/master/bin/winx64/node14/mg-dbx.node"
|
34 | };
|
35 | const dbx_node_file = 'node_modules/mg-dbx.node';
|
36 | const qm_adminui_path = 'www/qewd-monitor-adminui';
|
37 | const qm_adminui_qewd_apps_path = 'qewd-apps/qewd-monitor-adminui';
|
38 | const www_path = 'www';
|
39 | const components_path = 'www/components';
|
40 | const qewd_client_path = 'www/qewd-client.js';
|
41 | const mgWebComponents_path = 'www/mg-webComponents.js';
|
42 |
|
43 | const mgWebComponents_url = 'https://raw.githubusercontent.com/robtweed/mg-webComponents/master/mg-webComponents.js';
|
44 | const qewd_client_url = 'https://raw.githubusercontent.com/robtweed/qewd-client/master/qewd-client.js';
|
45 | const qm_adminui_url = 'https://github.com/robtweed/qewd-monitor-adminui';
|
46 |
|
47 | const wc_adminui_url = 'https://github.com/robtweed/wc-admin-ui';
|
48 | const wc_leaflet_url = 'https://github.com/robtweed/wc-leaflet';
|
49 | const wc_d3_url = 'https://github.com/robtweed/wc-d3';
|
50 |
|
51 | const fs = require('fs-extra');
|
52 | const run_qewd = require('./run');
|
53 | const git_clone = require('./git_clone');
|
54 | const https = require('https');
|
55 |
|
56 | let file;
|
57 | let request;
|
58 | let url;
|
59 | let path;
|
60 |
|
61 | function exit_process() {
|
62 | console.log('\n*** Installation Completed. QEWD will halt ***');
|
63 | console.log('*** Please restart QEWD again using "npm start" \n');
|
64 | process.exit();
|
65 | }
|
66 |
|
67 | if (!fs.existsSync(www_path)) {
|
68 | fs.mkdirSync(www_path);
|
69 | }
|
70 |
|
71 | if (!fs.existsSync(mgWebComponents_path)) {
|
72 | let file1 = fs.createWriteStream(mgWebComponents_path);
|
73 | https.get(mgWebComponents_url, function(response) {
|
74 | response.pipe(file1);
|
75 | console.log('mg-webComponents installed');
|
76 | });
|
77 | }
|
78 |
|
79 | if (!fs.existsSync(qewd_client_path)) {
|
80 | let file2 = fs.createWriteStream(qewd_client_path);
|
81 | https.get(qewd_client_url, function(response) {
|
82 | response.pipe(file2);
|
83 | console.log('qewd-client installed');
|
84 | });
|
85 | }
|
86 |
|
87 | if (!fs.existsSync(components_path)) {
|
88 | fs.mkdirSync(components_path);
|
89 | }
|
90 |
|
91 | let installed = true;
|
92 | let maxToFetch = 0;
|
93 | let count = 0;
|
94 | let halt;
|
95 |
|
96 | let patha = components_path + '/adminui';
|
97 | if (!fs.existsSync(patha)) {
|
98 | installed = false;
|
99 | maxToFetch++;
|
100 | git_clone(wc_adminui_url, patha, function() {
|
101 | count++;
|
102 | if (count === maxToFetch) {
|
103 | exit_process();
|
104 | |
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | }
|
111 | });
|
112 | }
|
113 |
|
114 | let pathb = components_path + '/leaflet';
|
115 | if (!fs.existsSync(pathb)) {
|
116 | installed = false;
|
117 | maxToFetch++;
|
118 | git_clone(wc_leaflet_url, pathb, function() {
|
119 | count++;
|
120 | if (count === maxToFetch) {
|
121 | exit_process();
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | }
|
129 | });
|
130 | }
|
131 |
|
132 | let pathc = components_path + '/d3';
|
133 | if (!fs.existsSync(pathc)) {
|
134 | installed = false;
|
135 | maxToFetch++;
|
136 | git_clone(wc_d3_url, pathc, function() {
|
137 | count++;
|
138 | if (count === maxToFetch) {
|
139 | exit_process();
|
140 | |
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | }
|
147 | });
|
148 | }
|
149 |
|
150 | if (!fs.existsSync(qm_adminui_path)) {
|
151 | installed = false;
|
152 | maxToFetch++;
|
153 | git_clone(qm_adminui_url, qm_adminui_path, function() {
|
154 | fs.moveSync(qm_adminui_path + '/qewd-apps', qm_adminui_qewd_apps_path);
|
155 | count++;
|
156 | if (count === maxToFetch) {
|
157 | exit_process();
|
158 | |
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | }
|
165 | });
|
166 | }
|
167 |
|
168 |
|
169 | if (process.platform === 'win32' && !fs.existsSync(dbx_node_file)) {
|
170 | installed = false;
|
171 | maxToFetch++;
|
172 | console.log('Installing mg-dbx interface module for Windows');
|
173 | let version = process.version.split('.')[0];
|
174 | url = dbx_github_url[version];
|
175 | if (url) {
|
176 | file = fs.createWriteStream(dbx_node_file);
|
177 | request = https.get(url, function(response) {
|
178 | let st = response.pipe(file);
|
179 |
|
180 | st.on('finish', function() {
|
181 | console.log('mg-dbx installed');
|
182 |
|
183 | let install_sql = require('./install_sql');
|
184 | install_sql();
|
185 |
|
186 | count++;
|
187 | if (count === maxToFetch) {
|
188 | exit_process();
|
189 | |
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | }
|
196 | });
|
197 | });
|
198 | }
|
199 | else {
|
200 | console.log('Node.js version ' + version + 'is not supported by QEWD');
|
201 | }
|
202 |
|
203 | }
|
204 |
|
205 | if (installed) {
|
206 | if (process.argv[2] && process.argv[2] !== '') {
|
207 | return run_qewd(null, process.argv[2], true);
|
208 | }
|
209 | run_qewd();
|
210 | }
|