"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/unpublish.js" (8 Mar 2017, 5293 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, Unpublish, auth, config, fs, path, readline, 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   readline = require('readline');
    9 
   10   yargs = require('yargs');
   11 
   12   auth = require('./auth');
   13 
   14   Command = require('./command');
   15 
   16   config = require('./apm');
   17 
   18   fs = require('./fs');
   19 
   20   request = require('./request');
   21 
   22   module.exports = Unpublish = (function(superClass) {
   23     extend(Unpublish, superClass);
   24 
   25     function Unpublish() {
   26       return Unpublish.__super__.constructor.apply(this, arguments);
   27     }
   28 
   29     Unpublish.commandNames = ['unpublish'];
   30 
   31     Unpublish.prototype.parseOptions = function(argv) {
   32       var options;
   33       options = yargs(argv).wrap(100);
   34       options.usage("Usage: apm unpublish [<package_name>]\n       apm unpublish <package_name>@<package_version>\n\nRemove a published package or package version from the atom.io registry.\n\nThe package in the current working directory will be used if no package\nname is specified.");
   35       options.alias('h', 'help').describe('help', 'Print this usage message');
   36       return options.alias('f', 'force').boolean('force').describe('force', 'Do not prompt for confirmation');
   37     };
   38 
   39     Unpublish.prototype.unpublishPackage = function(packageName, packageVersion, callback) {
   40       var packageLabel;
   41       packageLabel = packageName;
   42       if (packageVersion) {
   43         packageLabel += "@" + packageVersion;
   44       }
   45       process.stdout.write("Unpublishing " + packageLabel + " ");
   46       return auth.getToken((function(_this) {
   47         return function(error, token) {
   48           var options;
   49           if (error != null) {
   50             _this.logFailure();
   51             callback(error);
   52             return;
   53           }
   54           options = {
   55             uri: (config.getAtomPackagesUrl()) + "/" + packageName,
   56             headers: {
   57               authorization: token
   58             },
   59             json: true
   60           };
   61           if (packageVersion) {
   62             options.uri += "/versions/" + packageVersion;
   63           }
   64           return request.del(options, function(error, response, body) {
   65             var message, ref, ref1;
   66             if (body == null) {
   67               body = {};
   68             }
   69             if (error != null) {
   70               _this.logFailure();
   71               return callback(error);
   72             } else if (response.statusCode !== 204) {
   73               _this.logFailure();
   74               message = (ref = (ref1 = body.message) != null ? ref1 : body.error) != null ? ref : body;
   75               return callback("Unpublishing failed: " + message);
   76             } else {
   77               _this.logSuccess();
   78               return callback();
   79             }
   80           });
   81         };
   82       })(this));
   83     };
   84 
   85     Unpublish.prototype.promptForConfirmation = function(packageName, packageVersion, callback) {
   86       var packageLabel, question;
   87       packageLabel = packageName;
   88       if (packageVersion) {
   89         packageLabel += "@" + packageVersion;
   90       }
   91       if (packageVersion) {
   92         question = "Are you sure you want to unpublish '" + packageLabel + "'? (no) ";
   93       } else {
   94         question = ("Are you sure you want to unpublish ALL VERSIONS of '" + packageLabel + "'? ") + "This will remove it from the apm registry, including " + "download counts and stars, and this action is irreversible. (no)";
   95       }
   96       return this.prompt(question, (function(_this) {
   97         return function(answer) {
   98           answer = answer ? answer.trim().toLowerCase() : 'no';
   99           if (answer === 'y' || answer === 'yes') {
  100             return _this.unpublishPackage(packageName, packageVersion, callback);
  101           } else {
  102             return callback("Cancelled unpublishing " + packageLabel);
  103           }
  104         };
  105       })(this));
  106     };
  107 
  108     Unpublish.prototype.prompt = function(question, callback) {
  109       var prompt;
  110       prompt = readline.createInterface(process.stdin, process.stdout);
  111       return prompt.question(question, function(answer) {
  112         prompt.close();
  113         return callback(answer);
  114       });
  115     };
  116 
  117     Unpublish.prototype.run = function(options) {
  118       var atIndex, callback, name, ref, version;
  119       callback = options.callback;
  120       options = this.parseOptions(options.commandArgs);
  121       name = options.argv._[0];
  122       if ((name != null ? name.length : void 0) > 0) {
  123         atIndex = name.indexOf('@');
  124         if (atIndex !== -1) {
  125           version = name.substring(atIndex + 1);
  126           name = name.substring(0, atIndex);
  127         }
  128       }
  129       if (!name) {
  130         try {
  131           name = (ref = JSON.parse(fs.readFileSync('package.json'))) != null ? ref.name : void 0;
  132         } catch (undefined) {}
  133       }
  134       if (!name) {
  135         name = path.basename(process.cwd());
  136       }
  137       if (options.argv.force) {
  138         return this.unpublishPackage(name, version, callback);
  139       } else {
  140         return this.promptForConfirmation(name, version, callback);
  141       }
  142     };
  143 
  144     return Unpublish;
  145 
  146   })(Command);
  147 
  148 }).call(this);