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 | path = components_path + '/adminui';
|
85 | if (!fs.existsSync(path)) {
|
86 | git_clone(wc_adminui_url, path);
|
87 | }
|
88 |
|
89 | path = components_path + '/leaflet';
|
90 | if (!fs.existsSync(path)) {
|
91 | git_clone(wc_leaflet_url, path);
|
92 | }
|
93 |
|
94 | path = components_path + '/d3';
|
95 | if (!fs.existsSync(path)) {
|
96 | git_clone(wc_d3_url, path);
|
97 | }
|
98 |
|
99 | let installed = true;
|
100 | let maxToFetch = 0;
|
101 | let count = 0;
|
102 |
|
103 | if (!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 |
|
116 | if (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 |
|
138 | if (installed) {
|
139 | run_qewd();
|
140 | }
|