-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnormal-handler.js
50 lines (43 loc) · 2.2 KB
/
normal-handler.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// var exec = require('child-process-promise').exec;
// var execFile = require('child-process-promise').execFile;
// var AdmZip = require('adm-zip');
var promiseFromChildProcess = require('./promise-from-child-process.js');
var exec = require('child_process').exec;
var execFile = require('child_process').execFile;
module.exports = function (req, res) {
return promiseFromChildProcess(exec('bash scripts/create-temp-request-dir.sh ' + req.query.v.replace(/[.]/g, '-') + ' ' + req.requestId))
.then(function (result) {
// console.log(result);
// console.log("Created temp folder for request " + req.requestId);
return promiseFromChildProcess(execFile('scripts/create-entry-file.js', [req.requestId, req.query.components.replace(/\s/g, '')]));
})
.then(function (result) {
// console.log(result);
// console.log('Created entry.js file for webpack build for request ' + req.requestId);
return promiseFromChildProcess(exec('bash scripts/kickoff-webpack-build.sh ' + req.requestId));
})
.then(function (result) {
// console.log(result);
// console.log('Produced build output for request ' + req.requestId);
// create zip file and send it
// var zip = new AdmZip();
// zip.addLocalFile('webpack-builder/temp/' + req.requestId + '/build/bundle.js');
// zip.addLocalFile('webpack-builder/temp/' + req.requestId + '/build/bundle.js.map');
// zip.writeZip('webpack-builder/temp/' + req.requestId + '/build/bundle-with-map.zip');
// return res.download('webpack-builder/temp/' + req.requestId + '/build/bundle-with-map.zip');
// right now, just send single bundle file - worry about zipping later
// res.download('webpack-builder/temp/' + req.requestId + '/build/bundle.js', req.requestId + '.js');
res.download('webpack-builder/temp/' + req.requestId + '/build/bundle.js', req.requestId + '.js', function (err) {
if(err) {
console.log("Error in download call: ", err);
res.send("oops something went wrong, please try again");
}
promiseFromChildProcess(exec('rm -R webpack-builder/temp/' + req.requestId))
.then(function (result) {})
.catch(function (error) {
console.log("Error in deleting folder: ", error);
res.send("oops something went wrong, please try again");
});
});
});
};