Skip to content

Instantly share code, notes, and snippets.

@nuald
Created September 28, 2016 01:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nuald/3a7df998b2a5e2ea008493c651ea53eb to your computer and use it in GitHub Desktop.
Cordova gulp build hook
#!/bin/bash
echo "Building Web Project.";
cd ../web/;
gulp;
cd ../cordova/;
echo "Deleting files in ./www";
rm -rf ./www/*;
echo "Copying files from ./web/dist to ./www";
cp -r ../web/dist/* ./www/;
module.exports = (ctx) => {
var Q = ctx.requireCordovaModule('q'),
shell = ctx.requireCordovaModule('shelljs');
var gulpDeferral = new Q.defer(),
exitDeferral = new Q.defer();
console.log("Building Web Project.");
shell.cd('../web/');
shell.exec('gulp', (error, stdout, stderr) => {
if (!error) {
gulpDeferral.resolve();
} else {
exitDeferral.reject('gulp failed!');
}
});
gulpDeferral.promise.then(() => {
console.log("Deleting files in ./www");
shell.cd('../cordova/');
shell.rm('-rf', 'www/*');
console.log("Copying files from ../web/dist to ./www");
shell.cp('-Rf', '../web/dist/*', './www/');
exitDeferral.resolve();
});
return exitDeferral.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment