123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- 'use strict';
- module.exports = exports;
- exports.mockS3Http = require('./util/s3_setup').get_mockS3Http();
- exports.mockS3Http('on');
- const mocking = exports.mockS3Http('get');
- const fs = require('fs');
- const path = require('path');
- const nopt = require('nopt');
- const log = require('npmlog');
- log.disableProgress();
- const napi = require('./util/napi.js');
- const EE = require('events').EventEmitter;
- const inherits = require('util').inherits;
- const cli_commands = [
- 'clean',
- 'install',
- 'reinstall',
- 'build',
- 'rebuild',
- 'package',
- 'testpackage',
- 'publish',
- 'unpublish',
- 'info',
- 'testbinary',
- 'reveal',
- 'configure'
- ];
- const aliases = {};
- log.heading = 'node-pre-gyp';
- if (mocking) {
- log.warn(`mocking s3 to ${process.env.node_pre_gyp_mock_s3}`);
- }
- Object.defineProperty(exports, 'find', {
- get: function() {
- return require('./pre-binding').find;
- },
- enumerable: true
- });
- function Run({ package_json_path = './package.json', argv }) {
- this.package_json_path = package_json_path;
- this.commands = {};
- const self = this;
- cli_commands.forEach((command) => {
- self.commands[command] = function(argvx, callback) {
- log.verbose('command', command, argvx);
- return require('./' + command)(self, argvx, callback);
- };
- });
- this.parseArgv(argv);
-
-
- this.binaryHostSet = false;
- }
- inherits(Run, EE);
- exports.Run = Run;
- const proto = Run.prototype;
- proto.package = require('../package.json');
- proto.configDefs = {
- help: Boolean,
- arch: String,
- debug: Boolean,
- directory: String,
- proxy: String,
- loglevel: String
- };
- proto.shorthands = {
- release: '--no-debug',
- C: '--directory',
- debug: '--debug',
- j: '--jobs',
- silent: '--loglevel=silent',
- silly: '--loglevel=silly',
- verbose: '--loglevel=verbose'
- };
- proto.aliases = aliases;
- proto.parseArgv = function parseOpts(argv) {
- this.opts = nopt(this.configDefs, this.shorthands, argv);
- this.argv = this.opts.argv.remain.slice();
- const commands = this.todo = [];
-
- argv = this.argv.map((arg) => {
-
- if (arg in this.aliases) {
- arg = this.aliases[arg];
- }
- return arg;
- });
-
- argv.slice().forEach((arg) => {
- if (arg in this.commands) {
- const args = argv.splice(0, argv.indexOf(arg));
- argv.shift();
- if (commands.length > 0) {
- commands[commands.length - 1].args = args;
- }
- commands.push({ name: arg, args: [] });
- }
- });
- if (commands.length > 0) {
- commands[commands.length - 1].args = argv.splice(0);
- }
-
-
- let package_json_path = this.package_json_path;
- if (this.opts.directory) {
- package_json_path = path.join(this.opts.directory, package_json_path);
- }
- this.package_json = JSON.parse(fs.readFileSync(package_json_path));
-
- this.todo = napi.expand_commands(this.package_json, this.opts, commands);
-
- const npm_config_prefix = 'npm_config_';
- Object.keys(process.env).forEach((name) => {
- if (name.indexOf(npm_config_prefix) !== 0) return;
- const val = process.env[name];
- if (name === npm_config_prefix + 'loglevel') {
- log.level = val;
- } else {
-
- name = name.substring(npm_config_prefix.length);
-
-
-
- if (name === 'argv') {
- if (this.opts.argv &&
- this.opts.argv.remain &&
- this.opts.argv.remain.length) {
-
- } else {
- this.opts[name] = val;
- }
- } else {
- this.opts[name] = val;
- }
- }
- });
- if (this.opts.loglevel) {
- log.level = this.opts.loglevel;
- }
- log.resume();
- };
- proto.setBinaryHostProperty = function(command) {
- if (this.binaryHostSet) {
- return this.package_json.binary.host;
- }
- const p = this.package_json;
-
- if (!p || !p.binary || p.binary.host) {
- return '';
- }
-
- if (!p.binary.staging_host || !p.binary.production_host) {
- return '';
- }
- let target = 'production_host';
- if (command === 'publish' || command === 'unpublish') {
- target = 'staging_host';
- }
-
-
- const npg_s3_host = process.env.node_pre_gyp_s3_host;
- if (npg_s3_host === 'staging' || npg_s3_host === 'production') {
- target = `${npg_s3_host}_host`;
- } else if (this.opts['s3_host'] === 'staging' || this.opts['s3_host'] === 'production') {
- target = `${this.opts['s3_host']}_host`;
- } else if (this.opts['s3_host'] || npg_s3_host) {
- throw new Error(`invalid s3_host ${this.opts['s3_host'] || npg_s3_host}`);
- }
- p.binary.host = p.binary[target];
- this.binaryHostSet = true;
- return p.binary.host;
- };
- proto.usage = function usage() {
- const str = [
- '',
- ' Usage: node-pre-gyp <command> [options]',
- '',
- ' where <command> is one of:',
- cli_commands.map((c) => {
- return ' - ' + c + ' - ' + require('./' + c).usage;
- }).join('\n'),
- '',
- 'node-pre-gyp@' + this.version + ' ' + path.resolve(__dirname, '..'),
- 'node@' + process.versions.node
- ].join('\n');
- return str;
- };
- Object.defineProperty(proto, 'version', {
- get: function() {
- return this.package.version;
- },
- enumerable: true
- });
|