mirror of https://github.com/embarklabs/embark.git
extract tar extraction code
This commit is contained in:
parent
8e62a1f2e9
commit
a216aa980f
|
@ -2,9 +2,6 @@
|
||||||
// TODO: this is horrible and needs to be refactored ASAP
|
// TODO: this is horrible and needs to be refactored ASAP
|
||||||
let utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
let fs = require('../core/fs.js');
|
let fs = require('../core/fs.js');
|
||||||
let o_fs = require('fs-extra');
|
|
||||||
|
|
||||||
var tar = require('tar');
|
|
||||||
|
|
||||||
class Npm {
|
class Npm {
|
||||||
|
|
||||||
|
@ -46,19 +43,14 @@ class Npm {
|
||||||
self.logger.info("downloading " + packageName + " " + version + "....");
|
self.logger.info("downloading " + packageName + " " + version + "....");
|
||||||
|
|
||||||
utils.downloadFile(fileLocation, packageDirectory + "/" + packageName + ".js", function() {
|
utils.downloadFile(fileLocation, packageDirectory + "/" + packageName + ".js", function() {
|
||||||
o_fs.createReadStream(packageDirectory + "/" + packageName + ".js").pipe(
|
utils.extractTar(packageDirectory + "/" + packageName + ".js", packageDirectory, function() {
|
||||||
tar.x({
|
|
||||||
strip: 1,
|
|
||||||
C: packageDirectory
|
|
||||||
}).on('end', function() {
|
|
||||||
if (returnContent) {
|
if (returnContent) {
|
||||||
let distFile = packageDirectory + packageName + ".js";
|
let distFile = packageDirectory + packageName + ".js";
|
||||||
callback(fs.readFileSync(distFile).toString());
|
callback(fs.readFileSync(distFile).toString());
|
||||||
} else {
|
} else {
|
||||||
callback(packageDirectory);
|
callback(packageDirectory);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,19 +69,14 @@ class Npm {
|
||||||
self.logger.info("downloading " + packageName + " " + version + "....");
|
self.logger.info("downloading " + packageName + " " + version + "....");
|
||||||
|
|
||||||
utils.downloadFile(tarball, packageDirectory + "/downloaded_package.tgz", function() {
|
utils.downloadFile(tarball, packageDirectory + "/downloaded_package.tgz", function() {
|
||||||
o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe(
|
utils.extractTar(packageDirectory + "/downloaded_package.tgz", packageDirectory, function() {
|
||||||
tar.x({
|
|
||||||
strip: 1,
|
|
||||||
C: packageDirectory
|
|
||||||
}).on('end', function() {
|
|
||||||
if (returnContent) {
|
if (returnContent) {
|
||||||
let distFile = packageDirectory + returnContent;
|
let distFile = packageDirectory + returnContent;
|
||||||
callback(fs.readFileSync(distFile).toString());
|
callback(fs.readFileSync(distFile).toString());
|
||||||
} else {
|
} else {
|
||||||
callback(packageDirectory);
|
callback(packageDirectory);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ let merge = require('merge');
|
||||||
let http = require('follow-redirects').http;
|
let http = require('follow-redirects').http;
|
||||||
let https = require('follow-redirects').https;
|
let https = require('follow-redirects').https;
|
||||||
let shelljs = require('shelljs');
|
let shelljs = require('shelljs');
|
||||||
|
var tar = require('tar');
|
||||||
|
|
||||||
//let fs = require('../core/fs.js');
|
//let fs = require('../core/fs.js');
|
||||||
let o_fs = require('fs-extra');
|
let o_fs = require('fs-extra');
|
||||||
|
@ -92,6 +93,17 @@ function downloadFile(url, dest, cb) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractTar(filename, packageDirectory, cb) {
|
||||||
|
o_fs.createReadStream(filename).pipe(
|
||||||
|
tar.x({
|
||||||
|
strip: 1,
|
||||||
|
C: packageDirectory
|
||||||
|
}).on('end', function() {
|
||||||
|
cb();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
joinPath: joinPath,
|
joinPath: joinPath,
|
||||||
filesMatchingPattern: filesMatchingPattern,
|
filesMatchingPattern: filesMatchingPattern,
|
||||||
|
@ -104,5 +116,6 @@ module.exports = {
|
||||||
cd: cd,
|
cd: cd,
|
||||||
sed: sed,
|
sed: sed,
|
||||||
exit: exit,
|
exit: exit,
|
||||||
downloadFile: downloadFile
|
downloadFile: downloadFile,
|
||||||
|
extractTar: extractTar
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue