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
ba6763e3
Commit
ba6763e3
authored
7 years ago
by
Josefine Wegert
Browse files
Options
Downloads
Patches
Plain Diff
work in progress: part of downloader for backend
parent
027d1598
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
+185
-95
185 additions, 95 deletions
app.js
with
185 additions
and
95 deletions
app.js
+
185
−
95
View file @
ba6763e3
...
...
@@ -31,22 +31,22 @@
//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!
//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
;
};
});
//
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
){
...
...
@@ -67,6 +67,7 @@
app
.
get
(
'
/download
'
,
function
(
req
,
res
){
//holds promises for backend and/or frontend
const
promiseArray
=
[]
const
checkedFiles
=
req
.
query
.
checkedFiles
.
split
(
'
,
'
);
...
...
@@ -84,25 +85,113 @@
const
fileName
=
backendChecked
;
const
downloadURL
=
downloadFiles
[
backendChecked
];
const
backendPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
exec
(
'
git pull
'
+
'
&& cd
'
+
fileName
+
'
&& mvn compile war:war
'
,
(
error
,
stdout
,
stderr
)
=>
{
function
backendClean
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
exec
(
'
cd explorviz-ui-backend/plugins/net/explorviz/plugins/ && rm *
'
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
)
{
reject
(
error
);
return
;
}
console
.
log
(
stdout
);
console
.
log
(
stderr
);
resolve
();
})
})
}
function
backendPull
(){
if
(
error
)
{
reject
(
error
);
return
;
return
new
Promise
((
resolve
,
reject
)
=>
{
exec
(
'
cd
'
+
fileName
+
'
git pull
'
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
)
{
reject
(
error
);
return
;
}
console
.
log
(
stdout
);
console
.
log
(
stderr
);
resolve
();
});
})
}
function
backendInstallAddons
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
checkedPlugins
=
checkedFiles
.
filter
(
function
(
file
){
return
/
\b
explorviz-backend-plugin-
\w
*/
.
exec
(
file
);
});
if
(
checkedPlugins
.
length
!==
0
){
checkedPlugins
.
forEach
((
pluginName
)
=>
{
exec
(
'
git clone
'
+
downloadFiles
[
pluginName
]
+
'
cd
'
+
pluginName
+
'
cp -r . explorviz-ui-backend/plugins/net/explorviz/plugins/
'
,
(
error
,
stdout
,
stderr
)
=>
{
//'cd explorviz-ui-backend/plugins/net/explorviz/plugins/ ' +
if
(
error
)
{
reject
(
error
);
return
;
}
console
.
log
(
stdout
);
console
.
log
(
stderr
);
resolve
();
});
})
}
else
{
resolve
();
}
console
.
log
(
stdout
);
console
.
log
(
stderr
);
})
resolve
({
zipFileName
:
'
backend.war
'
,
path
:
'
explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war
'
});
});
})
}
promiseArray
.
push
(
backendPromise
);
}
function
backendBuild
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
exec
(
'
cd
'
+
fileName
+
'
&& mvn compile war:war
'
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
)
{
reject
(
error
);
return
;
}
console
.
log
(
stdout
);
console
.
log
(
stderr
);
resolve
({
zipFileName
:
'
backend.war
'
,
path
:
'
explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war
'
});
})
})
}
function
backendAll
(){
return
backendClean
().
then
(
function
(){
return
backendPull
().
then
(
function
(){
return
backendInstallAddons
().
then
(
function
(){
return
backendBuild
()
})
})
})
}
promiseArray
.
push
(
backendAll
());
finalizeZip
();
}
frontendChecked
=
checkedFiles
.
find
(
function
(
file
){
return
file
===
'
explorviz-ui-frontend
'
;
...
...
@@ -116,7 +205,8 @@
return
new
Promise
((
resolve
,
reject
)
=>
{
console
.
log
(
'
in frontendPull()
'
);
exec
(
'
cd
'
+
fileName
+
'
git pull
'
,
(
error
,
stdout
,
stderr
)
=>
{
//' git fetch origin && git reset --hard origin/master '
exec
(
'
cd
'
+
fileName
+
'
git checkout package.json && npm prune
'
+
'
&& git pull
'
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
)
{
reject
(
error
)
...
...
@@ -168,23 +258,23 @@
return
new
Promise
((
resolve
,
reject
)
=>
{
console
.
log
(
'
in frontendBuild()
'
);
exec
(
'
cd
'
+
fileName
+
'
&& ember build --environment=production
'
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
)
{
reject
(
error
);
return
;
}
exec
(
'
cd
'
+
fileName
+
'
&& ember build --environment=production
'
,
(
error
,
stdout
,
stderr
)
=>
{
console
.
log
(
stdout
);
console
.
log
(
stderr
);
if
(
error
)
{
reject
(
error
);
return
;
}
resolve
({
zipFileName
:
'
frontend
'
,
path
:
'
./explorviz-ui-frontend/dist/
'
});
});
console
.
log
(
stdout
);
console
.
log
(
stderr
);
resolve
({
zipFileName
:
'
frontend
'
,
path
:
'
./explorviz-ui-frontend/dist/
'
});
});
})
})
}
function
frontendAll
()
{
...
...
@@ -195,95 +285,95 @@
})
})
}
//frontend was selected and the next step (streaming to zip) has to wait until the frontend is built
promiseArray
.
push
(
frontendAll
());
finalizeZip
();
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
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
'
);
function
streamFilesToZip
(){
console
.
log
(
'
in streamFilesToZip
'
);
return
new
Promise
((
resolve
,
reject
)
=>
{
Promise
.
all
(
promiseArray
).
then
(
files
=>
{
console
.
log
(
'
in Promise.all
'
);
let
finishedArray
=
[];
files
.
forEach
(
file
=>
{
if
(
file
.
zipFileName
===
'
backend.war
'
){
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
();
}
})
return
new
Promise
((
resolve
,
reject
)
=>
{
Promise
.
all
(
promiseArray
).
then
(
files
=>
{
console
.
log
(
'
in Promise.all
'
);
let
finishedArray
=
[];
files
.
forEach
(
file
=>
{
if
(
file
.
zipFileName
===
'
backend.war
'
){
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
'
){
const
s
tream
=
fsReaddir
(
file
.
path
)
const
frontendS
tream
=
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
);
const
frontend
Reads
Stream
=
fs
.
createReadStream
(
data
[
i
]);
zip
.
file
(
data
[
i
],
frontend
Read
Stream
);
}
}).
on
(
'
finish
'
,
function
(){
finishedArray
.
push
(
'
frontend finished
'
);
if
(
finishedArray
.
length
===
files
.
length
){
resolve
();
}
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
'
);
});
})
})
};
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
'
);
});
}
})
}
...
...
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