"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/command.js" (8 Mar 2017, 7407 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var Command, _, child_process, config, git, path, semver,
    3     bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    4     slice = [].slice;
    5 
    6   child_process = require('child_process');
    7 
    8   path = require('path');
    9 
   10   _ = require('underscore-plus');
   11 
   12   semver = require('semver');
   13 
   14   config = require('./apm');
   15 
   16   git = require('./git');
   17 
   18   module.exports = Command = (function() {
   19     function Command() {
   20       this.logCommandResultsIfFail = bind(this.logCommandResultsIfFail, this);
   21       this.logCommandResults = bind(this.logCommandResults, this);
   22     }
   23 
   24     Command.prototype.spawn = function() {
   25       var args, callback, command, errorChunks, onChildExit, options, outputChunks, remaining, spawned;
   26       command = arguments[0], args = arguments[1], remaining = 3 <= arguments.length ? slice.call(arguments, 2) : [];
   27       if (remaining.length >= 2) {
   28         options = remaining.shift();
   29       }
   30       callback = remaining.shift();
   31       spawned = child_process.spawn(command, args, options);
   32       errorChunks = [];
   33       outputChunks = [];
   34       spawned.stdout.on('data', function(chunk) {
   35         if (options != null ? options.streaming : void 0) {
   36           return process.stdout.write(chunk);
   37         } else {
   38           return outputChunks.push(chunk);
   39         }
   40       });
   41       spawned.stderr.on('data', function(chunk) {
   42         if (options != null ? options.streaming : void 0) {
   43           return process.stderr.write(chunk);
   44         } else {
   45           return errorChunks.push(chunk);
   46         }
   47       });
   48       onChildExit = function(errorOrExitCode) {
   49         spawned.removeListener('error', onChildExit);
   50         spawned.removeListener('close', onChildExit);
   51         return typeof callback === "function" ? callback(errorOrExitCode, Buffer.concat(errorChunks).toString(), Buffer.concat(outputChunks).toString()) : void 0;
   52       };
   53       spawned.on('error', onChildExit);
   54       spawned.on('close', onChildExit);
   55       return spawned;
   56     };
   57 
   58     Command.prototype.fork = function() {
   59       var args, remaining, script;
   60       script = arguments[0], args = arguments[1], remaining = 3 <= arguments.length ? slice.call(arguments, 2) : [];
   61       args.unshift(script);
   62       return this.spawn.apply(this, [process.execPath, args].concat(slice.call(remaining)));
   63     };
   64 
   65     Command.prototype.packageNamesFromArgv = function(argv) {
   66       return this.sanitizePackageNames(argv._);
   67     };
   68 
   69     Command.prototype.sanitizePackageNames = function(packageNames) {
   70       if (packageNames == null) {
   71         packageNames = [];
   72       }
   73       packageNames = packageNames.map(function(packageName) {
   74         return packageName.trim();
   75       });
   76       return _.compact(_.uniq(packageNames));
   77     };
   78 
   79     Command.prototype.logSuccess = function() {
   80       if (process.platform === 'win32') {
   81         return process.stdout.write('done\n'.green);
   82       } else {
   83         return process.stdout.write('\u2713\n'.green);
   84       }
   85     };
   86 
   87     Command.prototype.logFailure = function() {
   88       if (process.platform === 'win32') {
   89         return process.stdout.write('failed\n'.red);
   90       } else {
   91         return process.stdout.write('\u2717\n'.red);
   92       }
   93     };
   94 
   95     Command.prototype.logCommandResults = function(callback, code, stderr, stdout) {
   96       if (stderr == null) {
   97         stderr = '';
   98       }
   99       if (stdout == null) {
  100         stdout = '';
  101       }
  102       if (code === 0) {
  103         this.logSuccess();
  104         return callback();
  105       } else {
  106         this.logFailure();
  107         return callback((stdout + "\n" + stderr).trim());
  108       }
  109     };
  110 
  111     Command.prototype.logCommandResultsIfFail = function(callback, code, stderr, stdout) {
  112       if (stderr == null) {
  113         stderr = '';
  114       }
  115       if (stdout == null) {
  116         stdout = '';
  117       }
  118       if (code === 0) {
  119         return callback();
  120       } else {
  121         this.logFailure();
  122         return callback((stdout + "\n" + stderr).trim());
  123       }
  124     };
  125 
  126     Command.prototype.normalizeVersion = function(version) {
  127       if (typeof version === 'string') {
  128         return version.replace(/-.*$/, '');
  129       } else {
  130         return version;
  131       }
  132     };
  133 
  134     Command.prototype.loadInstalledAtomMetadata = function(callback) {
  135       return this.getResourcePath((function(_this) {
  136         return function(resourcePath) {
  137           var electronVersion, ref, ref1, ref2, version;
  138           try {
  139             ref1 = (ref = require(path.join(resourcePath, 'package.json'))) != null ? ref : {}, version = ref1.version, electronVersion = ref1.electronVersion;
  140             version = _this.normalizeVersion(version);
  141             if (semver.valid(version)) {
  142               _this.installedAtomVersion = version;
  143             }
  144           } catch (undefined) {}
  145           _this.electronVersion = (ref2 = process.env.ATOM_ELECTRON_VERSION) != null ? ref2 : electronVersion;
  146           if (_this.electronVersion == null) {
  147             throw new Error('Could not determine Electron version');
  148           }
  149           return callback();
  150         };
  151       })(this));
  152     };
  153 
  154     Command.prototype.getResourcePath = function(callback) {
  155       if (this.resourcePath) {
  156         return process.nextTick((function(_this) {
  157           return function() {
  158             return callback(_this.resourcePath);
  159           };
  160         })(this));
  161       } else {
  162         return config.getResourcePath((function(_this) {
  163           return function(resourcePath1) {
  164             _this.resourcePath = resourcePath1;
  165             return callback(_this.resourcePath);
  166           };
  167         })(this));
  168       }
  169     };
  170 
  171     Command.prototype.addBuildEnvVars = function(env) {
  172       if (config.isWin32()) {
  173         this.updateWindowsEnv(env);
  174       }
  175       this.addNodeBinToEnv(env);
  176       return this.addProxyToEnv(env);
  177     };
  178 
  179     Command.prototype.getVisualStudioFlags = function() {
  180       var vsVersion;
  181       if (vsVersion = config.getInstalledVisualStudioFlag()) {
  182         return "--msvs_version=" + vsVersion;
  183       }
  184     };
  185 
  186     Command.prototype.updateWindowsEnv = function(env) {
  187       var localModuleBins;
  188       env.USERPROFILE = env.HOME;
  189       localModuleBins = path.resolve(__dirname, '..', 'node_modules', '.bin');
  190       if (env.Path) {
  191         env.Path += "" + path.delimiter + localModuleBins;
  192       } else {
  193         env.Path = localModuleBins;
  194       }
  195       return git.addGitToEnv(env);
  196     };
  197 
  198     Command.prototype.addNodeBinToEnv = function(env) {
  199       var nodeBinFolder, pathKey;
  200       nodeBinFolder = path.resolve(__dirname, '..', 'bin');
  201       pathKey = config.isWin32() ? 'Path' : 'PATH';
  202       if (env[pathKey]) {
  203         return env[pathKey] = "" + nodeBinFolder + path.delimiter + env[pathKey];
  204       } else {
  205         return env[pathKey] = nodeBinFolder;
  206       }
  207     };
  208 
  209     Command.prototype.addProxyToEnv = function(env) {
  210       var httpProxy, httpsProxy;
  211       httpProxy = this.npm.config.get('proxy');
  212       if (httpProxy) {
  213         if (env.HTTP_PROXY == null) {
  214           env.HTTP_PROXY = httpProxy;
  215         }
  216         if (env.http_proxy == null) {
  217           env.http_proxy = httpProxy;
  218         }
  219       }
  220       httpsProxy = this.npm.config.get('https-proxy');
  221       if (httpsProxy) {
  222         if (env.HTTPS_PROXY == null) {
  223           env.HTTPS_PROXY = httpsProxy;
  224         }
  225         return env.https_proxy != null ? env.https_proxy : env.https_proxy = httpsProxy;
  226       }
  227     };
  228 
  229     return Command;
  230 
  231   })();
  232 
  233 }).call(this);