1 |
|
2 | #
|
3 | # Licensed to the Apache Software Foundation (ASF) under one
|
4 | # or more contributor license agreements. See the NOTICE file
|
5 | # distributed with this work for additional information
|
6 | # regarding copyright ownership. The ASF licenses this file
|
7 | # to you under the Apache License, Version 2.0 (the
|
8 | # "License"); you may not use this file except in compliance
|
9 | # with the License. You may obtain a copy of the License at
|
10 | #
|
11 | # http://www.apache.org/licenses/LICENSE-2.0
|
12 | #
|
13 | # Unless required by applicable law or agreed to in writing,
|
14 | # software distributed under the License is distributed on an
|
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16 | # KIND, either express or implied. See the License for the
|
17 | # specific language governing permissions and limitations
|
18 | # under the License.
|
19 | #
|
20 | -->
|
21 |
|
22 | [![Build status](https://ci.appveyor.com/api/projects/status/wxkmo0jalsr8gane?svg=true)](https://ci.appveyor.com/project/ApacheSoftwareFoundation/cordova-common/branch/master)
|
23 | [![Build Status](https://travis-ci.org/apache/cordova-common.svg?branch=master)](https://travis-ci.org/apache/cordova-common)
|
24 | [![NPM](https://nodei.co/npm/cordova-common.png)](https://nodei.co/npm/cordova-common/)
|
25 |
|
26 | # cordova-common
|
27 | Expoeses shared functionality used by [cordova-lib](https://github.com/apache/cordova-lib/) and Cordova platforms.
|
28 | ## Exposed APIs
|
29 |
|
30 | ### `events`
|
31 |
|
32 | Represents special instance of NodeJS EventEmitter which is intended to be used to post events to cordova-lib and cordova-cli
|
33 |
|
34 | Usage:
|
35 | ```js
|
36 | var events = require('cordova-common').events;
|
37 | events.emit('warn', 'Some warning message')
|
38 | ```
|
39 |
|
40 | There are the following events supported by cordova-cli: `verbose`, `log`, `info`, `warn`, `error`.
|
41 |
|
42 | ### `CordovaError`
|
43 |
|
44 | An error class used by Cordova to throw cordova-specific errors. The CordovaError class is inherited from Error, so CordovaError instances is also valid Error instances (`instanceof` check succeeds).
|
45 |
|
46 | Usage:
|
47 |
|
48 | ```js
|
49 | var CordovaError = require('cordova-common').CordovaError;
|
50 | throw new CordovaError('Some error message', SOME_ERR_CODE);
|
51 | ```
|
52 |
|
53 | See [CordovaError](src/CordovaError/CordovaError.js) for supported error codes.
|
54 |
|
55 | ### `ConfigParser`
|
56 |
|
57 | Exposes functionality to deal with cordova project `config.xml` files. For ConfigParser API reference check [ConfigParser Readme](src/ConfigParser/README.md).
|
58 |
|
59 | Usage:
|
60 | ```js
|
61 | var ConfigParser = require('cordova-common').ConfigParser;
|
62 | var appConfig = new ConfigParser('path/to/cordova-app/config.xml');
|
63 | console.log(appconfig.name() + ':' + appConfig.version());
|
64 | ```
|
65 |
|
66 | ### `PluginInfoProvider` and `PluginInfo`
|
67 |
|
68 | `PluginInfo` is a wrapper for cordova plugins' `plugin.xml` files. This class may be instantiated directly or via `PluginInfoProvider`. The difference is that `PluginInfoProvider` caches `PluginInfo` instances based on plugin source directory.
|
69 |
|
70 | Usage:
|
71 | ```js
|
72 | var PluginInfo: require('cordova-common').PluginInfo;
|
73 | var PluginInfoProvider: require('cordova-common').PluginInfoProvider;
|
74 |
|
75 | // The following instances are equal
|
76 | var plugin1 = new PluginInfo('path/to/plugin_directory');
|
77 | var plugin2 = new PluginInfoProvider().get('path/to/plugin_directory');
|
78 |
|
79 | console.log('The plugin ' + plugin1.id + ' has version ' + plugin1.version)
|
80 | ```
|
81 |
|
82 | ### `ActionStack`
|
83 |
|
84 | Utility module for dealing with sequential tasks. Provides a set of tasks that are needed to be done and reverts all tasks that are already completed if one of those tasks fail to complete. Used internally by cordova-lib and platform's plugin installation routines.
|
85 |
|
86 | Usage:
|
87 | ```js
|
88 | var ActionStack = require('cordova-common').ActionStack;
|
89 | var stack = new ActionStack()
|
90 |
|
91 | var action1 = stack.createAction(task1, [<task parameters>], task1_reverter, [<reverter_parameters>]);
|
92 | var action2 = stack.createAction(task2, [<task parameters>], task2_reverter, [<reverter_parameters>]);
|
93 |
|
94 | stack.push(action1);
|
95 | stack.push(action2);
|
96 |
|
97 | stack.process()
|
98 | .then(function() {
|
99 | // all actions succeded
|
100 | })
|
101 | .catch(function(error){
|
102 | // One of actions failed with error
|
103 | })
|
104 | ```
|
105 |
|
106 | ### `superspawn`
|
107 |
|
108 | Module for spawning child processes with some advanced logic.
|
109 |
|
110 | Usage:
|
111 | ```js
|
112 | var superspawn = require('cordova-common').superspawn;
|
113 | superspawn.spawn('adb', ['devices'])
|
114 | .progress(function(data){
|
115 | if (data.stderr)
|
116 | console.error('"adb devices" raised an error: ' + data.stderr);
|
117 | })
|
118 | .then(function(devices){
|
119 | // Do something...
|
120 | })
|
121 | ```
|
122 |
|
123 | ### `xmlHelpers`
|
124 |
|
125 | A set of utility methods for dealing with xml files.
|
126 |
|
127 | Usage:
|
128 | ```js
|
129 | var xml = require('cordova-common').xmlHelpers;
|
130 |
|
131 | var xmlDoc1 = xml.parseElementtreeSync('some/xml/file');
|
132 | var xmlDoc2 = xml.parseElementtreeSync('another/xml/file');
|
133 |
|
134 | xml.mergeXml(doc1, doc2); // doc2 now contains all the nodes from doc1
|
135 | ```
|
136 |
|
137 | ### Other APIs
|
138 |
|
139 | The APIs listed below are also exposed but are intended to be only used internally by cordova plugin installation routines.
|
140 |
|
141 | ```
|
142 | PlatformJson
|
143 | ConfigChanges
|
144 | ConfigKeeper
|
145 | ConfigFile
|
146 | mungeUtil
|
147 | ```
|
148 |
|
149 | ## Setup
|
150 | * Clone this repository onto your local machine
|
151 | `git clone https://git-wip-us.apache.org/repos/asf/cordova-lib.git`
|
152 | * In terminal, navigate to the inner cordova-common directory
|
153 | `cd cordova-lib/cordova-common`
|
154 | * Install dependencies and npm-link
|
155 | `npm install && npm link`
|
156 | * Navigate to cordova-lib directory and link cordova-common
|
157 | `cd ../cordova-lib && npm link cordova-common && npm install`
|