vue-cli-plugin-cordova
vue-cli-plugin-cordova copied to clipboard
Use command line arguments for scripts.
What?
I think it would be easier to specify npm run scripts with command line arguments rather, as it would allow greater diversity in scripts that are runnable.
Example:
As an example I will use a simple add method that take command line arguments in its script:
// add.js
// adds two integers received as command line arguments
function add(a, b) {
return parseInt(a)+parseInt(b);
}
if(!process.argv[2] || !process.argv[3]) {
console.log('Insufficient number of arguments! Give two numbers please!');
}
else {
console.log('The sum of', process.argv[2], 'and', process.argv[3], 'is', add(process.argv[2], process.argv[3]));
}
The script becomes:
"js-add": "node add.js"
To run the script:
npm run js-add 2 3
Giving an output of:
The sum of 2 and 3 is 5
Relevance to vue-cli-plugin-cordova?
Using this method:
npm run cordova-serve-ios
can be replace with:
npm run cordova serve ios
This would be ideal in my situation, as I can't build my ios projects on the command line. So my typical build command would be cordova prepare ios
and then I would run the app through xcode. But because your cli commands don't allow for cordova prepare ios
I can't do this.
This way would also make adding commands like cordova prepare ios
easier.
Hello, this sounds nice, but I think you need at least 2 commands then, to distinct between dev and prod environment, because of this
This is because the command's expected mode needs to be known before loading environment variables, which in turn needs to happen before loading user options / applying the plugins.`
Nevertheless, I like your syntax more, than mine, so feel free to implement it, and sent me a pull request.
@cairinmichie have you given it a try ?
I haven't had a chance yet, was planning on doing it this weekend.
ok, no problem, I'll keep this issue open for 3 weeks, if nothing happens.
@cairinmichie do you have any progress?
No, sorry I have been too busy with other work.
@cairinmichie did you made any progress or should I close the ticket ?
It would be useful also to be able to specify command line arguments or a build.json file served to the cordova build
command. I need to be able to do something like this:
cordova build ios --release --buildFlag='-UseModernBuildSystem=0' --developmentTeam='MY_TEAM' --codeSignIdentity='iPhone Developer'
I could just run that command after running npm run cordova-build-ios
(which will fail), but the core purpose of this plugin is to wrap that functionality with the webpack part.
The build.json approach is cleaner:
- You save a build.json file:
{
"ios": {
"debug": {
"codeSignIdentity": "iPhone Developer",
"developmentTeam": "MY_TEAM",
"packageType": "development",
"automaticProvisioning": true,
"buildFlag": [
"-UseModernBuildSystem=0"
]
},
"release": {
"codeSignIdentity": "iPhone Developer",
"developmentTeam": "MY_TEAM",
"packageType": "app-store",
"automaticProvisioning": true,
"buildFlag": [
"-UseModernBuildSystem=0"
]
}
}
}
- Run command:
cordova build ios --buildConfig=./build.json
In this approach, the plugin does not need to parse command line arguments. Rather it could automatically check if build.json exists in src-cordova, and if so, then add it to the cordova build
command.
@jacobg you came to the same problem then here I think:
https://github.com/m0dch3n/vue-cli-plugin-cordova/issues/20
My question there was, how would you distinct between cordova and vue arguments ? If all the arguments are passed to cordova, you no longer can use the arguments, like these:
https://github.com/vuejs/vue-cli/blob/7c91a187e46d7bb9a9b83bcdf97631794ac36b10/packages/%40vue/cli-service/lib/commands/serve.js#L18
An idea I had, was having a prompt asking for the commands, if you run cordova with i.e. new --interactive flag...
@m0dch3n Thanks, I didn't notice issue #20
Does using build.json address your concern?
never tried build.json, so in fact, you can define all the arguments you need, for every cordova command and keep then command arguments away ?
If so, this would help a lot keeping all the special cordova features away from the plugin...
IMO it's important that the plugin is simple to understand and use, and if you are a more advanced user, you still can do more things with the plugin...
As the plugin is running 2 commands (vue serve, cordova run), it needs to be very clear, to which command, the arguments are passed...
That's why I had the idea of an interactive prompt, so you can normally pass the initial arguments to the vue command, and afterwards enter more arguments to the cordova command...
I agree about keeping it simple and being clear about separating of vue and cordova. Sounds like build.json accomplishes that. The npm commands remain exactly the same, and build.json is not required to maintain existing functionality.
I agree that the build.json seems to be the simplest way to give users more control.
ok, I'll give build.json a try, and we can mention and explain this in the README for the "advanced" users
Thanks @m0dch3n. What are your thoughts with respect to specifying a mode in the npm command? https://cli.vuejs.org/guide/mode-and-env.html#modes
For example, it's highly useful in order to specify which backend service environment the vue app should use (e.g., production, local development server, staging, etc). Then the specific project can define the .env.[mode] files to specify the environment variables that apply to that mode.
@jacobg modes are already working, if you do
"cordova-serve-android": "vue-cli-service cordova-serve-android --mode staging"
the app takes the vars from .env.staging...
so i.e. you could this
"cordova-staging-android": "vue-cli-service cordova-build-android --mode staging",
this would end up in :
vue-cli-service build --mode staging --dest src-cordova/www
cordova build android --release
BTW, if we go with only one command for the plugin flexibility, we cannot solve this issue in the same time, because during the plugin runtime, it's already to late ...
https://github.com/m0dch3n/vue-cli-plugin-cordova/issues/31
Ahh, that's great. I didn't realize that the vue cli will automatically use the mode even on custom commands. Thanks!
Any progress with adding build.json support :)
+1 for this. cordova-build-ios
/ cordova-serve-ios
is broken with the latest version of xcode (10). We need to be able to pass --buildFlag='-UseModernBuildSystem=0'
@alexcroox Are you running cordova-ios 4? Because that does require --buildFlag='-UseModernBuildSystem=0'
. But cordova-ios 5 works with the new modern build system, so you won't need that flag anymore.
Updated to 5 and it's working now thanks. How do I specify signing params and packageType for cordova-build-ios
? I have these created in a build.json but they seem to be ignored and it just gets built for Emulator
(instead of app-store) every time. Also I see Signing Identity: "-"
.
For that you need build.json. For now, you would need to manually run cordova build ios --buildConfig=./build.json
. You should only need to run it once in order to add those settings to your xcode project file.
Thanks, for now I'm running it after this plugin runs, but it still builds twice for the emulator
Sorry for the complexity of the build script, I'm building 2 different apps from the same codebase so I have to remove and re-install the ios platform every time I change the name.
"scripts": {
"app-init:ios": "cd src-cordova && cordova platform rm ios && cordova platform add ios && cd platforms/ios/cordova && npm install ios-sim",
"app-build:ios": "VUE_APP_PUBLIC_PATH='' && npm run app-init:ios && vue-cli-service cordova-build-ios && cd src-cordova && cordova build ios --buildConfig=./build.json",
}
{
"ios": {
"debug": {
"codeSignIdentity": "iPhone Developer",
"developmentTeam": "xxxx",
"packageType": "development",
"automaticProvisioning": true,
"buildFlag": ["-UseModernBuildSystem=0"]
},
"release": {
"codeSignIdentity": "iPhone Developer",
"developmentTeam": "xxxx",
"packageType": "app-store",
"automaticProvisioning": true,
"buildFlag": ["-UseModernBuildSystem=0"]
}
}
}
I've also tried cordova build ios --release --buildConfig=./build.json