"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/list.js" (7 Feb 2017, 11083 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, List, _, config, fs, getRepository, path, tree, 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   _ = require('underscore-plus');
    9 
   10   CSON = require('season');
   11 
   12   yargs = require('yargs');
   13 
   14   Command = require('./command');
   15 
   16   fs = require('./fs');
   17 
   18   config = require('./apm');
   19 
   20   tree = require('./tree');
   21 
   22   getRepository = require("./packages").getRepository;
   23 
   24   module.exports = List = (function(superClass) {
   25     extend(List, superClass);
   26 
   27     List.commandNames = ['list', 'ls'];
   28 
   29     function List() {
   30       var configPath, ref, ref1;
   31       this.userPackagesDirectory = path.join(config.getAtomDirectory(), 'packages');
   32       this.devPackagesDirectory = path.join(config.getAtomDirectory(), 'dev', 'packages');
   33       if (configPath = CSON.resolve(path.join(config.getAtomDirectory(), 'config'))) {
   34         try {
   35           this.disabledPackages = (ref = CSON.readFileSync(configPath)) != null ? (ref1 = ref.core) != null ? ref1.disabledPackages : void 0 : void 0;
   36         } catch (undefined) {}
   37       }
   38       if (this.disabledPackages == null) {
   39         this.disabledPackages = [];
   40       }
   41     }
   42 
   43     List.prototype.parseOptions = function(argv) {
   44       var options;
   45       options = yargs(argv).wrap(100);
   46       options.usage("\nUsage: apm list\n       apm list --themes\n       apm list --packages\n       apm list --installed\n       apm list --installed --bare > my-packages.txt\n       apm list --json\n\nList all the installed packages and also the packages bundled with Atom.");
   47       options.alias('b', 'bare').boolean('bare').describe('bare', 'Print packages one per line with no formatting');
   48       options.alias('d', 'dev').boolean('dev')["default"]('dev', true).describe('dev', 'Include dev packages');
   49       options.alias('h', 'help').describe('help', 'Print this usage message');
   50       options.alias('i', 'installed').boolean('installed').describe('installed', 'Only list installed packages/themes');
   51       options.alias('j', 'json').boolean('json').describe('json', 'Output all packages as a JSON object');
   52       options.alias('l', 'links').boolean('links')["default"]('links', true).describe('links', 'Include linked packages');
   53       options.alias('t', 'themes').boolean('themes').describe('themes', 'Only list themes');
   54       return options.alias('p', 'packages').boolean('packages').describe('packages', 'Only list packages');
   55     };
   56 
   57     List.prototype.isPackageDisabled = function(name) {
   58       return this.disabledPackages.indexOf(name) !== -1;
   59     };
   60 
   61     List.prototype.logPackages = function(packages, options) {
   62       var i, len, pack, packageLine;
   63       if (options.argv.bare) {
   64         for (i = 0, len = packages.length; i < len; i++) {
   65           pack = packages[i];
   66           packageLine = pack.name;
   67           if (pack.version != null) {
   68             packageLine += "@" + pack.version;
   69           }
   70           console.log(packageLine);
   71         }
   72       } else {
   73         tree(packages, (function(_this) {
   74           return function(pack) {
   75             var ref, repo, shaLine;
   76             packageLine = pack.name;
   77             if (pack.version != null) {
   78               packageLine += "@" + pack.version;
   79             }
   80             if (((ref = pack.apmInstallSource) != null ? ref.type : void 0) === 'git') {
   81               repo = getRepository(pack);
   82               shaLine = "#" + (pack.apmInstallSource.sha.substr(0, 8));
   83               if (repo != null) {
   84                 shaLine = repo + shaLine;
   85               }
   86               packageLine += (" (" + shaLine + ")").grey;
   87             }
   88             if (_this.isPackageDisabled(pack.name)) {
   89               packageLine += ' (disabled)';
   90             }
   91             return packageLine;
   92           };
   93         })(this));
   94       }
   95       return console.log();
   96     };
   97 
   98     List.prototype.listPackages = function(directoryPath, options) {
   99       var child, i, len, manifest, manifestPath, packages, ref;
  100       packages = [];
  101       ref = fs.list(directoryPath);
  102       for (i = 0, len = ref.length; i < len; i++) {
  103         child = ref[i];
  104         if (!fs.isDirectorySync(path.join(directoryPath, child))) {
  105           continue;
  106         }
  107         if (child.match(/^\./)) {
  108           continue;
  109         }
  110         if (!options.argv.links) {
  111           if (fs.isSymbolicLinkSync(path.join(directoryPath, child))) {
  112             continue;
  113           }
  114         }
  115         manifest = null;
  116         if (manifestPath = CSON.resolve(path.join(directoryPath, child, 'package'))) {
  117           try {
  118             manifest = CSON.readFileSync(manifestPath);
  119           } catch (undefined) {}
  120         }
  121         if (manifest == null) {
  122           manifest = {};
  123         }
  124         manifest.name = child;
  125         if (options.argv.themes) {
  126           if (manifest.theme) {
  127             packages.push(manifest);
  128           }
  129         } else if (options.argv.packages) {
  130           if (!manifest.theme) {
  131             packages.push(manifest);
  132           }
  133         } else {
  134           packages.push(manifest);
  135         }
  136       }
  137       return packages;
  138     };
  139 
  140     List.prototype.listUserPackages = function(options, callback) {
  141       var userPackages;
  142       userPackages = this.listPackages(this.userPackagesDirectory, options).filter(function(pack) {
  143         return !pack.apmInstallSource;
  144       });
  145       if (!(options.argv.bare || options.argv.json)) {
  146         console.log(("Community Packages (" + userPackages.length + ")").cyan, "" + this.userPackagesDirectory);
  147       }
  148       return typeof callback === "function" ? callback(null, userPackages) : void 0;
  149     };
  150 
  151     List.prototype.listDevPackages = function(options, callback) {
  152       var devPackages;
  153       if (!options.argv.dev) {
  154         return typeof callback === "function" ? callback(null, []) : void 0;
  155       }
  156       devPackages = this.listPackages(this.devPackagesDirectory, options);
  157       if (devPackages.length > 0) {
  158         if (!(options.argv.bare || options.argv.json)) {
  159           console.log(("Dev Packages (" + devPackages.length + ")").cyan, "" + this.devPackagesDirectory);
  160         }
  161       }
  162       return typeof callback === "function" ? callback(null, devPackages) : void 0;
  163     };
  164 
  165     List.prototype.listGitPackages = function(options, callback) {
  166       var gitPackages;
  167       gitPackages = this.listPackages(this.userPackagesDirectory, options).filter(function(pack) {
  168         var ref;
  169         return ((ref = pack.apmInstallSource) != null ? ref.type : void 0) === 'git';
  170       });
  171       if (gitPackages.length > 0) {
  172         if (!(options.argv.bare || options.argv.json)) {
  173           console.log(("Git Packages (" + gitPackages.length + ")").cyan, "" + this.userPackagesDirectory);
  174         }
  175       }
  176       return typeof callback === "function" ? callback(null, gitPackages) : void 0;
  177     };
  178 
  179     List.prototype.listBundledPackages = function(options, callback) {
  180       return config.getResourcePath(function(resourcePath) {
  181         var _atomPackages, metadata, metadataPath, packageName, packages;
  182         try {
  183           metadataPath = path.join(resourcePath, 'package.json');
  184           _atomPackages = JSON.parse(fs.readFileSync(metadataPath))._atomPackages;
  185         } catch (undefined) {}
  186         if (_atomPackages == null) {
  187           _atomPackages = {};
  188         }
  189         packages = (function() {
  190           var results;
  191           results = [];
  192           for (packageName in _atomPackages) {
  193             metadata = _atomPackages[packageName].metadata;
  194             results.push(metadata);
  195           }
  196           return results;
  197         })();
  198         packages = packages.filter(function(metadata) {
  199           if (options.argv.themes) {
  200             return metadata.theme;
  201           } else if (options.argv.packages) {
  202             return !metadata.theme;
  203           } else {
  204             return true;
  205           }
  206         });
  207         if (!(options.argv.bare || options.argv.json)) {
  208           if (options.argv.themes) {
  209             console.log('Built-in Atom Themes'.cyan + " (" + packages.length + ")");
  210           } else {
  211             console.log('Built-in Atom Packages'.cyan + " (" + packages.length + ")");
  212           }
  213         }
  214         return typeof callback === "function" ? callback(null, packages) : void 0;
  215       });
  216     };
  217 
  218     List.prototype.listInstalledPackages = function(options) {
  219       return this.listDevPackages(options, (function(_this) {
  220         return function(error, packages) {
  221           if (packages.length > 0) {
  222             _this.logPackages(packages, options);
  223           }
  224           return _this.listUserPackages(options, function(error, packages) {
  225             _this.logPackages(packages, options);
  226             return _this.listGitPackages(options, function(error, packages) {
  227               if (packages.length > 0) {
  228                 return _this.logPackages(packages, options);
  229               }
  230             });
  231           });
  232         };
  233       })(this));
  234     };
  235 
  236     List.prototype.listPackagesAsJson = function(options, callback) {
  237       var output;
  238       if (callback == null) {
  239         callback = function() {};
  240       }
  241       output = {
  242         core: [],
  243         dev: [],
  244         git: [],
  245         user: []
  246       };
  247       return this.listBundledPackages(options, (function(_this) {
  248         return function(error, packages) {
  249           if (error) {
  250             return callback(error);
  251           }
  252           output.core = packages;
  253           return _this.listDevPackages(options, function(error, packages) {
  254             if (error) {
  255               return callback(error);
  256             }
  257             output.dev = packages;
  258             return _this.listUserPackages(options, function(error, packages) {
  259               if (error) {
  260                 return callback(error);
  261               }
  262               output.user = packages;
  263               return _this.listGitPackages(options, function(error, packages) {
  264                 if (error) {
  265                   return callback(error);
  266                 }
  267                 output.git = packages;
  268                 console.log(JSON.stringify(output));
  269                 return callback();
  270               });
  271             });
  272           });
  273         };
  274       })(this));
  275     };
  276 
  277     List.prototype.run = function(options) {
  278       var callback;
  279       callback = options.callback;
  280       options = this.parseOptions(options.commandArgs);
  281       if (options.argv.json) {
  282         return this.listPackagesAsJson(options, callback);
  283       } else if (options.argv.installed) {
  284         this.listInstalledPackages(options);
  285         return callback();
  286       } else {
  287         return this.listBundledPackages(options, (function(_this) {
  288           return function(error, packages) {
  289             _this.logPackages(packages, options);
  290             _this.listInstalledPackages(options);
  291             return callback();
  292           };
  293         })(this));
  294       }
  295     };
  296 
  297     return List;
  298 
  299   })(Command);
  300 
  301 }).call(this);