]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / node-gyp / lib / node-gyp.js
1
2 /**
3  * Module exports.
4  */
5
6 module.exports = exports = gyp
7
8 /**
9  * Module dependencies.
10  */
11
12 var fs = require('graceful-fs')
13   , path = require('path')
14   , nopt = require('nopt')
15   , log = require('npmlog')
16   , child_process = require('child_process')
17   , EE = require('events').EventEmitter
18   , inherits = require('util').inherits
19   , commands = [
20       // Module build commands
21         'build'
22       , 'clean'
23       , 'configure'
24       , 'rebuild'
25       // Development Header File management commands
26       , 'install'
27       , 'list'
28       , 'remove'
29     ]
30   , aliases = {
31         'ls': 'list'
32       , 'rm': 'remove'
33     }
34
35 // differentiate node-gyp's logs from npm's
36 log.heading = 'gyp'
37
38 /**
39  * The `gyp` function.
40  */
41
42 function gyp () {
43   return new Gyp()
44 }
45
46 function Gyp () {
47   var self = this
48
49   // set the dir where node-gyp dev files get installed
50   // TODO: make this *more* configurable?
51   //       see: https://github.com/nodejs/node-gyp/issues/21
52   var homeDir = process.env.HOME || process.env.USERPROFILE
53   if (!homeDir) {
54     throw new Error(
55       "node-gyp requires that the user's home directory is specified " +
56       "in either of the environmental variables HOME or USERPROFILE"
57     );
58   }
59   this.devDir = path.resolve(homeDir, '.node-gyp')
60
61   this.commands = {}
62
63   commands.forEach(function (command) {
64     self.commands[command] = function (argv, callback) {
65       log.verbose('command', command, argv)
66       return require('./' + command)(self, argv, callback)
67     }
68   })
69 }
70 inherits(Gyp, EE)
71 exports.Gyp = Gyp
72 var proto = Gyp.prototype
73
74 /**
75  * Export the contents of the package.json.
76  */
77
78 proto.package = require('../package')
79
80 /**
81  * nopt configuration definitions
82  */
83
84 proto.configDefs = {
85     help: Boolean     // everywhere
86   , arch: String      // 'configure'
87   , cafile: String    // 'install'
88   , debug: Boolean    // 'build'
89   , directory: String // bin
90   , make: String      // 'build'
91   , msvs_version: String // 'configure'
92   , ensure: Boolean   // 'install'
93   , solution: String  // 'build' (windows only)
94   , proxy: String     // 'install'
95   , nodedir: String   // 'configure'
96   , loglevel: String  // everywhere
97   , python: String    // 'configure'
98   , 'dist-url': String // 'install'
99   , 'tarball': String // 'install'
100   , jobs: String      // 'build'
101   , thin: String      // 'configure'
102 }
103
104 /**
105  * nopt shorthands
106  */
107
108 proto.shorthands = {
109     release: '--no-debug'
110   , C: '--directory'
111   , debug: '--debug'
112   , j: '--jobs'
113   , silly: '--loglevel=silly'
114   , verbose: '--loglevel=verbose'
115   , silent: '--loglevel=silent'
116 }
117
118 /**
119  * expose the command aliases for the bin file to use.
120  */
121
122 proto.aliases = aliases
123
124 /**
125  * Parses the given argv array and sets the 'opts',
126  * 'argv' and 'command' properties.
127  */
128
129 proto.parseArgv = function parseOpts (argv) {
130   this.opts = nopt(this.configDefs, this.shorthands, argv)
131   this.argv = this.opts.argv.remain.slice()
132
133   var commands = this.todo = []
134
135   // create a copy of the argv array with aliases mapped
136   argv = this.argv.map(function (arg) {
137     // is this an alias?
138     if (arg in this.aliases) {
139       arg = this.aliases[arg]
140     }
141     return arg
142   }, this)
143
144   // process the mapped args into "command" objects ("name" and "args" props)
145   argv.slice().forEach(function (arg) {
146     if (arg in this.commands) {
147       var args = argv.splice(0, argv.indexOf(arg))
148       argv.shift()
149       if (commands.length > 0) {
150         commands[commands.length - 1].args = args
151       }
152       commands.push({ name: arg, args: [] })
153     }
154   }, this)
155   if (commands.length > 0) {
156     commands[commands.length - 1].args = argv.splice(0)
157   }
158
159   // support for inheriting config env variables from npm
160   var npm_config_prefix = 'npm_config_'
161   Object.keys(process.env).forEach(function (name) {
162     if (name.indexOf(npm_config_prefix) !== 0) return
163     var val = process.env[name]
164     if (name === npm_config_prefix + 'loglevel') {
165       log.level = val
166     } else {
167       // add the user-defined options to the config
168       name = name.substring(npm_config_prefix.length)
169       // gyp@741b7f1 enters an infinite loop when it encounters
170       // zero-length options so ensure those don't get through.
171       if (name) this.opts[name] = val
172     }
173   }, this)
174
175   if (this.opts.loglevel) {
176     log.level = this.opts.loglevel
177   }
178   log.resume()
179 }
180
181 /**
182  * Spawns a child process and emits a 'spawn' event.
183  */
184
185 proto.spawn = function spawn (command, args, opts) {
186   if (!opts) opts = {}
187   if (!opts.silent && !opts.stdio) {
188     opts.stdio = [ 0, 1, 2 ]
189   }
190   var cp = child_process.spawn(command, args, opts)
191   log.info('spawn', command)
192   log.info('spawn args', args)
193   return cp
194 }
195
196 /**
197  * Returns the usage instructions for node-gyp.
198  */
199
200 proto.usage = function usage () {
201   var str = [
202       ''
203     , '  Usage: node-gyp <command> [options]'
204     , ''
205     , '  where <command> is one of:'
206     , commands.map(function (c) {
207         return '    - ' + c + ' - ' + require('./' + c).usage
208       }).join('\n')
209     , ''
210     , 'node-gyp@' + this.version + '  ' + path.resolve(__dirname, '..')
211     , 'node@' + process.versions.node
212   ].join('\n')
213   return str
214 }
215
216 /**
217  * Version number getter.
218  */
219
220 Object.defineProperty(proto, 'version', {
221     get: function () {
222       return this.package.version
223     }
224   , enumerable: true
225 })
226