"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/apm-cli.js" (8 Feb 2018, 9306 Bytes) of package /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 _, colors, commandClass, commandClasses, commands, config, fs, getAtomVersion, getPythonVersion, git, i, j, len, len1, name, npm, parseOptions, path, printVersions, ref, ref1, setupTempDirectory, showHelp, spawn, wordwrap, yargs;
    3 
    4   spawn = require('child_process').spawn;
    5 
    6   path = require('path');
    7 
    8   _ = require('underscore-plus');
    9 
   10   colors = require('colors');
   11 
   12   npm = require('npm');
   13 
   14   yargs = require('yargs');
   15 
   16   wordwrap = require('wordwrap');
   17 
   18   require('asar-require');
   19 
   20   config = require('./apm');
   21 
   22   fs = require('./fs');
   23 
   24   git = require('./git');
   25 
   26   setupTempDirectory = function() {
   27     var temp, tempDirectory;
   28     temp = require('temp');
   29     tempDirectory = require('os').tmpdir();
   30     tempDirectory = path.resolve(fs.absolute(tempDirectory));
   31     temp.dir = tempDirectory;
   32     try {
   33       fs.makeTreeSync(temp.dir);
   34     } catch (undefined) {}
   35     return temp.track();
   36   };
   37 
   38   setupTempDirectory();
   39 
   40   commandClasses = [require('./clean'), require('./config'), require('./dedupe'), require('./develop'), require('./disable'), require('./docs'), require('./enable'), require('./featured'), require('./init'), require('./install'), require('./links'), require('./link'), require('./list'), require('./login'), require('./publish'), require('./rebuild'), require('./rebuild-module-cache'), require('./search'), require('./star'), require('./stars'), require('./test'), require('./uninstall'), require('./unlink'), require('./unpublish'), require('./unstar'), require('./upgrade'), require('./view')];
   41 
   42   commands = {};
   43 
   44   for (i = 0, len = commandClasses.length; i < len; i++) {
   45     commandClass = commandClasses[i];
   46     ref1 = (ref = commandClass.commandNames) != null ? ref : [];
   47     for (j = 0, len1 = ref1.length; j < len1; j++) {
   48       name = ref1[j];
   49       commands[name] = commandClass;
   50     }
   51   }
   52 
   53   parseOptions = function(args) {
   54     var arg, index, k, len2, options;
   55     if (args == null) {
   56       args = [];
   57     }
   58     options = yargs(args).wrap(100);
   59     options.usage("\napm - Atom Package Manager powered by https://atom.io\n\nUsage: apm <command>\n\nwhere <command> is one of:\n" + (wordwrap(4, 80)(Object.keys(commands).sort().join(', '))) + ".\n\nRun `apm help <command>` to see the more details about a specific command.");
   60     options.alias('v', 'version').describe('version', 'Print the apm version');
   61     options.alias('h', 'help').describe('help', 'Print this usage message');
   62     options.boolean('color')["default"]('color', true).describe('color', 'Enable colored output');
   63     options.command = options.argv._[0];
   64     for (index = k = 0, len2 = args.length; k < len2; index = ++k) {
   65       arg = args[index];
   66       if (!(arg === options.command)) {
   67         continue;
   68       }
   69       options.commandArgs = args.slice(index + 1);
   70       break;
   71     }
   72     return options;
   73   };
   74 
   75   showHelp = function(options) {
   76     var help;
   77     if (options == null) {
   78       return;
   79     }
   80     help = options.help();
   81     if (help.indexOf('Options:') >= 0) {
   82       help += "\n  Prefix an option with `no-` to set it to false such as --no-color to disable";
   83       help += "\n  colored output.";
   84     }
   85     return console.error(help);
   86   };
   87 
   88   printVersions = function(args, callback) {
   89     var apmVersion, nodeVersion, npmVersion, ref2, ref3, ref4;
   90     apmVersion = (ref2 = require('../package.json').version) != null ? ref2 : '';
   91     npmVersion = (ref3 = require('npm/package.json').version) != null ? ref3 : '';
   92     nodeVersion = (ref4 = process.versions.node) != null ? ref4 : '';
   93     return getPythonVersion(function(pythonVersion) {
   94       return git.getGitVersion(function(gitVersion) {
   95         return getAtomVersion(function(atomVersion) {
   96           var ref5, versions, visualStudioVersion;
   97           if (args.json) {
   98             versions = {
   99               apm: apmVersion,
  100               npm: npmVersion,
  101               node: nodeVersion,
  102               atom: atomVersion,
  103               python: pythonVersion,
  104               git: gitVersion,
  105               nodeArch: process.arch
  106             };
  107             if (config.isWin32()) {
  108               versions.visualStudio = config.getInstalledVisualStudioFlag();
  109             }
  110             console.log(JSON.stringify(versions));
  111           } else {
  112             if (pythonVersion == null) {
  113               pythonVersion = '';
  114             }
  115             if (gitVersion == null) {
  116               gitVersion = '';
  117             }
  118             if (atomVersion == null) {
  119               atomVersion = '';
  120             }
  121             versions = 'apm'.red + "  " + apmVersion.red + "\n" + 'npm'.green + "  " + npmVersion.green + "\n" + 'node'.blue + " " + nodeVersion.blue + " " + process.arch.blue + "\n" + 'atom'.cyan + " " + atomVersion.cyan + "\n" + 'python'.yellow + " " + pythonVersion.yellow + "\n" + 'git'.magenta + " " + gitVersion.magenta;
  122             if (config.isWin32()) {
  123               visualStudioVersion = (ref5 = config.getInstalledVisualStudioFlag()) != null ? ref5 : '';
  124               versions += "\n" + 'visual studio'.cyan + " " + visualStudioVersion.cyan;
  125             }
  126             console.log(versions);
  127           }
  128           return callback();
  129         });
  130       });
  131     });
  132   };
  133 
  134   getAtomVersion = function(callback) {
  135     return config.getResourcePath(function(resourcePath) {
  136       var error, error1, ref2, unknownVersion, version;
  137       unknownVersion = 'unknown';
  138       try {
  139         version = ((ref2 = require(path.join(resourcePath, 'package.json'))) != null ? ref2 : unknownVersion).version;
  140         return callback(version);
  141       } catch (error1) {
  142         error = error1;
  143         return callback(unknownVersion);
  144       }
  145     });
  146   };
  147 
  148   getPythonVersion = function(callback) {
  149     var npmOptions;
  150     npmOptions = {
  151       userconfig: config.getUserConfigPath(),
  152       globalconfig: config.getGlobalConfigPath()
  153     };
  154     return npm.load(npmOptions, function() {
  155       var outputChunks, python, pythonExe, ref2, ref3, rootDir, spawned;
  156       python = (ref2 = npm.config.get('python')) != null ? ref2 : process.env.PYTHON;
  157       if (config.isWin32() && !python) {
  158         rootDir = (ref3 = process.env.SystemDrive) != null ? ref3 : 'C:\\';
  159         if (rootDir[rootDir.length - 1] !== '\\') {
  160           rootDir += '\\';
  161         }
  162         pythonExe = path.resolve(rootDir, 'Python27', 'python.exe');
  163         if (fs.isFileSync(pythonExe)) {
  164           python = pythonExe;
  165         }
  166       }
  167       if (python == null) {
  168         python = 'python';
  169       }
  170       spawned = spawn(python, ['--version']);
  171       outputChunks = [];
  172       spawned.stderr.on('data', function(chunk) {
  173         return outputChunks.push(chunk);
  174       });
  175       spawned.stdout.on('data', function(chunk) {
  176         return outputChunks.push(chunk);
  177       });
  178       spawned.on('error', function() {});
  179       return spawned.on('close', function(code) {
  180         var ref4, version;
  181         if (code === 0) {
  182           ref4 = Buffer.concat(outputChunks).toString().split(' '), name = ref4[0], version = ref4[1];
  183           version = version != null ? version.trim() : void 0;
  184         }
  185         return callback(version);
  186       });
  187     });
  188   };
  189 
  190   module.exports = {
  191     run: function(args, callback) {
  192       var Command, base, base1, callbackCalled, command, options;
  193       config.setupApmRcFile();
  194       options = parseOptions(args);
  195       if (!options.argv.color) {
  196         colors.setTheme({
  197           blue: 'stripColors',
  198           cyan: 'stripColors',
  199           green: 'stripColors',
  200           magenta: 'stripColors',
  201           red: 'stripColors',
  202           yellow: 'stripColors',
  203           rainbow: 'stripColors'
  204         });
  205       }
  206       callbackCalled = false;
  207       options.callback = function(error) {
  208         var message, ref2;
  209         if (callbackCalled) {
  210           return;
  211         }
  212         callbackCalled = true;
  213         if (error != null) {
  214           if (_.isString(error)) {
  215             message = error;
  216           } else {
  217             message = (ref2 = error.message) != null ? ref2 : error;
  218           }
  219           if (message === 'canceled') {
  220             console.log();
  221           } else if (message) {
  222             console.error(message.red);
  223           }
  224         }
  225         return typeof callback === "function" ? callback(error) : void 0;
  226       };
  227       args = options.argv;
  228       command = options.command;
  229       if (args.version) {
  230         return printVersions(args, options.callback);
  231       } else if (args.help) {
  232         if (Command = commands[options.command]) {
  233           showHelp(typeof (base = new Command()).parseOptions === "function" ? base.parseOptions(options.command) : void 0);
  234         } else {
  235           showHelp(options);
  236         }
  237         return options.callback();
  238       } else if (command) {
  239         if (command === 'help') {
  240           if (Command = commands[options.commandArgs]) {
  241             showHelp(typeof (base1 = new Command()).parseOptions === "function" ? base1.parseOptions(options.commandArgs) : void 0);
  242           } else {
  243             showHelp(options);
  244           }
  245           return options.callback();
  246         } else if (Command = commands[command]) {
  247           return new Command().run(options);
  248         } else {
  249           return options.callback("Unrecognized command: " + command);
  250         }
  251       } else {
  252         showHelp(options);
  253         return options.callback();
  254       }
  255     }
  256   };
  257 
  258 }).call(this);