"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/rebuild-module-cache.js" (8 Mar 2017, 3670 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, RebuildModuleCache, async, config, fs, 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   path = require('path');
    7 
    8   async = require('async');
    9 
   10   yargs = require('yargs');
   11 
   12   Command = require('./command');
   13 
   14   config = require('./apm');
   15 
   16   fs = require('./fs');
   17 
   18   module.exports = RebuildModuleCache = (function(superClass) {
   19     extend(RebuildModuleCache, superClass);
   20 
   21     RebuildModuleCache.commandNames = ['rebuild-module-cache'];
   22 
   23     function RebuildModuleCache() {
   24       this.atomPackagesDirectory = path.join(config.getAtomDirectory(), 'packages');
   25     }
   26 
   27     RebuildModuleCache.prototype.parseOptions = function(argv) {
   28       var options;
   29       options = yargs(argv).wrap(100);
   30       options.usage("\nUsage: apm rebuild-module-cache\n\nRebuild the module cache for all the packages installed to\n~/.atom/packages\n\nYou can see the state of the module cache for a package by looking\nat the _atomModuleCache property in the package's package.json file.\n\nThis command skips all linked packages.");
   31       return options.alias('h', 'help').describe('help', 'Print this usage message');
   32     };
   33 
   34     RebuildModuleCache.prototype.getResourcePath = function(callback) {
   35       if (this.resourcePath) {
   36         return process.nextTick((function(_this) {
   37           return function() {
   38             return callback(_this.resourcePath);
   39           };
   40         })(this));
   41       } else {
   42         return config.getResourcePath((function(_this) {
   43           return function(resourcePath1) {
   44             _this.resourcePath = resourcePath1;
   45             return callback(_this.resourcePath);
   46           };
   47         })(this));
   48       }
   49     };
   50 
   51     RebuildModuleCache.prototype.rebuild = function(packageDirectory, callback) {
   52       return this.getResourcePath((function(_this) {
   53         return function(resourcePath) {
   54           var error, error1;
   55           try {
   56             if (_this.moduleCache == null) {
   57               _this.moduleCache = require(path.join(resourcePath, 'src', 'module-cache'));
   58             }
   59             _this.moduleCache.create(packageDirectory);
   60           } catch (error1) {
   61             error = error1;
   62             return callback(error);
   63           }
   64           return callback();
   65         };
   66       })(this));
   67     };
   68 
   69     RebuildModuleCache.prototype.run = function(options) {
   70       var callback, commands;
   71       callback = options.callback;
   72       commands = [];
   73       fs.list(this.atomPackagesDirectory).forEach((function(_this) {
   74         return function(packageName) {
   75           var packageDirectory;
   76           packageDirectory = path.join(_this.atomPackagesDirectory, packageName);
   77           if (fs.isSymbolicLinkSync(packageDirectory)) {
   78             return;
   79           }
   80           if (!fs.isFileSync(path.join(packageDirectory, 'package.json'))) {
   81             return;
   82           }
   83           return commands.push(function(callback) {
   84             process.stdout.write("Rebuilding " + packageName + " module cache ");
   85             return _this.rebuild(packageDirectory, function(error) {
   86               if (error != null) {
   87                 _this.logFailure();
   88               } else {
   89                 _this.logSuccess();
   90               }
   91               return callback(error);
   92             });
   93           });
   94         };
   95       })(this));
   96       return async.waterfall(commands, callback);
   97     };
   98 
   99     return RebuildModuleCache;
  100 
  101   })(Command);
  102 
  103 }).call(this);