Skip to content
Snippets Groups Projects
Commit 027d1598 authored by Josefine Wegert's avatar Josefine Wegert
Browse files

download frontend with addons finished

parent f6409722
No related branches found
No related tags found
No related merge requests found
......@@ -30,22 +30,23 @@ app.set('view engine', '.hbs');
//initialize the git repos
//TODO error handling is not working properly, error returned is not in let error, but in req + req and res are undefined!
// nanit.initialize(downloadFiles, function(req,res,err){
// // console.log('err in nanit.initialize:', err);
// // console.log('req in nanit.initialize:', req);
// // console.log('res in nanit.initialize:', res);
// let response =
// 'There was an error during cloning the git repositories. ' +
// 'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
// 'and add the following information: ' + req;
// if(err){
// console.log('nanit.initialize error');
// res.send(response);
// return;
// };
// });
//TODO add spinner for telling user to wait until initialization is done
nanit.initialize(downloadFiles, function(req,res,err){
// console.log('err in nanit.initialize:', err);
// console.log('req in nanit.initialize:', req);
// console.log('res in nanit.initialize:', res);
let response =
'There was an error during cloning the git repositories. ' +
'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
'and add the following information: ' + req;
if(err){
console.log('nanit.initialize error');
res.send(response);
return;
};
});
//routes
app.get('/', function(req, res){
......@@ -101,7 +102,6 @@ resolve({zipFileName:'backend.war', path:'explorviz-ui-backend/target/explorviz-
})
promiseArray.push(backendPromise);
console.log('promiseArray:',promiseArray);
}
frontendChecked = checkedFiles.find(function(file){
......@@ -115,7 +115,7 @@ if (frontendChecked){
function frontendPull(){
return new Promise((resolve, reject) => {
console.log('resolve frontendPullPromise', resolve);
console.log('in frontendPull()');
exec('cd ' + fileName + ' git pull ', (error, stdout, stderr) => {
if (error) {
......@@ -129,49 +129,52 @@ resolve();
});
})
}
promiseArray.push(frontendPull);
console.log('promiseArray.push(frontendPullPromise):',promiseArray);
function frontendInstallAddons(){
console.log('in frontendInstallAddons()');
return new Promise((resolve, reject) => {
checkedPlugins = checkedFiles.filter(function(file){
return /\bexplorviz-frontend-plugin-\w*/.exec(file);
});
if(checkedPlugins.length !== 0 ){
// const frontendInstallAddons = frontendPullPromise.then((resolve, reject) => {
checkedPlugins.forEach((pluginName) => {
exec('cd ' + 'explorviz-ui-frontend ' + 'ember install ' + downloadFiles[pluginName], (error, stdout, stderr) => {
// console.log('in installAddons()');
// checkedPlugins = checkedFiles.filter(function(file){
// return /\bexplorviz-frontend-plugin-\w*/.exec(file);
// });
// console.log('checkedPlugins', checkedPlugins);
// checkedPlugins.forEach((pluginName) => {
// exec('cd ' + 'explorviz-ui-frontend ' + 'ember install ' + downloadFiles[pluginName], (error, stdout, stderr) => {
// console.log('in exec plugin install');
// console.log('error in exec plugin install', error);
// if (error) {
// reject(error);
// return;
// }
if (error) {
reject(error);
return;
}
// console.log(stdout);
// console.log(stderr);
console.log(stdout);
console.log(stderr);
resolve();
// resolve({zipFileName:'Zwischenschritt2', path:'./explorviz-ui-frontend/dist/'});
});
// });
})
} else {
resolve();
}
// })
})
}
// })
//promiseArray.push(frontendInstallAddons);
//console.log('promiseArray.push(frontendInstallAddons):',promiseArray);
function frontendBuild(){
return new Promise((resolve,reject)=> {
console.log('resolve frontendBuildPromise', resolve);
//build everything you have
console.log('in frontendBuild()');
exec('cd ' + fileName +' && ember build --environment=production', (error, stdout, stderr) => {
// if (error) {
// reject(error);
// return;
// }
if (error) {
reject(error);
return;
}
console.log(stdout);
console.log(stderr);
......@@ -183,63 +186,109 @@ exec('cd ' + fileName +' && ember build --environment=production', (error, stdou
})
}
//console.log('frontendBuildPromise:', frontendBuildPromise);
//promiseArray.push(frontendBuild());
console.log('promiseArray:',promiseArray);
function frontendAll() {
return frontendPull().then(function(){
return frontendInstallAddons().then(function(){
return frontendBuild()
})
})
}
promiseArray.push(frontendAll());
finalizeZip();
};
function finalizeZip(){
return streamFilesToZip().then(function(){
return createZip()
}).catch(function(error) {let response =
'There was an error during your build. ' +
'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
'and add the following information: ' + error;
res.send(response);
})
}
function streamFilesToZip(){
console.log('in streamFilesToZip');
return new Promise((resolve,reject)=> {
Promise.all(promiseArray).then(files => {
console.log('in promise.all: promiseArray', promiseArray);
console.log('in Promise.all');
let finishedArray=[];
files.forEach(file => {
if (file.zipFileName === 'backend.war'){
backendStream = fs.createReadStream(file.path);
zip.file(file.zipFileName, backendStream);
const backendSteam = fsReaddir(file.path).on('data', function(data){
const backendReadStream = fs.createReadStream(data);
zip.file(zipFileName, backendReadStream);
}).on('error', function(){
console.log('error:', error);
}).on('finish', function(){
finishedArray.push('backend finished');
if(finishedArray.length === files.length){
resolve();
}
})
// backendStream = fs.createReadStream(file.path);
// zip.file(file.zipFileName, backendStream);
// finishedArray.push('backend done');
}
if(file.zipFileName === 'frontend'){
console.log('zipFileName: frontend', file.zipFileName);
const stream = fsReaddir(file.path)
.on('error', function(err) {
console.log('error:', err);
}).on('data', function(data){
for (let i=0; i<data.length; i++) {
const frontendStream = fs.createReadStream(data[i]);
console.log('frontend data[i]', data[i]);
zip.file(data[i], frontendStream);
}
}).on('finish', function(){
finishedArray.push('frontend finished');
if(finishedArray.length === files.length){
resolve();
}
})
}
});
})
})
})
};
function createZip(){
console.log('in createZip');
return new Promise((resolve,reject) => {
zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('finish', function () {
console.log('explorviz-builds.zip written.');
res.download('explorviz-builds.zip');
});
}).catch(function(error) {let response =
'There was an error during your build. ' +
'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
'and add the following information: ' + error;
res.send(response);
})
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment