"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/unstar.js" (11 Apr 2017, 3227 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 Command, Login, Unstar, async, config, 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   async = require('async');
    7 
    8   yargs = require('yargs');
    9 
   10   config = require('./apm');
   11 
   12   Command = require('./command');
   13 
   14   Login = require('./login');
   15 
   16   request = require('./request');
   17 
   18   module.exports = Unstar = (function(superClass) {
   19     extend(Unstar, superClass);
   20 
   21     function Unstar() {
   22       return Unstar.__super__.constructor.apply(this, arguments);
   23     }
   24 
   25     Unstar.commandNames = ['unstar'];
   26 
   27     Unstar.prototype.parseOptions = function(argv) {
   28       var options;
   29       options = yargs(argv).wrap(100);
   30       options.usage("\nUsage: apm unstar <package_name>...\n\nUnstar the given packages on https://atom.io\n\nRun `apm stars` to see all your starred packages.");
   31       return options.alias('h', 'help').describe('help', 'Print this usage message');
   32     };
   33 
   34     Unstar.prototype.starPackage = function(packageName, token, callback) {
   35       var requestSettings;
   36       if (process.platform === 'darwin') {
   37         process.stdout.write('\uD83D\uDC5F \u2B50  ');
   38       }
   39       process.stdout.write("Unstarring " + packageName + " ");
   40       requestSettings = {
   41         json: true,
   42         url: (config.getAtomPackagesUrl()) + "/" + packageName + "/star",
   43         headers: {
   44           authorization: token
   45         }
   46       };
   47       return request.del(requestSettings, (function(_this) {
   48         return function(error, response, body) {
   49           var message, ref, ref1;
   50           if (body == null) {
   51             body = {};
   52           }
   53           if (error != null) {
   54             _this.logFailure();
   55             return callback(error);
   56           } else if (response.statusCode !== 204) {
   57             _this.logFailure();
   58             message = (ref = (ref1 = body.message) != null ? ref1 : body.error) != null ? ref : body;
   59             return callback("Unstarring package failed: " + message);
   60           } else {
   61             _this.logSuccess();
   62             return callback();
   63           }
   64         };
   65       })(this));
   66     };
   67 
   68     Unstar.prototype.run = function(options) {
   69       var callback, packageNames;
   70       callback = options.callback;
   71       options = this.parseOptions(options.commandArgs);
   72       packageNames = this.packageNamesFromArgv(options.argv);
   73       if (packageNames.length === 0) {
   74         callback("Please specify a package name to unstar");
   75         return;
   76       }
   77       return Login.getTokenOrLogin((function(_this) {
   78         return function(error, token) {
   79           var commands;
   80           if (error != null) {
   81             return callback(error);
   82           }
   83           commands = packageNames.map(function(packageName) {
   84             return function(callback) {
   85               return _this.starPackage(packageName, token, callback);
   86             };
   87           });
   88           return async.waterfall(commands, callback);
   89         };
   90       })(this));
   91     };
   92 
   93     return Unstar;
   94 
   95   })(Command);
   96 
   97 }).call(this);