"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/star.js" (8 Mar 2017, 5037 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 CSON, Command, Login, Packages, Star, _, async, config, fs, path, request, 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   path = require('path');
    7 
    8   _ = require('underscore-plus');
    9 
   10   async = require('async');
   11 
   12   CSON = require('season');
   13 
   14   yargs = require('yargs');
   15 
   16   config = require('./apm');
   17 
   18   Command = require('./command');
   19 
   20   fs = require('./fs');
   21 
   22   Login = require('./login');
   23 
   24   Packages = require('./packages');
   25 
   26   request = require('./request');
   27 
   28   module.exports = Star = (function(superClass) {
   29     extend(Star, superClass);
   30 
   31     function Star() {
   32       return Star.__super__.constructor.apply(this, arguments);
   33     }
   34 
   35     Star.commandNames = ['star'];
   36 
   37     Star.prototype.parseOptions = function(argv) {
   38       var options;
   39       options = yargs(argv).wrap(100);
   40       options.usage("\nUsage: apm star <package_name>...\n\nStar the given packages on https://atom.io\n\nRun `apm stars` to see all your starred packages.");
   41       options.alias('h', 'help').describe('help', 'Print this usage message');
   42       return options.boolean('installed').describe('installed', 'Star all packages in ~/.atom/packages');
   43     };
   44 
   45     Star.prototype.starPackage = function(packageName, arg, callback) {
   46       var ignoreUnpublishedPackages, ref, requestSettings, token;
   47       ref = arg != null ? arg : {}, ignoreUnpublishedPackages = ref.ignoreUnpublishedPackages, token = ref.token;
   48       if (process.platform === 'darwin') {
   49         process.stdout.write('\u2B50  ');
   50       }
   51       process.stdout.write("Starring " + packageName + " ");
   52       requestSettings = {
   53         json: true,
   54         url: (config.getAtomPackagesUrl()) + "/" + packageName + "/star",
   55         headers: {
   56           authorization: token
   57         }
   58       };
   59       return request.post(requestSettings, (function(_this) {
   60         return function(error, response, body) {
   61           var message;
   62           if (body == null) {
   63             body = {};
   64           }
   65           if (error != null) {
   66             _this.logFailure();
   67             return callback(error);
   68           } else if (response.statusCode === 404 && ignoreUnpublishedPackages) {
   69             process.stdout.write('skipped (not published)\n'.yellow);
   70             return callback();
   71           } else if (response.statusCode !== 200) {
   72             _this.logFailure();
   73             message = request.getErrorMessage(response, body);
   74             return callback("Starring package failed: " + message);
   75           } else {
   76             _this.logSuccess();
   77             return callback();
   78           }
   79         };
   80       })(this));
   81     };
   82 
   83     Star.prototype.getInstalledPackageNames = function() {
   84       var child, i, installedPackages, len, manifestPath, metadata, ref, ref1, userPackagesDirectory;
   85       installedPackages = [];
   86       userPackagesDirectory = path.join(config.getAtomDirectory(), 'packages');
   87       ref = fs.list(userPackagesDirectory);
   88       for (i = 0, len = ref.length; i < len; i++) {
   89         child = ref[i];
   90         if (!fs.isDirectorySync(path.join(userPackagesDirectory, child))) {
   91           continue;
   92         }
   93         if (manifestPath = CSON.resolve(path.join(userPackagesDirectory, child, 'package'))) {
   94           try {
   95             metadata = (ref1 = CSON.readFileSync(manifestPath)) != null ? ref1 : {};
   96             if (metadata.name && Packages.getRepository(metadata)) {
   97               installedPackages.push(metadata.name);
   98             }
   99           } catch (undefined) {}
  100         }
  101       }
  102       return _.uniq(installedPackages);
  103     };
  104 
  105     Star.prototype.run = function(options) {
  106       var callback, packageNames;
  107       callback = options.callback;
  108       options = this.parseOptions(options.commandArgs);
  109       if (options.argv.installed) {
  110         packageNames = this.getInstalledPackageNames();
  111         if (packageNames.length === 0) {
  112           callback();
  113           return;
  114         }
  115       } else {
  116         packageNames = this.packageNamesFromArgv(options.argv);
  117         if (packageNames.length === 0) {
  118           callback("Please specify a package name to star");
  119           return;
  120         }
  121       }
  122       return Login.getTokenOrLogin((function(_this) {
  123         return function(error, token) {
  124           var commands, starOptions;
  125           if (error != null) {
  126             return callback(error);
  127           }
  128           starOptions = {
  129             ignoreUnpublishedPackages: options.argv.installed,
  130             token: token
  131           };
  132           commands = packageNames.map(function(packageName) {
  133             return function(callback) {
  134               return _this.starPackage(packageName, starOptions, callback);
  135             };
  136           });
  137           return async.waterfall(commands, callback);
  138         };
  139       })(this));
  140     };
  141 
  142     return Star;
  143 
  144   })(Command);
  145 
  146 }).call(this);