UNPKG

26.4 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 android platform to the project and remember that in config.xml & package.json.
87 cordova platform add android
88 # Check to see if your system is configured for building android platform.
89 cordova requirements android
90 # Build the android and emit verbose logs.
91 cordova build android --verbose
92 # Run the project on the android platform.
93 cordova run android
94 # Build for android platform in release mode with specified signing parameters.
95 cordova build android --release -- --keystore="..\android.keystore" --storePassword=android --alias=mykey
96
97## cordova create command
98
99### Synopsis
100
101Create the directory structure for the Cordova project in the specified path.
102
103### Syntax
104
105```
106cordova create path [id [name [config]]] [options]
107```
108
109| Value | Description |
110|-------|---------------|
111| path | Directory which should not already exist. Cordova will create this directory. For more details on the directory structure, see below. |
112| 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. |
113| 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. |
114| config | JSON string whose key/values will be included in `<path>`/.cordova/config.json |
115
116### Options
117
118| Option | Description |
119|--------|-------------|
120| --template | Use a custom template located locally, in NPM, or GitHub. |
121| --copy-from\|--src | _Deprecated_ <br/> Use --template instead. Specifies a directory from which to copy the current Cordova project. |
122|--link-to | Symlink to specified `www` directory without creating a copy. |
123
124### Directory structure
125
126Cordova CLI works with the following directory structure:
127
128```
129myapp/
130|-- config.xml
131|-- hooks/
132|-- merges/
133| | |-- android/
134| | |-- windows/
135| | |-- ios/
136|-- www/
137|-- platforms/
138| |-- android/
139| |-- windows/
140| |-- ios/
141|-- plugins/
142 |--cordova-plugin-camera/
143```
144
145#### config.xml
146
147Configures your application and allows you to customize the behavior of your project. See also [config.xml reference documentation][config.xml ref]
148
149#### www/
150
151Contains 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.
152
153#### platforms/
154
155Contains all the source code and build scripts for the platforms that you add to your project.
156
157> **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.
158
159#### plugins/
160
161Any added plugins will be extracted or copied into this directory.
162
163#### hooks/
164
165This 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.
166
167Refer to [Hooks Guide] for more information.
168
169#### merges/
170
171Platform-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:
172
173```
174merges/
175|-- ios/
176| -- app.js
177|-- android/
178| -- android.js
179www/
180-- app.js
181```
182
183After 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/`.
184
185#### Version control
186
187It 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.
188
189### Examples
190
191- Create a Cordova project in `myapp` directory using the specified ID and display name:
192
193 cordova create myapp com.mycompany.myteam.myapp MyApp
194
195- 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:
196
197 cordova create myapp --link-to=../www
198
199
200## cordova platform command
201
202### Synopsis
203
204Manage 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.
205
206### Syntax
207
208```bash
209cordova {platform | platforms} [
210 add <platform-spec> [...] {--save | link=<path> } |
211 {remove | rm} platform [...] {--save}|
212 {list | ls} |
213 check |
214 save |
215 update ]
216```
217
218| Sub-command | Option | Description |
219------------------------|-------------|------|
220| add `<platform-spec>` [...] | | Add specified platforms |
221| | --nosave | Do not save `<platform-spec>` into `config.xml` & `package.json` after installing them using `<engine>` tag |
222| | --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)
223| remove `<platform>` [...] | | Remove specified platforms |
224| | --nosave | Do not delete specified platforms from `config.xml` & `package.json` after removing them |
225| update `platform` [...] | | Update specified platforms |
226| | --save | Updates the version specified in `config.xml` |
227| list | | List all installed and available platforms |
228| check | | List platforms which can be updated via cordova-cli with the command `platform update` |
229| save | | Save `<platform-spec>` of all platforms added to config.xml |
230
231### Platform-spec
232
233There are a number of ways to specify a platform:
234
235```
236<platform-spec> : platform[@version] | path | url[#commit-ish]
237```
238
239| Value | Description |
240|-----------|-------------|
241| 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. |
242| version | Major.minor.patch version specifier using semver |
243| path | Path to a directory or tarball containing a platform |
244| url | URL to a git repository or tarball containing a platform |
245| commit-ish | Commit/tag/branch reference. If none is specified, 'master' is used |
246
247### Supported Platforms
248
249- Android
250- iOS
251- Windows (8.1, Phone 8.1, UWP - Windows 10)
252- Browser
253- Electron
254
255### Examples
256
257- Add pinned version of the `android` and `ios` platform and save the downloaded version to `config.xml` & `package.json`:
258
259 cordova platform add android ios
260
261- Add `android` platform with [semver](http://semver.org/) version ^5.0.0 and save it to `config.xml` & `package.json`:
262
263 cordova platform add android@^5.0.0
264
265- Add platform by cloning the specified git repo and checkout to the `4.0.0` tag:
266
267 cordova platform add https://github.com/myfork/cordova-android.git#4.0.0
268
269- Add platform using a local directory named `android`:
270
271 cordova platform add ../android
272
273- Add platform using the specified tarball:
274
275 cordova platform add ../cordova-android.tgz
276
277- Remove `android` platform from the project and remove from `config.xml` & `package.json`:
278
279 cordova platform rm android
280
281- Remove `android` platform from the project and do NOT remove from `config.xml` & `package.json`:
282
283 cordova platform rm android --nosave
284
285- List available and installed platforms with version numbers. This is useful to find version numbers when reporting issues:
286
287 cordova platform ls
288
289- Save versions of all platforms currently added to the project to `config.xml` & `package.json`
290
291 cordova platform save
292
293## cordova plugin command
294
295### Synopsis
296
297Manage project plugins
298
299### Syntax
300
301```bash
302cordova {plugin | plugins} [
303 add <plugin-spec> [..] {--searchpath=<directory> | --noregistry | --link | --save | --force} |
304 {remove | rm} {<pluginid> | <name>} --save |
305 {list | ls} |
306 save |
307]
308```
309
310| Sub-command | Option | Description
311|------------------------|-------------|------
312| add `<plugin-spec>` [...] | | Add specified plugins
313| |--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.
314| |--noregistry | Don't search the registry for plugins.
315| |--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.
316| |--nosave | Do NOT save the `<plugin-spec>` as part of the `plugin` element into `config.xml` or `package.json`.
317| |--force | _Introduced in version 6.1._ Forces copying source files from the plugin even if the same file already exists in the target directory.
318| remove `<pluginid>|<name>` [...]| | Remove plugins with the given IDs/name.
319| |--nosave | Do NOT remove the specified plugin from config.xml or package.json
320|list | | List currently installed plugins
321|save | | Save `<plugin-spec>` of all plugins currently added to the project
322
323### Plugin-spec
324
325There are a number of ways to specify a plugin:
326
327 <plugin-spec> : [@scope/]pluginID[@version]|directory|url[#commit-ish][:subdir]
328
329| Value | Description
330|-------------|--------------------
331| scope | Scope of plugin published as a [scoped npm package]
332| plugin | Plugin id (id of plugin in npm registry or in --searchPath)
333| version | Major.minor.patch version specifier using semver
334| directory | Directory containing plugin.xml
335| url | Url to a git repository containing a plugin.xml
336| commit-ish | Commit/tag/branch reference. If none is specified, 'master' is used
337
338### Algorithm for resolving plugins
339
340When adding a plugin to a project, the CLI will resolve the plugin
341based on the following criteria (listed in order of precedence):
342
3431. The `plugin-spec` given in the command (e.g. `cordova plugin add pluginID@version`)
3442. The `plugin-spec` saved in `config.xml` & `package.json` (i.e. if the plugin was previously added without `--nosave`)
3453. 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`)
3464. The latest plugin version published to npm
347
348### Examples
349
350- 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.
351
352 cordova plugin add cordova-plugin-camera cordova-plugin-file --save --searchpath ../plugins
353
354- Add `cordova-plugin-camera` with [semver](http://semver.org/) version ^2.0.0 and save it to `config.xml` & `package.json`:
355
356 cordova plugin add cordova-plugin-camera@^2.0.0
357
358- Add the plugin from the specified local directory:
359
360 cordova plugin add ../cordova-plugin-camera
361
362- Add the plugin from the specified tarball file:
363
364 cordova plugin add ../cordova-plugin-camera.tgz
365
366- Remove the plugin from the project and the `config.xml` & `package.json`:
367
368 cordova plugin rm camera
369
370- Remove the plugin from the project, but not the `config.xml` or `package.json`:
371
372 cordova plugin rm camera --nosave
373
374- List all plugins installed in the project:
375
376 cordova plugin ls
377
378### Conflicting plugins
379Conflicting 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.
380
381This 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.
382
383Refer 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.
384
385## cordova prepare command
386
387### Synopsis
388
389Transforms config.xml metadata to platform-specific manifest files, copies icons & splashscreens,
390copies plugin files for specified platforms so that the project is ready to build with each native SDK.
391
392### Syntax
393
394```
395cordova prepare [<platform> [..]]
396```
397
398### Options
399
400| Option | Description
401|------------|------------------
402| `<platform> [..]` | Platform name(s) to prepare. If not specified, all platforms are built.
403
404## cordova compile command
405
406### Synopsis
407
408`cordova compile` is a subset of the [cordova build command](#cordova-build-command).
409It 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].
410
411### Syntax
412
413```bash
414cordova build [<platform> [...]]
415 [--debug|--release]
416 [--device|--emulator|--target=<targetName>]
417 [--buildConfig=<configfile>]
418 [-- <platformOpts>]
419```
420For detailed documentation see [cordova build command](#cordova-build-command) docs below.
421
422## cordova build command
423
424### Synopsis
425
426Shortcut for `cordova prepare` + `cordova compile` for all/the specified platforms. Allows you to build the app for the specified platform.
427
428### Syntax
429
430```bash
431cordova build [<platform> [...]]
432 [--debug|--release]
433 [--device|--emulator]
434 [--buildConfig=<configfile>]
435 [-- <platformOpts>]
436```
437
438| Option | Description
439|------------|------------------
440| `<platform> [..]` | Platform name(s) to build. If not specified, all platforms are built.
441| --debug | Perform a debug build. This typically translates to debug mode for the underlying platform being built.
442| --release | Perform a release build. This typically translates to release mode for the underlying platform being built.
443| --device | Build it for a device
444| --emulator | Build it for an emulator. In particular, the platform architecture might be different for a device Vs emulator.
445| --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.
446| `<platformOpts>` | To provide platform specific options, you must include them after `--` separator. Review platform guide docs for more details.
447
448### Examples
449
450- Build for `android` and `windows` platform in `debug` mode for deployment to device:
451
452 cordova build android windows --debug --device
453
454- Build for `android` platform in `release` mode and use the specified build configuration:
455
456 cordova build android --release --buildConfig=..\myBuildConfig.json
457
458- Build for `android` platform in release mode and pass custom platform options to android build process:
459
460 cordova build android --release -- --keystore="..\android.keystore" --storePassword=android --alias=mykey
461
462## cordova run command
463
464### Synopsis
465
466Prepares, 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.
467
468### Syntax
469
470```bash
471cordova run [<platform> [...]]
472 [--list | --debug | --release]
473 [--noprepare] [--nobuild]
474 [--device|--emulator|--target=<targetName>]
475 [--buildConfig=<configfile>]
476 [-- <platformOpts>]
477```
478
479| Option | Description
480|-------------|------------------
481| `<platform> [..]` | Platform name(s) to run. If not specified, all platforms are run.
482| --list | Lists available targets. Displays both device and emulator deployment targets unless specified
483| --debug | Deploy a debug build. This is the default behavior unless `--release` is specified.
484| --release | Deploy a release build
485| --noprepare | Skip preparing (available in Cordova v6.2 or later)
486| --nobuild | Skip building
487| --device | Deploy to a device
488| --emulator | Deploy to an emulator
489| --target | Deploy to a specific target emulator/device. Use `--list` to display target options
490| --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.
491| `<platformOpts>` | To provide platform specific options, you must include them after `--` separator. Review platform guide docs for more details.
492
493### Examples
494
495- 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:
496
497 cordova run android --release --buildConfig=..\myBuildConfig.json --target=Nexus_5_API_23_x86
498
499- 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:
500
501 cordova run android --nobuild
502
503- Run a debug build of current cordova project on an `ios` device:
504
505 cordova run ios --device
506
507- Enumerate names of all the connected devices and available emulators that can be used to run this app:
508
509 cordova run ios --list
510
511
512## cordova emulate command
513
514### Synopsis
515
516Alias for `cordova run --emulator`. Launches the emulator instead of device.
517See [cordova run command docs](#cordova-run-command) for more details.
518
519## cordova clean command
520
521### Synopsis
522
523Cleans the build artifacts for all the platforms, or the specified platform by running platform-specific build cleanup.
524
525### Syntax
526
527```
528cordova clean [<platform> [...]]
529```
530
531### Example
532
533- Clean `android` platform build artifacts:
534
535 cordova clean android
536
537
538## cordova requirements command
539
540### Synopsis
541
542Checks and print out all the requirements for platforms specified (or all platforms added
543to project if none specified). If all requirements for each platform are met, exits with code 0
544otherwise exits with non-zero code.
545
546This can be useful when setting up a machine for building a particular platform.
547
548### Syntax
549
550```
551cordova requirements android
552```
553
554## cordova info command
555
556### Synopsis
557
558Print out useful information helpful for submitting bug
559reports and getting help. Creates an info.txt file at the
560base of your project.
561
562### Syntax
563
564```
565cordova info
566```
567
568## cordova serve command
569
570### Synopsis
571
572Run a local web server for www/ assets using specified `port` or default of 8000. Access projects at: `http://HOST_IP:PORT/PLATFORM/www`
573
574### Syntax
575
576```
577cordova serve [port]
578```
579
580## cordova telemetry command
581
582### Synopsis
583
584Turns telemetry collection on or off.
585
586### Syntax
587
588```
589cordova telemetry [STATE]
590```
591
592| Option | Description
593|-------------|------------------
594| on | Turn telemetry collection on.
595| off | Turn telemetry collection off.
596
597### Details
598 A timed prompt asking the user to opt-in or out is displayed the first time cordova is run.
599 It lasts for 30 seconds, after which the user is automatically opted-out if he doesn't provide any answer.
600 In CI environments, the `CI` environment variable can be set, which will prevent the prompt from showing up.
601 Telemetry collection can also be turned off on a single command by using the `--no-telemetry` flag.
602
603### Examples
604```
605cordova telemetry on
606cordova telemetry off
607cordova build --no-telemetry
608```
609
610For details, see our privacy notice: https://cordova.apache.org/privacy
611
612## cordova help command
613
614### Synopsis
615
616Show syntax summary, or the help for a specific command.
617
618### Syntax
619
620```
621cordova help [command]
622cordova [command] -h
623cordova -h [command]
624```
625
626## cordova config command
627
628### Synopsis
629
630Set, get, delete, edit, and list global cordova options.
631
632### Syntax
633
634```
635cordova config ls
636cordova config edit
637cordova config set <key> <value>
638cordova config get <key>
639cordova config delete <key>
640```
641### Examples
642
643```
644cordova config set autosave false
645```
646
647[Hooks guide]: http://cordova.apache.org/docs/en/latest/guide_appdev_hooks_index.md.html
648[config.xml ref]: http://cordova.apache.org/docs/en/latest/config_ref/index.html
649[Cordova dependencies]: http://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html#specifying-project-requirements
650[scoped npm package]: https://docs.npmjs.com/misc/scope