This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
55 lines (50 loc) · 1.99 KB
/
index.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
50
51
52
53
54
55
var path = require('path')
var tar = require('tar-fs')
var fs = require('fs')
/**
* Installs git binaries and updates this process's PATH to include
* them, so you can child_process.exec('git') successfully.
*
* Git bundle is extracted to the the target directory. This defaults to
* /tmp/git, but can be set with the `targetDirectory` option.
*
* The current process's path is prefixed with the binary folder, and other
* required env vars for Git are set. If you set `updateEnv` to false in
* your options then no changes will be made an object will be returned
* instead including `binPath` (the path to the binaries folder) and `env`,
* a set of required environmental variables.
*/
module.exports = function installGit(options) {
return new Promise((resolve) => {
options = options || {}
var targetDirectory = options.targetDirectory || '/tmp/git'
var updateEnv = (options.updateEnv !== undefined) ? options.updateEnv : true
var reader = fs.createReadStream(path.join(__dirname, 'git-2.4.3.tar'))
reader.pipe(tar.extract(targetDirectory))
reader.on('end', done)
var GIT_TEMPLATE_DIR = path.join(targetDirectory, 'usr/share/git-core/templates')
var GIT_EXEC_PATH = path.join(targetDirectory, 'usr/libexec/git-core')
var LD_LIBRARY_PATH = path.join(targetDirectory, 'usr/lib64')
var binPath = path.join(targetDirectory, 'usr/bin')
function done() {
if (updateEnv) {
process.env.PATH = process.env.PATH + ":" + binPath
process.env.GIT_TEMPLATE_DIR = GIT_TEMPLATE_DIR
process.env.GIT_EXEC_PATH = GIT_EXEC_PATH
process.env.LD_LIBRARY_PATH = process.env.LD_LIBRARY_PATH
? process.env.LD_LIBRARY_PATH + ":" + LD_LIBRARY_PATH
: LD_LIBRARY_PATH
resolve()
} else {
resolve({
binPath: binPath,
env: {
GIT_TEMPLATE_DIR: GIT_TEMPLATE_DIR,
GIT_EXEC_PATH: GIT_EXEC_PATH,
LD_LIBRARY_PATH: LD_LIBRARY_PATH
}
})
}
}
})
}