"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/featured.js" (7 Feb 2017, 5626 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, Featured, _, config, request, tree, yargs,
    3     extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    4     hasProp = {}.hasOwnProperty;
    5 
    6   _ = require('underscore-plus');
    7 
    8   yargs = require('yargs');
    9 
   10   Command = require('./command');
   11 
   12   config = require('./apm');
   13 
   14   request = require('./request');
   15 
   16   tree = require('./tree');
   17 
   18   module.exports = Featured = (function(superClass) {
   19     extend(Featured, superClass);
   20 
   21     function Featured() {
   22       return Featured.__super__.constructor.apply(this, arguments);
   23     }
   24 
   25     Featured.commandNames = ['featured'];
   26 
   27     Featured.prototype.parseOptions = function(argv) {
   28       var options;
   29       options = yargs(argv).wrap(100);
   30       options.usage("\nUsage: apm featured\n       apm featured --themes\n       apm featured --compatible 0.49.0\n\nList the Atom packages and themes that are currently featured in the\natom.io registry.");
   31       options.alias('h', 'help').describe('help', 'Print this usage message');
   32       options.alias('t', 'themes').boolean('themes').describe('themes', 'Only list themes');
   33       options.alias('c', 'compatible').string('compatible').describe('compatible', 'Only list packages/themes compatible with this Atom version');
   34       return options.boolean('json').describe('json', 'Output featured packages as JSON array');
   35     };
   36 
   37     Featured.prototype.getFeaturedPackagesByType = function(atomVersion, packageType, callback) {
   38       var ref, requestSettings;
   39       if (_.isFunction(atomVersion)) {
   40         ref = [atomVersion, null], callback = ref[0], atomVersion = ref[1];
   41       }
   42       requestSettings = {
   43         url: (config.getAtomApiUrl()) + "/" + packageType + "/featured",
   44         json: true
   45       };
   46       if (atomVersion) {
   47         requestSettings.qs = {
   48           engine: atomVersion
   49         };
   50       }
   51       return request.get(requestSettings, function(error, response, body) {
   52         var message, packages;
   53         if (body == null) {
   54           body = [];
   55         }
   56         if (error != null) {
   57           return callback(error);
   58         } else if (response.statusCode === 200) {
   59           packages = body.filter(function(pack) {
   60             var ref1;
   61             return (pack != null ? (ref1 = pack.releases) != null ? ref1.latest : void 0 : void 0) != null;
   62           });
   63           packages = packages.map(function(arg) {
   64             var downloads, metadata, readme, stargazers_count;
   65             readme = arg.readme, metadata = arg.metadata, downloads = arg.downloads, stargazers_count = arg.stargazers_count;
   66             return _.extend({}, metadata, {
   67               readme: readme,
   68               downloads: downloads,
   69               stargazers_count: stargazers_count
   70             });
   71           });
   72           packages = _.sortBy(packages, 'name');
   73           return callback(null, packages);
   74         } else {
   75           message = request.getErrorMessage(response, body);
   76           return callback("Requesting packages failed: " + message);
   77         }
   78       });
   79     };
   80 
   81     Featured.prototype.getAllFeaturedPackages = function(atomVersion, callback) {
   82       return this.getFeaturedPackagesByType(atomVersion, 'packages', (function(_this) {
   83         return function(error, packages) {
   84           if (error != null) {
   85             return callback(error);
   86           }
   87           return _this.getFeaturedPackagesByType(atomVersion, 'themes', function(error, themes) {
   88             if (error != null) {
   89               return callback(error);
   90             }
   91             return callback(null, packages.concat(themes));
   92           });
   93         };
   94       })(this));
   95     };
   96 
   97     Featured.prototype.run = function(options) {
   98       var callback, listCallback;
   99       callback = options.callback;
  100       options = this.parseOptions(options.commandArgs);
  101       listCallback = function(error, packages) {
  102         if (error != null) {
  103           return callback(error);
  104         }
  105         if (options.argv.json) {
  106           console.log(JSON.stringify(packages));
  107         } else {
  108           if (options.argv.themes) {
  109             console.log('Featured Atom Themes'.cyan + " (" + packages.length + ")");
  110           } else {
  111             console.log('Featured Atom Packages'.cyan + " (" + packages.length + ")");
  112           }
  113           tree(packages, function(arg) {
  114             var description, downloads, label, name, stargazers_count, version;
  115             name = arg.name, version = arg.version, description = arg.description, downloads = arg.downloads, stargazers_count = arg.stargazers_count;
  116             label = name.yellow;
  117             if (description) {
  118               label += " " + (description.replace(/\s+/g, ' '));
  119             }
  120             if (downloads >= 0 && stargazers_count >= 0) {
  121               label += (" (" + (_.pluralize(downloads, 'download')) + ", " + (_.pluralize(stargazers_count, 'star')) + ")").grey;
  122             }
  123             return label;
  124           });
  125           console.log();
  126           console.log("Use `apm install` to install them or visit " + 'http://atom.io/packages'.underline + " to read more about them.");
  127           console.log();
  128         }
  129         return callback();
  130       };
  131       if (options.argv.themes) {
  132         return this.getFeaturedPackagesByType(options.argv.compatible, 'themes', listCallback);
  133       } else {
  134         return this.getAllFeaturedPackages(options.argv.compatible, listCallback);
  135       }
  136     };
  137 
  138     return Featured;
  139 
  140   })(Command);
  141 
  142 }).call(this);