Skip to content

Commit

Permalink
Moved zip folder utility to services/themes
Browse files Browse the repository at this point in the history
refs #9178

- it's only used for themes currently
- this is definitely a util which could be useful lib
- if we have a second use case, we can move it
  • Loading branch information
kirrg001 committed Dec 14, 2017
1 parent fc5b4dd commit 849e976
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions core/server/services/themes/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fs = require('fs-extra'),
Promise = require('bluebird'),
config = require('../../config'),
security = require('../../lib/security'),
zipFolder = require('../../utils/zip-folder'),
localUtils = require('./utils'),
LocalFileStorage = require('../../adapters/storage/LocalFileStorage');

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ class ThemeStorage extends LocalFileStorage {

fs.ensureDir(zipBasePath)
.then(function () {
return Promise.promisify(zipFolder)(themePath, zipPath);
return Promise.promisify(localUtils.zipFolder)(themePath, zipPath);
})
.then(function (length) {
res.set({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var fs = require('fs-extra');
'use strict';

module.exports = function zipFolder(folderToZip, destination, callback) {
const fs = require('fs-extra');

exports.zipFolder = function zipFolder(folderToZip, destination, callback) {
var archiver = require('archiver'),
output = fs.createWriteStream(destination),
archive = archiver.create('zip', {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ var should = require('should'), // jshint ignore:line
path = require('path'),
fs = require('fs-extra'),
extract = require('extract-zip'),
zipFolder = require('../../../server/utils/zip-folder');
themeUtils = require('../../../../server/services/themes/utils');

describe('Utils: zip-folder', 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');
describe('services/themes: theme utils', 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);
Expand All @@ -25,7 +25,7 @@ describe('Utils: zip-folder', function () {
it('ensure symlinks work', function (done) {
fs.symlink(folderToSymlink, symlinkPath);

zipFolder(symlinkPath, zipDestination, function (err) {
themeUtils.zipFolder(symlinkPath, zipDestination, function (err) {
if (err) {
return done(err);
}
Expand Down

0 comments on commit 849e976

Please sign in to comment.