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 | if (!fs.existsSync(www_path)) {
|
62 | fs.mkdirSync(www_path);
|
63 | }
|
64 |
|
65 | if (!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 |
|
73 | if (!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 |
|
81 | if (!fs.existsSync(components_path)) {
|
82 | fs.mkdirSync(components_path);
|
83 | }
|
84 |
|
85 | let installed = true;
|
86 | let maxToFetch = 0;
|
87 | let count = 0;
|
88 |
|
89 | let patha = components_path + '/adminui';
|
90 | if (!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 |
|
105 | let pathb = components_path + '/leaflet';
|
106 | if (!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 |
|
121 | let pathc = components_path + '/d3';
|
122 | if (!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 |
|
137 | if (!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 |
|
153 | if (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 |
|
178 | if (installed) {
|
179 | if (process.argv[2] && process.argv[2] !== '') {
|
180 | return run_qewd(null, process.argv[2], true);
|
181 | }
|
182 | run_qewd();
|
183 | }
|