<commit_before>var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var npm = require("npm");
var request = require("request");

var npmIsLoaded = false;
var withNpm = function(npmfn) {
  if (npmIsLoaded) return npmfn();

  npm.load({}, function(er) {
    if (er) return npmfn(er);

    npmIsLoaded = true;
    npm.on("log", function(message) {
      console.log('npm: ',message)
    });
    npmfn();
  });
}

var tasks = 0

function wrapTaskCb(cb) {
  tasks++;

  return function() {
    cb && cb.apply(this, arguments);
    tasks--;
    if (tasks == 0) onAllTasksFinished();
  }
}

function onAllTasksFinished() {
  hooks.aCallAll("restartServer", {}, function() {});
}

exports.uninstall = function(plugin_name, cb) {
  cb = wrapTaskCb(cb);

  withNpm(function(er) {
    if (er) return cb && cb(er);

    npm.commands.uninstall([plugin_name], function(er) {
      if (er) return cb && cb(er);

      hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name}, function(er, data) {
        if (er) return cb(er);

        plugins.update(cb);
      });
    });
  });
};

exports.install = function(plugin_name, cb) {
  cb = wrapTaskCb(cb);

  withNpm(function(er) {
    if (er) return cb && cb(er);

    npm.commands.install([plugin_name], function(er) {
      if (er) return cb && cb(er);

      hooks.aCallAll("pluginInstall", {plugin_name: plugin_name}, function(er, data) {
        if (er) return cb(er);

        plugins.update(cb);
      });
    });
  });
};

exports.availablePlugins = null;
var cacheTimestamp = 0;

exports.getAvailablePlugins = function(maxCacheAge, cb) {
  request("https://static.etherpad.org/plugins.json", function(er, response, plugins){
    if (er) return cb && cb(er);<commit_msg>pluginfw/installer.js: use Promise version of hooks.aCallAll() in install(), uninstall()<commit_after>var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var npm = require("npm");
var request = require("request");

var npmIsLoaded = false;
var withNpm = function(npmfn) {
  if (npmIsLoaded) return npmfn();

  npm.load({}, function(er) {
    if (er) return npmfn(er);

    npmIsLoaded = true;
    npm.on("log", function(message) {
      console.log('npm: ',message)
    });
    npmfn();
  });
}

var tasks = 0

function wrapTaskCb(cb) {
  tasks++;

  return function() {
    cb && cb.apply(this, arguments);
    tasks--;
    if (tasks == 0) onAllTasksFinished();
  }
}

function onAllTasksFinished() {
  hooks.aCallAll("restartServer", {}, function() {});
}

/*
 * We cannot use arrow functions in this file, because code in /src/static
 * can end up being loaded in browsers, and we still support IE11.
 */
exports.uninstall = function(plugin_name, cb) {
  cb = wrapTaskCb(cb);

  withNpm(function(er) {
    if (er) return cb && cb(er);

    npm.commands.uninstall([plugin_name], function(er) {
      if (er) return cb && cb(er);
      hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name})
        .then(plugins.update)
        .then(function() { cb(null) })
        .catch(function(er) { cb(er) });
    });
  });
};

/*
 * We cannot use arrow functions in this file, because code in /src/static
 * can end up being loaded in browsers, and we still support IE11.
 */
exports.install = function(plugin_name, cb) {
  cb = wrapTaskCb(cb);

  withNpm(function(er) {
    if (er) return cb && cb(er);

    npm.commands.install([plugin_name], function(er) {
      if (er) return cb && cb(er);
      hooks.aCallAll("pluginInstall", {plugin_name: plugin_name})
        .then(plugins.update)
        .then(function() { cb(null) })
        .catch(function(er) { cb(er) });
    });
  });
};

exports.availablePlugins = null;
var cacheTimestamp = 0;

exports.getAvailablePlugins = function(maxCacheAge, cb) {
  request("https://static.etherpad.org/plugins.json", function(er, response, plugins){
    if (er) return cb && cb(er);
{'fraction_non_alphanumeric': 0.16595957075118542, 'fraction_numerical': 0.0024956326428749688, 'mean_word_length': 3.54421768707483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4900606', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1350, 'n_words': 309}