Skip to content

Commit a7ee51c

Browse files
committed
start prepublishing generation
1 parent ca1e873 commit a7ee51c

File tree

4 files changed

+120
-63
lines changed

4 files changed

+120
-63
lines changed

.npmignore

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
/doc/
1+
/build/
22
/example/
3-
/node_modules/
3+
/generate/
44
/test/
5+
/vendor/libgit2/
6+
/vendor/libssh2/
7+
/vendor/http_parser/
8+
/vendor/Release/
9+
10+
.astylerc
11+
.editorconfig
12+
.gitignore
13+
.gitmodules
14+
.jshintrc
15+
.travis.yml
16+
.appveyor.yml
17+
18+
*.vcxproj
19+
*.filters
20+
*.sln
21+
*.log
22+
*.md

install.js

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function systemPath(parts) {
4848
}
4949

5050
// Will be used near the end to configure `node-gyp`.
51-
var pythonPath = '/usr/bin/python';
51+
var pythonPath = "";
5252

5353
var local = path.join.bind(path, __dirname);
5454

@@ -58,12 +58,7 @@ var paths = envOverride({
5858
libgit2: local("vendor/libgit2/"),
5959
libssh2: local("vendor/libssh2/"),
6060
http_parser: local("vendor/http_parser/"),
61-
sys: {
62-
include: local("include/sys/"),
63-
src: local("src/sys/"),
64-
build: local("build/Release/obj.target/src/sys/")
65-
},
66-
release: local("build/Release/")
61+
release: local("build/Release/"),
6762
});
6863

