UNPKG

5.09 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 11 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}
84path = components_path + '/adminui';
85if (!fs.existsSync(path)) {
86 git_clone(wc_adminui_url, path);
87}
88
89path = components_path + '/leaflet';
90if (!fs.existsSync(path)) {
91 git_clone(wc_leaflet_url, path);
92}
93
94path = components_path + '/d3';
95if (!fs.existsSync(path)) {
96 git_clone(wc_d3_url, path);
97}
98
99let installed = true;
100let maxToFetch = 0;
101let count = 0;
102
103if (!fs.existsSync(qm_adminui_path)) {
104 installed = false;
105 maxToFetch++;
106 git_clone(qm_adminui_url, qm_adminui_path, function() {
107 fs.moveSync(qm_adminui_path + '/qewd-apps', qm_adminui_qewd_apps_path);
108 count++;
109 if (count === maxToFetch) {
110 run_qewd();
111 }
112 });
113}
114
115
116if (process.platform === 'win32' && !fs.existsSync(dbx_node_file)) {
117 installed = false;
118 maxToFetch++;
119 console.log('Installing mg-dbx interface module for Windows');
120 let version = process.version.split('.')[0];
121 url = dbx_github_url[version];
122 if (url) {
123 file = fs.createWriteStream(dbx_node_file);
124 request = https.get(url, function(response) {
125 response.pipe(file);
126 console.log('mg-dbx installed. QEWD can now start');
127 count++;
128 if (count === maxToFetch) {
129 run_qewd();
130 }
131 });
132 }
133 else {
134 console.log('Node.js version ' + version + 'is not supported by QEWD');
135 }
136}
137
138if (installed) {
139 run_qewd();
140}