Skip to content

Commit 2d71044

Browse files
committed
Updated install script
1 parent e887670 commit 2d71044

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

install.js

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
var async = require('async'),
22
child_process = require('child_process'),
33
spawn = child_process.spawn,
4-
path = require('path');
4+
path = require('path'),
5+
fs = require('fs'),
6+
request = require('request'),
7+
AdmZip = require('adm-zip');
58

69
function passthru() {
710
var args = Array.prototype.slice.call(arguments);
@@ -27,14 +30,62 @@ function envpassthru() {
2730
passthru.apply(null, ['/usr/bin/env'].concat(Array.prototype.slice.call(arguments)));
2831
}
2932

33+
var updateSubmodules = function(mainCallback) {
34+
console.log('[nodegit] Downloading libgit2 dependency.');
35+
async.series([
36+
function(callback) {
37+
envpassthru('git', 'submodule', 'init', callback);
38+
}, function(callback) {
39+
envpassthru('git', 'submodule', 'update', callback);
40+
}
41+
], function(error) {
42+
if (error) process.exit(error);
43+
mainCallback();
44+
});
45+
};
46+
47+
var checkoutDependencies = function(mainCallback) {
48+
console.log('[nodegit] Downloading libgit2 dependency.');
49+
50+
var libgit2ZipUrl = 'https://github.com/libgit2/libgit2/archive/v0.15.0.zip';
51+
zipFile = __dirname + '/vendor/libgit2.zip',
52+
unzippedFolderName = __dirname + '/vendor/libgit2-0.15.0',
53+
targetFolderName = __dirname + '/vendor/libgit2';
54+
55+
async.series([
56+
function(callback) {
57+
request(libgit2ZipUrl)
58+
.pipe(fs.createWriteStream(zipFile))
59+
.on('close', function () {
60+
callback();
61+
});
62+
63+
}, function(callback) {
64+
var zip = new AdmZip(zipFile);
65+
zip.extractAllTo(__dirname + '/vendor/', true);
66+
fs.unlink(zipFile);
67+
callback();
68+
},
69+
function renameLibgit2Folder(callback) {
70+
fs.rename(unzippedFolderName, targetFolderName, callback);
71+
}
72+
], function(error) {
73+
if (error) process.exit(error);
74+
mainCallback();
75+
});
76+
};
77+
3078
var buildDir = path.join(__dirname, 'vendor/libgit2/build');
3179
async.series([
3280
function(callback) {
33-
console.log('[nodegit] Downloading libgit2 dependency.');
34-
envpassthru('git', 'submodule', 'init', callback);
35-
},
36-
function(callback) {
37-
envpassthru('git', 'submodule', 'update', callback);
81+
// Check for presence of .git folder
82+
fs.exists(__dirname + '/.git', function(exists) {
83+
if (exists) {
84+
updateSubmodules(callback);
85+
} else {
86+
checkoutDependencies(callback);
87+
}
88+
});
3889
},
3990
function(callback) {
4091
console.log('[nodegit] Building libgit2 dependency.');

0 commit comments

Comments
 (0)