ionic-team / ionic-package-hooks

Cordova hooks that you can run in Ionic Package
Other
68 stars 38 forks source link

JS hooks included in config.xml file need to be implemented as node modules. #7

Closed carson-drake closed 8 years ago

carson-drake commented 8 years ago

Not sure if this is just because of my local versions of cordova and ionic-cli, but any javascript hook called out in the config.xml file must be configured as a node module (as seen here). I noticed this after attempting to integrate android_ignore_translation_errors.js into my actual project. It failed but locally and with ionic package build android -p ### --release. It's hard to confirm that the ionic package failed attempts were because of this since I can only see the build error, but it was the same build error as I was getting when running ionic build android --release. After investigating I noticed only hooks in the hooks/after_prepare directory or .sh hooks included in the config.xml file were executing. the following seemed to fix my issue locally.


// add additional build-extras.gradle file to instruct android's lint to ignore translation errors
// v0.1.c
// causing error in the build --release
// Issue: https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/80
//
// Warning: This solution does not solve the problem only makes it possible to build --release
module.exports = function(ctx){
    // make sure android platform is part of build 
    if(ctx.opts.platforms.indexOf('android') < 0){
        return;
    }
    var fs = ctx.requireCordovaModule('fs'),
        path = ctx.requireCordovaModule('path'),
        deferral = ctx.requireCordovaModule('q').defer();

    var rootdir = path.join(ctx.opts.projectRoot, 'platforms/android');

    if(rootdir){

        var platforms = ctx.opts.platforms;
        for(var x = 0; x < platforms.length; x++){
            var platform = platforms[x].trim().toLowerCase();
            try{
                if(platform == 'android'){
                    var lintOptions = 'android { \nlintOptions {\ndisable \'MissingTranslation\' \ndisable \'ExtraTranslation\' \n} \n}';
                    fs.appendFileSync('platforms/android/build-extras.gradle', lintOptions, 'UTF-8');
                    console.log('Added build-extras.gradle ');
                    deferral.resolve();
                }
            }
            catch(e){
                console.log(e);
            }
        }
    }
    return deferral.promise;
};
imhoffd commented 8 years ago

This I did not know. This must have changed. Kind neat, though, because they allow promises to be returned from these hooks instead of just running it until it finishes.

imhoffd commented 8 years ago

I'm confused. Does add_platform_class.js not work, then? It seems to work, but it is not a node module.

carson-drake commented 8 years ago

Unless I had hooks/after_prepare/add_platform_class.js loaded, the hook would not run. So I can't confidently say it was being executed in package build either.