Skip to content
mwbrooks edited this page Oct 23, 2014 · 8 revisions

PhoneGap CLI

http://github.com/phonegap/phonegap-cli

Overview

The PhoneGap Command-line Interface (CLI) is a command-line tool for Windows, OS X, and Linux. It allows you to create, build, and install PhoneGap apps for each of the supported platforms. It can also utilize PhoneGap Build for those who don't have their local SDK setup!

For this workshop, we wouldn't be diving deep into the CLI. So, let's start off by installing it and creating our first project!

Install

OS X

  1. Install node.js.
  2. Open Terminal.app or iTerm2.
  • Tip: use Spotlight in find the app.
  1. Install PhoneGap with the following command:

     $ sudo npm install -g phonegap
    

Users who installed node.js into their user directory can discard sudo. You know who you are. If you aren't sure, then you probably need sudo.

Windows

  1. Install node.js.

  2. Install Git (I recommend msysGit)

  3. Open Command Prompt for node.js or Git Bash.

  4. Install PhoneGap with the following command:

     $ npm install -g phonegap
    

Linux

  1. Install node.js.

  2. Open your favourite terminal.

  3. Install PhoneGap with the following command:

     $ npm install -g phonegap
    

Depending on how your package manager installed node.js, you may need to add sudo. You'll know because you'll receive an access denied error.

Usage

The PhoneGap CLI is used similar to other command-line tools.

While the PhoneGap CLI inherits from the Apache Cordova CLI, it does use different commands. This is annoying and will be changing very soon!

1. Help

The PhoneGap CLI is very helpful. You can add help to any command to learn how to use it.

Let's look at an example:

$ phonegap help
$ phonegap --help
$ phonegap -h

All display:

Usage: phonegap [options] [commands]

Description:

  PhoneGap command-line tool.

...

Examples:

  $ phonegap help create
  $ phonegap help remote build
  $ phonegap create path/to/my-app
  $ phonegap remote build android

And likewise to learn about create:

$ phonegap help create
$ phonegap create help
$ phonegap create --help
$ phonegap create -h

All display:

Usage: phonegap create [options] <path> [id [name]]

Description:

  Creates a new application at the provided path.

  The application name and package ID can also be customized.
  These values are set in the app manifest (www/config.xml) and are used when
  creating a native project (platforms/<platform>/).

Options:

  --name, -n <name>    application name (default: "Hello World")
  --id, -i <package>   package name (default: "com.phonegap.hello-world")

Examples:

  $ phonegap create path/to/my-app
  $ phonegap create path/to/my-app "com.example.app" "My App"
  $ phonegap create path/to/my-app --id "com.example.app" --name "My App"

The only help that help doesn't provide is about help. Yep.

2. Create a Project

  1. Type $ phonegap help to find the command to create a project.
  • _You'll notice that $ phonegap create is the command.
  1. Type $ phonegap help create to learn how to create a project.
  2. Type $ phonegap create my-app to create a new project called My App.
  3. Type $ cd my-app/ to change into that app's directory.

Putting all of the command together, it would look like:

$ phonegap help
$ phonegap help create
$ phonegap create my-app
$ cd my-app/

Congratulations! You've created your first PhoneGap project!

Report a Bug

Did you find a bug, quirk, or improvement? Please take a moment to submit a brief issue to phonegap/phonegap-cli/issues!

Thanks, you rock!