blittle/bower-installer — pull request #68 by bessdsv (2014-08-15 11:58:06+00:00)
Title: Create post install hook for dependency instalation

In my project, I needed to slightly modify the installed files of dependencies.

According to this idea to create a set of events on which to run some scripts.

At present, the function simply executes the configured script.

In the future it is planned to separate these two types of scripts:
1) simple script (not only on nodejs)
2) the module on nodejs running through the fork which will be sent a list of command-line arguments, and a list of files that were installed as part of this dependence.
Implemented so far only the first type.

an example of the configuration and script code:
/*bower.json*/
{
"install": {
"path": {
"jasmine-jquery" : "tests/libs/jasmine/plugins/jasmine-jquery",
},
"scripts" : {
"postinstall" : {
"jasmine-jquery" : "tests/scripts/JasmineJqueryPluginPostInstallScript.js"
}
}
},
"dependencies": {
"jasmine-jquery": "~2.0.5",
}
}

/*JasmineJqueryPluginPostInstallScript.js*/
var fs = require('fs');
var someFile = 'tests/libs/jasmine/plugins/jasmine-jquery/jasmine-jquery.js';
fs.readFile(someFile, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = data.replace(/window\.jQuery/g, 'jq2');

fs.writeFile(someFile, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});

This was done due to the fact that the product I'm using one version of jquery and the plugin requires a different version of this and I need to safely connect two versions but the original version of the file does not let me do it.