質問

I want to know the current platform being used in a cordova hook script.

For example if I run

cordova build ios

I want a way to get ios from within an after_prepare hook.

I thought the CORDOVA_PLATFORMS envroinment variable might help but it's inconsistent. Sometimes I get all platforms in the case of the above command and other times like cordova platform add android I just get the new platform.

役に立ちましたか?

解決

using process.env.CORDOVA_PLATFORMS, it returns a string including all build platforms targets, separated by a comma.

process.env contains all information you may need for the build. Dump it for more information.

if you're using module.export

module.exports = function(ctx) {
    // make sure android platform is part of build
    if (ctx.opts.platforms.indexOf('android') < 0) {
        return;
    }
};

Check Cordova Hooks documentation

他のヒント

CORDOVA_PLATFORMS does seem the be the sane way to do it. I don't know why it wasn't working right for me initially. It's a comma separated list of platforms so cordova build ios android would have it set to "ios,android".

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top