"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/enable.js" (8 Mar 2017, 2867 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, Enable, _, 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 
    6   _ = require('underscore-plus');
    7 
    8   path = require('path');
    9 
   10   CSON = require('season');
   11 
   12   yargs = require('yargs');
   13 
   14   config = require('./apm');
   15 
   16   Command = require('./command');
   17 
   18   module.exports = Enable = (function(superClass) {
   19     extend(Enable, superClass);
   20 
   21     function Enable() {
   22       return Enable.__super__.constructor.apply(this, arguments);
   23     }
   24 
   25     Enable.commandNames = ['enable'];
   26 
   27     Enable.prototype.parseOptions = function(argv) {
   28       var options;
   29       options = yargs(argv).wrap(100);
   30       options.usage("\nUsage: apm enable [<package_name>]...\n\nEnables the named package(s).");
   31       return options.alias('h', 'help').describe('help', 'Print this usage message');
   32     };
   33 
   34     Enable.prototype.run = function(options) {
   35       var callback, configFilePath, disabledPackages, error, error1, error2, errorPackages, keyPath, packageNames, ref, result, settings;
   36       callback = options.callback;
   37       options = this.parseOptions(options.commandArgs);
   38       packageNames = this.packageNamesFromArgv(options.argv);
   39       configFilePath = CSON.resolve(path.join(config.getAtomDirectory(), 'config'));
   40       if (!configFilePath) {
   41         callback("Could not find config.cson. Run Atom first?");
   42         return;
   43       }
   44       try {
   45         settings = CSON.readFileSync(configFilePath);
   46       } catch (error1) {
   47         error = error1;
   48         callback("Failed to load `" + configFilePath + "`: " + error.message);
   49         return;
   50       }
   51       keyPath = '*.core.disabledPackages';
   52       disabledPackages = (ref = _.valueForKeyPath(settings, keyPath)) != null ? ref : [];
   53       errorPackages = _.difference(packageNames, disabledPackages);
   54       if (errorPackages.length > 0) {
   55         console.log("Not Disabled:\n  " + (errorPackages.join('\n  ')));
   56       }
   57       packageNames = _.difference(packageNames, errorPackages);
   58       if (packageNames.length === 0) {
   59         callback("Please specify a package to enable");
   60         return;
   61       }
   62       result = _.difference(disabledPackages, packageNames);
   63       _.setValueForKeyPath(settings, keyPath, result);
   64       try {
   65         CSON.writeFileSync(configFilePath, settings);
   66       } catch (error2) {
   67         error = error2;
   68         callback("Failed to save `" + configFilePath + "`: " + error.message);
   69         return;
   70       }
   71       console.log("Enabled:\n  " + (packageNames.join('\n  ')));
   72       this.logSuccess();
   73       return callback();
   74     };
   75 
   76     return Enable;
   77 
   78   })(Command);
   79 
   80 }).call(this);