"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/apm-cli.js" (11 Apr 2017, 8536 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, 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         var ref5, versions, visualStudioVersion;
   96         if (args.json) {
   97           versions = {
   98             apm: apmVersion,
   99             npm: npmVersion,
  100             node: nodeVersion,
  101             python: pythonVersion,
  102             git: gitVersion,
  103             nodeArch: process.arch
  104           };
  105           if (config.isWin32()) {
  106             versions.visualStudio = config.getInstalledVisualStudioFlag();
  107           }
  108           console.log(JSON.stringify(versions));
  109         } else {
  110           if (pythonVersion == null) {
  111             pythonVersion = '';
  112           }
  113           if (gitVersion == null) {
  114             gitVersion = '';
  115           }
  116           versions = 'apm'.red + "  " + apmVersion.red + "\n" + 'npm'.green + "  " + npmVersion.green + "\n" + 'node'.blue + " " + nodeVersion.blue + " " + process.arch.blue + "\n" + 'python'.yellow + " " + pythonVersion.yellow + "\n" + 'git'.magenta + " " + gitVersion.magenta;
  117           if (config.isWin32()) {
  118             visualStudioVersion = (ref5 = config.getInstalledVisualStudioFlag()) != null ? ref5 : '';
  119             versions += "\n" + 'visual studio'.cyan + " " + visualStudioVersion.cyan;
  120           }
  121           console.log(versions);
  122         }
  123         return callback();
  124       });
  125     });
  126   };
  127 
  128   getPythonVersion = function(callback) {
  129     var npmOptions;
  130     npmOptions = {
  131       userconfig: config.getUserConfigPath(),
  132       globalconfig: config.getGlobalConfigPath()
  133     };
  134     return npm.load(npmOptions, function() {
  135       var outputChunks, python, pythonExe, ref2, ref3, rootDir, spawned;
  136       python = (ref2 = npm.config.get('python')) != null ? ref2 : process.env.PYTHON;
  137       if (config.isWin32() && !python) {
  138         rootDir = (ref3 = process.env.SystemDrive) != null ? ref3 : 'C:\\';
  139         if (rootDir[rootDir.length - 1] !== '\\') {
  140           rootDir += '\\';
  141         }
  142         pythonExe = path.resolve(rootDir, 'Python27', 'python.exe');
  143         if (fs.isFileSync(pythonExe)) {
  144           python = pythonExe;
  145         }
  146       }
  147       if (python == null) {
  148         python = 'python';
  149       }
  150       spawned = spawn(python, ['--version']);
  151       outputChunks = [];
  152       spawned.stderr.on('data', function(chunk) {
  153         return outputChunks.push(chunk);
  154       });
  155       spawned.stdout.on('data', function(chunk) {
  156         return outputChunks.push(chunk);
  157       });
  158       spawned.on('error', function() {});
  159       return spawned.on('close', function(code) {
  160         var ref4, version;
  161         if (code === 0) {
  162           ref4 = Buffer.concat(outputChunks).toString().split(' '), name = ref4[0], version = ref4[1];
  163           version = version != null ? version.trim() : void 0;
  164         }
  165         return callback(version);
  166       });
  167     });
  168   };
  169 
  170   module.exports = {
  171     run: function(args, callback) {
  172       var Command, base, base1, callbackCalled, command, options;
  173       config.setupApmRcFile();
  174       options = parseOptions(args);
  175       if (!options.argv.color) {
  176         colors.setTheme({
  177           blue: 'stripColors',
  178           cyan: 'stripColors',
  179           green: 'stripColors',
  180           magenta: 'stripColors',
  181           red: 'stripColors',
  182           yellow: 'stripColors',
  183           rainbow: 'stripColors'
  184         });
  185       }
  186       callbackCalled = false;
  187       options.callback = function(error) {
  188         var message, ref2;
  189         if (callbackCalled) {
  190           return;
  191         }
  192         callbackCalled = true;
  193         if (error != null) {
  194           if (_.isString(error)) {
  195             message = error;
  196           } else {
  197             message = (ref2 = error.message) != null ? ref2 : error;
  198           }
  199           if (message === 'canceled') {
  200             console.log();
  201           } else if (message) {
  202             console.error(message.red);
  203           }
  204         }
  205         return typeof callback === "function" ? callback(error) : void 0;
  206       };
  207       args = options.argv;
  208       command = options.command;
  209       if (args.version) {
  210         return printVersions(args, options.callback);
  211       } else if (args.help) {
  212         if (Command = commands[options.command]) {
  213           showHelp(typeof (base = new Command()).parseOptions === "function" ? base.parseOptions(options.command) : void 0);
  214         } else {
  215           showHelp(options);
  216         }
  217         return options.callback();
  218       } else if (command) {
  219         if (command === 'help') {
  220           if (Command = commands[options.commandArgs]) {
  221             showHelp(typeof (base1 = new Command()).parseOptions === "function" ? base1.parseOptions(options.commandArgs) : void 0);
  222           } else {
  223             showHelp(options);
  224           }
  225           return options.callback();
  226         } else if (Command = commands[command]) {
  227           return new Command().run(options);
  228         } else {
  229           return options.callback("Unrecognized command: " + command);
  230         }
  231       } else {
  232         showHelp(options);
  233         return options.callback();
  234       }
  235     }
  236   };
  237 
  238 }).call(this);