UNPKG

6.79 kBJavaScriptView Raw
1/*
2
3 ----------------------------------------------------------------------------
4 | qewd-up: Rapid QEWD API Development |
5 | |
6 | Copyright (c) 2018-20 M/Gateway Developments Ltd, |
7 | Redhill, Surrey UK. |
8 | All rights reserved. |
9 | |
10 | http://www.mgateway.com |
11 | Email: rtweed@mgateway.com |
12 | |
13 | |
14 | Licensed under the Apache License, Version 2.0 (the "License"); |
15 | you may not use this file except in compliance with the License. |
16 | You may obtain a copy of the License at |
17 | |
18 | http://www.apache.org/licenses/LICENSE-2.0 |
19 | |
20 | Unless required by applicable law or agreed to in writing, software |
21 | distributed under the License is distributed on an "AS IS" BASIS, |
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
23 | See the License for the specific language governing permissions and |
24 | limitations under the License. |
25 ----------------------------------------------------------------------------
26
27 3 June 2020
28
29*/
30
31const 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};
35const dbx_node_file = 'node_modules/mg-dbx.node';
36const qm_adminui_path = 'www/qewd-monitor-adminui';
37const qm_adminui_qewd_apps_path = 'qewd-apps/qewd-monitor-adminui';
38const www_path = 'www';
39const components_path = 'www/components';
40const qewd_client_path = 'www/qewd-client.js';
41const mgWebComponents_path = 'www/mg-webComponents.js';
42
43const mgWebComponents_url = 'https://raw.githubusercontent.com/robtweed/mg-webComponents/master/mg-webComponents.js';
44const qewd_client_url = 'https://raw.githubusercontent.com/robtweed/qewd-client/master/qewd-client.js';
45const qm_adminui_url = 'https://github.com/robtweed/qewd-monitor-adminui';
46
47const wc_adminui_url = 'https://github.com/robtweed/wc-admin-ui';
48const wc_leaflet_url = 'https://github.com/robtweed/wc-leaflet';
49const wc_d3_url = 'https://github.com/robtweed/wc-d3';
50
51const fs = require('fs-extra');
52const run_qewd = require('./run');
53const git_clone = require('./git_clone');
54const https = require('https');
55
56let file;
57let request;
58let url;
59let path;
60
61function 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
67if (!fs.existsSync(www_path)) {
68 fs.mkdirSync(www_path);
69}
70
71if (!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
79if (!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
87if (!fs.existsSync(components_path)) {
88 fs.mkdirSync(components_path);
89}
90
91let installed = true;
92let maxToFetch = 0;
93let count = 0;
94let halt;
95
96let patha = components_path + '/adminui';
97if (!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 if (process.argv[2] && process.argv[2] !== '') {
106 return run_qewd(null, process.argv[2], true);
107 }
108 run_qewd();
109 */
110 }
111 });
112}
113
114let pathb = components_path + '/leaflet';
115if (!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 if (process.argv[2] && process.argv[2] !== '') {
124 return run_qewd(null, process.argv[2], true);
125 }
126 run_qewd();
127 */
128 }
129 });
130}
131
132let pathc = components_path + '/d3';
133if (!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 if (process.argv[2] && process.argv[2] !== '') {
142 return run_qewd(null, process.argv[2], true);
143 }
144 run_qewd();
145 */
146 }
147 });
148}
149
150if (!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 if (process.argv[2] && process.argv[2] !== '') {
160 return run_qewd(null, process.argv[2], true);
161 }
162 run_qewd();
163 */
164 }
165 });
166}
167
168
169if (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 if (process.argv[2] && process.argv[2] !== '') {
191 return run_qewd(null, process.argv[2], true);
192 }
193 run_qewd();
194 */
195 }
196 });
197 });
198 }
199 else {
200 console.log('Node.js version ' + version + 'is not supported by QEWD');
201 }
202
203}
204
205if (installed) {
206 if (process.argv[2] && process.argv[2] !== '') {
207 return run_qewd(null, process.argv[2], true);
208 }
209 run_qewd();
210}