6964
// Load the package.json.
@@ -76,8 +71,7 @@ if (NODE_VERSION === 0.1) {
7671
fse.ensureDir(path.resolve(__dirname, paths.release))
7772
.then(detectNodeWebkit.call(null, __dirname))
7873
.then(fetch)
79-
.then(finish, compile)
80-
.done()
74+
.then(finish, compile);
8175

8276
function fetch() {
8377
console.info("[nodegit] Fetching binary from S3.");
@@ -104,83 +98,103 @@ function compile(err) {
10498

10599
console.info("[nodegit] Determining dependencies.");
106100

107-
return python()
108-
.then(getVendorLib("libgit2", "https://github.com/libgit2/libgit2/tarball/" + pkg.libgit2.sha))
109-
.then(getVendorLib("libssh2", pkg.libssh2.url))
110-
.then(getVendorLib("http_parser", pkg.http_parser.url))
111-
.then(buildNative)
112-
.then(finish, fail);
113-
101+
return Promise.all([
102+
python(),
103+
getVendorLib("libgit2", "https://github.com/libgit2/libgit2/tarball/" + pkg.libgit2.sha),
104+
getVendorLib("libssh2", pkg.libssh2.url),
105+
getVendorLib("http_parser", pkg.http_parser.url),
106+
guardGenerated()
107+
])
108+
.then(buildNative)
109+
.then(finish, fail);
114110
}
115111

116112
function python() {
117-
return exec("which python2")
113+
var pathFinderCommand = process.platform === "win32" ? "where" : "which";
114+
115+
return exec(pathFinderCommand + " python2")
118116
.then(function(which){
119117
return which;
120118
}, function(err) {
121119
return null;
122120
})
123121
.then(function(path) {
124-
return path || exec("which python");
122+
return path || exec(pathFinderCommand + " python");
125123
})
126-
.then(function(which) {
127-
return which;
124+
.then(function(path) {
125+
return path;
128126
}, function(err) {
129127
return null;
130128
})
131129
.then(function(path) {
132-
pythonPath = path.trim();
133-
if (!pythonPath) {
130+
if (!path) {
134131
throw new Error("Python is required to build libgit2.");
135132
}
133+
return path.trim();
134+
}, function(err) {
135+
throw new Error("Error finding python.");
136136
})
137-
.then(function() {
138-
return exec(pythonPath + " -V 2>&1");
137+
.then(function(path) {
138+
pythonPath = path;
139+
return exec(path + " -V 2>&1");
139140
})
140141
.then(function(version) {
141-
if (version[1].indexOf("Python 3") === 0) {
142+
if (version.trim().indexOf("Python 3") === 0) {
142143
throw new Error("Incorrect version of Python, gyp requires < 3.");
143144
}
144145
});
145146
}
146147

147148
function getVendorLib(name, url) {
148-
return function() {
149-
var version = pkg[name].sha || pkg[name].version;
150-
console.info("[nodegit] Detecting vendor/" + name + ".");
151-
if (fse.existsSync(paths[name] + version)) {
152-
console.info("[nodegit] vendor/" + name + " already exists.");
153-
return new Promise(function(resolve, reject) {resolve() });
154-
}
155-
else {
156-
console.info("[nodegit] Removing outdated vendor/" + name + ".");
157-
return fse.remove(paths[name])
158-
.then(function() {
159-
return new Promise(function (resolve, reject) {
160-
161-
console.info("[nodegit] Fetching vendor/" + name + ".");
149+
var version = pkg[name].sha || pkg[name].version;
150+
console.info("[nodegit] Detecting vendor/" + name + ".");
151+
if (fse.existsSync(paths[name] + version)) {
152+
console.info("[nodegit] vendor/" + name + " already exists.");
153+
return Promise.resolve();
154+
}
155+
else {
156+
console.info("[nodegit] Removing outdated vendor/" + name + ".");
157+
return fse.remove(paths[name])
158+
.then(function() {
159+
return new Promise(function (resolve, reject) {
162160

163-
var extract = tar.Extract({
164-
path: paths[name],
165-
strip: true
166-
});
161+
console.info("[nodegit] Fetching vendor/" + name + ".");
167162

168-
request.get(url).pipe(zlib.createUnzip()).pipe(extract)
169-
.on("error", reject)
170-
.on("end", resolve);
163+
var extract = tar.Extract({
164+
path: paths[name],
165+
strip: true
171166
});
172-
}).then(function() {
173-
return fse.writeFile(paths[name] + version, "");
174-
}).then(function() {
175-
if ((name == "libssh2") && (process.platform !== "win32")) {
176167

177-
return exec(paths[name] + "configure", {cwd: paths[name]});
178-
}
168+
request.get(url).pipe(zlib.createUnzip()).pipe(extract)
169+
.on("error", reject)
170+
.on("end", resolve);
179171
});
180-
}
172+
}).then(function() {
173+
return fse.writeFile(paths[name] + version, "");
174+
}).then(function() {
175+
if ((name == "libssh2") && (process.platform !== "win32")) {
176+
return exec(paths[name] + "configure", {cwd: paths[name]});
177+
}
178+
});
181179
}
182180
}
183181

182+
function guardGenerated() {
183+
return Promise.all([
184+
fse.stat(path.resolve(__dirname, "src/")),
185+
fse.stat(path.resolve(__dirname, "include/"))
186+
]).then(function() {
187+
return Promise.resolve();
188+
}, function() {
189+
console.info("[nodegit] C++ files not found, generating now.");
190+
console.info("[nodegit] Installing all devDependencies");
191+
return exec("npm install --ignore-scripts --dont-prepublish")
192+
.then(function() {
193+
return exec("node generate");
194+
});
195+
});
196+
}
197+
184198
function buildNative() {
185199
return exec("cd " + __dirname).then(function() {
186200
if (nodeWebkit) {
@@ -221,7 +235,21 @@ function detectNodeWebkit(directory) {
221235

222236
function finish() {
223237
console.info("[nodegit] Completed installation successfully.");
224-
return Promise.resolve().done();
238+
if (!buildOnly) {
239+
console.info("[nodegit] Cleaning up");
240+
return Promise.all([
241+
fse.remove(path.resolve(__dirname, "src")),
242+
fse.remove(path.resolve(__dirname, "include")),
243+
fse.remove(path.resolve(__dirname, "generate/output")),
244+
fse.remove(path.resolve(__dirname, paths.libgit2)),
245+
fse.remove(path.resolve(__dirname, paths.libssh2)),
246+
fse.remove(path.resolve(__dirname, paths.http_parser))
247+
// exec("npm prune --production")
248+
]).done();
249+
}
250+
else {
251+
return Promise.resolve().done();
252+
}
225253
}
226254

227255
function fail(message) {

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,8 @@
6060
"node-pre-gyp"
6161
],
6262
"dependencies": {
63-
"combyne": "~0.6.2",
6463
"find-parent-dir": "^0.3.0",
6564
"fs-extra": "^0.12.0",
66-
"istanbul": "~0.3.2",
67-
"js-beautify": "^1.5.4",
68-
"jshint": "~2.5.6",
69-
"lodash": "^2.4.1",
70-
"mocha": "~1.21.4",
7165
"nan": "~1.3.0",
7266
"node-gyp": "~1.0.2",
7367
"node-pre-gyp": "~0.5.27",
@@ -77,6 +71,14 @@
7771
"request": "~2.45.0",
7872
"tar": "~1.0.1"
7973
},
74+
"devDependencies": {
75+
"mocha": "~1.21.4",
76+
"combyne": "~0.6.2",
77+
"istanbul": "~0.3.2",
78+
"js-beautify": "^1.5.4",
79+
"jshint": "~2.5.6",
80+
"lodash": "^2.4.1"
81+
},
8082
"binary": {
8183
"module_name": "nodegit",
8284
"module_path": "./build/Release/",
@@ -91,8 +93,9 @@
9193
"generateJson": "node generate/scripts/generateJson",
9294
"generateNativeCode": "node generate/scripts/generateNativeCode",
9395
"generateMissingTests": "node generate/scripts/generateMissingTests",
96+
"prepublish": "node prepublish",
9497
"publish": "node-pre-gyp package && node-pre-gyp publish",
95-
"install": "node generate && node install",
98+
"install": "node install",
9699
"recompile": "BUILD_ONLY=true npm install",
97100
"rebuild": "BUILD_ONLY=true node generate && node-gyp configure build"
98101
}

prepublish.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var exec = require('child_process').exec;
2+
try {
3+
require("./build/Release/nodegit");
4+
console.info("[nodegit] Nothing to do.")
5+
}
6+
catch (e) {
7+
exec("node generate");
8+
}

0 commit comments

Comments
 (0)