Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer local cordova CLI with npx #987

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions www/contribute/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,27 @@ If you aren't sure about the priority, leave the default (major) selected. Pleas

You can quickly find out versions of platforms/plugins you're using by running:

cordova platform ls
```bash
$ npx cordova platform ls
```

or

cordova plugin ls
```bash
$ npx cordova plugin ls
```

in your project respectively. You can find out the version of the Cordova CLI you're using by running:

cordova --version
```bash
$ npx cordova --version
```

If you have installed `cordova` globally (which is an alternative way to use Cordova), you just invoke the same commands without `npx`:

```bash
$ cordova --version
```

# Generating CLI logs

Expand Down
10 changes: 5 additions & 5 deletions www/contribute/nightly_builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ The nightly builds are untested and may contain known and unknown defects, undec
To try out the latest nightly version you can do:

```bash
npm install cordova@nightly
./node_modules/.bin/cordova --version
$ npm install cordova@nightly
$ npx cordova --version
```

You can supply the `--global` option to NPM to install the nightly version globally. _Note_ that this will replace your main Cordova distribution.
You can supply the `--global` option to NPM to install the nightly version globally. _Note_ that it is generally discouraged to install `cordova` globally.

```bash
npm install --global cordova@nightly
$ npm install --global cordova@nightly
```

## Submitting issues
Expand All @@ -42,5 +42,5 @@ Please let us know about any issues in the nightly builds so we can fix them as
When submitting an issue, please add a note that the issue was reproduced using a nightly build, and provide the nightly version that you are using. You can get this via:

```bash
cordova --version
$ npx cordova --version
```
2 changes: 1 addition & 1 deletion www/docs/en/dev/config_ref/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ One icon can be used for the application and installer, but this icon should be

_Notice: If a customized icon is not provided, the Apache Cordova default icons are used._

_Notice: macOS does not display custom icons when using `cordova run`. It defaults to the Electron's icon._
_Notice: macOS does not display custom icons when using `npx cordova run`. It defaults to the Electron's icon._

```xml
<platform name="electron">
Expand Down
6 changes: 3 additions & 3 deletions www/docs/en/dev/guide/appdev/hooks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ for more details.

You can now add android platform and execute build.

```
cordova platform add android
```bash
$ npx cordova platform add android
..
cordova build
$ npx cordova build
..
Size of path\to\app\platforms\android\build\outputs\apk\android-debug.apk is 1821193 bytes
```
Expand Down
92 changes: 34 additions & 58 deletions www/docs/en/dev/guide/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,78 +35,54 @@ The Cordova command-line tool is distributed as an npm package.
To install the `cordova` command-line tool, follow these steps:

