UNPKG

26.7 kBMarkdownView Raw
1---
2title: CLI Reference
3description: Learn how to use Cordova CLI commands and their options.
4---
5
6<!--
7#
8# Licensed to the Apache Software Foundation (ASF) under one
9# or more contributor license agreements. See the NOTICE file
10# distributed with this work for additional information
11# regarding copyright ownership. The ASF licenses this file
12# to you under the Apache License, Version 2.0 (the
13# "License"); you may not use this file except in compliance
14# with the License. You may obtain a copy of the License at
15#
16# http://www.apache.org/licenses/LICENSE-2.0
17#
18# Unless required by applicable law or agreed to in writing,
19# software distributed under the License is distributed on an
20# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21# KIND, either express or implied. See the License for the
22# specific language governing permissions and limitations
23# under the License.
24#
25-->
26
27# Cordova Command-line-interface (CLI) Reference
28
29## Syntax
30
31```bash
32cordova <command> [options] -- [platformOpts]
33```
34
35## Global Command List
36
37These commands are available at all times.
38
39| Command | Description
40|----------|--------------
41| create | Create a project
42| help <command> | Get help for a command
43| telemetry | Turn telemetry collection on or off
44| config | Set, get, delete, edit, and list global cordova options
45
46## Project Command List
47
48These commands are supported when the current working directory is a valid Cordova project.
49
50| Command | Description
51|--------------|--------------
52| info | Generate project information
53| requirements | Checks and print out all the installation requirements for platforms specified
54| platform | Manage project platforms
55| plugin | Manage project plugins
56| prepare | Copy files into platform(s) for building
57| compile | Build platform(s)
58| clean | Cleanup project from build artifacts
59| run | Run project (including prepare && compile)
60| serve | Run project with a local webserver (including prepare)
61
62## Common options
63
64These options apply to all cordova-cli commands.
65
66| Option | Description
67|----------------------|------------------------
68| -d or --verbose | Pipe out more verbose output to your shell. You can also subscribe to `log` and `warn` events if you are consuming `cordova-cli` as a node module by calling `cordova.on('log', function() {})` or `cordova.on('warn', function() {})`.
69| -v or --version | Print out the version of your `cordova-cli` install.
70| --no-update-notifier | Will disable updates check. Alternatively set `"optOut": true` in `~/.config/configstore/update-notifier-cordova.json` or set `NO_UPDATE_NOTIFIER` environment variable with any value (see details in [update-notifier docs](https://www.npmjs.com/package/update-notifier#user-settings)).
71|--nohooks | Suppress executing hooks (taking RegExp hook patterns as parameters)
72| --no-telemetry | Disable telemetry collection for the current command.
73
74## Platform-specific options
75
76Certain commands have options (`platformOpts`) that are specific to a particular platform. They can be provided to the cordova-cli with a '--' separator that stops the command parsing within the cordova-lib module and passes through rest of the options for platforms to parse.
77
78## Examples
79- This example demonstrates how cordova-cli can be used to create a project with the `camera` plugin and run it for `android` platform. In particular, platform specific options like `--keystore` can be provided:
80
81 # Create a cordova project
82 cordova create myApp com.myCompany.myApp myApp
83 cd myApp
84 # Add camera plugin to the project and remember that in config.xml & package.json.
85 cordova plugin add cordova-plugin-camera
86 # Add camera plugin to the project and remember that in config.xml and package.json.
87 cordova plugin add cordova-plugin-camera
88 # Add android platform to the project and remember that in config.xml & package.json.
89 cordova platform add android
90 # Check to see if your system is configured for building android platform.
91 cordova requirements android
92 # Build the android and emit verbose logs.
93 cordova build android --verbose
94 # Run the project on the android platform.
95 cordova run android
96 # Build for android platform in release mode with specified signing parameters.
97 cordova build android --release -- --keystore="..\android.keystore" --storePassword=android --alias=mykey
98
99## cordova create command
100
101### Synopsis
102
103Create the directory structure for the Cordova project in the specified path.
104
105### Syntax
106
107```
108cordova create path [id [name [config]]] [options]
109```
110
111| Value | Description |
112|-------|---------------|
113| path | Directory which should not already exist. Cordova will create this directory. For more details on the directory structure, see below. |
114| id | _Default_: `io.cordova.hellocordova` <br/> Reverse domain-style identifier that maps to `id` attribute of `widget` element in `config.xml`. This can be changed but there may be code generated using this value, such as Java package names. It is recommended that you select an appropriate value. |
115| name | _Default_: `HelloCordova` <br/> Application's display title that maps `name` element in `config.xml` file. This can be changed but there may be code generated using this value, such as Java class names. The default value is `HelloCordova`, but it is recommended that you select an appropriate value. |
116| config | JSON string whose key/values will be included in `<path>`/.cordova/config.json |
117
118### Options
119
120| Option | Description |
121|--------|-------------|
122| --template | Use a custom template located locally, in NPM, or GitHub. |
123| --copy-from\|--src | _Deprecated_ <br/> Use --template instead. Specifies a directory from which to copy the current Cordova project. |
124|--link-to | Symlink to specified `www` directory without creating a copy. |
125
126### Directory structure
127
128Cordova CLI works with the following directory structure:
129
130```
131myapp/
132|-- config.xml
133|-- hooks/
134|-- merges/
135| | |-- android/
136| | |-- windows/
137| | |-- ios/
138|-- www/
139|-- platforms/
140| |-- android/
141| |-- windows/
142| |-- ios/
143|-- plugins/
144 |--cordova-plugin-camera/
145```
146
147#### config.xml
148
149Configures your application and allows you to customize the behavior of your project. See also [config.xml reference documentation][config.xml ref]
150
151#### www/
152
153Contains the project's web artifacts, such as .html, .css and .js files. As a cordova application developer, most of your code and assets will go here. They will be copied on a `cordova prepare` to each platform's www directory. The www source directory is reproduced within each platform's subdirectory, appearing for example in `platforms/ios/www` or `platforms/android/assets/www`. Because the CLI constantly copies over files from the source www folder, you should only edit these files and not the ones located under the platforms subdirectories. If you use version control software, you should add this source www folder, along with the merges folder, to your version control system.
154
155#### platforms/
156
157Contains all the source code and build scripts for the platforms that you add to your project.
158
159> **WARNING:** When using the CLI to build your application, you should not edit any files in the /platforms/ directory unless you know what you are doing, or if documentation specifies otherwise. The files in this directory are routinely overwritten when preparing applications for building, or when plugins are re-installed.
160
161#### plugins/
162
163Any added plugins will be extracted or copied into this directory.
164
165#### hooks/
166
167This directory may contains scripts used to customize cordova-cli commands. Any scripts you add to these directories will be executed before and after the commands corresponding to the directory name. Useful for integrating your own build systems or integrating with version control systems.
168
169Refer to [Hooks Guide] for more information.
170
171#### merges/
172
173Platform-specific web assets (HTML, CSS and JavaScript files) are contained within appropriate subfolders in this directory. These are deployed during a `prepare` to the appropriate native directory. Files placed under `merges/` will override matching files in the `www/` folder for the relevant platform. A quick example, assuming a project structure of:
174
175```
176merges/
177|-- ios/
178| -- app.js
179|-- android/
180| -- android.js
181www/
182-- app.js
183```
184
185After building the Android and iOS projects, the Android application will contain both `app.js` and `android.js`. However, the iOS application will only contain an `app.js`, and it will be the one from `merges/ios/app.js`, overriding the "common" `app.js` located inside `www/`.
186
187#### Version control
188
189It is recommended not to check in `platforms/` and `plugins/` directories into version control as they are considered a build artifact. Your platforms and plugins will be saved in config.xml & package.json automatically. These platforms/plugins will be downloaded when `cordova prepare` is invoked.
190
191### Examples
192
193- Create a Cordova project in `myapp` directory using the specified ID and display name:
194
195 cordova create myapp com.mycompany.myteam.myapp MyApp
196
197- Create a Cordova project with a symlink to an existing `www` directory. This can be useful if you have a custom build process or existing web assets that you want to use in your Cordova app:
198
199 cordova create myapp --link-to=../www
200
201
202## cordova platform command
203
204### Synopsis
205
206Manage cordova platforms - allowing you to add, remove, update, list and check for updates. Running commands to add or remove platforms affects the contents of the project's platforms directory.
207
208### Syntax
209
210```bash
211cordova {platform | platforms} [
212 add <platform-spec> [...] {--save | link=<path> } |
213 {remove | rm} platform [...] {--save}|
214 {list | ls} |
215 check |
216 save |
217 update ]
218```
219
220| Sub-command | Option | Description |
221------------------------|-------------|------|
222| add `<platform-spec>` [...] | | Add specified platforms |
223| | --nosave | Do not save `<platform-spec>` into `config.xml` & `package.json` after installing them using `<engine>` tag |
224| | --link=`<path>` | When `<platform-spec>` is a local path, links the platform library directly instead of making a copy of it (support varies by platform; useful for platform development)
225| remove `<platform>` [...] | | Remove specified platforms |
226| | --nosave | Do not delete specified platforms from `config.xml` & `package.json` after removing them |
227| update `platform` [...] | | Update specified platforms |
228| | --save | Updates the version specified in `config.xml` |
229| list | | List all installed and available platforms |
230| check | | List platforms which can be updated via cordova-cli with the command `platform update` |
231| save | | Save `<platform-spec>` of all platforms added to config.xml |
232
233### Platform-spec
234
235There are a number of ways to specify a platform:
236
237```
238<platform-spec> : platform[@version] | path | url[#commit-ish]
239```
240
241| Value | Description |
242|-----------|-------------|
243| platform | Platform name e.g. android, ios, windows etc. to be added to the project. Every release of cordova CLI pins a version for each platform. When no version is specified this version is used to add the platform. |
244| version | Major.minor.patch version specifier using semver |
245| path | Path to a directory or tarball containing a platform |
246| url | URL to a git repository or tarball containing a platform |
247| commit-ish | Commit/tag/branch reference. If none is specified, 'master' is used |
248
249### Supported Platforms
250
251- Android
252- iOS
253- Windows (8.1, Phone 8.1, UWP - Windows 10)
254- Blackberry10
255- Ubuntu
256- Browser
257
258### Deprecated Platforms
259
260- Amazon-fireos (use Android platform instead)
261- WP8 (use Windows platform instead)
262- Windows 8.0 (use older versions of cordova)
263- Firefox OS (use older versions of cordova)
264
265### Examples
266
267- Add pinned version of the `android` and `ios` platform and save the downloaded version to `config.xml` & `package.json`:
268
269 cordova platform add android ios
270
271- Add `android` platform with [semver](http://semver.org/) version ^5.0.0 and save it to `config.xml` & `package.json`:
272
273 cordova platform add android@^5.0.0
274
275- Add platform by cloning the specified git repo and checkout to the `4.0.0` tag:
276
277 cordova platform add https://github.com/myfork/cordova-android.git#4.0.0
278
279- Add platform using a local directory named `android`:
280
281 cordova platform add ../android
282
283- Add platform using the specified tarball:
284
285 cordova platform add ../cordova-android.tgz
286
287- Remove `android` platform from the project and remove from `config.xml` & `package.json`:
288
289 cordova platform rm android
290
291- Remove `android` platform from the project and do NOT remove from `config.xml` & `package.json`:
292
293 cordova platform rm android --nosave
294
295- List available and installed platforms with version numbers. This is useful to find version numbers when reporting issues:
296
297 cordova platform ls
298
299- Save versions of all platforms currently added to the project to `config.xml` & `package.json`
300
301 cordova platform save
302
303## cordova plugin command
304
305### Synopsis
306
307Manage project plugins
308
309### Syntax
310
311```bash
312cordova {plugin | plugins} [
313 add <plugin-spec> [..] {--searchpath=<directory> | --noregistry | --link | --save | --force} |
314 {remove | rm} {<pluginid> | <name>} --save |
315 {list | ls} |
316 save |
317]
318```
319
320| Sub-command | Option | Description
321|------------------------|-------------|------
322| add `<plugin-spec>` [...] | | Add specified plugins
323| |--searchpath `<directory>` | When looking up plugins by ID, look in this directory and each of its subdirectories before hitting the registry. Multiple search paths can be specified. Use ':' as a separator in `*nix` based systems and ';' for Windows.
324| |--noregistry | Don't search the registry for plugins.
325| |--link | When installing from a local path, creates a symbolic link instead of copying files. The extent to which files are linked varies by platform. Useful for plugin development.
326| |--nosave | Do NOT save the `<plugin-spec>` as part of the `plugin` element into `config.xml` or `package.json`.
327| |--force | _Introduced in version 6.1._ Forces copying source files from the plugin even if the same file already exists in the target directory.
328| remove `<pluginid>|<name>` [...]| | Remove plugins with the given IDs/name.
329| |--nosave | Do NOT remove the specified plugin from config.xml or package.json
330|list | | List currently installed plugins
331|save | | Save `<plugin-spec>` of all plugins currently added to the project
332
333### Plugin-spec
334
335There are a number of ways to specify a plugin:
336
337 <plugin-spec> : [@scope/]pluginID[@version]|directory|url[#commit-ish][:subdir]
338
339| Value | Description
340|-------------|--------------------
341| scope | Scope of plugin published as a [scoped npm package]
342| plugin | Plugin id (id of plugin in npm registry or in --searchPath)
343| version | Major.minor.patch version specifier using semver
344| directory | Directory containing plugin.xml
345| url | Url to a git repository containing a plugin.xml
346| commit-ish | Commit/tag/branch reference. If none is specified, 'master' is used
347
348### Algorithm for resolving plugins
349
350When adding a plugin to a project, the CLI will resolve the plugin
351based on the following criteria (listed in order of precedence):
352
3531. The `plugin-spec` given in the command (e.g. `cordova plugin add pluginID@version`)
3542. The `plugin-spec` saved in `config.xml` & `package.json` (i.e. if the plugin was previously added without `--nosave`)
3553. As of Cordova version 6.1, the latest plugin version published to npm that the current project can support (only applies to plugins that list their [Cordova dependencies] in their `package.json`)
3564. The latest plugin version published to npm
357
358### Examples
359
360- Add `cordova-plugin-camera` and `cordova-plugin-file` to the project and save it to `config.xml` & `package.json`. Use `../plugins` directory to search for the plugins.
361
362 cordova plugin add cordova-plugin-camera cordova-plugin-file --save --searchpath ../plugins
363
364- Add `cordova-plugin-camera` with [semver](http://semver.org/) version ^2.0.0 and save it to `config.xml` & `package.json`:
365
366 cordova plugin add cordova-plugin-camera@^2.0.0
367
368- Add the plugin from the specified local directory:
369
370 cordova plugin add ../cordova-plugin-camera
371
372- Add the plugin from the specified tarball file:
373
374 cordova plugin add ../cordova-plugin-camera.tgz
375
376- Remove the plugin from the project and the `config.xml` & `package.json`:
377
378 cordova plugin rm camera
379
380- Remove the plugin from the project, but not the `config.xml` or `package.json`:
381
382 cordova plugin rm camera --nosave
383
384- List all plugins installed in the project:
385
386 cordova plugin ls
387
388### Conflicting plugins
389Conflicting plugins may occur when adding plugins that use `edit-config` tags in their plugin.xml file. `edit-config` allows plugins to add or replace attributes of XML elements.
390
391This feature can cause issues with the application if more than one plugin tries to modify the same XML element. Conflict detection has been implemented to prevent plugins from being added so one plugin doesn't try to overwrite another plugin's `edit-config` changes. An error will be thrown when a conflict in `edit-config` has been found and the plugin won't be added. The error message will mention that all conflicts must be resolved before the plugin can be added. One option to resolving the `edit-config` conflict is to make changes to the affected plugins' plugin.xml so that they do not modify the same XML element. The other option is to use the `--force` flag to force add the plugin. This option should be used with caution as it ignores the conflict detection and will overwrite all conflicts it has with other plugins, thus may leave the other plugins in a bad state.
392
393Refer to the [plugin.xml guide](https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#edit-config) for managing `edit-config`, resolving conflicts, and examples.
394
395## cordova prepare command
396
397### Synopsis
398
399Transforms config.xml metadata to platform-specific manifest files, copies icons & splashscreens,
400copies plugin files for specified platforms so that the project is ready to build with each native SDK.
401
402### Syntax
403
404```
405cordova prepare [<platform> [..]]
406```
407
408### Options
409
410| Option | Description
411|------------|------------------
412| `<platform> [..]` | Platform name(s) to prepare. If not specified, all platforms are built.
413
414## cordova compile command
415
416### Synopsis
417
418`cordova compile` is a subset of the [cordova build command](#cordova-build-command).
419It only performs the compilation step without doing prepare. It's common to invoke `cordova build` instead of this command - however, this stage is useful to allow extending using [hooks][Hooks guide].
420
421### Syntax
422
423```bash
424cordova build [<platform> [...]]
425 [--debug|--release]
426 [--device|--emulator|--target=<targetName>]
427 [--buildConfig=<configfile>]
428 [-- <platformOpts>]
429```
430For detailed documentation see [cordova build command](#cordova-build-command) docs below.
431
432## cordova build command
433
434### Synopsis
435
436Shortcut for `cordova prepare` + `cordova compile` for all/the specified platforms. Allows you to build the app for the specified platform.
437
438### Syntax
439
440```bash
441cordova build [<platform> [...]]
442 [--debug|--release]
443 [--device|--emulator]
444 [--buildConfig=<configfile>]
445 [-- <platformOpts>]
446```
447
448| Option | Description
449|------------|------------------
450| `<platform> [..]` | Platform name(s) to build. If not specified, all platforms are built.
451| --debug | Perform a debug build. This typically translates to debug mode for the underlying platform being built.
452| --release | Perform a release build. This typically translates to release mode for the underlying platform being built.
453| --device | Build it for a device
454| --emulator | Build it for an emulator. In particular, the platform architecture might be different for a device Vs emulator.
455| --buildConfig=`<configFile>` | Default: build.json in cordova root directory. <br/> Use the specified build configuration file. `build.json` file is used to specify paramaters to customize the app build process especially related to signing the package.
456| `<platformOpts>` | To provide platform specific options, you must include them after `--` separator. Review platform guide docs for more details.
457
458### Examples
459
460- Build for `android` and `windows` platform in `debug` mode for deployment to device:
461
462 cordova build android windows --debug --device
463
464- Build for `android` platform in `release` mode and use the specified build configuration:
465
466 cordova build android --release --buildConfig=..\myBuildConfig.json
467
468- Build for `android` platform in release mode and pass custom platform options to android build process:
469
470 cordova build android --release -- --keystore="..\android.keystore" --storePassword=android --alias=mykey
471
472## cordova run command
473
474### Synopsis
475
476Prepares, builds, and deploys app on specified platform devices/emulators. If a device is connected it will be used, unless an eligible emulator is already running.
477
478### Syntax
479
480```bash
481cordova run [<platform> [...]]
482 [--list | --debug | --release]
483 [--noprepare] [--nobuild]
484 [--device|--emulator|--target=<targetName>]
485 [--buildConfig=<configfile>]
486 [-- <platformOpts>]
487```
488
489| Option | Description
490|-------------|------------------
491| `<platform> [..]` | Platform name(s) to run. If not specified, all platforms are run.
492| --list | Lists available targets. Displays both device and emulator deployment targets unless specified
493| --debug | Deploy a debug build. This is the default behavior unless `--release` is specified.
494| --release | Deploy a release build
495| --noprepare | Skip preparing (available in Cordova v6.2 or later)
496| --nobuild | Skip building
497| --device | Deploy to a device
498| --emulator | Deploy to an emulator
499| --target | Deploy to a specific target emulator/device. Use `--list` to display target options
500| --buildConfig=`<configFile>` | Default: build.json in cordova root directory. <br/> Use the specified build configuration file. `build.json` file is used to specify paramaters to customize the app build process especially related to signing the package.
501| `<platformOpts>` | To provide platform specific options, you must include them after `--` separator. Review platform guide docs for more details.
502
503### Examples
504
505- Run a release build of current cordova project on `android` platform emulator named `Nexus_5_API_23_x86`. Use the spcified build configuration when running:
506
507 cordova run android --release --buildConfig=..\myBuildConfig.json --target=Nexus_5_API_23_x86
508
509- Run a debug build of current cordova project on `android` platform using a device or emulator (if no device is connected). Skip doing the build:
510
511 cordova run android --nobuild
512
513- Run a debug build of current cordova project on an `ios` device:
514
515 cordova run ios --device
516
517- Enumerate names of all the connected devices and available emulators that can be used to run this app:
518
519 cordova run ios --list
520
521
522## cordova emulate command
523
524### Synopsis
525
526Alias for `cordova run --emulator`. Launches the emulator instead of device.
527See [cordova run command docs](#cordova-run-command) for more details.
528
529## cordova clean command
530
531### Synopsis
532
533Cleans the build artifacts for all the platforms, or the specified platform by running platform-specific build cleanup.
534
535### Syntax
536
537```
538cordova clean [<platform> [...]]
539```
540
541### Example
542
543- Clean `android` platform build artifacts:
544
545 cordova clean android
546
547
548## cordova requirements command
549
550### Synopsis
551
552Checks and print out all the requirements for platforms specified (or all platforms added
553to project if none specified). If all requirements for each platform are met, exits with code 0
554otherwise exits with non-zero code.
555
556This can be useful when setting up a machine for building a particular platform.
557
558### Syntax
559
560```
561cordova requirements android
562```
563
564## cordova info command
565
566### Synopsis
567
568Print out useful information helpful for submitting bug
569reports and getting help. Creates an info.txt file at the
570base of your project.
571
572### Syntax
573
574```
575cordova info
576```
577
578## cordova serve command
579
580### Synopsis
581
582Run a local web server for www/ assets using specified `port` or default of 8000. Access projects at: `http://HOST_IP:PORT/PLATFORM/www`
583
584### Syntax
585
586```
587cordova serve [port]
588```
589
590## cordova telemetry command
591
592### Synopsis
593
594Turns telemetry collection on or off.
595
596### Syntax
597
598```
599cordova telemetry [STATE]
600```
601
602| Option | Description
603|-------------|------------------
604| on | Turn telemetry collection on.
605| off | Turn telemetry collection off.
606
607### Details
608 A timed prompt asking the user to opt-in or out is displayed the first time cordova is run.
609 It lasts for 30 seconds, after which the user is automatically opted-out if he doesn't provide any answer.
610 In CI environments, the `CI` environment variable can be set, which will prevent the prompt from showing up.
611 Telemetry collection can also be turned off on a single command by using the `--no-telemetry` flag.
612
613### Examples
614```
615cordova telemetry on
616cordova telemetry off
617cordova build --no-telemetry
618```
619
620For details, see our privacy notice: https://cordova.apache.org/privacy
621
622## cordova help command
623
624### Synopsis
625
626Show syntax summary, or the help for a specific command.
627
628### Syntax
629
630```
631cordova help [command]
632cordova [command] -h
633cordova -h [command]
634```
635
636## cordova config command
637
638### Synopsis
639
640Set, get, delete, edit, and list global cordova options.
641
642### Syntax
643
644```
645cordova config ls
646cordova config edit
647cordova config set <key> <value>
648cordova config get <key>
649cordova config delete <key>
650```
651### Examples
652
653```
654cordova config set autosave false
655```
656
657[Hooks guide]: http://cordova.apache.org/docs/en/latest/guide_appdev_hooks_index.md.html
658[config.xml ref]: http://cordova.apache.org/docs/en/latest/config_ref/index.html
659[Cordova dependencies]: http://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html#specifying-project-requirements
660[scoped npm package]: https://docs.npmjs.com/misc/scope