Skip to content

Instantly share code, notes, and snippets.

@sgdavis1
Created February 27, 2015 20:54
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 sgdavis1/bbeb84efba13eee6fc47 to your computer and use it in GitHub Desktop.
Save sgdavis1/bbeb84efba13eee6fc47 to your computer and use it in GitHub Desktop.
hooks/before_build/010_check_cordovalib.js
#!/usr/bin/env node
// This hook ensures no one has accidentally deleted the "cordova" script tag
var fs = require('fs');
var path = require('path');
var sys = require('sys')
var rootdir = process.argv[2];
var config = fs.readFileSync(path.join(rootdir, 'config.xml'));
var content = "";
if (matches = /<content\s+src=['"](\S+)['"]/.exec(config))
{
sys.puts(' Looking for script tag to "cordova.js" in: ' + matches[1]);
content = fs.readFileSync(path.join(rootdir, "www", matches[1]));
if (matches2 = /<script\s[^>]*src=['"]cordova.js['"].*\/script>/.exec(content))
{
sys.puts(' Looks like you are including the cordova libs:');
sys.puts(' ' + matches2[0]);
sys.puts('');
}
else
{
sys.puts(' Cannot find the Cordova lib script tag :(');
sys.puts(' (If you verify it is included, check my RegExp, it might need to be adjusted)');
sys.puts('');
process.exit(1);
}
}
@hassansaeed999
Copy link

where to put this code ..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment