"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/disable.js" (7 Feb 2017, 4272 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, Disable, List, _, config, path, 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     slice = [].slice;
    6 
    7   _ = require('underscore-plus');
    8 
    9   path = require('path');
   10 
   11   CSON = require('season');
   12 
   13   yargs = require('yargs');
   14 
   15   config = require('./apm');
   16 
   17   Command = require('./command');
   18 
   19   List = require('./list');
   20 
   21   module.exports = Disable = (function(superClass) {
   22     extend(Disable, superClass);
   23 
   24     function Disable() {
   25       return Disable.__super__.constructor.apply(this, arguments);
   26     }
   27 
   28     Disable.commandNames = ['disable'];
   29 
   30     Disable.prototype.parseOptions = function(argv) {
   31       var options;
   32       options = yargs(argv).wrap(100);
   33       options.usage("\nUsage: apm disable [<package_name>]...\n\nDisables the named package(s).");
   34       return options.alias('h', 'help').describe('help', 'Print this usage message');
   35     };
   36 
   37     Disable.prototype.getInstalledPackages = function(callback) {
   38       var lister, options;
   39       options = {
   40         argv: {
   41           theme: false,
   42           bare: true
   43         }
   44       };
   45       lister = new List();
   46       return lister.listBundledPackages(options, function(error, core_packages) {
   47         return lister.listDevPackages(options, function(error, dev_packages) {
   48           return lister.listUserPackages(options, function(error, user_packages) {
   49             return callback(null, core_packages.concat(dev_packages, user_packages));
   50           });
   51         });
   52       });
   53     };
   54 
   55     Disable.prototype.run = function(options) {
   56       var callback, configFilePath, error, error1, packageNames, settings;
   57       callback = options.callback;
   58       options = this.parseOptions(options.commandArgs);
   59       packageNames = this.packageNamesFromArgv(options.argv);
   60       configFilePath = CSON.resolve(path.join(config.getAtomDirectory(), 'config'));
   61       if (!configFilePath) {
   62         callback("Could not find config.cson. Run Atom first?");
   63         return;
   64       }
   65       try {
   66         settings = CSON.readFileSync(configFilePath);
   67       } catch (error1) {
   68         error = error1;
   69         callback("Failed to load `" + configFilePath + "`: " + error.message);
   70         return;
   71       }
   72       return this.getInstalledPackages((function(_this) {
   73         return function(error, installedPackages) {
   74           var disabledPackages, error2, installedPackageNames, keyPath, pkg, ref, result, uninstalledPackageNames;
   75           if (error) {
   76             return callback(error);
   77           }
   78           installedPackageNames = (function() {
   79             var i, len, results;
   80             results = [];
   81             for (i = 0, len = installedPackages.length; i < len; i++) {
   82               pkg = installedPackages[i];
   83               results.push(pkg.name);
   84             }
   85             return results;
   86           })();
   87           uninstalledPackageNames = _.difference(packageNames, installedPackageNames);
   88           if (uninstalledPackageNames.length > 0) {
   89             console.log("Not Installed:\n  " + (uninstalledPackageNames.join('\n  ')));
   90           }
   91           packageNames = _.difference(packageNames, uninstalledPackageNames);
   92           if (packageNames.length === 0) {
   93             callback("Please specify a package to disable");
   94             return;
   95           }
   96           keyPath = '*.core.disabledPackages';
   97           disabledPackages = (ref = _.valueForKeyPath(settings, keyPath)) != null ? ref : [];
   98           result = _.union.apply(_, [disabledPackages].concat(slice.call(packageNames)));
   99           _.setValueForKeyPath(settings, keyPath, result);
  100           try {
  101             CSON.writeFileSync(configFilePath, settings);
  102           } catch (error2) {
  103             error = error2;
  104             callback("Failed to save `" + configFilePath + "`: " + error.message);
  105             return;
  106           }
  107           console.log("Disabled:\n  " + (packageNames.join('\n  ')));
  108           _this.logSuccess();
  109           return callback();
  110         };
  111       })(this));
  112     };
  113 
  114     return Disable;
  115 
  116   })(Command);
  117 
  118 }).call(this);