Flesh out helpers to support all OP(Rails) plugins

This currently use a very native approach to determines if a gem is a
OpenProject plugin - simply matching 'openproject-'.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/2193/head
Alex Coles 10 years ago
parent 35f2c7a978
commit 15ca1a0999
  1. 41
      config/rails-plugins.conf.js

@ -1,11 +1,41 @@
require('shelljs/global');
var path = require('path');
var path = require('path'),
_ = require('lodash');
function rubyBundler(subCmd) {
var fullCmd = exec('bundle ' + subCmd);
var fullCmd = exec('bundle ' + subCmd, { silent: true });
return fullCmd.code === 0 ? fullCmd.output : null;
}
var OpenProjectPlugins = {
pluginPaths: _.memoize(function() {
var allPaths = (rubyBundler('list --paths') || '').split('\n');
return allPaths.filter(function(name) {
// naive match
return name.match(/openproject-/);
});
}),
pluginNamesPaths: function() {
return this.pluginPaths().reduce(function(obj, pluginPath) {
var pluginName = path.basename(pluginPath).replace(/-[0-9a-fA-F]{12}$/, '');
obj[pluginName] = pluginPath;
return obj;
}, {});
},
findPluginPath: _.memoize(function(name) {
return this.pluginNamesPaths()[name];
}, _.identity),
pluginDirectories: function() {
return this.pluginPaths().reduce(function(dirList, pluginPath) {
var pluginDir = path.dirname(pluginPath);
return dirList.indexOf(pluginDir) === -1 ? dirList.concat(pluginDir) : dirList;
}, []);
}
};
var TranslationsPlugin = {
envPath: function() {
if (env['OPENPROJECT_TRANSLATIONS_ROOT']) {
@ -13,12 +43,8 @@ var TranslationsPlugin = {
}
},
findBundlerPath: function() {
return rubyBundler('show openproject-translations');
},
findPluginPath: function() {
return this.envPath() || this.findBundlerPath() || '';
return this.envPath() || OpenProjectPlugins.findPluginPath('openproject-translations') || '';
},
findLocaleFiles: function() {
@ -29,5 +55,6 @@ var TranslationsPlugin = {
}
};
exports.pluginDirectories = OpenProjectPlugins.pluginDirectories();
exports.translationsPluginLocales = TranslationsPlugin.findLocaleFiles();
exports.translationsPluginPath = TranslationsPlugin.findPluginPath();

Loading…
Cancel
Save