官术网_书友最值得收藏!

Using the PhoneGap CLI

You can use the Cordova command-line interface to initialize the project code, after which you can use various platforms' SDKs to develop them further. In the previous chapter, we discussed how to create a new project, add the required platforms, and build them using the CLI.

Apart from creating a project by using the CLI tool, there are several other functions carried out by the CLI of Cordova. As the steps for installing the CLI are already covered, let's move on with advanced CLI usage. Once you create a project, use cd to move into it and you can execute a variety of project-level commands.

The following is the list of the most used CLI commands:

  • platform add <platform>: This adds a platform as a build target for the project.
  • platform [rm | remove] <platform>: This removes a platform which was previously added to the project.
  • platform [ls | list]: This lists all platforms for which the project will build.
  • platform [up | update] <platform>: This updates the Cordova version used for the given platform.
  • plugin [ls | list]: This lists all the plugins included in the project.
  • plugin add <path-to-plugin> [<path-to-plugin> ...]: This adds one (or more) plugins to the project.
  • plugin [rm | remove] <plugin-name> [<plugin-name> ...]: This removes one (or more) plugins from the project.
  • plugin search [<keyword1> <keyword2> ...]: This searches the plugin registry for plugins matching the list of keywords.
  • prepare [platform...]: This copies files into the specified platforms, or all platforms. It is then ready for building by Eclipse, Xcode, and so on.
  • compile [platform...]: This compiles the app into a binary for each targeted platform. With no parameters, it builds for all platforms; otherwise, it builds for the specified platforms.
  • build [<platform> [<platform> [...]]]: This is an alias for cordova prepare followed by cordova compile.
  • emulate [<platform> [<platform> [...]]]: This launches emulators and deploys the app to them. With no parameters, it emulates the app for all the platforms added to the project; otherwise, it emulates the app for the specified platforms.
  • serve [port]: This launches a local web server allowing you to access each platform's www directory on the given port (default 8000).

All the preceding CLI commands are to be executed inside the project directory. Some of the example usages are as follows:

c:\hello>phonegap platform add android
c:\hello>phonegap platform add ios
c:\hello>phonegap platform remove android
c:\hello>phonegap platform list

The help command is a global command, which displays a help page with all the available commands and the syntax to use them. This command can be executed at any command window and not necessarily within the project directory:

c:\> phonegap help
主站蜘蛛池模板: 元谋县| 花莲市| 巴青县| 九寨沟县| 香格里拉县| 青河县| 通道| 临桂县| 都昌县| 苏州市| 博客| 深圳市| 岱山县| 贡嘎县| 桐城市| 兴义市| 辛集市| 正安县| 尼玛县| 霍林郭勒市| 于田县| 金坛市| 枞阳县| 永嘉县| 巴中市| 图木舒克市| 二连浩特市| 瑞安市| 鄂托克旗| 大连市| 五台县| 清苑县| 博野县| 连江县| 吉林市| 南投县| 丁青县| 漯河市| 鄱阳县| 永康市| 清河县|