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
e854c7e7
Commit
e854c7e7
authored
7 years ago
by
Josefine Wegert
Browse files
Options
Downloads
Patches
Plain Diff
refactoring of zip functions
parent
38771f07
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.js
+2
-85
2 additions, 85 deletions
app.js
zipFunctions.js
+91
-0
91 additions, 0 deletions
zipFunctions.js
with
93 additions
and
85 deletions
app.js
+
2
−
85
View file @
e854c7e7
...
...
@@ -6,7 +6,6 @@ var execSync = require('child_process').execSync;
var
fs
=
require
(
'
fs
'
);
var
path
=
require
(
'
path
'
);
var
fsReaddir
=
require
(
'
fs-readdir
'
);
var
Zip
=
require
(
'
node-zip
'
);
var
JSZip
=
require
(
'
jszip
'
);
var
exphbs
=
require
(
'
express-handlebars
'
);
...
...
@@ -20,6 +19,7 @@ const downloadNames = Object.keys(downloadFiles);
//load functions for frontend and backend build
let
backendFunctions
=
require
(
'
./backendFunctions.js
'
);
let
frontendFunctions
=
require
(
'
./frontendFunctions.js
'
);
let
zipFunctions
=
require
(
'
./zipFunctions.js
'
);
var
app
=
express
();
...
...
@@ -120,93 +120,10 @@ app.use(bodyParser.json());
};
finalizeZip
();
//TODO put all zip-things in zipFunctions.js;
//problem: createZip has to know the res from /download-route and if just the other functions will be exported, the zip has to be passed to createZip with resolve()
// create a file to stream archive data to.
const
zip
=
new
JSZip
();
zip
.
file
(
"
README.txt
"
,
"
text for README
"
);
let
finishedArray
=
[];
function
streamFilesToZip
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
Promise
.
all
(
promiseArray
).
then
(
files
=>
{
files
.
forEach
(
file
=>
{
if
(
file
.
zipFileName
===
'
backend.war
'
){
fs
.
readFileAsync
=
function
(
filePath
){
return
new
Promise
(
function
(
resolve
,
reject
)
{
fs
.
readFile
(
filePath
,
function
(
err
,
data
)
{
if
(
err
)
{
reject
(
err
);
}
else
{
resolve
(
data
);
}
});
});
}
function
addBackendToZip
(
data
){
return
new
Promise
(
function
(
resolve
,
reject
){
zip
.
file
(
file
.
zipFileName
,
data
);
resolve
();
})
}
console
.
log
(
'
in backend.war
'
);
backendContent
=
fs
.
readFileAsync
(
file
.
path
);
backendContent
.
then
(
function
(
data
){
addBackendToZip
(
data
).
then
(
function
(){
finishedArray
.
push
(
'
backend finished
'
);
if
(
finishedArray
.
length
===
promiseArray
.
length
){
resolve
(
zip
);
}
})
})
}
if
(
file
.
zipFileName
===
'
frontend
'
){
const
frontendStream
=
fsReaddir
(
file
.
path
)
.
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
'
error:
'
,
err
);
}).
on
(
'
data
'
,
function
(
data
){
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
const
frontendReadStream
=
fs
.
createReadStream
(
data
[
i
]);
zip
.
file
(
data
[
i
],
frontendReadStream
);
}
}).
on
(
'
finish
'
,
function
(){
finishedArray
.
push
(
'
frontend finished
'
);
if
(
finishedArray
.
length
===
promiseArray
.
length
){
resolve
(
zip
);
}
console
.
log
(
'
finishedArray in frontend:
'
,
finishedArray
);
})
}
})
})
})
}
function
finalizeZip
(){
return
streamFilesToZip
().
then
(
function
(
zip
){
return
zipFunctions
.
streamFilesToZip
(
promiseArray
).
then
(
function
(
zip
){
return
createZip
(
zip
)
}).
catch
(
function
(
error
)
{
let
response
=
'
There was an error during your build.
'
+
...
...
This diff is collapsed.
Click to expand it.
zipFunctions.js
0 → 100644
+
91
−
0
View file @
e854c7e7
var
express
=
require
(
'
express
'
);
var
fs
=
require
(
'
fs
'
);
var
fsReaddir
=
require
(
'
fs-readdir
'
);
var
JSZip
=
require
(
'
jszip
'
);
const
zip
=
new
JSZip
();
zip
.
file
(
"
README.txt
"
,
"
text for README
"
);
let
finishedArray
=
[];
function
streamFilesToZip
(
promiseArray
){
return
new
Promise
((
resolve
,
reject
)
=>
{
Promise
.
all
(
promiseArray
).
then
(
files
=>
{
files
.
forEach
(
file
=>
{
if
(
file
.
zipFileName
===
'
backend.war
'
){
fs
.
readFileAsync
=
function
(
filePath
){
return
new
Promise
(
function
(
resolve
,
reject
)
{
fs
.
readFile
(
filePath
,
function
(
err
,
data
)
{
if
(
err
)
{
reject
(
err
);
}
else
{
resolve
(
data
);
}
});
});
}
function
addBackendToZip
(
data
){
return
new
Promise
(
function
(
resolve
,
reject
){
zip
.
file
(
file
.
zipFileName
,
data
);
resolve
();
})
}
console
.
log
(
'
in backend.war
'
);
backendContent
=
fs
.
readFileAsync
(
file
.
path
);
backendContent
.
then
(
function
(
data
){
addBackendToZip
(
data
).
then
(
function
(){
finishedArray
.
push
(
'
backend finished
'
);
if
(
finishedArray
.
length
===
promiseArray
.
length
){
resolve
(
zip
);
}
})
})
}
if
(
file
.
zipFileName
===
'
frontend
'
){
const
frontendStream
=
fsReaddir
(
file
.
path
)
.
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
'
error:
'
,
err
);
}).
on
(
'
data
'
,
function
(
data
){
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
const
frontendReadStream
=
fs
.
createReadStream
(
data
[
i
]);
zip
.
file
(
data
[
i
],
frontendReadStream
);
}
}).
on
(
'
finish
'
,
function
(){
finishedArray
.
push
(
'
frontend finished
'
);
if
(
finishedArray
.
length
===
promiseArray
.
length
){
resolve
(
zip
);
}
console
.
log
(
'
finishedArray in frontend:
'
,
finishedArray
);
})
}
})
})
})
}
module
.
exports
=
{
streamFilesToZip
}
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