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 | var fs = require('fs-extra');
|
32 | var os = require('os');
|
33 | var https = require('https');
|
34 | var readline = require('readline');
|
35 | var child_process = require('child_process');
|
36 |
|
37 | const rl = readline.createInterface({
|
38 | input: process.stdin,
|
39 | output: process.stdout
|
40 | });
|
41 |
|
42 | function download(url, dest, cb) {
|
43 | var file = fs.createWriteStream(dest);
|
44 | var request = https.get(url, function(response) {
|
45 | response.pipe(file);
|
46 | file.on('finish', function() {
|
47 | file.close(cb);
|
48 | });
|
49 | }).on('error', function(err) {
|
50 | fs.unlink(dest);
|
51 | if (cb) cb(err.message);
|
52 | });
|
53 | };
|
54 |
|
55 | function npmInstall(moduleName) {
|
56 | child_process.execSync('npm install ' + moduleName, {stdio: 'inherit'});
|
57 | }
|
58 |
|
59 | function runBash(scriptName) {
|
60 | child_process.execSync('sh ' + scriptName, {stdio: 'inherit'});
|
61 | }
|
62 |
|
63 | function ok() {
|
64 | console.log('QEWD.js is ready to run');
|
65 | console.log('You should now be able to start QEWD by typing: node qewd');
|
66 | }
|
67 |
|
68 | function startupFile(dir) {
|
69 | rl.question('Which database/server setup are you using (cache | gtm | yottadb | redis | rpi): ', (db) => {
|
70 | if (!db || db === '') {
|
71 | console.log('You must specify a database!');
|
72 | return startupFile(dir);
|
73 | }
|
74 |
|
75 | var fromPath;
|
76 | var toPath = dir + '/qewd.js';
|
77 |
|
78 | if (db === 'cache') {
|
79 |
|
80 | var oPath = {
|
81 | Linux: 'linux',
|
82 | Windows_NT: 'win64',
|
83 | Darwin: 'osx'
|
84 | };
|
85 | var fileNames = {
|
86 | '4': '421',
|
87 | '6': '610',
|
88 | '7': '700',
|
89 | '8': '800'
|
90 | };
|
91 | var nodeVer = process.version;
|
92 | nodeVer = nodeVer.split('v')[1];
|
93 | nodeVer = nodeVer.split('.')[0];
|
94 | var platform = os.type();
|
95 |
|
96 | var url = 'https://s3-eu-west-1.amazonaws.com/cache.node/build-140/' + oPath[platform] + '/cache' + fileNames[nodeVer] + '.node';
|
97 |
|
98 | var dest = dir + '/node_modules/cache.node';
|
99 |
|
100 | console.log('cache.node url: ' + url);
|
101 | console.log('to be saved as ' + dest);
|
102 |
|
103 | download(url, dest, function(err) {
|
104 | if (!err) {
|
105 | fromPath = dir + '/node_modules/qewd/example/qewd.js';
|
106 | fs.copySync(fromPath, toPath);
|
107 | console.log('Check the Cache configuration parameters in your startup file: ' + dir + '/qewd.js');
|
108 | console.log('Then you can start up QEWD by typing: node qewd');
|
109 | }
|
110 | rl.close();
|
111 | });
|
112 | return;
|
113 | }
|
114 |
|
115 | if (db === 'redis') {
|
116 | var platform = os.type();
|
117 | if (platform === 'Linux') {
|
118 | var prepareScript = dir + '/node_modules/qewd/installers/prepare.sh';
|
119 | runBash(prepareScript);
|
120 | }
|
121 |
|
122 | npmInstall('tcp-netx');
|
123 | npmInstall('ewd-redis-globals');
|
124 | fromPath = dir + '/node_modules/qewd/example/qewd-redis.js';
|
125 | fs.copySync(fromPath, toPath);
|
126 | ok();
|
127 | rl.close();
|
128 | return;
|
129 | }
|
130 |
|
131 | if (db === 'rpi') {
|
132 | npmInstall('tcp-netx');
|
133 | npmInstall('ewd-redis-globals');
|
134 | fromPath = dir + '/node_modules/qewd/example/qewd-rpi.js';
|
135 | fs.copySync(fromPath, toPath);
|
136 | ok();
|
137 | rl.close();
|
138 | return;
|
139 | }
|
140 |
|
141 | if (db === 'gtm' || db === 'yottadb') {
|
142 |
|
143 | if (!fs.existsSync(dir + '/node_modules/nodem') && typeof process.env['gtm_dist'] !== 'undefined') {
|
144 |
|
145 | runBash(dir + '/node_modules/qewd/installers/install_nodem.sh ' + dir);
|
146 | }
|
147 |
|
148 | fromPath = dir + '/node_modules/qewd/example/qewd-gtm.js';
|
149 | fs.copySync(fromPath, toPath);
|
150 | ok();
|
151 | rl.close();
|
152 | return;
|
153 | }
|
154 |
|
155 | console.log('Invalid database! Try again');
|
156 | startupFile(dir);
|
157 | });
|
158 | }
|
159 |
|
160 | function run() {
|
161 |
|
162 | var cwd = process.cwd();
|
163 | if (cwd.indexOf('node_modules/') !== -1) process.chdir('../..');
|
164 | cwd = process.cwd();
|
165 |
|
166 | rl.question('QEWD Installation Directory: (' + process.cwd() + '): ', (dir) => {
|
167 | if (!dir || dir === '') dir = process.cwd();
|
168 |
|
169 | console.log('Setting up QEWD in directory ' + dir);
|
170 |
|
171 | var wwwPath = dir + '/www';
|
172 | var www_exists = fs.existsSync(wwwPath);
|
173 | console.log('www exists: ' + www_exists);
|
174 |
|
175 | if (!www_exists) {
|
176 | fs.mkdirSync(wwwPath);
|
177 | console.log('www directory created');
|
178 | }
|
179 |
|
180 | var monitorPath = wwwPath + '/qewd-monitor';
|
181 | var path_exists = fs.existsSync(monitorPath);
|
182 | console.log('www/qewd-monitor exists: ' + path_exists);
|
183 |
|
184 | if (!path_exists) {
|
185 | fs.mkdirSync(monitorPath);
|
186 | console.log('www/qewd-monitor directory created');
|
187 | }
|
188 |
|
189 | var fromPath = dir + '/node_modules/qewd-monitor/www';
|
190 |
|
191 | fs.copySync(fromPath, monitorPath);
|
192 |
|
193 | startupFile(dir);
|
194 | });
|
195 | }
|
196 |
|
197 | run();
|
198 |
|