1. Download and install [Node.js](https://nodejs.org/en/download/). On
installation you should be able to invoke `node` and `npm` on your
installation you should be able to invoke `node`, `npm` and `npx` on your
command line.

1. (Optional) Download and install a [git client](http://git-scm.com/downloads), if you don't
already have one. Following installation, you should be able to invoke `git`
on your command line. The CLI uses it to download assets when they are referenced using a url to a git repo.

1. Install the `cordova` module using `npm` utility of Node.js. The `cordova`
module will automatically be downloaded by the `npm` utility.

* on OS X and Linux:
```bash
$ sudo npm install -g cordova
```
## Create the App

On OS X and Linux, prefixing the `npm` command with
`sudo` may be necessary to install this development utility in
otherwise restricted directories such as
`/usr/local/share`. If you are using the optional
nvm/nave tool or have write access to the install directory,
you may be able to omit the `sudo` prefix. There are
[more tips](http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears)
available on using `npm` without `sudo`, if you desire to do that.
Go to the directory where you maintain your source code, and create a cordova project:

* on Windows:
```
C:\>npm install -g cordova
```
```bash
$ npx cordova create hello com.example.hello HelloWorld
```

The `-g` flag above tells `npm` to install `cordova` globally. Otherwise
it will be installed in the `node_modules` subdirectory of the current
working directory.
This creates the required directory structure for your cordova app. By default, the `cordova create` script generates a skeletal web-based application whose home page is the project's `www/index.html` file.

Following installation, you should be able to run
`cordova` on the command line with no arguments and it should
print help text.
All subsequent commands need to be run within the project's directory,
or any subdirectories:

## Create the App
```bash
$ cd hello
```

Go to the directory where you maintain your source code, and create a cordova project:
Until necessary adjustments have been made to Cordova to do this for your automatically, you're going to want to install the current version of Cordova into your new project:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Until necessary adjustments have been made to Cordova to do this for your automatically, you're going to want to install the current version of Cordova into your new project:
Until necessary adjustments have been made to Cordova to do this for you automatically, you're going to want to install the current version of Cordova into your new project:


```bash
$ cordova create hello com.example.hello HelloWorld
$ npm --save-dev cordova
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ npm install --save-dev cordova

```

This creates the required directory structure for your cordova app. By default, the `cordova create` script generates a skeletal web-based application whose home page is the project's `www/index.html` file.

###See Also
- [Cordova create command reference documentation][cdv_create]
- [Cordova project directory structure][cdv_dir]
- [Cordova project templates][cdv_template]

## Add Platforms

All subsequent commands need to be run within the project's directory,
or any subdirectories:

```bash
$ cd hello
```

Add the platforms that you want to target your app. We will add the 'ios' and 'android' platform and ensure they get saved to `config.xml` and `package.json`:

```bash
$ cordova platform add ios
$ cordova platform add android
$ npx cordova platform add ios
$ npx cordova platform add android
```

To check your current set of platforms:

```bash
$ cordova platform ls
$ npx cordova platform ls
```

Running commands to add or remove platforms affects the contents of
Expand All @@ -126,8 +102,8 @@ To build and run apps, you need to install SDKs for each platform you wish to ta

To check if you satisfy requirements for building the platform:

```
$ cordova requirements
```bash
$ npx cordova requirements
Requirements check results for android:
Java JDK: installed .
Android SDK: installed
Expand All @@ -147,19 +123,19 @@ Error: Some of requirements check failed

## Build the App

By default, `cordova create` script generates a skeletal web-based application whose start page is the project's `www/index.html` file. Any
By default, the `cordova create` script generates a skeletal web-based application whose start page is the project's `www/index.html` file. Any
initialization should be specified as part of the [deviceready][DeviceReadyEvent] event handler defined in `www/js/index.js`.

Run the following command to build the project for _all_ platforms:

```bash
$ cordova build
$ npx cordova build
```

You can optionally limit the scope of each build to specific platforms - 'ios' in this case:

```bash
$ cordova build ios
$ npx cordova build ios
```

###See Also
Expand All @@ -174,12 +150,12 @@ command such as the following to rebuild the app and view it within a
specific platform's emulator:

```bash
$ cordova emulate android
$ npx cordova emulate android
```

![]({{ site.baseurl }}/static/img/guide/cli/android_emulate_init.png)

Following up with the `cordova emulate` command refreshes the emulator
Following up with the `npx cordova emulate` command refreshes the emulator
image to display the latest application, which is now available for
launch from the home screen:

Expand All @@ -189,7 +165,7 @@ Alternately, you can plug the handset into your computer and test the
app directly:

```bash
$ cordova run android
$ npx cordova run android
```

Before running this command, you need to set up the device for
Expand All @@ -209,13 +185,13 @@ A _plugin_ exposes a Javascript API for native SDK functionality. Plugins are ty
npm and you can search for them on the [plugin search page](/plugins/). Some key APIs are provided by the Apache Cordova open source project and these are referred to as [Core Plugin APIs]. You can also use the CLI to launch the search page:

```bash
$ cordova plugin search camera
$ npx cordova plugin search camera
```

To add and save the camera plugin to `config.xml` and `package.json`, we will specify the npm package name for the camera plugin:

```
$ cordova plugin add cordova-plugin-camera
$ npx cordova plugin add cordova-plugin-camera
Fetching plugin "cordova-plugin-camera@~2.1.0" via npm
Installing "cordova-plugin-camera" for android
Installing "cordova-plugin-camera" for ios
Expand All @@ -232,8 +208,8 @@ add plugins separately for each platform. (For more information, see
Use `plugin ls` (or `plugin list`, or `plugin` by itself) to view
currently installed plugins. Each displays by its identifier:

```
$ cordova plugin ls
```bash
$ npx cordova plugin ls
cordova-plugin-camera 2.1.0 "Camera"
cordova-plugin-whitelist 1.2.1 "Whitelist"
```
Expand Down Expand Up @@ -294,16 +270,16 @@ After installing the `cordova` utility, you can always update it to
the latest version by running the following command:

```bash
$ sudo npm update -g cordova
$ npm update cordova
```

Use this syntax to install a specific version:

```bash
$ sudo npm install -g cordova@3.1.0-0.2.0
$ npm install cordova@3.1.0-0.2.0
```

Run `cordova -v` to see which version is currently running. To find the latest released cordova version, you can run:
Run `npx cordova -v` to see which version is currently running. To find the latest released cordova version, you can run:

```bash
$ npm info cordova version
Expand All @@ -312,8 +288,8 @@ $ npm info cordova version
To update platform that you're targeting:

```bash
$ cordova platform update android --save
$ cordova platform update ios --save
$ npx cordova platform update android --save
$ npx cordova platform update ios --save
...etc.
```

Expand Down
8 changes: 4 additions & 4 deletions www/docs/en/dev/guide/cli/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Find a template to create your app from by seaching for the keyword `cordova:tem
After locating a template you wish to use. Create your project using that template, by specifying the `--template` flag during the `create` command, followed by your template source.

Creating a cordova project from an NPM package, Git repository, or local path:
```
$ cordova create hello com.example.hello HelloWorld --template <npm-package-name>
$ cordova create hello com.example.hello HelloWorld --template <git-remote-url>
$ cordova create hello com.example.hello HelloWorld --template <path-to-template>
```bash
$ npx cordova create hello com.example.hello HelloWorld --template <npm-package-name>
$ npx cordova create hello com.example.hello HelloWorld --template <git-remote-url>
$ npx cordova create hello com.example.hello HelloWorld --template <path-to-template>
```

After succesfully using a template to create your project, you'll want to indicate the platforms that you intend to target with your app. Go into your project folder and [add platforms](http://cordova.apache.org/docs/en/latest/guide/cli/index.html#add-platforms).
Expand Down
2 changes: 1 addition & 1 deletion www/docs/en/dev/guide/hybrid/plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ argument to that command is the URL for a _git_ repository containing
the plugin code. This example implements Cordova's Device API:

```bash
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
$ npx cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
```

The plugin repository must feature a top-level `plugin.xml` manifest
Expand Down
12 changes: 6 additions & 6 deletions www/docs/en/dev/guide/next/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ Note that the online and offline events, as well as the Network Connection API,

There is no upgrade command for Cordova projects. Instead, remove the platform from your project, and re-add it to get the latest version:

```
cordova platform rm android
cordova platform add android
```bash
$ npx cordova platform rm android
$ npx cordova platform add android
```

It is absolutely critical that you read up on what was changed in the updated version, as the update may break your code. The best place to find this information will be in the release notes published both in the repositories and on the Cordova blog. You will want to test your app thoroughly in order to verify that it is working correctly after you perform the update.
Expand All @@ -90,9 +90,9 @@ Note: some plugins may not be compatible with the new version of Cordova. If a p
## Plugin Upgrades
Upgrading plugins involves the same process as platforms - remove it, then re-add it.

```
cordova plugin rm some-plugin
cordova plugin add some-plugin
```bash
$ npx cordova plugin rm some-plugin
$ npx cordova plugin add some-plugin
```
Refer to [Manage versions and platforms](../../platform_plugin_versioning_ref/index.html) for more details.

Expand Down