mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 22:34:24 +00:00
extract file download
This commit is contained in:
parent
79c8c72477
commit
bee4d0e1f2
@ -4,8 +4,6 @@ let utils = require('../utils/utils.js');
|
|||||||
let fs = require('../core/fs.js');
|
let fs = require('../core/fs.js');
|
||||||
let o_fs = require('fs-extra');
|
let o_fs = require('fs-extra');
|
||||||
|
|
||||||
let http = require('follow-redirects').http;
|
|
||||||
let https = require('follow-redirects').https;
|
|
||||||
var tar = require('tar');
|
var tar = require('tar');
|
||||||
|
|
||||||
class Npm {
|
class Npm {
|
||||||
@ -30,19 +28,6 @@ class Npm {
|
|||||||
|
|
||||||
let tarball = registryJSON.dist.tarball;
|
let tarball = registryJSON.dist.tarball;
|
||||||
|
|
||||||
var download = function(url, dest, cb) {
|
|
||||||
var file = o_fs.createWriteStream(dest);
|
|
||||||
(url.substring(0,5) === 'https' ? https : http).get(url, function(response) {
|
|
||||||
response.pipe(file);
|
|
||||||
file.on('finish', function() {
|
|
||||||
file.close(cb); // close() is async, call cb after close completes.
|
|
||||||
});
|
|
||||||
}).on('error', function(err) { // Handle errors
|
|
||||||
fs.unlink(dest); // Delete the file async. (But we don't check the result)
|
|
||||||
if (cb) cb(err.message);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (getFromGit) {
|
if (getFromGit) {
|
||||||
let repoName = registryJSON.repository.url.replace("git+https://github.com/", "").replace(".git","");
|
let repoName = registryJSON.repository.url.replace("git+https://github.com/", "").replace(".git","");
|
||||||
let gitHead = registryJSON.gitHead;
|
let gitHead = registryJSON.gitHead;
|
||||||
@ -66,7 +51,7 @@ class Npm {
|
|||||||
fs.mkdirpSync(packageDirectory);
|
fs.mkdirpSync(packageDirectory);
|
||||||
self.logger.info("downloading " + packageName + " " + version + "....");
|
self.logger.info("downloading " + packageName + " " + version + "....");
|
||||||
|
|
||||||
download(fileLocation, packageDirectory + "/" + packageName + ".js", function() {
|
utils.downloadFile(fileLocation, packageDirectory + "/" + packageName + ".js", function() {
|
||||||
o_fs.createReadStream(packageDirectory + "/" + packageName + ".js").pipe(
|
o_fs.createReadStream(packageDirectory + "/" + packageName + ".js").pipe(
|
||||||
tar.x({
|
tar.x({
|
||||||
strip: 1,
|
strip: 1,
|
||||||
@ -97,7 +82,7 @@ class Npm {
|
|||||||
fs.mkdirpSync(packageDirectory);
|
fs.mkdirpSync(packageDirectory);
|
||||||
self.logger.info("downloading " + packageName + " " + version + "....");
|
self.logger.info("downloading " + packageName + " " + version + "....");
|
||||||
|
|
||||||
download(tarball, packageDirectory + "/downloaded_package.tgz", function() {
|
utils.downloadFile(tarball, packageDirectory + "/downloaded_package.tgz", function() {
|
||||||
o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe(
|
o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe(
|
||||||
tar.x({
|
tar.x({
|
||||||
strip: 1,
|
strip: 1,
|
||||||
|
@ -5,6 +5,9 @@ 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');
|
||||||
|
|
||||||
|
//let fs = require('../core/fs.js');
|
||||||
|
let o_fs = require('fs-extra');
|
||||||
|
|
||||||
function joinPath() {
|
function joinPath() {
|
||||||
return path.join.apply(path.join, arguments);
|
return path.join.apply(path.join, arguments);
|
||||||
}
|
}
|
||||||
@ -61,7 +64,19 @@ function exit(code) {
|
|||||||
process.exit(code);
|
process.exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Maybe desired to just `module.exports = this` ?
|
function downloadFile(url, dest, cb) {
|
||||||
|
var file = o_fs.createWriteStream(dest);
|
||||||
|
(url.substring(0,5) === 'https' ? https : http).get(url, function(response) {
|
||||||
|
response.pipe(file);
|
||||||
|
file.on('finish', function() {
|
||||||
|
file.close(cb);
|
||||||
|
});
|
||||||
|
}).on('error', function(err) {
|
||||||
|
o_fs.unlink(dest);
|
||||||
|
if (cb) cb(err.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
joinPath: joinPath,
|
joinPath: joinPath,
|
||||||
filesMatchingPattern: filesMatchingPattern,
|
filesMatchingPattern: filesMatchingPattern,
|
||||||
@ -73,5 +88,6 @@ module.exports = {
|
|||||||
runCmd: runCmd,
|
runCmd: runCmd,
|
||||||
cd: cd,
|
cd: cd,
|
||||||
sed: sed,
|
sed: sed,
|
||||||
exit: exit
|
exit: exit,
|
||||||
|
downloadFile: downloadFile
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user