-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved zip folder, read csv and package-json to lib/fs
refs #9178, refs 849e976 - i've reconsidered, these modules belong to lib - prettify package-json module
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs-extra'); | ||
|
||
module.exports = function zipFolder(folderToZip, destination, callback) { | ||
var archiver = require('archiver'), | ||
output = fs.createWriteStream(destination), | ||
archive = archiver.create('zip', {}); | ||
|
||
// If folder to zip is a symlink, we want to get the target | ||
// of the link and zip that instead of zipping the symlink | ||
if (fs.lstatSync(folderToZip).isSymbolicLink()) { | ||
folderToZip = fs.realpathSync(folderToZip); | ||
} | ||
|
||
output.on('close', function () { | ||
callback(null, archive.pointer()); | ||
}); | ||
|
||
archive.on('error', function (err) { | ||
callback(err, null); | ||
}); | ||
|
||
archive.directory(folderToZip, '/'); | ||
archive.pipe(output); | ||
archive.finalize(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var should = require('should'), // jshint ignore:line | ||
path = require('path'), | ||
fs = require('fs-extra'), | ||
extract = require('extract-zip'), | ||
fsLib = require('../../../../server/lib/fs'); | ||
|
||
describe('lib/fs: read csv', function () { | ||
const symlinkPath = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink'), | ||
folderToSymlink = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'casper'), | ||
zipDestination = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink.zip'), | ||
unzipDestination = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink-unzipped'); | ||
|
||
before(function () { | ||
fs.removeSync(symlinkPath); | ||
fs.removeSync(zipDestination); | ||
fs.removeSync(unzipDestination); | ||
}); | ||
|
||
after(function () { | ||
fs.removeSync(symlinkPath); | ||
fs.removeSync(zipDestination); | ||
fs.removeSync(unzipDestination); | ||
}); | ||
|
||
it('ensure symlinks work', function (done) { | ||
fs.symlink(folderToSymlink, symlinkPath); | ||
|
||
fsLib.zipFolder(symlinkPath, zipDestination, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
extract(zipDestination, {dir: unzipDestination}, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
fs.readdir(unzipDestination, function (err, files) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
files.length.should.eql(12); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |