Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
explorviz-downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ExplorViz
explorviz-github-archive
explorviz-downloader
Commits
ce6f3a95
Commit
ce6f3a95
authored
7 years ago
by
Josefine Wegert
Browse files
Options
Downloads
Patches
Plain Diff
work in progress: promises for zip
parent
b992a4fa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.js
+88
-123
88 additions, 123 deletions
app.js
with
88 additions
and
123 deletions
app.js
+
88
−
123
View file @
ce6f3a95
...
@@ -14,10 +14,10 @@ var exphbs = require('express-handlebars');
...
@@ -14,10 +14,10 @@ var exphbs = require('express-handlebars');
//initializer
//initializer
var
nanit
=
require
(
'
nanit
'
);
var
nanit
=
require
(
'
nanit
'
);
//load names of available download files
//load names of available download files
var
downloadFiles
=
require
(
'
./downloadFiles.json
'
);
const
downloadFiles
=
require
(
'
./downloadFiles.json
'
);
var
downloadNames
=
Object
.
keys
(
downloadFiles
);
const
downloadNames
=
Object
.
keys
(
downloadFiles
);
var
app
=
express
();
let
app
=
express
();
app
.
use
(
bodyParser
.
urlencoded
({
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
extended
:
true
...
@@ -29,13 +29,13 @@ app.engine('.hbs', exphbs({extname: '.hbs'}));
...
@@ -29,13 +29,13 @@ app.engine('.hbs', exphbs({extname: '.hbs'}));
app
.
set
(
'
view engine
'
,
'
.hbs
'
);
app
.
set
(
'
view engine
'
,
'
.hbs
'
);
//initialize the git repos
//initialize the git repos
//TODO error handling is not working properly, error returned is not in
var
error, but in req + req and res are undefined!
//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){
// nanit.initialize(downloadFiles, function(req,res,err){
// // console.log('err in nanit.initialize:', err);
// // console.log('err in nanit.initialize:', err);
// // console.log('req in nanit.initialize:', req);
// // console.log('req in nanit.initialize:', req);
// // console.log('res in nanit.initialize:', res);
// // console.log('res in nanit.initialize:', res);
//
var
response =
//
let
response =
// 'There was an error during cloning the git repositories. ' +
// 'There was an error during cloning the git repositories. ' +
// 'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
// 'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
// 'and add the following information: ' + req;
// 'and add the following information: ' + req;
...
@@ -69,14 +69,11 @@ app.get('/download', function(req, res){
...
@@ -69,14 +69,11 @@ app.get('/download', function(req, res){
const
promiseArray
=
[]
const
promiseArray
=
[]
const
checkedFiles
=
req
.
query
.
checkedFiles
.
split
(
'
,
'
);
const
checkedFiles
=
req
.
query
.
checkedFiles
.
split
(
'
,
'
);
const
zip
=
new
JSZip
();
// create a file to stream archive data to.
// create a file to stream archive data to.
const
zip
=
new
JSZip
();
zip
.
file
(
"
README.txt
"
,
"
text for README
"
);
zip
.
file
(
"
README.txt
"
,
"
text for README
"
);
var
frontendFinished
=
false
;
var
backendFinished
=
false
;
//----------------------------------------------------------------backend
backendChecked
=
checkedFiles
.
find
(
function
(
file
){
backendChecked
=
checkedFiles
.
find
(
function
(
file
){
return
file
===
'
explorviz-ui-backend
'
;
return
file
===
'
explorviz-ui-backend
'
;
});
});
...
@@ -86,30 +83,26 @@ if (backendChecked){
...
@@ -86,30 +83,26 @@ if (backendChecked){
const
fileName
=
backendChecked
;
const
fileName
=
backendChecked
;
const
downloadURL
=
downloadFiles
[
backendChecked
];
const
downloadURL
=
downloadFiles
[
backendChecked
];
const
backendPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
const
backendPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
exec
(
'
git pull
'
+
'
&& cd
'
+
fileName
+
'
&& mvn compile war:war
'
,
(
error
,
stdout
,
stderr
)
=>
{
exec
(
'
git pull
'
+
'
&& cd
'
+
fileName
+
'
&& mvn compile war:war
'
,
(
error
,
stdout
,
stderr
)
=>
{
//addBackend();
console
.
log
(
'
error in exec
'
,
error
);
if
(
error
)
{
if
(
error
)
{
reject
(
error
);
reject
(
error
);
// res.send(response); beim promise.all
return
;
return
;
}
}
console
.
log
(
stdout
);
console
.
log
(
stdout
);
console
.
log
(
stderr
);
console
.
log
(
stderr
);
resolve
({
fileName
:
"
backend.war
"
,
path
:
"
explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war
"
});
resolve
({
zipFileName
:
'
backend.war
'
,
path
:
'
explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war
'
});
});
});
})
})
promiseArray
.
push
(
backendPromise
);
promiseArray
.
push
(
backendPromise
);
console
.
log
(
'
promiseArray:
'
,
promiseArray
);
console
.
log
(
'
promiseArray:
'
,
promiseArray
);
}
}
//--------------------------------------------------------------------------------frontend
frontendChecked
=
checkedFiles
.
find
(
function
(
file
){
frontendChecked
=
checkedFiles
.
find
(
function
(
file
){
return
file
===
'
explorviz-ui-frontend
'
;
return
file
===
'
explorviz-ui-frontend
'
;
...
@@ -119,123 +112,113 @@ if (frontendChecked){
...
@@ -119,123 +112,113 @@ if (frontendChecked){
const
fileName
=
frontendChecked
;
const
fileName
=
frontendChecked
;
const
downloadURL
=
downloadFiles
[
frontendChecked
];
const
downloadURL
=
downloadFiles
[
frontendChecked
];
exec
(
'
git pull
'
,
(
error
,
stdout
,
stderr
)
=>
{
const
frontendPullPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
installAddons
();
console
.
log
(
'
resolve frontendPullPromise
'
,
resolve
);
var
response
=
exec
(
'
cd
'
+
fileName
+
'
git pull
'
,
(
error
,
stdout
,
stderr
)
=>
{
'
There was an error during your build.
'
+
'
Please contact "explorviz-developers-request@listserv.dfn.de"
'
+
'
and add the following information:
'
+
error
;
if
(
error
)
{
if
(
error
)
{
re
s
.
send
(
response
);
re
ject
(
error
)
return
;
return
;
}
}
});
console
.
log
(
stdout
);
console
.
log
(
stderr
);
resolve
();
});
})
promiseArray
.
push
(
frontendPullPromise
);
console
.
log
(
'
promiseArray.push(frontendPullPromise):
'
,
promiseArray
);
};
function
installAddons
(){
// const frontendInstallAddons = frontendPullPromise.then((resolve, reject) => {
console
.
log
(
'
in installAddons()
'
);
checkedPlugins
=
checkedFiles
.
filter
(
function
(
file
){
return
/
\b
explorviz-frontend-plugin-
\w
*/
.
exec
(
file
);
});
checkedPlugins
.
forEach
((
pluginName
)
=>
{
// console.log('in installAddons()');
exec
(
'
cd
'
+
'
explorviz-ui-frontend
'
+
'
ember install
'
+
downloadFiles
[
pluginName
],
(
error
,
stdout
,
stderr
)
=>
{
// checkedPlugins = checkedFiles.filter(function(file){
// return /\bexplorviz-frontend-plugin-\w*/.exec(file);
var
response
=
// });
'
There was an error during your build.
'
+
// console.log('checkedPlugins', checkedPlugins);
'
Please contact "explorviz-developers-request@listserv.dfn.de"
'
+
// checkedPlugins.forEach((pluginName) => {
'
and add the following information:
'
+
error
;
// 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
)
{
// console.log(stdout);
res
.
send
(
response
);
// console.log(stderr);
return
;
}
console
.
log
(
stdout
);
// resolve({zipFileName:'Zwischenschritt2', path:'./explorviz-ui-frontend/dist/'});
console
.
log
(
stderr
);
});
//
});
});
// })
buildFrontend
();
};
// })
//promiseArray.push(frontendInstallAddons);
//console.log('promiseArray.push(frontendInstallAddons):',promiseArray);
function
buildFrontend
()
{
const
frontendBuildPromise
=
frontendPullPromise
.
then
((
resolve
)
=>
{
console
.
log
(
'
buildFrontend()
'
);
console
.
log
(
'
resolve frontendBuildPromise
'
,
resolve
);
//build everything you have
//build everything you have
exec
(
'
cd explorviz-ui-frontend && ember build --environment=production
'
,
(
error
,
stdout
,
stderr
)
=>
{
exec
(
'
cd
'
+
fileName
+
'
&& ember build --environment=production
'
,
(
error
,
stdout
,
stderr
)
=>
{
//exec('cd explorviz-ui-frontend', (error, stdout, stderr) => {
addFrontend
();
// if (error) {
// reject(error);
// return;
// }
console
.
log
(
stdout
);
console
.
log
(
stderr
);
var
response
=
resolve
({
zipFileName
:
'
frontend
'
,
path
:
'
./explorviz-ui-frontend/dist/
'
});
'
There was an error during your build.
'
+
});
'
Please contact "explorviz-developers-request@listserv.dfn.de"
'
+
'
and add the following information:
'
+
error
;
if
(
error
)
{
res
.
send
(
response
);
return
;
}
console
.
log
(
stdout
);
console
.
log
(
stderr
);
});
})
};
// ------------------------------------------ember build
console
.
log
(
'
frontendBuildPromise:
'
,
frontendBuildPromise
);
promiseArray
.
push
(
frontendBuildPromise
);
console
.
log
(
'
promiseArray:
'
,
promiseArray
);
// function addBackend(){
// // read a file as a stream and add it to a zip
// console.log('addBackend()');
// const backendStream = fs.createReadStream("explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war");
// zip.file("backend.war", backendStream);
// backendFinished = true;
// createZip();
// };
function
addFrontend
(){
console
.
log
(
"
in addFrontend
"
);
var
stream
=
fsReaddir
(
'
./explorviz-ui-frontend/dist/
'
)
.
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
'
error:
'
,
err
);
}).
on
(
'
data
'
,
function
(
data
){
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
const
frontendStream
=
fs
.
createReadStream
(
data
[
i
]);
zip
.
file
(
data
[
i
],
frontendStream
);
}
}).
on
(
'
finish
'
,
function
(){
frontendFinished
=
true
;
createZip
();
});
};
};
Promise
.
all
(
promiseArray
).
then
(
files
=>
{
//if (files.fileName === "backend.war"){
console
.
log
(
'
files.path
'
,
files
.
path
);
console
.
log
(
'
files.fileName
'
,
files
.
fileName
);
backendStream
=
fs
.
createReadStream
(
files
.
path
);
zip
.
file
(
files
.
fileName
,
backendStream
);
Promise
.
all
(
promiseArray
).
then
(
files
=>
{
console
.
log
(
'
in promise.all: promiseArray
'
,
promiseArray
);
files
.
forEach
(
file
=>
{
if
(
file
.
zipFileName
===
'
backend.war
'
){
backendStream
=
fs
.
createReadStream
(
file
.
path
);
zip
.
file
(
file
.
zipFileName
,
backendStream
);
}
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
]);
zip
.
file
(
data
[
i
],
frontendStream
);
}
})
}
});
zip
.
generateNodeStream
({
type
:
'
nodebuffer
'
,
streamFiles
:
true
}).
pipe
(
fs
.
createWriteStream
(
'
explorviz-builds.zip
'
)).
on
(
'
finish
'
,
function
()
{
zip
.
generateNodeStream
({
type
:
'
nodebuffer
'
,
streamFiles
:
true
}).
pipe
(
fs
.
createWriteStream
(
'
explorviz-builds.zip
'
)).
on
(
'
finish
'
,
function
()
{
console
.
log
(
'
explorviz-builds.zip written.
'
);
console
.
log
(
'
explorviz-builds.zip written.
'
);
res
.
download
(
'
explorviz-builds.zip
'
);
res
.
download
(
'
explorviz-builds.zip
'
);
});
});
}).
catch
(
function
(
error
)
{
let
response
=
}).
catch
(
function
(
error
)
{
let
response
=
'
There was an error during your build.
'
+
'
There was an error during your build.
'
+
'
Please contact "explorviz-developers-request@listserv.dfn.de"
'
+
'
Please contact "explorviz-developers-request@listserv.dfn.de"
'
+
'
and add the following information:
'
+
error
;
'
and add the following information:
'
+
error
;
...
@@ -243,24 +226,6 @@ zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWrite
...
@@ -243,24 +226,6 @@ zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWrite
})
})
// function createZip(){
// console.log('frontendFinished', frontendFinished);
// console.log('backendFinished', backendFinished);
// //create zip and download it
// zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('finish', function () {
// // JSZip generates a readable stream with a "end" event,
// // but is piped here in a writable stream which emits a "finish" event.
// console.log("explorviz-builds.zip written.");
// res.download('explorviz-builds.zip');
// });
// };
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment