UNPKG

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