"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/uninstall.js" (7 Feb 2017, 4948 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, Uninstall, async, auth, 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   async = require('async');
    9 
   10   CSON = require('season');
   11 
   12   yargs = require('yargs');
   13 
   14   auth = require('./auth');
   15 
   16   Command = require('./command');
   17 
   18   config = require('./apm');
   19 
   20   fs = require('./fs');
   21 
   22   request = require('./request');
   23 
   24   module.exports = Uninstall = (function(superClass) {
   25     extend(Uninstall, superClass);
   26 
   27     function Uninstall() {
   28       return Uninstall.__super__.constructor.apply(this, arguments);
   29     }
   30 
   31     Uninstall.commandNames = ['deinstall', 'delete', 'erase', 'remove', 'rm', 'uninstall'];
   32 
   33     Uninstall.prototype.parseOptions = function(argv) {
   34       var options;
   35       options = yargs(argv).wrap(100);
   36       options.usage("\nUsage: apm uninstall <package_name>...\n\nDelete the installed package(s) from the ~/.atom/packages directory.");
   37       options.alias('h', 'help').describe('help', 'Print this usage message');
   38       options.alias('d', 'dev').boolean('dev').describe('dev', 'Uninstall from ~/.atom/dev/packages');
   39       return options.boolean('hard').describe('hard', 'Uninstall from ~/.atom/packages and ~/.atom/dev/packages');
   40     };
   41 
   42     Uninstall.prototype.getPackageVersion = function(packageDirectory) {
   43       var error, error1, ref;
   44       try {
   45         return (ref = CSON.readFileSync(path.join(packageDirectory, 'package.json'))) != null ? ref.version : void 0;
   46       } catch (error1) {
   47         error = error1;
   48         return null;
   49       }
   50     };
   51 
   52     Uninstall.prototype.registerUninstall = function(arg, callback) {
   53       var packageName, packageVersion;
   54       packageName = arg.packageName, packageVersion = arg.packageVersion;
   55       if (!packageVersion) {
   56         return callback();
   57       }
   58       return auth.getToken(function(error, token) {
   59         var requestOptions;
   60         if (!token) {
   61           return callback();
   62         }
   63         requestOptions = {
   64           url: (config.getAtomPackagesUrl()) + "/" + packageName + "/versions/" + packageVersion + "/events/uninstall",
   65           json: true,
   66           headers: {
   67             authorization: token
   68           }
   69         };
   70         return request.post(requestOptions, function(error, response, body) {
   71           return callback();
   72         });
   73       });
   74     };
   75 
   76     Uninstall.prototype.run = function(options) {
   77       var callback, devPackagesDirectory, error, error1, i, len, packageDirectory, packageName, packageNames, packageVersion, packagesDirectory, uninstallError, uninstallsToRegister;
   78       callback = options.callback;
   79       options = this.parseOptions(options.commandArgs);
   80       packageNames = this.packageNamesFromArgv(options.argv);
   81       if (packageNames.length === 0) {
   82         callback("Please specify a package name to uninstall");
   83         return;
   84       }
   85       packagesDirectory = path.join(config.getAtomDirectory(), 'packages');
   86       devPackagesDirectory = path.join(config.getAtomDirectory(), 'dev', 'packages');
   87       uninstallsToRegister = [];
   88       uninstallError = null;
   89       for (i = 0, len = packageNames.length; i < len; i++) {
   90         packageName = packageNames[i];
   91         process.stdout.write("Uninstalling " + packageName + " ");
   92         try {
   93           if (!options.argv.dev) {
   94             packageDirectory = path.join(packagesDirectory, packageName);
   95             if (fs.existsSync(packageDirectory)) {
   96               packageVersion = this.getPackageVersion(packageDirectory);
   97               fs.removeSync(packageDirectory);
   98               if (packageVersion) {
   99                 uninstallsToRegister.push({
  100                   packageName: packageName,
  101                   packageVersion: packageVersion
  102                 });
  103               }
  104             } else if (!options.argv.hard) {
  105               throw new Error("Does not exist");
  106             }
  107           }
  108           if (options.argv.hard || options.argv.dev) {
  109             packageDirectory = path.join(devPackagesDirectory, packageName);
  110             if (fs.existsSync(packageDirectory)) {
  111               fs.removeSync(packageDirectory);
  112             } else if (!options.argv.hard) {
  113               throw new Error("Does not exist");
  114             }
  115           }
  116           this.logSuccess();
  117         } catch (error1) {
  118           error = error1;
  119           this.logFailure();
  120           uninstallError = new Error("Failed to delete " + packageName + ": " + error.message);
  121           break;
  122         }
  123       }
  124       return async.eachSeries(uninstallsToRegister, this.registerUninstall.bind(this), function() {
  125         return callback(uninstallError);
  126       });
  127     };
  128 
  129     return Uninstall;
  130 
  131   })(Command);
  132 
  133 }).call(this);