代码改变世界

Cordova CLI命令行工具

2013-09-05 21:49  张智清  阅读(604)  评论(0编辑  收藏  举报

Cordova CLI用于构建、部署和管理基于Cordova应用的命令行工具。

 Cordova CLI要求的环境需求:

  • nodejs
  • 各个平台相应的SDK支持

安装Cordova

  $ npm  install  -g  cordova

用法:

先用全局级命令来创建项目工程:

create <directory> [<id> [<name>]]

其中可带参数id是指定包名,一般形如域名倒写的风格

然后在创建好的项目中,使用工程项目级的命令来配置编译、运行项目:

  • platform [ls | list] list all platforms the project will build to
  • platform add <platform> [<platform> ...] add one (or more) platforms as a build target for the project
  • platform [rm | remove] <platform> [<platform> ...] removes one (or more) platforms as a build target for the project
  • plugin [ls | list] list all plugins added to the project
  • plugin add <path-to-plugin> [<path-to-plugin> ...] add one (or more) plugins to the project
  • plugin [rm | remove] <plugin-name> [<plugin-name> ...] remove one (or more) added plugins
  • prepare [platform...] copies files into the specified platforms, or all platforms. it is then ready for building by Eclipse/Xcode/etc.
  • compile [platform...] compiles the app into a binary for each added platform. With no parameters, builds for all platforms, otherwise builds for the specified platforms.
  • build [<platform> [<platform> [...]]] an alias for cordova prepare followed by cordova compile
  • emulate [<platform> [<platform> [...]]] launch emulators and deploy app to them. With no parameters emulates for all platforms added to the project, otherwise emulates for the specified platforms
  • serve <platform> [port] launch a local web server for that platform's www directory on the given port (default 8000).

其它标识

  • -d or --verbose will pipe out more verbose output to your shell. You can also subscribe to log andwarn events if you are consuming cordova-cli as a node module by callingcordova.on('log', function() {}) or cordova.on('warn', function() {}).
  • -v or --version will print out the version of your cordova-cli install.

用Cordova CLI创建的工程项目的目录结构(以myApp项目为例)

myApp/
|--.cordova/
|-- merges/
| | |-- android/
| | |-- blackberry10/
| | `-- ios/
|-- www/
| `-- config.xml
|-- platforms/
| |-- android/
| |-- blackberry10/
| `-- ios/
`-- plugins/