UNPKG

26.5 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- Browser
255- Electron
256
257### Examples
258
259- Add pinned version of the `android` and `ios` platform and save the downloaded version to `config.xml` & `package.json`:
260
261 cordova platform add android ios
262
263- Add `android` platform with [semver](http://semver.org/) version ^5.0.0 and save it to `config.xml` & `package.json`:
264
265 cordova platform add android@^5.0.0
266
267- Add platform by cloning the specified git repo and checkout to the `4.0.0` tag:
268
269 cordova platform add https://github.com/myfork/cordova-android.git#4.0.0
270
271- Add platform using a local directory named `android`:
272
273 cordova platform add ../android
274
275- Add platform using the specified tarball:
276
277 cordova platform add ../cordova-android.tgz
278
279- Remove `android` platform from the project and remove from `config.xml` & `package.json`:
280
281 cordova platform rm android
282
283- Remove `android` platform from the project and do NOT remove from `config.xml` & `package.json`:
284
285 cordova platform rm android --nosave
286
287- List available and installed platforms with version numbers. This is useful to find version numbers when reporting issues:
288
289 cordova platform ls
290
291- Save versions of all platforms currently added to the project to `config.xml` & `package.json`
292
293 cordova platform save
294
295## cordova plugin command
296
297### Synopsis
298
299Manage project plugins
300
301### Syntax
302
303```bash
304cordova {plugin | plugins} [
305 add <plugin-spec> [..] {--searchpath=<directory> | --noregistry | --link | --save | --force} |
306 {remove | rm} {<pluginid> | <name>} --save |
307 {list | ls} |
308 save |
309]
310```
311
312| Sub-command | Option | Description
313|------------------------|-------------|------
314| add `<plugin-spec>` [...] | | Add specified plugins
315| |--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.
316| |--noregistry | Don't search the registry for plugins.
317| |--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.
318| |--nosave | Do NOT save the `<plugin-spec>` as part of the `plugin` element into `config.xml` or `package.json`.
319| |--force | _Introduced in version 6.1._ Forces copying source files from the plugin even if the same file already exists in the target directory.
320| remove `<pluginid>|<name>` [...]| | Remove plugins with the given IDs/name.
321| |--nosave | Do NOT remove the specified plugin from config.xml or package.json
322|list | | List currently installed plugins
323|save | | Save `<plugin-spec>` of all plugins currently added to the project
324
325### Plugin-spec
326
327There are a number of ways to specify a plugin:
328
329 <plugin-spec> : [@scope/]pluginID[@version]|directory|url[#commit-ish][:subdir]
330
331| Value | Description
332|-------------|--------------------
333| scope | Scope of plugin published as a [scoped npm package]
334| plugin | Plugin id (id of plugin in npm registry or in --searchPath)
335| version | Major.minor.patch version specifier using semver
336| directory | Directory containing plugin.xml
337| url | Url to a git repository containing a plugin.xml
338| commit-ish | Commit/tag/branch reference. If none is specified, 'master' is used
339
340### Algorithm for resolving plugins
341
342When adding a plugin to a project, the CLI will resolve the plugin
343based on the following criteria (listed in order of precedence):
344
3451. The `plugin-spec` given in the command (e.g. `cordova plugin add pluginID@version`)
3462. The `plugin-spec` saved in `config.xml` & `package.json` (i.e. if the plugin was previously added without `--nosave`)
3473. 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`)
3484. The latest plugin version published to npm
349
350### Examples
351
352- 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.
353
354 cordova plugin add cordova-plugin-camera cordova-plugin-file --save --searchpath ../plugins
355
356- Add `cordova-plugin-camera` with [semver](http://semver.org/) version ^2.0.0 and save it to `config.xml` & `package.json`:
357
358 cordova plugin add cordova-plugin-camera@^2.0.0
359
360- Add the plugin from the specified local directory:
361
362 cordova plugin add ../cordova-plugin-camera
363
364- Add the plugin from the specified tarball file:
365
366 cordova plugin add ../cordova-plugin-camera.tgz
367
368- Remove the plugin from the project and the `config.xml` & `package.json`:
369
370 cordova plugin rm camera
371
372- Remove the plugin from the project, but not the `config.xml` or `package.json`:
373
374 cordova plugin rm camera --nosave
375
376- List all plugins installed in the project:
377
378 cordova plugin ls
379
380### Conflicting plugins
381Conflicting 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.
382
383This 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.
384
385Refer 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.
386
387## cordova prepare command
388
389### Synopsis
390
391Transforms config.xml metadata to platform-specific manifest files, copies icons & splashscreens,
392copies plugin files for specified platforms so that the project is ready to build with each native SDK.
393
394### Syntax
395
396```
397cordova prepare [<platform> [..]]
398```
399
400### Options
401
402| Option | Description
403|------------|------------------
404| `<platform> [..]` | Platform name(s) to prepare. If not specified, all platforms are built.
405
406## cordova compile command
407
408### Synopsis
409
410`cordova compile` is a subset of the [cordova build command](#cordova-build-command).
411It 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].
412
413### Syntax
414
415```bash
416cordova build [<platform> [...]]
417 [--debug|--release]
418 [--device|--emulator|--target=<targetName>]
419 [--buildConfig=<configfile>]
420 [-- <platformOpts>]
421```
422For detailed documentation see [cordova build command](#cordova-build-command) docs below.
423
424## cordova build command
425
426### Synopsis
427
428Shortcut for `cordova prepare` + `cordova compile` for all/the specified platforms. Allows you to build the app for the specified platform.
429
430### Syntax
431
432```bash
433cordova build [<platform> [...]]
434 [--debug|--release]
435 [--device|--emulator]
436 [--buildConfig=<configfile>]
437 [-- <platformOpts>]
438```
439
440| Option | Description
441|------------|------------------
442| `<platform> [..]` | Platform name(s) to build. If not specified, all platforms are built.
443| --debug | Perform a debug build. This typically translates to debug mode for the underlying platform being built.
444| --release | Perform a release build. This typically translates to release mode for the underlying platform being built.
445| --device | Build it for a device
446| --emulator | Build it for an emulator. In particular, the platform architecture might be different for a device Vs emulator.
447| --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.
448| `<platformOpts>` | To provide platform specific options, you must include them after `--` separator. Review platform guide docs for more details.
449
450### Examples
451
452- Build for `android` and `windows` platform in `debug` mode for deployment to device:
453
454 cordova build android windows --debug --device
455
456- Build for `android` platform in `release` mode and use the specified build configuration:
457
458 cordova build android --release --buildConfig=..\myBuildConfig.json
459
460- Build for `android` platform in release mode and pass custom platform options to android build process:
461
462 cordova build android --release -- --keystore="..\android.keystore" --storePassword=android --alias=mykey
463
464## cordova run command
465
466### Synopsis
467
468Prepares, 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.
469
470### Syntax
471
472```bash
473cordova run [<platform> [...]]
474 [--list | --debug | --release]
475 [--noprepare] [--nobuild]
476 [--device|--emulator|--target=<targetName>]
477 [--buildConfig=<configfile>]
478 [-- <platformOpts>]
479```
480
481| Option | Description
482|-------------|------------------
483| `<platform> [..]` | Platform name(s) to run. If not specified, all platforms are run.
484| --list | Lists available targets. Displays both device and emulator deployment targets unless specified
485| --debug | Deploy a debug build. This is the default behavior unless `--release` is specified.
486| --release | Deploy a release build
487| --noprepare | Skip preparing (available in Cordova v6.2 or later)
488| --nobuild | Skip building
489| --device | Deploy to a device
490| --emulator | Deploy to an emulator
491| --target | Deploy to a specific target emulator/device. Use `--list` to display target options
492| --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.
493| `<platformOpts>` | To provide platform specific options, you must include them after `--` separator. Review platform guide docs for more details.
494
495### Examples
496
497- 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:
498
499 cordova run android --release --buildConfig=..\myBuildConfig.json --target=Nexus_5_API_23_x86
500
501- 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:
502
503 cordova run android --nobuild
504
505- Run a debug build of current cordova project on an `ios` device:
506
507 cordova run ios --device
508
509- Enumerate names of all the connected devices and available emulators that can be used to run this app:
510
511 cordova run ios --list
512
513
514## cordova emulate command
515
516### Synopsis
517
518Alias for `cordova run --emulator`. Launches the emulator instead of device.
519See [cordova run command docs](#cordova-run-command) for more details.
520
521## cordova clean command
522
523### Synopsis
524
525Cleans the build artifacts for all the platforms, or the specified platform by running platform-specific build cleanup.
526
527### Syntax
528
529```
530cordova clean [<platform> [...]]
531```
532
533### Example
534
535- Clean `android` platform build artifacts:
536
537 cordova clean android
538
539
540## cordova requirements command
541
542### Synopsis
543
544Checks and print out all the requirements for platforms specified (or all platforms added
545to project if none specified). If all requirements for each platform are met, exits with code 0
546otherwise exits with non-zero code.
547
548This can be useful when setting up a machine for building a particular platform.
549
550### Syntax
551
552```
553cordova requirements android
554```
555
556## cordova info command
557
558### Synopsis
559
560Print out useful information helpful for submitting bug
561reports and getting help. Creates an info.txt file at the
562base of your project.
563
564### Syntax
565
566```
567cordova info
568```
569
570## cordova serve command
571
572### Synopsis
573
574Run a local web server for www/ assets using specified `port` or default of 8000. Access projects at: `http://HOST_IP:PORT/PLATFORM/www`
575
576### Syntax
577
578```
579cordova serve [port]
580```
581
582## cordova telemetry command
583
584### Synopsis
585
586Turns telemetry collection on or off.
587
588### Syntax
589
590```
591cordova telemetry [STATE]
592```
593
594| Option | Description
595|-------------|------------------
596| on | Turn telemetry collection on.
597| off | Turn telemetry collection off.
598
599### Details
600 A timed prompt asking the user to opt-in or out is displayed the first time cordova is run.
601 It lasts for 30 seconds, after which the user is automatically opted-out if he doesn't provide any answer.
602 In CI environments, the `CI` environment variable can be set, which will prevent the prompt from showing up.
603 Telemetry collection can also be turned off on a single command by using the `--no-telemetry` flag.
604
605### Examples
606```
607cordova telemetry on
608cordova telemetry off
609cordova build --no-telemetry
610```
611
612For details, see our privacy notice: https://cordova.apache.org/privacy
613
614## cordova help command
615
616### Synopsis
617
618Show syntax summary, or the help for a specific command.
619
620### Syntax
621
622```
623cordova help [command]
624cordova [command] -h
625cordova -h [command]
626```
627
628## cordova config command
629
630### Synopsis
631
632Set, get, delete, edit, and list global cordova options.
633
634### Syntax
635
636```
637cordova config ls
638cordova config edit
639cordova config set <key> <value>
640cordova config get <key>
641cordova config delete <key>
642```
643### Examples
644
645```
646cordova config set autosave false
647```
648
649[Hooks guide]: http://cordova.apache.org/docs/en/latest/guide_appdev_hooks_index.md.html
650[config.xml ref]: http://cordova.apache.org/docs/en/latest/config_ref/index.html
651[Cordova dependencies]: http://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html#specifying-project-requirements
652[scoped npm package]: https://docs.npmjs.com/misc/scope