FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/install.js at v0.2.1 · nodegit/nodegit · GitHub
nodegit
nodegit
Repository navigation
Code
Issues
344
(344)
Pull requests
21
(21)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
install.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
199 lines (169 loc) · 5.37 KB
Breadcrumbs
nodegit
/
install.js
Copy path
File metadata and controls
199 lines (169 loc) · 5.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
var
os
=
require
(
"os"
)
;
var
path
=
require
(
"path"
)
;
var
zlib
=
require
(
"zlib"
)
;
var
tar
=
require
(
"tar"
)
;
var
Promise
=
require
(
"nodegit-promise"
)
;
var
promisify
=
require
(
"promisify-node"
)
;
var
request
=
require
(
"request"
)
;
var
fse
=
promisify
(
require
(
"fs-extra"
)
)
;
fse
.
ensureDir
=
promisify
(
fse
.
ensureDir
)
;
var
exec
=
promisify
(
function
(
command
,
opts
,
callback
)
{
return
require
(
"child_process"
)
.
exec
(
command
,
opts
,
callback
)
;
}
)
;
var
NODE_VERSION
=
Number
(
process
.
version
.
match
(
/
^
v
(
\d
+
\.
\d
+
)
/
)
[
1
]
)
;
// If the build only flag is set.
var
buildOnly
=
process
.
env
.
BUILD_ONLY
;
// This will take in an object and find any matching keys in the environment
// to use as overrides.
//
// ENV variables:
//
// PKG: Location of `package.json` sans `.json`.
// LIBGIT2: Location of libgit2 source.
// BUILD: Location of nodegit build directory.
function
envOverride
(
obj
)
{
// Look through all keys.
return
Object
.
keys
(
obj
)
.
reduce
(
function
(
obj
,
key
)
{
var
normalize
=
key
.
toUpperCase
(
)
;
// Check for process environment existence.
if
(
normalize
in
process
.
env
)
{
obj
[
key
]
=
process
.
env
[
normalize
]
;
}
return
obj
;
}
,
obj
)
;
}
// Convert to the correct system path.
function
systemPath
(
parts
)
{
return
parts
.
join
(
path
.
sep
)
;
}
// Will be used near the end to configure `node-gyp`.
var
pythonPath
=
'/usr/bin/python'
;
var
local
=
path
.
join
.
bind
(
path
,
__dirname
)
;
// Common reusable paths that can be overwritten by environment variables.
var
paths
=
envOverride
(
{
pkg
:
local
(
"package"
)
,
libgit2
:
local
(
"vendor/libgit2/"
)
,
libssh2
:
local
(
"vendor/libssh2/"
)
,
http_parser
:
local
(
"vendor/http_parser/"
)
,
sys
:
{
include
:
local
(
"include/sys/"
)
,
src
:
local
(
"src/sys/"
)
,
build
:
local
(
"build/Release/obj.target/src/sys/"
)
}
,
release
:
local
(
"build/Release/"
)
}
)
;
// Load the package.json.
var
pkg
=
require
(
paths
.
pkg
)
;
if
(
NODE_VERSION
===
0.1
)
{
pkg
.
http_parser
=
pkg
.
http_parser
[
"0.10"
]
;
}
fse
.
ensureDir
(
path
.
resolve
(
__dirname
,
paths
.
release
)
)
.
then
(
fetch
)
.
then
(
finish
,
compile
)
.
done
(
)
function
fetch
(
)
{
if
(
!
buildOnly
)
{
console
.
info
(
"[nodegit] Fetching binary from S3."
)
;
// Using the node-pre-gyp module, attempt to fetch a compatible build.
return
exec
(
"node-pre-gyp install"
)
;
}
throw
new
Error
(
"BUILD_ONLY is set to true, no fetching allowed."
)
;
}
function
compile
(
)
{
if
(
!
buildOnly
)
{
console
.
info
(
"[nodegit] Failed to install prebuilt, attempting compile."
)
;
}
console
.
info
(
"[nodegit] Determining dependencies."
)
;
return
python
(
)
.
then
(
getVendorLib
(
"libgit2"
,
"https://github.com/libgit2/libgit2/tarball/"
+
pkg
.
libgit2
.
sha
)
)
.
then
(
getVendorLib
(
"libssh2"
,
pkg
.
libssh2
.
url
)
)
.
then
(
getVendorLib
(
"http_parser"
,
pkg
.
http_parser
.
url
)
)
.
then
(
buildNative
)
.
then
(
finish
,
fail
)
;
}
function
python
(
)
{
return
exec
(
"which python2"
)
.
then
(
function
(
which
)
{
return
which
;
}
,
function
(
err
)
{
return
null
;
}
)
.
then
(
function
(
path
)
{
return
path
||
exec
(
"which python"
)
;
}
)
.
then
(
function
(
which
)
{
return
which
;
}
,
function
(
err
)
{
return
null
;
}
)
.
then
(
function
(
path
)
{
pythonPath
=
path
.
trim
(
)
;
if
(
!
pythonPath
)
{
throw
new
Error
(
"Python is required to build libgit2."
)
;
}
}
)
.
then
(
function
(
)
{
return
exec
(
pythonPath
+
" -V 2>&1"
)
;
}
)
.
then
(
function
(
version
)
{
if
(
version
[
1
]
.
indexOf
(
"Python 3"
)
===
0
)
{
throw
new
Error
(
"Incorrect version of Python, gyp requires < 3."
)
;
}
}
)
;
}
function
getVendorLib
(
name
,
url
)
{
return
function
(
)
{
var
version
=
pkg
[
name
]
.
sha
||
pkg
[
name
]
.
version
;
console
.
info
(
"[nodegit] Detecting vendor/"
+
name
+
"."
)
;
if
(
fse
.
existsSync
(
paths
[
name
]
+
version
)
)
{
console
.
info
(
"[nodegit] vendor/"
+
name
+
" already exists."
)
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
resolve
(
)
}
)
;
}
else
{
console
.
info
(
"[nodegit] Removing outdated vendor/"
+
name
+
"."
)
;
return
fse
.
remove
(
paths
[
name
]
)
.
then
(
function
(
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
console
.
info
(
"[nodegit] Fetching vendor/"
+
name
+
"."
)
;
var
extract
=
tar
.
Extract
(
{
path
:
paths
[
name
]
,
strip
:
true
}
)
;
request
.
get
(
url
)
.
pipe
(
zlib
.
createUnzip
(
)
)
.
pipe
(
extract
)
.
on
(
"error"
,
reject
)
.
on
(
"end"
,
resolve
)
;
}
)
;
}
)
.
then
(
function
(
)
{
return
fse
.
writeFile
(
paths
[
name
]
+
version
,
""
)
;
}
)
.
then
(
function
(
)
{
if
(
(
name
==
"libssh2"
)
&&
(
process
.
platform
!==
"win32"
)
)
{
return
exec
(
paths
[
name
]
+
"configure"
,
{
cwd
:
paths
[
name
]
}
)
;
}
}
)
;
}
}
}
function
buildNative
(
)
{
return
exec
(
"cd "
+
__dirname
)
.
then
(
function
(
)
{
console
.
info
(
"[nodegit] Building native node module."
)
;
var
pythonFlag
=
" --python \""
+
pythonPath
+
"\""
;
var
cmd
=
path
.
resolve
(
systemPath
(
[
"."
,
"node_modules"
,
".bin"
,
"node-gyp clean configure build"
+
pythonFlag
]
)
)
;
var
opts
=
{
cwd
:
__dirname
,
maxBuffer
:
Number
.
MAX_VALUE
}
;
return
exec
(
cmd
,
opts
)
;
}
)
}
function
finish
(
)
{
console
.
info
(
"[nodegit] Completed installation successfully."
)
;
return
Promise
.
resolve
(
)
.
done
(
)
;
}
function
fail
(
message
)
{
console
.
info
(
"[nodegit] Failed to build and install nodegit."
)
;
console
.
info
(
message
.
message
)
;
//console.info(message.stack);
return
Promise
.
resolve
(
)
.
done
(
)
;
}
Back
|
FazBrowse Home
|
New Git URL