Skip to content

Commit

Permalink
make it actionhero v13 ready ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
S3bb1 committed Feb 20, 2016
1 parent f072090 commit 318c14c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
1 change: 0 additions & 1 deletion actions/calcStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ action.run = function(api, data, next){
// iterate through all available statistics and get their corresponding timeseries value
async.each(stats, function(stat, callback) {
api.ahDashboard.timesSeries.getHits(stat, timeInterval, timechunks, function(err, res){
console.dir(res);
for(var a in res){
res[a].push(new Date((res[a][0]*1000)));
}
Expand Down
64 changes: 48 additions & 16 deletions actions/getPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,68 @@ action.outputExample = {
action.run = function(api, data, next){
api.ahDashboard.session.checkAuth(data, function(session){
var plugins = [];
api.config.general.paths.plugin.forEach(function(p){
api.config.general.plugins.forEach(function(pluginName){
var pluginPackageBase = path.normalize(p + '/' + pluginName);
// Check if plugin folder isnt ah root folder AND the folder exists (if multiple plugins folder are defined)
if(api.project_root != pluginPackageBase && fs.existsSync(pluginPackageBase)){
var plugin = {};
var foundPlugins = [];

// try to get any plugin link
[ 'actions', 'tasks', 'public', 'servers', 'initializers'].forEach(function(pluginPath){
// get a local link directory
var localLinkDirectory = api.projectRoot + path.sep + pluginPath + path.sep + 'plugins';

// check if the directory exists
if( fs.existsSync(localLinkDirectory) ){
// when it exists, read the whole directory
var pluginDir = fs.readdirSync(localLinkDirectory);
// now iterate over all registered plugins
for(var i=0; i<pluginDir.length; i++){
// because the linked file is named ***.link we have to split it
var pluginNameSplitted = pluginDir[i].split('.');
if(pluginNameSplitted.length === 2){
// get the plugin name
var pluginName = pluginNameSplitted[0];
// add it to the plugins array when it not contains the plugin already
if(plugins.indexOf(pluginName) === -1){
plugins.push(pluginName);
}
}
}
}
});

// now iterate over all registered plugin folders
api.config.general.paths.plugin.forEach(function(pluginPath){

// in each folder we have to iterate over all found plugins
plugins.forEach(function(pluginName){
// now check if the plugin exists in the current plugin path
var pluginPathAttempt = path.normalize(pluginPath + path.sep + pluginName);
if(fs.existsSync(pluginPath + path.sep + pluginName) ){

// set the package base to the registered plugin path + the current plugin name
var pluginPackageBase = pluginPath + path.sep + pluginName;
var foundPlugin = {};

var package_json = String(fs.readFileSync(pluginPackageBase + '/package.json'));
var readme = String(pluginPackageBase + '/README.md');
var changelog = String(pluginPackageBase + '/VERSIONS.md');

plugin.readme = 'n.a.';
foundPlugin.readme = 'n.a.';
if (fs.existsSync(readme)) {
plugin.readme = markdown.toHTML(fs.readFileSync(readme, 'utf8'));
foundPlugin.readme = markdown.toHTML(fs.readFileSync(readme, 'utf8'));
}

plugin.changelog = 'n.a.';
foundPlugin.changelog = 'n.a.';
if (fs.existsSync(changelog)) {
plugin.changelog = markdown.toHTML(fs.readFileSync(changelog, 'utf8'));
foundPlugin.changelog = markdown.toHTML(fs.readFileSync(changelog, 'utf8'));
}

plugin.version = JSON.parse(package_json).version;
plugin.name = JSON.parse(package_json).name;
plugin.description = JSON.parse(package_json).description;
plugins.push(plugin);
foundPlugin.version = JSON.parse(package_json).version;
foundPlugin.name = JSON.parse(package_json).name;
foundPlugin.description = JSON.parse(package_json).description;
foundPlugins.push(foundPlugin);
}
});
});

data.response.plugins = plugins;
data.response.plugins = foundPlugins;

next();
}, next );
Expand Down

0 comments on commit 318c14c

Please sign in to comment.