Why does Ionic Cli remove command parameters passed to the cordova hooks?


#1

I’m implementing a Hook in before_prepare and I need to pass a parameter to my command. Only I realized that the parameter was not being sent to the cordova, not getting into my script, then removes the ionic from the command and the parameter arrives in the script correctly.

Here’s what’s happening:

config.xml:

// ...
<hook src="hooks/build-environment-config.js" type="before_prepare" />
// ...

hooks/build-environment-config.js:

module.exports = function (ctx) {
    console.log(ctx.opts.options);
    console.log(ctx.cmdLine);
};

Outputs:

$ cordova prepare android --flavor=dev
{ flavor: 'dev', argv: [], fetch: true }
C:\Program Files\nodejs\node.exe C:\Users\Usuario\AppData\Roaming\npm\node_modules\cordova\bin\cordova prepare android --flavor=dev
$ ionic cordova prepare android --flavor=dev
> cordova prepare android
{ argv: [], fetch: true }
C:\Program Files\nodejs\node.exe C:\Users\Usuario\AppData\Roaming\npm\node_modules\cordova\bin\cordova prepare android

What can I do so I can perform the command with ionic and pass the parameter to the cordova hook script?

Environment:

Ionic CLI: 3.13.2
Cordova: 7.1.0


Same base and project for multiple apps
#2

A hunch: Try -- --flavor=dev.


#3

@Sujan12 This really worked:

$ ionic cordova prepare android -- --flavor=dev
> cordova prepare android --flavor=dev
{ flavor: 'dev', argv: [], fetch: true }
C:\Program Files\nodejs\node.exe C:\Users\Usuario\AppData\Roaming\npm\node_modules\cordova\bin\cordova prepare android --flavor=dev

But why “extra”? Why Ionic “steals” the last parameter in a convensional way?

Is this a hack? I would understand why it occurs not to make another mistake when working with Ionic CLI.


#4

I can’ t say much about why this is implemented this way, but as I understood it with -- you specify params for ionic. If you want to specificy params for the level underneath (cordova), you have to add another --. And for some things with Gradle that takes params, an additional -- is required.