UNPKG

6.32 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 12 May 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
61if (!fs.existsSync(www_path)) {
62 fs.mkdirSync(www_path);
63}
64
65if (!fs.existsSync(mgWebComponents_path)) {
66 let file1 = fs.createWriteStream(mgWebComponents_path);
67 https.get(mgWebComponents_url, function(response) {
68 response.pipe(file1);
69 console.log('mg-webComponents installed');
70 });
71}
72
73if (!fs.existsSync(qewd_client_path)) {
74 let file2 = fs.createWriteStream(qewd_client_path);
75 https.get(qewd_client_url, function(response) {
76 response.pipe(file2);
77 console.log('qewd-client installed');
78 });
79}
80
81if (!fs.existsSync(components_path)) {
82 fs.mkdirSync(components_path);
83}
84
85let installed = true;
86let maxToFetch = 0;
87let count = 0;
88
89let patha = components_path + '/adminui';
90if (!fs.existsSync(patha)) {
91 installed = false;
92 maxToFetch++;
93 git_clone(wc_adminui_url, patha, function() {
94 let res = fs.removeSync(patha + '/.git');
95 count++;
96 if (count === maxToFetch) {
97 if (process.argv[2] && process.argv[2] !== '') {
98 return run_qewd(null, process.argv[2], true);
99 }
100 run_qewd();
101 }
102 });
103}
104
105let pathb = components_path + '/leaflet';
106if (!fs.existsSync(pathb)) {
107 installed = false;
108 maxToFetch++;
109 git_clone(wc_leaflet_url, pathb, function() {
110 fs.removeSync(pathb + '/.git');
111 count++;
112 if (count === maxToFetch) {
113 if (process.argv[2] && process.argv[2] !== '') {
114 return run_qewd(null, process.argv[2], true);
115 }
116 run_qewd();
117 }
118 });
119}
120
121let pathc = components_path + '/d3';
122if (!fs.existsSync(pathc)) {
123 installed = false;
124 maxToFetch++;
125 git_clone(wc_d3_url, pathc, function() {
126 fs.removeSync(pathc + '/.git');
127 count++;
128 if (count === maxToFetch) {
129 if (process.argv[2] && process.argv[2] !== '') {
130 return run_qewd(null, process.argv[2], true);
131 }
132 run_qewd();
133 }
134 });
135}
136
137if (!fs.existsSync(qm_adminui_path)) {
138 installed = false;
139 maxToFetch++;
140 git_clone(qm_adminui_url, qm_adminui_path, function() {
141 fs.moveSync(qm_adminui_path + '/qewd-apps', qm_adminui_qewd_apps_path);
142 count++;
143 if (count === maxToFetch) {
144 if (process.argv[2] && process.argv[2] !== '') {
145 return run_qewd(null, process.argv[2], true);
146 }
147 run_qewd();
148 }
149 });
150}
151
152
153if (process.platform === 'win32' && !fs.existsSync(dbx_node_file)) {
154 installed = false;
155 maxToFetch++;
156 console.log('Installing mg-dbx interface module for Windows');
157 let version = process.version.split('.')[0];
158 url = dbx_github_url[version];
159 if (url) {
160 file = fs.createWriteStream(dbx_node_file);
161 request = https.get(url, function(response) {
162 response.pipe(file);
163 console.log('mg-dbx installed');
164 count++;
165 if (count === maxToFetch) {
166 if (process.argv[2] && process.argv[2] !== '') {
167 return run_qewd(null, process.argv[2], true);
168 }
169 run_qewd();
170 }
171 });
172 }
173 else {
174 console.log('Node.js version ' + version + 'is not supported by QEWD');
175 }
176}
177
178if (installed) {
179 if (process.argv[2] && process.argv[2] !== '') {
180 return run_qewd(null, process.argv[2], true);
181 }
182 run_qewd();
183}