UNPKG

1.56 kBJavaScriptView Raw
1"use strict";
2
3module.exports = exports = build;
4
5exports.usage = 'Attempts to compile the module by dispatching to node-gyp or nw-gyp';
6
7var compile = require('./util/compile.js');
8var handle_gyp_opts = require('./util/handle_gyp_opts.js');
9var configure = require('./configure.js');
10
11function do_build(gyp,argv,callback) {
12 handle_gyp_opts(gyp,argv,function(err,result) {
13 var final_args = ['build'].concat(result.gyp).concat(result.pre);
14 if (result.unparsed.length > 0) {
15 final_args = final_args.
16 concat(['--']).
17 concat(result.unparsed);
18 }
19 compile.run_gyp(final_args,result.opts,function(err) {
20 return callback(err);
21 });
22 });
23}
24
25function build(gyp, argv, callback) {
26
27 // Form up commands to pass to node-gyp:
28 // We map `node-pre-gyp build` to `node-gyp configure build` so that we do not
29 // trigger a clean and therefore do not pay the penalty of a full recompile
30 if (argv.length && (argv.indexOf('rebuild') > -1)) {
31 // here we map `node-pre-gyp rebuild` to `node-gyp rebuild` which internally means
32 // "clean + configure + build" and triggers a full recompile
33 compile.run_gyp(['clean'],{},function(err) {
34 if (err) return callback(err);
35 configure(gyp,argv,function(err) {
36 if (err) return callback(err);
37 return do_build(gyp,argv,callback);
38 });
39 });
40 } else {
41 return do_build(gyp,argv,callback);
42 }
43}