forked from necccc/npm-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tgz.js
49 lines (39 loc) · 1.38 KB
/
tgz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const compressing = require('compressing')
const path = require('path')
const async = require('async')
const curry = require('lodash.curry')
const unpackTarball = function (tarball, callback) {
let to = tarball.replace('.tgz', '')
return compressing.tgz.uncompress(tarball, to)
.then(() => callback(null, path.resolve(to, 'package')))
.catch((err) => callback(err))
}
const packTarball = function (folder, callback) {
return compressing.tgz.compressDir(folder, path.resolve(folder, '..') + '/package.tgz')
.then(() => callback(null, folder))
.catch((err) => callback(err))
}
module.exports.unpack = function (tarballs) {
let curried_unpackTarball = curry(unpackTarball)
let series = tarballs.map((tarball) => curried_unpackTarball(tarball))
return new Promise((resolve, reject) => {
async.series(
series,
(err, results) => {
if (err) return reject(err);
resolve(results)
})
})
}
module.exports.pack = function (folders) {
let curried_packTarball = curry(packTarball)
let series = folders.map((folder) => curried_packTarball(folder))
return new Promise((resolve, reject) => {
async.series(
series,
(err, results) => {
if (err) return reject(err);
resolve(results)
})
})
}