Skip to content

Instantly share code, notes, and snippets.

@slattery
Last active October 21, 2015 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slattery/9c0566753d80c04f3b15 to your computer and use it in GitHub Desktop.
Save slattery/9c0566753d80c04f3b15 to your computer and use it in GitHub Desktop.
Git branch reporter for npm-linked actionhero plugins

#gitcheck.js This initializer checks plugin directories for git branches, and reports which branch is being loaded by the server.

I use npm link to serve up my plugins-in-progress for actionhero. I ask npm's preinstall hook to run npm link $PLUGIN so that the plugin will be in actionhero's node_modules dir when the main install happens.

It works very well for us, but when the gitflow is feverish I need to double check which branch I'm running in a given actionhero config.

I put this initializer at the projectRoot level, and it sweeps my plugins to report on git branches.

2015-05-19 20:46:51 - notice: environment: singlebox
2015-05-19 20:46:51 - notice: Plugin ah-spa-plugin is serving git branch: ⎇  master
2015-05-19 20:46:51 - notice: Plugin ah-app-plugin is serving git branch: ⎇  feature/bumpah
2015-05-19 20:46:51 - notice: *** Server Started @ 2015-05-19 20:46:51 ***
var path = require('path'),
fs = require('fs'),
exec = require('child_process').execSync,
brchar ="⎇ ";
module.exports = {
loadPriority: 1000,
startPriority: 1000,
stopPriority: 1000,
initialize: function(api, next){
next();
},
start: function(api, next){
// connect to server
if (!api.gitcheck){
// these three lines came right out of the AH configLoader
api.config.general.paths.plugin.forEach(function(p){
api.config.general.plugins.forEach(function(plugin){
var pluginPackageBase = path.normalize(p + '/' + plugin);
try {
var b = exec('git rev-parse --abbrev-ref HEAD', {cwd: pluginPackageBase});
if (b){
var txt = "Plugin " + plugin + " is serving git branch: "
+ brchar + b.toString().replace(/[\n\r]/g, '');
api.log( txt, "notice" );
}
} catch(er){
api.log( "Plugin " + plugin + " is not in a git repo", "debug" );
}
})
});
api.gitcheck = true;
}
next();
},
stop: function(api, next){
// disconnect from server
api.gitcheck = false;
next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment