Last commit july 5th

This commit is contained in:
2024-07-05 13:46:23 +02:00
parent dad0d86e8c
commit b0e4dfbb76
24982 changed files with 2621219 additions and 413 deletions

37
spa/node_modules/cordova-common/CONTRIBUTING.md generated vendored Normal file
View File

@@ -0,0 +1,37 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
# Contributing to Apache Cordova
Anyone can contribute to Cordova. And we need your contributions.
There are multiple ways to contribute: report bugs, improve the docs, and
contribute code.
For instructions on this, start with the
[contribution overview](http://cordova.apache.org/contribute/).
The details are explained there, but the important items are:
- Check for Github issues that corresponds to your contribution and link or create them if necessary.
- Run the tests so your patch doesn't break existing functionality.
We look forward to your contributions!

202
spa/node_modules/cordova-common/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

5
spa/node_modules/cordova-common/NOTICE generated vendored Normal file
View File

@@ -0,0 +1,5 @@
Apache Cordova
Copyright 2015 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

177
spa/node_modules/cordova-common/README.md generated vendored Normal file
View File

@@ -0,0 +1,177 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
# cordova-common
[![NPM](https://nodei.co/npm/cordova-common.png)](https://nodei.co/npm/cordova-common/)
[![Node CI](https://github.com/apache/cordova-common/workflows/Node%20CI/badge.svg?branch=master)](https://github.com/apache/cordova-common/actions?query=branch%3Amaster)
Exposes shared functionality used by [cordova-lib](https://github.com/apache/cordova-lib/) and Cordova platforms.
## Exposed APIs
### `events`
Represents special instance of NodeJS `EventEmitter` which is intended to be used to post events to `cordova-lib` and `cordova-cli`
Usage:
```js
const { events } = require('cordova-common');
events.emit('warn', 'Some warning message')
```
Here are the following supported events by `cordova-cli`:
* `verbose`
* `log`
* `info`
* `warn`
* `error`
### `CordovaError`
An error class used by Cordova to throw cordova-specific errors. The `CordovaError` class is inherited from `Error`, so it is a valid instance of `Error`. (`instanceof` check succeeds).
Usage:
```js
const { CordovaError } = require('cordova-common');
throw new CordovaError('Some error message', SOME_ERR_CODE);
```
See [CordovaError](src/CordovaError/CordovaError.js) for supported error codes.
### `ConfigParser`
Exposes functionality to deal with cordova project `config.xml` files. For `ConfigParser` API reference check [ConfigParser Readme](src/ConfigParser/README.md).
Usage:
```js
const { ConfigParser } = require('cordova-common');
const appConfig = new ConfigParser('path/to/cordova-app/config.xml');
console.log(`${appconfig.name()}:${appConfig.version()}`);
```
### `PluginInfoProvider` and `PluginInfo`
`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.
Usage:
```js
const { PluginInfo, PluginInfoProvider } = require('cordova-common');
// The following instances are equal
const plugin1 = new PluginInfo('path/to/plugin_directory');
const plugin2 = new PluginInfoProvider().get('path/to/plugin_directory');
console.log(`The plugin ${plugin1.id} has version ${plugin1.version}`)
```
### `ActionStack`
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.
Usage:
```js
const { ActionStack } = require('cordova-common');
const stack = new ActionStack();
const action1 = stack.createAction(task1, [<task parameters>], task1_reverter, [<reverter_parameters>]);
const action2 = stack.createAction(task2, [<task parameters>], task2_reverter, [<reverter_parameters>]);
stack.push(action1);
stack.push(action2);
stack.process()
.then(() => {
// all actions succeded
})
.catch(error => {
// One of actions failed with error
});
```
### `superspawn`
Module for spawning child processes with some advanced logic.
Usage:
```js
const { superspawn } = require('cordova-common');
superspawn.spawn('adb', ['devices'])
.progress(data => {
if (data.stderr) console.error(`"adb devices" raised an error: ${data.stderr}`);
})
.then(devices => {
// Do something...
});
```
### `xmlHelpers`
A set of utility methods for dealing with XML files.
Usage:
```js
const { xmlHelpers } = require('cordova-common');
const doc1 = xmlHelpers.parseElementtreeSync('some/xml/file');
const doc2 = xmlHelpers.parseElementtreeSync('another/xml/file');
xmlHelpers.mergeXml(doc1, doc2); // doc2 now contains all the nodes from doc1
```
### Other APIs
The APIs listed below are also exposed but are intended to be only used internally by cordova plugin installation routines.
* `PlatformJson`
* `ConfigChanges`
* `ConfigKeeper`
* `ConfigFile`
## Setup
* Clone this repository onto your local machine
```bash
git clone https://github.com/apache/cordova-common.git
```
* Navigate to cordova-common directory, install dependencies and npm-link
```bash
cd cordova-common && npm install && npm link
```
* Navigate to cordova-lib directory and link cordova-common
```bash
cd <cordova-lib directory> && npm link cordova-common && npm install
```

270
spa/node_modules/cordova-common/RELEASENOTES.md generated vendored Normal file
View File

@@ -0,0 +1,270 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
# cordova-common Release Notes
### 5.0.0 (Feb 28, 2023)
* [GH-186](https://github.com/apache/cordova-common/pull/186) feat!: bump package requirement node>=16
* [GH-197](https://github.com/apache/cordova-common/pull/197) feat(android): added monochrome attribute
* [GH-99](https://github.com/apache/cordova-common/pull/99) chore: drop q where possible
* [GH-198](https://github.com/apache/cordova-common/pull/198) test: Removed obsolete test
* [GH-196](https://github.com/apache/cordova-common/pull/196) dep: bump @cordova/eslint-config@^5.0.0
* [GH-192](https://github.com/apache/cordova-common/pull/192) dep!: bump all available packages
* [GH-193](https://github.com/apache/cordova-common/pull/193) refactor: replace underscore w/ lodash module pkgs
* [GH-194](https://github.com/apache/cordova-common/pull/194) refactor: renamed variable
* [GH-188](https://github.com/apache/cordova-common/pull/188) ci(actions): test w/ node 14, 16, 18
* [GH-187](https://github.com/apache/cordova-common/pull/187) ci(actions): update workflow
### 4.1.0 (Nov 08, 2022)
* [GH-181](https://github.com/apache/cordova-common/pull/181) feat(PluginInfo): Allow XML Attributes to be passed through to core platforms
* [GH-158](https://github.com/apache/cordova-common/pull/158) fix(ConfigChanges): do not pass PlistValue to xml_helpers.resolveParent
* [GH-162](https://github.com/apache/cordova-common/pull/162) refactor(PlatformMunger): DRY & simplify config munging
* [GH-160](https://github.com/apache/cordova-common/pull/160) refactor(xml-helpers): document & check function signature types
* [GH-159](https://github.com/apache/cordova-common/pull/159) refactor(ConfigChanges): use for-of loop for iterating over array
* [GH-184](https://github.com/apache/cordova-common/pull/184) chore: rebuild package-lock.json
* [GH-176](https://github.com/apache/cordova-common/pull/176) chore(npm): rebuilt package-lock to v2
* [GH-173](https://github.com/apache/cordova-common/pull/173) chore: npmrc
* [GH-180](https://github.com/apache/cordova-common/pull/180) ci: Remove Node 10/12 from matrix. Added Node 16 and 18.
* [GH-150](https://github.com/apache/cordova-common/pull/150) ci: add node 14 to workflow
* [GH-161](https://github.com/apache/cordova-common/pull/161) test: fix invalid config for jasmine-spec-reporter
### 4.0.2 (Jul 01, 2020)
* [GH-144](https://github.com/apache/cordova-common/pull/144) fix(ios): resolve correct path to app info `plist` when multiple `plist` files are present
* [GH-147](https://github.com/apache/cordova-common/pull/147) chore: remove trailing whitespace
* [GH-146](https://github.com/apache/cordova-common/pull/146) chore: bump `devDependencies` `nyc` -> `^15.1.0`
* [GH-145](https://github.com/apache/cordova-common/pull/145) test: remove unused test fixtures
### 4.0.1 (May 14, 2020)
* [GH-141](https://github.com/apache/cordova-common/pull/141) chore: apply random missing minor changes
* [GH-143](https://github.com/apache/cordova-common/pull/143) fix: typo in access & allow navigation
* [GH-142](https://github.com/apache/cordova-common/pull/142) fix(`ConfigParser`): `ImageResources` constructor
### 4.0.0 (Mar 26, 2020)
* [GH-140](https://github.com/apache/cordova-common/pull/140) breaking: bump all dependencies to latest
* bump `fs-extra@^9.0.0`
* bump `@cordova/eslint-config@^3.0.0`
* bump `jasmine-spec-reporter@^5.0.1`
* bump Github Actions `actions/checkout@v2`
* [GH-139](https://github.com/apache/cordova-common/pull/139) chore: various cleanup tasks
* [GH-138](https://github.com/apache/cordova-common/pull/138) chore(dependency): update dev & non-dev dependencies
* [GH-137](https://github.com/apache/cordova-common/pull/137) refactor: transform `var` to `let`/`const`
* [GH-136](https://github.com/apache/cordova-common/pull/136) ci: final migration to actions
* [GH-85](https://github.com/apache/cordova-common/pull/85) style: improve line spacing & group like items
* [GH-124](https://github.com/apache/cordova-common/pull/124) fix(`ConfigFile`): correctly resolve *-Info.plist file path
* [GH-135](https://github.com/apache/cordova-common/pull/135) fix(`ConfigFile`): Normalize globbed file paths
* [GH-134](https://github.com/apache/cordova-common/pull/134) test(`ConfigFile`): minor improvements
* [GH-121](https://github.com/apache/cordova-common/pull/121) feat(`CordovaError`): support for error cause & more
* [GH-133](https://github.com/apache/cordova-common/pull/133) refactor(`ConfigParser`): cleanup & simplify
* [GH-132](https://github.com/apache/cordova-common/pull/132) refactor(`PluginInfo`): cleanup & simplify
* [GH-131](https://github.com/apache/cordova-common/pull/131) refactor(misc): cleanup & simplify
* [GH-130](https://github.com/apache/cordova-common/pull/130) refactor(`ConfigChanges`): simplify
* [GH-128](https://github.com/apache/cordova-common/pull/128) refactor(`xml-helpers`): DRY & simplify
* [GH-129](https://github.com/apache/cordova-common/pull/129) fix: broken lock file from [#95](https://github.com/apache/cordova-common/pu#95)
* [GH-127](https://github.com/apache/cordova-common/pull/127) refactor(`munge-util`): DRY & simplify
* [GH-95](https://github.com/apache/cordova-common/pull/95) TEST: Test using GitHub workflows for CI
* [GH-125](https://github.com/apache/cordova-common/pull/125) test(`ConfigFile`): group & cleanup tests
* [GH-126](https://github.com/apache/cordova-common/pull/126) chore!: remove main export `mungeUtil`
* [GH-123](https://github.com/apache/cordova-common/pull/123) refactor: `FileUpdater`
* [GH-119](https://github.com/apache/cordova-common/pull/119) refactor: use ES6 classes where applicable
* [GH-118](https://github.com/apache/cordova-common/pull/118) refactor: use template strings where applicable
* [GH-116](https://github.com/apache/cordova-common/pull/116) refactor: use property shorthand notation
* [GH-115](https://github.com/apache/cordova-common/pull/115) refactor: transform `var` to `let`/`const`
* [GH-114](https://github.com/apache/cordova-common/pull/114) refactor: do not alias `this`
* [GH-113](https://github.com/apache/cordova-common/pull/113) refactor: use arrow functions where applicable
* [GH-120](https://github.com/apache/cordova-common/pull/120) refactor: move `CordovaError` module up
* [GH-117](https://github.com/apache/cordova-common/pull/117) refactor(`CordovaError`)!: remove unused features
* [GH-111](https://github.com/apache/cordova-common/pull/111) chore: remove support for ubuntu platform
* [GH-109](https://github.com/apache/cordova-common/pull/109) chore: consolidate eslint configs
* [GH-108](https://github.com/apache/cordova-common/pull/108) style: drop jasmine env workaround
* [GH-105](https://github.com/apache/cordova-common/pull/105) refactor: eslint setup
* [GH-107](https://github.com/apache/cordova-common/pull/107) test: always run code coverage during `npm test`
* [GH-106](https://github.com/apache/cordova-common/pull/106) ci(travis): run codecov using npx in `after_success`
* [GH-103](https://github.com/apache/cordova-common/pull/103) chore: bump production dependencies
* [GH-101](https://github.com/apache/cordova-common/pull/101) chore: update jasmine dependencies & config
* [GH-100](https://github.com/apache/cordova-common/pull/100) chore: replace `instanbul` w/ `nyc`
* [GH-102](https://github.com/apache/cordova-common/pull/102) chore: drop unused & unneeded dependencies
* [GH-104](https://github.com/apache/cordova-common/pull/104) chore: improve npm ignore list
* [GH-96](https://github.com/apache/cordova-common/pull/96) feat: Replace `addProperty` with ES6 getters
* [GH-94](https://github.com/apache/cordova-common/pull/94) fix: `PluginInfoProvider` for scoped plugins
* [GH-71](https://github.com/apache/cordova-common/pull/71) chore: update `strip-bom@4`
* [GH-90](https://github.com/apache/cordova-common/pull/90) chore: drop node 6 and 8 support
* [GH-97](https://github.com/apache/cordova-common/pull/97) Use `Array.prototype.find` in `CordovaError`
* [GH-93](https://github.com/apache/cordova-common/pull/93) Re-apply fix for failing `CordovaError` test
* [GH-92](https://github.com/apache/cordova-common/pull/92) Remove obsolete JSHint comments
* [GH-87](https://github.com/apache/cordova-common/pull/87) Convert `CordovaError` to ES6 class
### 3.2.1 (Oct 28, 2019)
* [GH-78](https://github.com/apache/cordova-common/pull/78) (windows) Add `.jsproj` as file extension for XML files ([GH-62](https://github.com/apache/cordova-common/pull/62))
* [GH-89](https://github.com/apache/cordova-common/pull/89) revert: ([GH-24](https://github.com/apache/cordova-common/pull/24)) [CB-14108](https://issues.apache.org/jira/browse/CB-14108) fix incorrect count in `config_munge`
* [GH-82](https://github.com/apache/cordova-common/pull/82) General cleanup with eslint updates
* [GH-86](https://github.com/apache/cordova-common/pull/86) eslint cleanup fixes: `operator-linebreak`
* [GH-81](https://github.com/apache/cordova-common/pull/81) remove `no-throw-literal` lint exception not needed
* [GH-83](https://github.com/apache/cordova-common/pull/83) Fix ESLint violations where applicable
* [GH-80](https://github.com/apache/cordova-common/pull/80) Update to jasmine 3.4 & fix resulting spec failures
* [GH-79](https://github.com/apache/cordova-common/pull/79) Promise handling cleanup in specs
* [GH-77](https://github.com/apache/cordova-common/pull/77) Do not ignore AppVeyor failures on Node.js 12
### 3.2.0 (Jun 12, 2019)
* (ios) plist document not indented with tabs ([#69](https://github.com/apache/cordova-common/pull/69))
* Update fs-extra to v8 ([#70](https://github.com/apache/cordova-common/pull/70))
* Add example usage of podspec declarations ([#67](https://github.com/apache/cordova-common/pull/67))
* implement setPreference and setPlatformPreference ([#63](https://github.com/apache/cordova-common/pull/63))
* Catch leaked exceptions in superspawn and convert them to rejections ([#66](https://github.com/apache/cordova-common/pull/66))
### 3.1.0 (Dec 24, 2018)
* Update Cordova events into a real singleton class ([#60](https://github.com/apache/cordova-common/pull/60))
* Refactor CordovaLogger to singleton class ([#53](https://github.com/apache/cordova-common/pull/53))
### 3.0.0 (Nov 05, 2018)
* [CB-14166](https://issues.apache.org/jira/browse/CB-14166) Use `cross-spawn` for platform-independent spawning
* add `PluginInfo.getPodSpecs` method
* [CB-13496](https://issues.apache.org/jira/browse/CB-13496) Fix greedy regex in plist-helpers
* [CB-14108](https://issues.apache.org/jira/browse/CB-14108) fix incorrect count in config_munge in ios.json and android.json
* [CB-13685](https://issues.apache.org/jira/browse/CB-13685) **Android**: Update ConfigParser for Adaptive Icons
* [CB-10071](https://issues.apache.org/jira/browse/CB-10071) Add BridgingHeader type attributes for header-file
* [CB-12016](https://issues.apache.org/jira/browse/CB-12016) Removed cordova-registry-mapper dependency
* [CB-14099](https://issues.apache.org/jira/browse/CB-14099) **osx**: Fixed Resolve Config Path for OSX
* [CB-14140](https://issues.apache.org/jira/browse/CB-14140) Replace shelljs calls with fs-extra & which
### 2.2.2 (May 30, 2018)
* [CB-13979](https://issues.apache.org/jira/browse/CB-13979) More consistency for `config.xml` lookups
* [CB-14064](https://issues.apache.org/jira/browse/CB-14064) Remove Node 4 from CI matrix
* [CB-14088](https://issues.apache.org/jira/browse/CB-14088) Update dependencies
* [CB-11691](https://issues.apache.org/jira/browse/CB-11691) Fix for modifying binary plists
* [CB-13770](https://issues.apache.org/jira/browse/CB-13770) Warn when <edit-config> or <config-file> not found
* [CB-13471](https://issues.apache.org/jira/browse/CB-13471) Fix tests and path issues for **Windows**
* [CB-13471](https://issues.apache.org/jira/browse/CB-13471) added unit test for config file provider
* [CB-13744](https://issues.apache.org/jira/browse/CB-13744) Recognize storyboards as XML files
* [CB-13674](https://issues.apache.org/jira/browse/CB-13674) Incremented package version to -dev
### 2.2.1 (Dec 14, 2017)
* [CB-13674](https://issues.apache.org/jira/browse/CB-13674): updated dependencies
### 2.2.0 (Nov 22, 2017)
* [CB-13471](https://issues.apache.org/jira/browse/CB-13471) File Provider fix belongs in cordova-common
* [CB-11244](https://issues.apache.org/jira/browse/CB-11244) Spot fix for upcoming `cordova-android@7` changes. https://github.com/apache/cordova-android/pull/389
### 2.1.1 (Oct 04, 2017)
* [CB-13145](https://issues.apache.org/jira/browse/CB-13145) added `getFrameworks` to unit tests
* [CB-13145](https://issues.apache.org/jira/browse/CB-13145) added variable replacing to framework tag
### 2.1.0 (August 30, 2017)
* [CB-13145](https://issues.apache.org/jira/browse/CB-13145) added variable replacing to `framework` tag
* [CB-13211](https://issues.apache.org/jira/browse/CB-13211) Add `allows-arbitrary-loads-for-media` attribute parsing for `getAccesses`
* [CB-11968](https://issues.apache.org/jira/browse/CB-11968) Added support for `<config-file>` in `config.xml`
* [CB-12895](https://issues.apache.org/jira/browse/CB-12895) set up `eslint` and removed `jshint`
* [CB-12785](https://issues.apache.org/jira/browse/CB-12785) added `.gitignore`, `travis`, and `appveyor` support
* [CB-12250](https://issues.apache.org/jira/browse/CB-12250) & [CB-12409](https://issues.apache.org/jira/browse/CB-12409) *iOS*: Fix bug with escaping properties from `plist` file
* [CB-12762](https://issues.apache.org/jira/browse/CB-12762) updated `common`, `fetch`, and `serve` `pkgJson` to point `pkgJson` repo items to github mirrors
* [CB-12766](https://issues.apache.org/jira/browse/CB-12766) Consistently write `JSON` with 2 spaces indentation
### 2.0.3 (May 02, 2017)
* [CB-8978](https://issues.apache.org/jira/browse/CB-8978) Add option to get `resource-file` from `root`
* [CB-11908](https://issues.apache.org/jira/browse/CB-11908) Add tests for `edit-config` in `config.xml`
* [CB-12665](https://issues.apache.org/jira/browse/CB-12665) removed `enginestrict` since it is deprecated
### 2.0.2 (Apr 14, 2017)
* [CB-11233](https://issues.apache.org/jira/browse/CB-11233) - Support installing frameworks into 'Embedded Binaries' section of the Xcode project
* [CB-10438](https://issues.apache.org/jira/browse/CB-10438) - Install correct dependency version. Removed shell.remove, added pkg.json to dependency tests 1-3, and updated install.js (.replace) to fix tests in uninstall.spec.js and update to workw with jasmine 2.0
* [CB-11120](https://issues.apache.org/jira/browse/CB-11120) - Allow short/display name in config.xml
* [CB-11346](https://issues.apache.org/jira/browse/CB-11346) - Remove known platforms check
* [CB-11977](https://issues.apache.org/jira/browse/CB-11977) - updated engines and enginescript for common, fetch, and serve
### 2.0.1 (Mar 09, 2017)
* [CB-12557](https://issues.apache.org/jira/browse/CB-12557) add both stdout and stderr properties to the error object passed to superspawn reject handler.
### 2.0.0 (Jan 17, 2017)
* [CB-8978](https://issues.apache.org/jira/browse/CB-8978) Add `resource-file` parsing to `config.xml`
* [CB-12018](https://issues.apache.org/jira/browse/CB-12018): updated `jshint` and updated tests to work with `jasmine@2` instead of `jasmine-node`
* [CB-12163](https://issues.apache.org/jira/browse/CB-12163) Add reference attrib to `resource-file` for **Windows**
* Move windows-specific logic to `cordova-windows`
* [CB-12189](https://issues.apache.org/jira/browse/CB-12189) Add implementation attribute to framework
### 1.5.1 (Oct 12, 2016)
* [CB-12002](https://issues.apache.org/jira/browse/CB-12002) Add `getAllowIntents()` to `ConfigParser`
* [CB-11998](https://issues.apache.org/jira/browse/CB-11998) `cordova platform add` error with `cordova-common@1.5.0`
### 1.5.0 (Oct 06, 2016)
* [CB-11776](https://issues.apache.org/jira/browse/CB-11776) Add test case for different `edit-config` targets
* [CB-11908](https://issues.apache.org/jira/browse/CB-11908) Add `edit-config` to `config.xml`
* [CB-11936](https://issues.apache.org/jira/browse/CB-11936) Support four new **App Transport Security (ATS)** keys
* update `config.xml` location if it is a **Android Studio** project.
* use `array` methods and `object.keys` for iterating. avoiding `for-in` loops
* [CB-11517](https://issues.apache.org/jira/browse/CB-11517) Allow `.folder` matches
* [CB-11776](https://issues.apache.org/jira/browse/CB-11776) check `edit-config` target exists
### 1.4.1 (Aug 09, 2016)
* Add general purpose `ConfigParser.getAttribute` API
* [CB-11653](https://issues.apache.org/jira/browse/CB-11653) moved `findProjectRoot` from `cordova-lib` to `cordova-common`
* [CB-11636](https://issues.apache.org/jira/browse/CB-11636) Handle attributes with quotes correctly
* [CB-11645](https://issues.apache.org/jira/browse/CB-11645) added check to see if `getEditConfig` exists before trying to use it
* [CB-9825](https://issues.apache.org/jira/browse/CB-9825) framework tag spec parsing
### 1.4.0 (Jul 12, 2016)
* [CB-11023](https://issues.apache.org/jira/browse/CB-11023) Add edit-config functionality
### 1.3.0 (May 12, 2016)
* [CB-11259](https://issues.apache.org/jira/browse/CB-11259): Improving prepare and build logging
* [CB-11194](https://issues.apache.org/jira/browse/CB-11194) Improve cordova load time
* [CB-1117](https://issues.apache.org/jira/browse/CB-1117) Add `FileUpdater` module to `cordova-common`.
* [CB-11131](https://issues.apache.org/jira/browse/CB-11131) Fix `TypeError: message.toUpperCase` is not a function in `CordovaLogger`
### 1.2.0 (Apr 18, 2016)
* [CB-11022](https://issues.apache.org/jira/browse/CB-11022) Save modulesMetadata to both www and platform_www when necessary
* [CB-10833](https://issues.apache.org/jira/browse/CB-10833) Deduplicate common logic for plugin installation/uninstallation
* [CB-10822](https://issues.apache.org/jira/browse/CB-10822) Manage plugins/modules metadata using PlatformJson
* [CB-10940](https://issues.apache.org/jira/browse/CB-10940) Can't add Android platform from path
* [CB-10965](https://issues.apache.org/jira/browse/CB-10965) xml helper allows multiple instances to be merge in config.xml
### 1.1.1 (Mar 18, 2016)
* [CB-10694](https://issues.apache.org/jira/browse/CB-10694) Update test to reflect merging of [CB-9264](https://issues.apache.org/jira/browse/CB-9264) fix
* [CB-10694](https://issues.apache.org/jira/browse/CB-10694) Platform-specific configuration preferences don't override global settings
* [CB-9264](https://issues.apache.org/jira/browse/CB-9264) Duplicate entries in `config.xml`
* [CB-10791](https://issues.apache.org/jira/browse/CB-10791) Add `adjustLoggerLevel` to `cordova-common.CordovaLogger`
* [CB-10662](https://issues.apache.org/jira/browse/CB-10662) Add tests for `ConfigParser.getStaticResources`
* [CB-10622](https://issues.apache.org/jira/browse/CB-10622) fix target attribute being ignored for images in `config.xml`.
* [CB-10583](https://issues.apache.org/jira/browse/CB-10583) Protect plugin preferences from adding extra Array properties.
### 1.1.0 (Feb 16, 2016)
* [CB-10482](https://issues.apache.org/jira/browse/CB-10482) Remove references to windows8 from cordova-lib/cli
* [CB-10430](https://issues.apache.org/jira/browse/CB-10430) Adds forwardEvents method to easily connect two EventEmitters
* [CB-10176](https://issues.apache.org/jira/browse/CB-10176) Adds CordovaLogger class, based on logger module from cordova-cli
* [CB-10052](https://issues.apache.org/jira/browse/CB-10052) Expose child process' io streams via promise progress notification
* [CB-10497](https://issues.apache.org/jira/browse/CB-10497) Prefer .bat over .cmd on windows platform
* [CB-9984](https://issues.apache.org/jira/browse/CB-9984) Bumps plist version and fixes failing cordova-common test
### 1.0.0 (Oct 29, 2015)
* [CB-9890](https://issues.apache.org/jira/browse/CB-9890) Documents cordova-common
* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Correct cordova-lib -> cordova-common in README
* Pick ConfigParser changes from apache@0c3614e
* [CB-9743](https://issues.apache.org/jira/browse/CB-9743) Removes system frameworks handling from ConfigChanges
* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Cleans out code which has been moved to `cordova-common`
* Pick ConfigParser changes from apache@ddb027b
* Picking CordovaError changes from apache@a3b1fca
* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Adds tests and fixtures based on existing cordova-lib ones
* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Initial implementation for cordova-common

42
spa/node_modules/cordova-common/cordova-common.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
module.exports = {
get events () { return require('./src/events'); },
get superspawn () { return require('./src/superspawn'); },
get ActionStack () { return require('./src/ActionStack'); },
get CordovaError () { return require('./src/CordovaError'); },
get CordovaLogger () { return require('./src/CordovaLogger'); },
get CordovaCheck () { return require('./src/CordovaCheck'); },
get PlatformJson () { return require('./src/PlatformJson'); },
get ConfigParser () { return require('./src/ConfigParser/ConfigParser'); },
get FileUpdater () { return require('./src/FileUpdater'); },
get PluginInfo () { return require('./src/PluginInfo/PluginInfo'); },
get PluginInfoProvider () { return require('./src/PluginInfo/PluginInfoProvider'); },
get PluginManager () { return require('./src/PluginManager'); },
get ConfigChanges () { return require('./src/ConfigChanges/ConfigChanges'); },
get ConfigKeeper () { return require('./src/ConfigChanges/ConfigKeeper'); },
get ConfigFile () { return require('./src/ConfigChanges/ConfigFile'); },
get xmlHelpers () { return require('./src/util/xml-helpers'); }
};

57
spa/node_modules/cordova-common/package.json generated vendored Normal file
View File

@@ -0,0 +1,57 @@
{
"author": "Apache Software Foundation",
"name": "cordova-common",
"description": "Apache Cordova tools and platforms shared routines",
"license": "Apache-2.0",
"version": "5.0.0",
"repository": "github:apache/cordova-common",
"bugs": "https://github.com/apache/cordova-common/issues",
"main": "cordova-common.js",
"engines": {
"node": ">=16.0.0"
},
"scripts": {
"test": "npm run lint && npm run cover",
"test:unit": "jasmine \"spec/**/*.spec.js\"",
"lint": "eslint .",
"cover": "nyc npm run test:unit"
},
"dependencies": {
"@netflix/nerror": "^1.1.3",
"ansi": "^0.3.1",
"bplist-parser": "^0.3.2",
"cross-spawn": "^7.0.3",
"elementtree": "^0.1.7",
"endent": "^2.1.0",
"fast-glob": "^3.2.12",
"fs-extra": "^11.1.0",
"glob": "^7.1.6",
"lodash.assign": "^4.2.0",
"lodash.isdate": "^4.0.1",
"lodash.isobject": "^3.0.2",
"lodash.zip": "^4.2.0",
"plist": "^3.0.6",
"q": "^1.5.1",
"read-chunk": "^3.2.0",
"strip-bom": "^4.0.0"
},
"devDependencies": {
"@cordova/eslint-config": "^5.0.0",
"@nodelib/fs.macchiato": "^1.0.4",
"jasmine": "^4.5.0",
"jasmine-spec-reporter": "^7.0.0",
"nyc": "^15.1.0",
"rewire": "^6.0.0"
},
"nyc": {
"all": true,
"exclude": [
"coverage/",
"spec/"
],
"reporter": [
"lcov",
"text"
]
}
}

84
spa/node_modules/cordova-common/src/ActionStack.js generated vendored Normal file
View File

@@ -0,0 +1,84 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const events = require('./events');
class ActionStack {
constructor () {
this.stack = [];
this.completed = [];
}
createAction (handler, action_params, reverter, revert_params) {
return {
handler: {
run: handler,
params: action_params
},
reverter: {
run: reverter,
params: revert_params
}
};
}
push (tx) {
this.stack.push(tx);
}
// Returns a promise.
process (platform) {
events.emit('verbose', `Beginning processing of action stack for ${platform} project...`);
while (this.stack.length) {
const action = this.stack.shift();
const handler = action.handler.run;
const action_params = action.handler.params;
try {
handler.apply(null, action_params);
} catch (e) {
events.emit('warn', 'Error during processing of action! Attempting to revert...');
this.stack.unshift(action);
let issue = 'Uh oh!\n';
// revert completed tasks
while (this.completed.length) {
const undo = this.completed.shift();
const revert = undo.reverter.run;
const revert_params = undo.reverter.params;
try {
revert.apply(null, revert_params);
} catch (err) {
events.emit('warn', 'Error during reversion of action! We probably really messed up your project now, sorry! D:');
issue += `A reversion action failed: ${err.message}\n`;
}
}
e.message = issue + e.message;
return Promise.reject(e);
}
this.completed.push(action);
}
events.emit('verbose', 'Action stack processing complete.');
return Promise.resolve();
}
}
module.exports = ActionStack;

View File

@@ -0,0 +1,310 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/*
* This module deals with shared configuration / dependency "stuff". That is:
* - XML configuration files such as config.xml, AndroidManifest.xml or WMAppManifest.xml.
* - plist files in iOS
* Essentially, any type of shared resources that we need to handle with awareness
* of how potentially multiple plugins depend on a single shared resource, should be
* handled in this module.
*
* The implementation uses an object as a hash table, with "leaves" of the table tracking
* reference counts.
*/
const path = require('path');
const et = require('elementtree');
const ConfigKeeper = require('./ConfigKeeper');
const events = require('../events');
const mungeutil = require('./munge-util');
const xml_helpers = require('../util/xml-helpers');
exports.process = (plugins_dir, project_dir, platform, platformJson, pluginInfoProvider) => {
const munger = new PlatformMunger(platform, project_dir, platformJson, pluginInfoProvider);
munger.process(plugins_dir);
munger.save_all();
};
/******************************************************************************
* PlatformMunger class
*
* Can deal with config file of a single project.
* Parsed config files are cached in a ConfigKeeper object.
******************************************************************************/
class PlatformMunger {
constructor (platform, project_dir, platformJson, pluginInfoProvider) {
this.platform = platform;
this.project_dir = project_dir;
this.config_keeper = new ConfigKeeper(project_dir);
this.platformJson = platformJson;
this.pluginInfoProvider = pluginInfoProvider;
}
// Write out all unsaved files.
save_all () {
this.config_keeper.save_all();
this.platformJson.save();
}
// Apply a munge object to a single config file.
// The remove parameter tells whether to add the change or remove it.
apply_file_munge (file, munge, remove) {
for (const selector in munge.parents) {
for (const mungeElem of munge.parents[selector]) {
// this xml child is new, graft it (only if config file exists)
const config_file = this.config_keeper.get(this.project_dir, this.platform, file);
if (config_file.exists) {
const operation = remove ? 'prune_child' : 'graft_child';
config_file[operation](selector, mungeElem);
} else {
events.emit('warn', `config file ${file} requested for changes not found at ${config_file.filepath}, ignoring`);
}
}
}
}
remove_plugin_changes (pluginInfo, is_top_level) {
const platform_config = this.platformJson.root;
const plugin_vars = is_top_level
? platform_config.installed_plugins[pluginInfo.id]
: platform_config.dependent_plugins[pluginInfo.id];
const edit_config_changes = this._getChanges(pluginInfo, 'EditConfig');
// get config munge, aka how did this plugin change various config files
const config_munge = this.generate_plugin_config_munge(pluginInfo, plugin_vars, edit_config_changes);
this._munge_helper(config_munge, { remove: true });
// Remove from installed_plugins
this.platformJson.removePlugin(pluginInfo.id, is_top_level);
return this;
}
add_plugin_changes (pluginInfo, plugin_vars, is_top_level, should_increment, plugin_force) {
const edit_config_changes = this._getChanges(pluginInfo, 'EditConfig');
const { configConflicts, pluginConflicts } = this._is_conflicting(edit_config_changes);
if (Object.keys(configConflicts.files).length > 0) {
// plugin.xml cannot overwrite config.xml changes even if --force is used
throw new Error(`${pluginInfo.id} cannot be added. <edit-config> changes in this plugin conflicts with <edit-config> changes in config.xml. Conflicts must be resolved before plugin can be added.`);
}
if (plugin_force) {
events.emit('warn', '--force is used. edit-config will overwrite conflicts if any. Conflicting plugins may not work as expected.');
// remove conflicting munges, if any
this._munge_helper(pluginConflicts, { remove: true });
} else if (Object.keys(pluginConflicts.files).length > 0) {
// plugin cannot overwrite other plugin changes without --force
const witness = Object.values(Object.values(pluginConflicts.files)[0].parents)[0][0];
const conflictingPlugin = witness.plugin;
throw new Error(`There was a conflict trying to modify attributes with <edit-config> in plugin ${pluginInfo.id}. The conflicting plugin, ${conflictingPlugin}, already modified the same attributes. The conflict must be resolved before ${pluginInfo.id} can be added. You may use --force to add the plugin and overwrite the conflicting attributes.`);
}
// get config munge, aka how should this plugin change various config files
const config_munge = this.generate_plugin_config_munge(pluginInfo, plugin_vars, edit_config_changes);
this._munge_helper(config_munge, { should_increment });
// Move to installed/dependent_plugins
this.platformJson.addPlugin(pluginInfo.id, plugin_vars || {}, is_top_level);
return this;
}
// Handle edit-config changes from config.xml
add_config_changes (config, should_increment) {
const changes = [
...this._getChanges(config, 'EditConfig'),
...this._getChanges(config, 'ConfigFile')
];
const { configConflicts, pluginConflicts } = this._is_conflicting(changes);
if (Object.keys(pluginConflicts.files).length !== 0) {
events.emit('warn', 'Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes');
}
// remove conflicting config.xml & plugin.xml munges, if any
for (const conflict_munge of [configConflicts, pluginConflicts]) {
this._munge_helper(conflict_munge, { remove: true });
}
// Add config.xml edit-config and config-file munges
const config_munge = this.generate_config_xml_munge(config, changes, 'config.xml');
this._munge_helper(config_munge, { should_increment });
// Move to installed/dependent_plugins
return this;
}
/** @private */
_munge_helper (config_munge, { should_increment = true, remove = false } = {}) {
// global munge looks at all changes to config files
// TODO: The should_increment param is only used by cordova-cli and is going away soon.
// If should_increment is set to false, avoid modifying the global_munge (use clone)
// and apply the entire config_munge because it's already a proper subset of the global_munge.
const platform_config = this.platformJson.root;
const global_munge = platform_config.config_munge;
const method = remove ? 'decrement_munge' : 'increment_munge';
const munge = should_increment
? mungeutil[method](global_munge, config_munge)
: config_munge;
for (const file in munge.files) {
this.apply_file_munge(file, munge.files[file], remove);
}
return this;
}
// Load the global munge from platform json and apply all of it.
// Used by cordova prepare to re-generate some config file from platform
// defaults and the global munge.
reapply_global_munge () {
const platform_config = this.platformJson.root;
const global_munge = platform_config.config_munge;
for (const file in global_munge.files) {
this.apply_file_munge(file, global_munge.files[file]);
}
return this;
}
// Generate the munge object from config.xml
generate_config_xml_munge (config, config_changes, type) {
const originInfo = { id: type === 'config.xml' ? type : config.id };
return this._generateMunge(config_changes, originInfo);
}
// Generate the munge object from plugin.xml + vars
generate_plugin_config_munge (pluginInfo, vars, edit_config_changes) {
const changes = pluginInfo.getConfigFiles(this.platform);
if (edit_config_changes) {
Array.prototype.push.apply(changes, edit_config_changes);
}
const filteredChanges = changes.filter(({ mode }) => mode !== 'remove');
const originInfo = { plugin: pluginInfo.id };
return this._generateMunge(filteredChanges, originInfo, vars || {});
}
/** @private */
_generateMunge (changes, originInfo, vars = {}) {
const munge = { files: {} };
changes.forEach(change => {
const [file, selector, rest] = change.mode
? [change.file, change.target, { mode: change.mode, ...originInfo }]
: [change.target, change.parent, { after: change.after }];
change.xmls.forEach(xml => {
// 1. stringify each xml
let stringified = (new et.ElementTree(xml)).write({ xml_declaration: false });
// interpolate vars, if any
Object.keys(vars).forEach(key => {
const regExp = new RegExp(`\\$${key}`, 'g');
stringified = stringified.replace(regExp, vars[key]);
});
// 2. add into munge
mungeutil.deep_add(munge, file, selector, { xml: stringified, count: 1, ...rest });
});
});
return munge;
}
/** @private */
_getChanges (cfg, changeType) {
const method = `get${changeType}s`;
return (cfg[method] && cfg[method](this.platform)) || [];
}
/** @private */
_is_conflicting (editchanges) {
const platform_config = this.platformJson.root;
const { files } = platform_config.config_munge;
const configConflicts = { files: {} }; // config.xml edit-config conflicts
const pluginConflicts = { files: {} }; // plugin.xml edit-config conflicts
const registerConflict = (file, selector) => {
const witness = files[file].parents[selector][0];
const conflictMunge = witness.id === 'config.xml' ? configConflicts : pluginConflicts;
mungeutil.deep_add(conflictMunge, file, selector, witness);
};
editchanges.forEach(({ file, target }) => {
if (!files[file]) return;
const { parents: changesBySelector } = files[file];
const conflicts = changesBySelector[target] || [];
if (conflicts.length > 0) return registerConflict(file, target);
const targetFile = this.config_keeper.get(this.project_dir, this.platform, file);
// For non-XML files (e.g. plist), the selector in editchange.target uniquely identifies its target.
// Thus we already know that we have no conflict if we are not dealing with an XML file here.
if (targetFile.type !== 'xml') return;
// For XML files, the selector does NOT uniquely identify its target. So we resolve editchange.target
// and any existing selectors to their matched elements and compare those for equality.
const resolveEditTarget = xml_helpers.resolveParent(targetFile.data, target);
if (!resolveEditTarget) return;
const selector = Object.keys(changesBySelector).find(parent =>
resolveEditTarget === xml_helpers.resolveParent(targetFile.data, parent)
);
if (selector) return registerConflict(file, selector);
});
return {
configConflicts,
pluginConflicts
};
}
// Go over the prepare queue and apply the config munges for each plugin
// that has been (un)installed.
process (plugins_dir) {
const platform_config = this.platformJson.root;
// Uninstallation first
platform_config.prepare_queue.uninstalled.forEach(u => {
const pluginInfo = this.pluginInfoProvider.get(path.join(plugins_dir, u.plugin));
this.remove_plugin_changes(pluginInfo, u.topLevel);
});
// Now handle installation
platform_config.prepare_queue.installed.forEach(u => {
const pluginInfo = this.pluginInfoProvider.get(path.join(plugins_dir, u.plugin));
this.add_plugin_changes(pluginInfo, u.vars, u.topLevel, true, u.force);
});
// Empty out installed/ uninstalled queues.
platform_config.prepare_queue.uninstalled = [];
platform_config.prepare_queue.installed = [];
}
}
exports.PlatformMunger = PlatformMunger;

View File

@@ -0,0 +1,256 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
const fs = require('fs-extra');
const path = require('path');
const readChunk = require('read-chunk');
// Use delay loading to ensure plist and other node modules to not get loaded
// on Android, Windows platforms
const modules = {
get bplist () { return require('bplist-parser'); },
get et () { return require('elementtree'); },
get glob () { return require('glob'); },
get plist () { return require('plist'); },
get plist_helpers () { return require('../util/plist-helpers'); },
get xml_helpers () { return require('../util/xml-helpers'); }
};
/******************************************************************************
* ConfigFile class
*
* Can load and keep various types of config files. Provides some functionality
* specific to some file types such as grafting XML children. In most cases it
* should be instantiated by ConfigKeeper.
*
* For plugin.xml files use as:
* plugin_config = this.config_keeper.get(plugin_dir, '', 'plugin.xml');
*
* TODO: Consider moving it out to a separate file and maybe partially with
* overrides in platform handlers.
******************************************************************************/
class ConfigFile {
constructor (project_dir, platform, file_tag) {
this.project_dir = project_dir;
this.platform = platform;
this.file_tag = file_tag;
this.is_changed = false;
this.load();
}
load () {
// config file may be in a place not exactly specified in the target
const filepath = this.filepath = resolveConfigFilePath(this.project_dir, this.platform, this.file_tag);
if (!filepath || !fs.existsSync(filepath)) {
this.exists = false;
return;
}
this.exists = true;
this.mtime = fs.statSync(this.filepath).mtime;
const ext = path.extname(filepath);
// Windows8 uses an appxmanifest, and wp8 will likely use
// the same in a future release
if (ext === '.xml' || ext === '.appxmanifest' || ext === '.storyboard' || ext === '.jsproj') {
this.type = 'xml';
this.data = modules.xml_helpers.parseElementtreeSync(filepath);
} else {
// plist file
this.type = 'plist';
// TODO: isBinaryPlist() reads the file and then parse re-reads it again.
// We always write out text plist, not binary.
// Do we still need to support binary plist?
// If yes, use plist.parseStringSync() and read the file once.
this.data = isBinaryPlist(filepath)
? modules.bplist.parseBuffer(fs.readFileSync(filepath))[0]
: modules.plist.parse(fs.readFileSync(filepath, 'utf8'));
}
}
save () {
if (this.type === 'xml') {
fs.writeFileSync(this.filepath, this.data.write({ indent: 4 }), 'utf-8');
} else {
// plist
const regExp = /<string>[ \t\r\n]+?<\/string>/g;
fs.writeFileSync(this.filepath, modules.plist.build(this.data, { indent: '\t', offset: -1 }).replace(regExp, '<string></string>'));
}
this.is_changed = false;
}
graft_child (selector, xml_child) {
let result;
if (this.type === 'xml') {
const xml_to_graft = [modules.et.XML(xml_child.xml)];
switch (xml_child.mode) {
case 'merge':
result = modules.xml_helpers.graftXMLMerge(this.data, xml_to_graft, selector, xml_child);
break;
case 'overwrite':
result = modules.xml_helpers.graftXMLOverwrite(this.data, xml_to_graft, selector, xml_child);
break;
case 'remove':
result = modules.xml_helpers.pruneXMLRemove(this.data, selector, xml_to_graft);
break;
default:
result = modules.xml_helpers.graftXML(this.data, xml_to_graft, selector, xml_child.after);
}
if (!result) {
throw new Error(`Unable to graft xml at selector "${selector}" from "${this.filepath}" during config install`);
}
} else {
// plist file
result = modules.plist_helpers.graftPLIST(this.data, xml_child.xml, selector);
if (!result) {
throw new Error(`Unable to graft plist "${this.filepath}" during config install`);
}
}
this.is_changed = true;
}
prune_child (selector, xml_child) {
let result;
if (this.type === 'xml') {
const xml_to_graft = [modules.et.XML(xml_child.xml)];
switch (xml_child.mode) {
case 'merge':
case 'overwrite':
result = modules.xml_helpers.pruneXMLRestore(this.data, selector, xml_child);
break;
case 'remove':
result = modules.xml_helpers.pruneXMLRemove(this.data, selector, xml_to_graft);
break;
default:
result = modules.xml_helpers.pruneXML(this.data, xml_to_graft, selector);
}
} else {
// plist file
result = modules.plist_helpers.prunePLIST(this.data, xml_child.xml, selector);
}
if (!result) {
throw new Error(`Pruning at selector "${selector}" from "${this.filepath}" went bad.`);
}
this.is_changed = true;
}
}
// Some config-file target attributes are not qualified with a full leading directory, or contain wildcards.
// Resolve to a real path in this function.
// TODO: getIOSProjectname is slow because of glob, try to avoid calling it several times per project.
function resolveConfigFilePath (project_dir, platform, file) {
let filepath = path.join(project_dir, file);
let matches;
file = path.normalize(file);
if (file.includes('*')) {
// handle wildcards in targets using glob.
matches = modules.glob.sync(path.join(project_dir, '**', file))
.map(p => path.normalize(p));
if (matches.length) filepath = matches[0];
// [CB-5989] multiple Info.plist files may exist. default to $PROJECT_NAME-Info.plist
if (matches.length > 1 && file.includes('-Info.plist')) {
const projName = getIOSProjectname(project_dir);
const plistName = `${projName}-Info.plist`;
const plistPath = path.join(project_dir, projName, plistName);
if (matches.includes(plistPath)) return plistPath;
}
return filepath;
}
// XXX this checks for android studio projects
// only if none of the options above are satisfied does this get called
// TODO: Move this out of cordova-common and into the platforms somehow
if (platform === 'android' && !fs.existsSync(filepath)) {
let config_file;
if (file === 'AndroidManifest.xml') {
filepath = path.join(project_dir, 'app', 'src', 'main', 'AndroidManifest.xml');
} else if (file.endsWith('config.xml')) {
filepath = path.join(project_dir, 'app', 'src', 'main', 'res', 'xml', 'config.xml');
} else if (file.endsWith('strings.xml')) {
// Plugins really shouldn't mess with strings.xml, since it's able to be localized
filepath = path.join(project_dir, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
} else if (file.includes(path.join('res', 'values'))) {
config_file = path.basename(file);
filepath = path.join(project_dir, 'app', 'src', 'main', 'res', 'values', config_file);
} else if (file.includes(path.join('res', 'xml'))) {
// Catch-all for all other stored XML configuration in legacy plugins
config_file = path.basename(file);
filepath = path.join(project_dir, 'app', 'src', 'main', 'res', 'xml', config_file);
}
return filepath;
}
// special-case config.xml target that is just "config.xml" for other platforms. This should
// be resolved to the real location of the file.
// TODO: Move this out of cordova-common into platforms
if (file === 'config.xml') {
if (platform === 'ios' || platform === 'osx') {
filepath = path.join(
project_dir,
module.exports.getIOSProjectname(project_dir),
'config.xml'
);
} else {
matches = modules.glob.sync(path.join(project_dir, '**', 'config.xml'));
if (matches.length) filepath = matches[0];
}
return filepath;
}
// None of the special cases matched, returning project_dir/file.
return filepath;
}
// Find out the real name of an iOS or OSX project
// TODO: glob is slow, need a better way or caching, or avoid using more than once.
function getIOSProjectname (project_dir) {
const matches = modules.glob.sync('*.xcodeproj', { cwd: project_dir });
if (matches.length !== 1) {
const msg = matches.length === 0
? 'Does not appear to be an xcode project, no xcode project file'
: 'There are multiple *.xcodeproj dirs';
throw new Error(`${msg} in ${project_dir}`);
}
return path.basename(matches[0], '.xcodeproj');
}
// determine if a plist file is binary
// i.e. they start with the magic header "bplist"
function isBinaryPlist (filename) {
return readChunk.sync(filename, 0, 6).toString() === 'bplist';
}
module.exports = ConfigFile;
module.exports.isBinaryPlist = isBinaryPlist;
module.exports.getIOSProjectname = getIOSProjectname;
module.exports.resolveConfigFilePath = resolveConfigFilePath;

View File

@@ -0,0 +1,62 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
const path = require('path');
const ConfigFile = require('./ConfigFile');
/******************************************************************************
* ConfigKeeper class
*
* Used to load and store config files to avoid re-parsing and writing them out
* multiple times.
*
* The config files are referred to by a fake path constructed as
* project_dir/platform/file
* where file is the name used for the file in config munges.
******************************************************************************/
class ConfigKeeper {
constructor (project_dir, plugins_dir) {
this.project_dir = project_dir;
this.plugins_dir = plugins_dir;
this._cache = new Map();
}
get (project_dir, platform, file) {
// This fixes a bug with older plugins - when specifying config xml instead of res/xml/config.xml
// https://issues.apache.org/jira/browse/CB-6414
if (file === 'config.xml' && platform === 'android') {
file = 'res/xml/config.xml';
}
const fake_path = path.join(project_dir, platform, file);
if (!this._cache.has(fake_path)) {
// File was not cached, need to load.
const config_file = new ConfigFile(project_dir, platform, file);
this._cache.set(fake_path, config_file);
}
return this._cache.get(fake_path);
}
save_all () {
this._cache.forEach(config_file => {
if (config_file.is_changed) config_file.save();
});
}
}
module.exports = ConfigKeeper;

View File

@@ -0,0 +1,189 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
// @ts-check
/**
* @typedef {Object} MungeElement
* @property {String} xml
* @property {Number} count
* @property {import('elementtree').Attributes} [oldAttrib]
*
* @property {'merge' | 'overwrite' | 'remove'} [mode] edit-config only
*
* @property {String} [id] 'config.xml' or the id of the plugin from whose
* plugin.xml this was taken; edit-config only
* @property {String} [after] a ;-separated priority list of tags after which
* the insertion should be made. E.g. if we need to insert an element C, and the
* order of children has to be As, Bs, Cs then `after` will be equal to "C;B;A".
* config-file only
*/
/**
* @typedef {Object} FileMunge
* @property {Object.<string, MungeElement[]>} parents
*/
/**
* @typedef {Object} Munge
* @property {Object.<string, FileMunge>} files
*/
/**
* Adds element.count to obj[file][selector][element]
*
* @return {Boolean} true iff it didn't exist before
*/
exports.deep_add = (...args) => {
const { element, siblings } = processArgs(...args, { create: true });
const matchingSibling = siblings.find(sibling => sibling.xml === element.xml);
if (matchingSibling) {
matchingSibling.after = matchingSibling.after || element.after;
matchingSibling.count += element.count;
} else {
siblings.push(element);
}
return !matchingSibling;
};
/**
* Subtracts element.count from obj[file][selector][element]
*
* @return {Boolean} true iff element was removed or not found
*/
exports.deep_remove = (...args) => {
const { element, siblings } = processArgs(...args);
const index = siblings.findIndex(sibling => sibling.xml === element.xml);
if (index < 0) return true;
const matchingSibling = siblings[index];
if (matchingSibling.oldAttrib) {
element.oldAttrib = Object.assign({}, matchingSibling.oldAttrib);
}
matchingSibling.count -= element.count;
if (matchingSibling.count > 0) return false;
siblings.splice(index, 1);
return true;
};
/**
* Find element with given key in obj
*
* @return {MungeElement} the sought-after object or undefined if not found
*/
exports.deep_find = (...args) => {
const { element, siblings } = processArgs(...args);
const elementXml = (element.xml || element);
return siblings.find(sibling => sibling.xml === elementXml);
};
function processArgs (obj, fileName, selector, element, opts) {
if (Array.isArray(fileName)) {
opts = selector;
[fileName, selector, element] = fileName;
}
const siblings = getElements(obj, [fileName, selector], opts);
return { element, siblings };
}
/**
* Get the element array for given keys
*
* If a key entry is missing, create it if opts.create is true else return []
*
* @param {Munge} obj
* @param {String[]} keys [fileName, selector]
* @param {{create: Boolean}} [opts]
* @return {MungeElement[]}
*/
function getElements ({ files }, [fileName, selector], opts = { create: false }) {
if (!files[fileName] && !opts.create) return [];
const { parents: fileChanges } = (files[fileName] = files[fileName] || { parents: {} });
if (!fileChanges[selector] && !opts.create) return [];
return (fileChanges[selector] = fileChanges[selector] || []);
}
/**
* All values from munge are added to base as
* base[file][selector][child] += munge[file][selector][child]
*
* @param {Munge} base
* @param {Munge} munge
* @return {Munge} A munge object containing values that exist in munge but not
* in base.
*/
exports.increment_munge = (base, munge) => {
return mungeItems(base, munge, exports.deep_add);
};
/**
* Update the base munge object as
* base[file][selector][child] -= munge[file][selector][child]
*
* @param {Munge} base
* @param {Munge} munge
* @return {Munge} nodes that reached zero value are removed from base and added
* to the returned munge object
*/
exports.decrement_munge = (base, munge) => {
return mungeItems(base, munge, exports.deep_remove);
};
/**
* For every key [file, selector, element] in munge run mungeOperation on base.
*
* @param {Munge} base
* @param {Munge} munge
* @param {typeof exports.deep_add} mungeOperation - TODO how can I constrain
* that to an enum of functions
* @return {Munge} - the union of all changes for which mungeOperation returned
* true
*/
function mungeItems (base, { files }, mungeOperation) {
const diff = { files: {} };
for (const file in files) {
for (const selector in files[file].parents) {
for (const element of files[file].parents[selector]) {
// if node not in base, add it to diff and base
// else increment it's value in base without adding to diff
const hasChanges = mungeOperation(base, [file, selector, element]);
if (hasChanges) exports.deep_add(diff, [file, selector, element]);
}
}
}
return diff;
}
/**
* Clones given munge
*
* @param {Munge} munge
* @return {Munge} clone of munge
*/
exports.clone_munge = munge => exports.increment_munge({ files: {} }, munge);

View File

@@ -0,0 +1,637 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const et = require('elementtree');
const { parseElementtreeSync } = require('../util/xml-helpers');
const CordovaError = require('../CordovaError');
const fs = require('fs-extra');
const events = require('../events');
const CDV_XMLNS_URI = 'http://cordova.apache.org/ns/1.0';
/** Wraps a config.xml file */
class ConfigParser {
constructor (path) {
this.path = path;
try {
this.doc = parseElementtreeSync(path);
this.cdvNamespacePrefix = getCordovaNamespacePrefix(this.doc);
et.register_namespace(this.cdvNamespacePrefix, CDV_XMLNS_URI);
} catch (e) {
events.emit('error', `Parsing ${path} failed`);
throw e;
}
const root = this.doc.getroot();
if (root.tag !== 'widget') {
throw new CordovaError(`${path} has incorrect root node name (expected "widget", was "${root.tag}")`);
}
}
getAttribute (attr) {
return this.doc.getroot().attrib[attr];
}
packageName () {
return this.getAttribute('id');
}
setPackageName (id) {
this.doc.getroot().attrib.id = id;
}
android_packageName () {
return this.getAttribute('android-packageName');
}
android_activityName () {
return this.getAttribute('android-activityName');
}
ios_CFBundleIdentifier () {
return this.getAttribute('ios-CFBundleIdentifier');
}
name () {
return getNodeTextSafe(this.doc.find('name'));
}
setName (name) {
findOrCreate(this.doc, 'name').text = name;
}
shortName () {
return this.doc.find('name').attrib.short || this.name();
}
setShortName (shortname) {
const el = findOrCreate(this.doc, 'name');
if (!el.text) el.text = shortname;
el.attrib.short = shortname;
}
description () {
return getNodeTextSafe(this.doc.find('description'));
}
setDescription (text) {
findOrCreate(this.doc, 'description').text = text;
}
version () {
return this.getAttribute('version');
}
windows_packageVersion () {
return this.getAttribute('windows-packageVersion');
}
android_versionCode () {
return this.getAttribute('android-versionCode');
}
ios_CFBundleVersion () {
return this.getAttribute('ios-CFBundleVersion');
}
setVersion (value) {
this.doc.getroot().attrib.version = value;
}
author () {
return getNodeTextSafe(this.doc.find('author'));
}
getGlobalPreference (name) {
return this._getPrefElem(name).attrib.value;
}
setGlobalPreference (name, value) {
this._getPrefElem(name, { create: true }).attrib.value = value;
}
getPlatformPreference (name, platform) {
return this._getPrefElem(name, { platform }).attrib.value;
}
setPlatformPreference (name, platform, value) {
this._getPrefElem(name, { platform, create: true }).attrib.value = value;
}
getPreference (name, platform) {
return (platform && this.getPlatformPreference(name, platform)) ||
this.getGlobalPreference(name);
}
setPreference (name, platform, value) {
if (!value) {
value = platform;
platform = undefined;
}
this._getPrefElem(name, { platform, create: true }).attrib.value = value;
}
/**
* Finds the element that determines the value of preference `name` within `parent`.
*
* @param {String} name preference name to search for (case insensitive)
* @param {{create?: boolean, platform?: string}} [opts]
* @return {et.Element} the last matching preference in `parent` (possibly created)
*/
_getPrefElem (name, { create = false, platform } = {}) {
const parent = platform
? this.doc.findall(`./platform[@name="${platform}"]`).pop()
: this.doc.getroot();
const makeElem = create ? et.SubElement.bind(null, parent) : et.Element;
const getFallBackElem = () => makeElem('preference', { name, value: '' });
if (!parent) {
if (create) {
throw new CordovaError(`platform does not exist (received platform: ${platform})`);
}
return getFallBackElem();
}
return parent.findall('preference')
.filter(elem => elem.attrib.name.toLowerCase() === name.toLowerCase())
.pop() || getFallBackElem();
}
/**
* Returns all resources for the platform specified.
*
* @param {string} platform The platform.
* @param {string} resourceName Type of static resources to return.
* "icon" and "splash" currently supported.
* @return {ImageResources} Resources for the platform specified.
*/
getStaticResources (platform, resourceName) {
const normalizedAttrs = ({ attrib }) => ({
density: attrib[`${this.cdvNamespacePrefix}:density`] ||
attrib['gap:density'],
...attrib
});
// platform specific icons
const platformResources = platform
? this.doc.findall(`./platform[@name="${platform}"]/${resourceName}`)
.map(elt => new ImageResource(normalizedAttrs(elt), { platform }))
: [];
// root level resources
const commonResources = this.doc.findall(resourceName)
.map(elt => new ImageResource(normalizedAttrs(elt)));
return ImageResources.create(...platformResources, ...commonResources);
}
/**
* Returns all icons for specific platform.
*
* @param {string} platform Platform name
* @return {ImageResources} Array of icon objects.
*/
getIcons (platform) {
return this.getStaticResources(platform, 'icon');
}
/**
* Returns all splash images for specific platform.
*
* @param {string} platform Platform name
* @return {ImageResources} Array of Splash objects.
*/
getSplashScreens (platform) {
return this.getStaticResources(platform, 'splash');
}
/**
* Returns all resource-files for a specific platform.
*
* @param {string} platform Platform name
* @param {boolean} includeGlobal Whether to return resource-files at the
* root level.
* @return {FileResource[]} Array of resource file objects.
*/
getFileResources (platform, includeGlobal) {
const platformResources = platform
? this.doc.findall(`./platform[@name="${platform}"]/resource-file`)
: [];
const globalResources = includeGlobal
? this.doc.findall('resource-file')
: [];
return [].concat(platformResources, globalResources)
.map(({ attrib }) => new FileResource(attrib, { platform }));
}
/**
* Returns all hook scripts for the hook type specified.
*
* @param {String} hook The hook type.
* @param {Array} platforms Platforms to look for scripts into (root scripts will be included as well).
* @return {Array} Script elements.
*/
getHookScripts (hook, platforms = []) {
return this.doc.findall('./hook')
.concat(...platforms.map(platform =>
this.doc.findall(`./platform[@name="${platform}"]/hook`)
))
.filter(({ attrib: { src, type } }) =>
src && type && type.toLowerCase() === hook
);
}
/**
* Returns a list of plugin (IDs).
*
* This function also returns any plugin's that
* were defined using the legacy <feature> tags.
*
* @return {string[]} Array of plugin IDs
*/
getPluginIdList () {
const plugins = this.doc.findall('plugin');
const result = plugins.map(plugin => plugin.attrib.name);
const features = this.doc.findall('feature');
features.forEach(element => {
const idTag = element.find('./param[@name="id"]');
if (idTag) result.push(idTag.attrib.value);
});
return result;
}
getPlugins () {
return this.getPluginIdList().map(pluginId => this.getPlugin(pluginId));
}
/**
* Adds a plugin element. Does not check for duplicates.
*
* @param {object} attributes name and spec are supported
* @param {Array|object} variables name, value or arbitary object
*/
addPlugin (attributes, variables) {
if (!attributes && !attributes.name) return;
// support arbitrary object as variables source
variables = variables || [];
if (typeof variables === 'object' && !Array.isArray(variables)) {
variables = Object.entries(variables)
.map(([name, value]) => ({ name, value }));
}
const el = et.SubElement(this.doc.getroot(), 'plugin', attributes);
variables.forEach(({ name, value }) => {
et.SubElement(el, 'variable', { name, value });
});
}
/**
* Retrives the plugin with the given id or null if not found.
*
* This function also returns any plugin's that
* were defined using the legacy <feature> tags.
*
* @param {String} id
* @returns {object} plugin including any variables
*/
getPlugin (id) {
if (!id) return undefined;
const pluginElement = this.doc.find(`./plugin/[@name="${id}"]`);
if (pluginElement === null) {
const legacyFeature = this.doc.find(`./feature/param[@name="id"][@value="${id}"]/..`);
if (legacyFeature) {
events.emit('log', `Found deprecated feature entry for ${id} in config.xml.`);
return featureToPlugin(legacyFeature);
}
return undefined;
}
const { name, spec, src, version } = pluginElement.attrib;
const varFragments = pluginElement.findall('variable')
.map(({ attrib: { name, value } }) =>
name ? { [name]: value } : null
);
const variables = Object.assign({}, ...varFragments);
return { name, spec: spec || src || version, variables };
}
/**
* Remove the plugin entry with give name (id).
*
* This function also operates on any plugin's that
* were defined using the legacy <feature> tags.
*
* @param {string} id name of the plugin
*/
removePlugin (id) {
if (!id) return;
const root = this.doc.getroot();
removeChildren(root, `./plugin/[@name="${id}"]`);
removeChildren(root, `./feature/param[@name="id"][@value="${id}"]/..`);
}
// Add any element to the root
addElement (name, attributes) {
et.SubElement(this.doc.getroot(), name, attributes);
}
/**
* Adds an engine. Does not check for duplicates.
*
* @param {String} name the engine name
* @param {String} [spec] engine source location or version
*/
addEngine (name, spec) {
if (!name) return;
const attrs = Object.assign({ name }, spec ? { spec } : null);
et.SubElement(this.doc.getroot(), 'engine', attrs);
}
/**
* Removes all the engines with given name
*
* @param {String} name the engine name.
*/
removeEngine (name) {
removeChildren(this.doc.getroot(), `./engine/[@name="${name}"]`);
}
getEngines () {
return this.doc.findall('./engine').map(engine => ({
name: engine.attrib.name,
spec: engine.attrib.spec || engine.attrib.version || null
}));
}
/**
* @typedef {Object} CommonRuleOptions
* @prop {string} [minimum_tls_version]
* @prop {StringifiedBool} [requires_forward_secrecy]
* @prop {StringifiedBool} [requires_certificate_transparency]
*
* @typedef {string} StringifiedBool has either the value 'true' or 'false'
*/
/**
* Get all the access tags
*
* @returns {AccessRule[]}
*
* @typedef {CommonRuleOptions} AccessRule
* @prop {string} origin
* @prop {StringifiedBool} [allows_arbitrary_loads_in_web_content]
* @prop {StringifiedBool} [allows_arbitrary_loads_in_media] (DEPRECATED)
* @prop {StringifiedBool} [allows_arbitrary_loads_for_media]
* @prop {StringifiedBool} [allows_local_networking]
*/
getAccesses () {
return this.doc.findall('./access').map(element => ({
origin: element.attrib.origin,
minimum_tls_version: element.get('minimum-tls-version'),
requires_forward_secrecy: element.get('requires-forward-secrecy'),
requires_certificate_transparency: element.get('requires-certificate-transparency'),
allows_arbitrary_loads_in_web_content: element.get('allows-arbitrary-loads-in-web-content'),
allows_arbitrary_loads_in_media: element.get('allows-arbitrary-loads-in-media'),
allows_arbitrary_loads_for_media: element.get('allows-arbitrary-loads-for-media'),
allows_local_networking: element.get('allows-local-networking')
}));
}
/**
* Get all the allow-navigation tags
*
* @returns {AllowNavigationRule[]}
* @typedef {{href: string} & CommonRuleOptions} AllowNavigationRule
*/
getAllowNavigations () {
return this.doc.findall('./allow-navigation').map(element => ({
href: element.attrib.href,
minimum_tls_version: element.get('minimum-tls-version'),
requires_forward_secrecy: element.get('requires-forward-secrecy'),
requires_certificate_transparency: element.get('requires-certificate-transparency')
}));
}
/**
* Get all the allow-intent tags
*
* @returns {{href: string}[]}
*/
getAllowIntents () {
return this.doc.findall('./allow-intent').map(element => ({
href: element.attrib.href
}));
}
/** Get all edit-config tags */
getEditConfigs (platform) {
const platform_edit_configs = this.doc.findall(`./platform[@name="${platform}"]/edit-config`);
const edit_configs = this.doc.findall('edit-config').concat(platform_edit_configs);
return edit_configs.map(tag => ({
file: tag.attrib.file,
target: tag.attrib.target,
mode: tag.attrib.mode,
id: 'config.xml',
xmls: tag.getchildren()
}));
}
/** Get all config-file tags */
getConfigFiles (platform) {
const platform_config_files = this.doc.findall(`./platform[@name="${platform}"]/config-file`);
const config_files = this.doc.findall('config-file').concat(platform_config_files);
return config_files.map(tag => ({
target: tag.attrib.target,
parent: tag.attrib.parent,
after: tag.attrib.after,
xmls: tag.getchildren(),
// To support demuxing via versions
versions: tag.attrib.versions,
deviceTarget: tag.attrib['device-target']
}));
}
write () {
fs.writeFileSync(this.path, this.doc.write({ indent: 4 }), 'utf-8');
}
}
function getNodeTextSafe (el) {
return el && el.text && el.text.trim();
}
function findOrCreate (doc, name) {
const parent = doc.getroot();
return parent.find(name) || new et.SubElement(parent, name);
}
function getCordovaNamespacePrefix (doc) {
const attrs = doc.getroot().attrib;
const nsAttr = Object.keys(attrs).find(key =>
key.startsWith('xmlns:') && attrs[key] === CDV_XMLNS_URI
);
return nsAttr ? nsAttr.split(':')[1] : 'cdv';
}
// remove child from element for each match
function removeChildren (el, selector) {
el.findall(selector).forEach(child => el.remove(child));
}
function featureToPlugin (featureElement) {
const plugin = {};
plugin.variables = [];
let pluginVersion, pluginSrc;
const nodes = featureElement.findall('param');
nodes.forEach(element => {
const n = element.attrib.name;
const v = element.attrib.value;
if (n === 'id') {
plugin.name = v;
} else if (n === 'version') {
pluginVersion = v;
} else if (n === 'url' || n === 'installPath') {
pluginSrc = v;
} else {
plugin.variables[n] = v;
}
});
const spec = pluginSrc || pluginVersion;
if (spec) {
plugin.spec = spec;
}
return plugin;
}
/**
* The attribute target is only used for the Windows & Electron platforms
*/
class BaseResource {
constructor (attrs, { platform = null } = {}) {
// null means resource is shared between platforms
this.platform = platform || null;
this.src = attrs.src;
this.target = attrs.target || undefined;
}
}
/**
* The attributes density, background, and foreground are only used for the
* Android platform
*/
class ImageResource extends BaseResource {
constructor (attrs, opts) {
super(attrs, opts);
this.density = attrs.density;
this.width = Number(attrs.width) || undefined;
this.height = Number(attrs.height) || undefined;
this.background = attrs.background || undefined;
this.foreground = attrs.foreground || undefined;
this.monochrome = attrs.monochrome || undefined;
}
}
class FileResource extends BaseResource {
constructor (attrs, opts) {
super(attrs, opts);
this.versions = attrs.versions;
this.deviceTarget = attrs['device-target'];
this.arch = attrs.arch;
}
}
class ImageResources extends Array {
/**
* Creates an ImageResources instance with defaultResource property.
*
* It is easy to break native Array methods like `map` when carelessly
* overriding the array constructor, so it's safer to use this factory
* function for our needs instead.
*
* @param {...ImageResource} args - The entries of this array
* @return {ImageResources} An ImageResources instance with args as entries
*/
static create (...args) {
const defaultResource = args.filter(res =>
!res.width && !res.height && !res.density
).pop();
return Object.assign(new ImageResources(...args), { defaultResource });
}
/**
* Returns resource with specified width and/or height.
* @param {number} width Width of resource.
* @param {number} height Height of resource.
* @return {ImageResource} Resource object or null if not found.
*/
getBySize (width, height) {
return this.find(res =>
(res.width || res.height) &&
(!res.width || (width === res.width)) &&
(!res.height || (height === res.height))
) || null;
}
/**
* Returns resource with specified density.
*
* Only used by Android platform.
*
* @param {string} density Density of resource.
* @return {ImageResource} Resource object or null if not found.
*/
getByDensity (density) {
return this.find(res => res.density === density) || null;
}
/**
* Returns the default icon
* @return {ImageResource} Resource object or null if not found.
*/
getDefault () {
return this.defaultResource;
}
}
module.exports = ConfigParser;

79
spa/node_modules/cordova-common/src/CordovaCheck.js generated vendored Normal file
View File

@@ -0,0 +1,79 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const fs = require('fs-extra');
const path = require('path');
function isRootDir (dir) {
if (fs.existsSync(path.join(dir, 'www'))) {
if (fs.existsSync(path.join(dir, 'config.xml'))) {
// For sure is.
return fs.existsSync(path.join(dir, 'platforms')) ? 2 : 1;
}
// Might be (or may be under platforms/).
if (fs.existsSync(path.join(dir, 'www', 'config.xml'))) {
return 1;
}
}
return 0;
}
// Runs up the directory chain looking for a .cordova directory.
// IF it is found we are in a Cordova project.
// Omit argument to use CWD.
function isCordova (dir) {
if (!dir) {
// Prefer PWD over cwd so that symlinked dirs within your PWD work correctly (CB-5687).
const pwd = process.env.PWD;
const cwd = process.cwd();
const hasPwd = pwd && pwd !== cwd && pwd !== 'undefined';
return (hasPwd && isCordova(pwd)) || isCordova(cwd);
}
let bestReturnValueSoFar = false;
for (let i = 0; i < 1000; ++i) {
const result = isRootDir(dir);
if (result === 2) {
return dir;
}
if (result === 1) {
bestReturnValueSoFar = dir;
}
const parentDir = path.normalize(path.join(dir, '..'));
// Detect fs root.
if (parentDir === dir) {
return bestReturnValueSoFar;
}
dir = parentDir;
}
console.error('Hit an unhandled case in CordovaCheck.isCordova');
return false;
}
module.exports = {
findProjectRoot: isCordova
};

53
spa/node_modules/cordova-common/src/CordovaError.js generated vendored Normal file
View File

@@ -0,0 +1,53 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
// @ts-check
const { VError } = require('@netflix/nerror');
/**
* @public
* @typedef {Object} CordovaErrorOptions
* @param {String} [name] - Name of the error.
* @param {Error} [cause] - Indicates that the new error was caused by `cause`.
* @param {Object} [info] - Specifies arbitrary informational properties.
*/
/**
* A custom exception class derived from VError
*/
class CordovaError extends VError {
/**
* @param {String} message - Error message
* @param {Error|CordovaErrorOptions} [causeOrOpts] - The Error that caused
* this to be thrown or a CordovaErrorOptions object.
*/
constructor (message, causeOrOpts = {}) {
const defaults = { name: 'CordovaError' };
const overrides = { strict: false, skipPrintf: true };
const userOpts = causeOrOpts instanceof Error
? { cause: causeOrOpts }
: causeOrOpts;
const opts = Object.assign(defaults, userOpts, overrides);
super(opts, message);
}
}
module.exports = CordovaError;

228
spa/node_modules/cordova-common/src/CordovaLogger.js generated vendored Normal file
View File

@@ -0,0 +1,228 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const ansi = require('ansi');
const EventEmitter = require('events').EventEmitter;
const EOL = require('os').EOL;
const formatError = require('./util/formatError');
const INSTANCE_KEY = Symbol.for('org.apache.cordova.common.CordovaLogger');
/**
* @typedef {'verbose'|'normal'|'warn'|'info'|'error'|'results'} CordovaLoggerLevel
*/
/**
* Implements logging facility that anybody could use.
*
* Should not be instantiated directly! `CordovaLogger.get()` method should be
* used instead to acquire the logger instance.
*/
class CordovaLogger {
// Encapsulate the default logging level values with constants:
static get VERBOSE () { return 'verbose'; }
static get NORMAL () { return 'normal'; }
static get WARN () { return 'warn'; }
static get INFO () { return 'info'; }
static get ERROR () { return 'error'; }
static get RESULTS () { return 'results'; }
/**
* Static method to create new or acquire existing instance.
*
* @returns {CordovaLogger} Logger instance
*/
static get () {
// This singleton instance pattern is based on the ideas from
// https://derickbailey.com/2016/03/09/creating-a-true-singleton-in-node-js-with-es6-symbols/
if (Object.getOwnPropertySymbols(global).indexOf(INSTANCE_KEY) === -1) {
global[INSTANCE_KEY] = new CordovaLogger();
}
return global[INSTANCE_KEY];
}
constructor () {
/** @private */
this.levels = {};
/** @private */
this.colors = {};
/** @private */
this.stdout = process.stdout;
/** @private */
this.stderr = process.stderr;
/** @private */
this.stdoutCursor = ansi(this.stdout);
/** @private */
this.stderrCursor = ansi(this.stderr);
this.addLevel(CordovaLogger.VERBOSE, 1000, 'grey');
this.addLevel(CordovaLogger.NORMAL, 2000);
this.addLevel(CordovaLogger.WARN, 2000, 'yellow');
this.addLevel(CordovaLogger.INFO, 3000, 'blue');
this.addLevel(CordovaLogger.ERROR, 5000, 'red');
this.addLevel(CordovaLogger.RESULTS, 10000);
this.setLevel(CordovaLogger.NORMAL);
}
/**
* Emits log message to process' stdout/stderr depending on message's
* severity and current log level. If severity is less than current
* logger's level, then the message is ignored.
*
* @param {CordovaLoggerLevel} logLevel - The message's log level. The
* logger should have corresponding level added (via logger.addLevel),
* otherwise `CordovaLogger.NORMAL` level will be used.
*
* @param {string} message - The message, that should be logged to
* process's stdio.
*
* @returns {CordovaLogger} Return the current instance, to allow chaining.
*/
log (logLevel, message) {
// if there is no such logLevel defined, or provided level has
// less severity than active level, then just ignore this call and return
if (!this.levels[logLevel] || this.levels[logLevel] < this.levels[this.logLevel]) {
// return instance to allow to chain calls
return this;
}
const isVerbose = this.logLevel === CordovaLogger.VERBOSE;
let cursor = this.stdoutCursor;
if (message instanceof Error || logLevel === CordovaLogger.ERROR) {
message = formatError(message, isVerbose);
cursor = this.stderrCursor;
}
const color = this.colors[logLevel];
if (color) {
cursor.bold().fg[color]();
}
cursor.write(message).reset().write(EOL);
return this;
}
/**
* Adds a new level to logger instance.
*
* This method also creates a shortcut method to log events with the level
* provided.
* (i.e. after adding new level 'debug', the method `logger.debug(message)`
* will exist, equal to `logger.log('debug', message)`)
*
* @param {CordovaLoggerLevel} level - A log level name. The levels with
* the following names are added by default to every instance: 'verbose',
* 'normal', 'warn', 'info', 'error', 'results'.
*
* @param {number} severity - A number that represents level's severity.
*
* @param {string} color - A valid color name, that will be used to log
* messages with this level. Any CSS color code or RGB value is allowed
* (according to ansi documentation:
* https://github.com/TooTallNate/ansi.js#features).
*
* @returns {CordovaLogger} Return the current instance, to allow chaining.
*/
addLevel (level, severity, color) {
this.levels[level] = severity;
if (color) {
this.colors[level] = color;
}
// Define own method with corresponding name
if (!this[level]) {
Object.defineProperty(this, level, {
get () { return this.log.bind(this, level); }
});
}
return this;
}
/**
* Sets the current logger level to provided value.
*
* If logger doesn't have level with this name, `CordovaLogger.NORMAL` will
* be used.
*
* @param {CordovaLoggerLevel} logLevel - Level name. The level with this
* name should be added to logger before.
*
* @returns {CordovaLogger} Current instance, to allow chaining.
*/
setLevel (logLevel) {
this.logLevel = this.levels[logLevel] ? logLevel : CordovaLogger.NORMAL;
return this;
}
/**
* Adjusts the current logger level according to the passed options.
*
* @param {Object|Array<string>} opts - An object or args array with
* options.
*
* @returns {CordovaLogger} Current instance, to allow chaining.
*/
adjustLevel (opts) {
if (opts.verbose || (Array.isArray(opts) && opts.includes('--verbose'))) {
this.setLevel('verbose');
} else if (opts.silent || (Array.isArray(opts) && opts.includes('--silent'))) {
this.setLevel('error');
}
return this;
}
/**
* Attaches logger to EventEmitter instance provided.
*
* @param {EventEmitter} eventEmitter - An EventEmitter instance to attach
* the logger to.
*
* @returns {CordovaLogger} Current instance, to allow chaining.
*/
subscribe (eventEmitter) {
if (!(eventEmitter instanceof EventEmitter)) {
throw new Error('Subscribe method only accepts an EventEmitter instance as argument');
}
eventEmitter.on('verbose', this.verbose)
.on('log', this.normal)
.on('info', this.info)
.on('warn', this.warn)
.on('warning', this.warn)
// Set up event handlers for logging and results emitted as events.
.on('results', this.results);
return this;
}
}
module.exports = CordovaLogger;

347
spa/node_modules/cordova-common/src/FileUpdater.js generated vendored Normal file
View File

@@ -0,0 +1,347 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
'use strict';
const fs = require('fs-extra');
const path = require('path');
const fastGlob = require('fast-glob');
/**
* Logging callback used in the FileUpdater methods.
* @callback loggingCallback
* @param {string} message A message describing a single file update operation.
*/
/**
* Updates a target file or directory with a source file or directory. (Directory updates are
* not recursive.) Stats for target and source items must be passed in. This is an internal
* helper function used by other methods in this module.
*
* @param {?string} sourcePath Source file or directory to be used to update the
* destination. If the source is null, then the destination is deleted if it exists.
* @param {?fs.Stats} sourceStats An instance of fs.Stats for the source path, or null if
* the source does not exist.
* @param {string} targetPath Required destination file or directory to be updated. If it does
* not exist, it will be created.
* @param {?fs.Stats} targetStats An instance of fs.Stats for the target path, or null if
* the target does not exist.
* @param {Object} [options] Optional additional parameters for the update.
* @param {string} [options.rootDir] Optional root directory (such as a project) to which target
* and source path parameters are relative; may be omitted if the paths are absolute. The
* rootDir is always omitted from any logged paths, to make the logs easier to read.
* @param {boolean} [options.all] If true, all files are copied regardless of last-modified times.
* Otherwise, a file is copied if the source's last-modified time is greather than or
* equal to the target's last-modified time, or if the file sizes are different.
* @param {loggingCallback} [log] Optional logging callback that takes a string message
* describing any file operations that are performed.
* @return {boolean} true if any changes were made, or false if the force flag is not set
* and everything was up to date
*/
function updatePathWithStats (sourcePath, sourceStats, targetPath, targetStats, options, log = () => {}) {
const rootDir = (options && options.rootDir) || '';
const copyAll = (options && options.all) || false;
const targetFullPath = path.join(rootDir, targetPath);
// Source or target could be a device, socket or pipe. We just skip these.
const isSpecial = stats => stats && !stats.isFile() && !stats.isDirectory();
if (isSpecial(targetStats) || isSpecial(sourceStats)) return false;
if (!sourceStats) {
if (!targetStats) return false;
// The target exists but the source not, so we delete the target.
log(`delete ${targetPath} (no source)`);
fs.removeSync(targetFullPath);
return true;
}
if (targetStats && (targetStats.isDirectory() !== sourceStats.isDirectory())) {
// The target exists but the directory status doesn't match the source.
// So we delete it and let it be created again by the code below.
log(`delete ${targetPath} (wrong type)`);
fs.removeSync(targetFullPath);
targetStats = null;
}
if (sourceStats.isDirectory() && !targetStats) {
// The target directory does not exist, so we create it.
log(`mkdir ${targetPath}`);
fs.ensureDirSync(targetFullPath);
return true;
}
if (sourceStats.isFile()) {
// The source is a file and the target either is one too or missing.
// If the caller did not specify that all files should be copied, check
// if the source has been modified since it was copied to the target, or
// if the file sizes are different. (The latter catches most cases in
// which something was done to the file after copying.) Comparison is >=
// rather than > to allow for timestamps lacking sub-second precision in
// some filesystems.
const needsUpdate = !targetStats || copyAll ||
sourceStats.size !== targetStats.size ||
sourceStats.mtime.getTime() >= targetStats.mtime.getTime();
if (!needsUpdate) return false;
const type = targetStats ? 'updated' : 'new';
log(`copy ${sourcePath} ${targetPath} (${type} file)`);
fs.copySync(path.join(rootDir, sourcePath), targetFullPath);
return true;
}
return false;
}
/**
* Helper for updatePath and updatePaths functions. Queries stats for source and target
*/
function updatePathInternal (sourcePath, targetPath, options, log) {
const rootDir = (options && options.rootDir) || '';
const targetFullPath = path.join(rootDir, targetPath);
const targetStats = fs.existsSync(targetFullPath) ? fs.statSync(targetFullPath) : null;
let sourceStats = null;
if (sourcePath) {
// A non-null source path was specified. It should exist.
const sourceFullPath = path.join(rootDir, sourcePath);
if (!fs.existsSync(sourceFullPath)) {
throw new Error(`Source path does not exist: ${sourcePath}`);
}
sourceStats = fs.statSync(sourceFullPath);
}
return updatePathWithStats(sourcePath, sourceStats, targetPath, targetStats, options, log);
}
/**
* Updates a target file or directory with a source file or directory. (Directory updates are
* not recursive.)
*
* @param {?string} sourcePath Source file or directory to be used to update the
* destination. If the source is null, then the destination is deleted if it exists.
* @param {string} targetPath Required destination file or directory to be updated. If it does
* not exist, it will be created.
* @param {Object} [options] Optional additional parameters for the update.
* @param {string} [options.rootDir] Optional root directory (such as a project) to which target
* and source path parameters are relative; may be omitted if the paths are absolute. The
* rootDir is always omitted from any logged paths, to make the logs easier to read.
* @param {boolean} [options.all] If true, all files are copied regardless of last-modified times.
* Otherwise, a file is copied if the source's last-modified time is greather than or
* equal to the target's last-modified time, or if the file sizes are different.
* @param {loggingCallback} [log] Optional logging callback that takes a string message
* describing any file operations that are performed.
* @return {boolean} true if any changes were made, or false if the force flag is not set
* and everything was up to date
*/
function updatePath (sourcePath, targetPath, options, log) {
if (sourcePath !== null && typeof sourcePath !== 'string') {
throw new Error('A source path (or null) is required.');
}
if (!targetPath || typeof targetPath !== 'string') {
throw new Error('A target path is required.');
}
return updatePathInternal(sourcePath, targetPath, options, log);
}
/**
* Updates files and directories based on a mapping from target paths to source paths. Targets
* with null sources in the map are deleted.
*
* @param {Object} pathMap A dictionary mapping from target paths to source paths.
* @param {Object} [options] Optional additional parameters for the update.
* @param {string} [options.rootDir] Optional root directory (such as a project) to which target
* and source path parameters are relative; may be omitted if the paths are absolute. The
* rootDir is always omitted from any logged paths, to make the logs easier to read.
* @param {boolean} [options.all] If true, all files are copied regardless of last-modified times.
* Otherwise, a file is copied if the source's last-modified time is greather than or
* equal to the target's last-modified time, or if the file sizes are different.
* @param {loggingCallback} [log] Optional logging callback that takes a string message
* describing any file operations that are performed.
* @return {boolean} true if any changes were made, or false if the force flag is not set
* and everything was up to date
*/
function updatePaths (pathMap, options, log) {
if (!pathMap || typeof pathMap !== 'object' || Array.isArray(pathMap)) {
throw new Error('An object mapping from target paths to source paths is required.');
}
// Iterate in sorted order for nicer logs
return Object.keys(pathMap).sort().map(targetPath => {
const sourcePath = pathMap[targetPath];
return updatePathInternal(sourcePath, targetPath, options, log);
}).some(updated => updated);
}
/**
* Updates a target directory with merged files and subdirectories from source directories.
*
* @param {string|string[]} sourceDirs Required source directory or array of source directories
* to be merged into the target. The directories are listed in order of precedence; files in
* directories later in the array supersede files in directories earlier in the array
* (regardless of timestamps).
* @param {string} targetDir Required destination directory to be updated. If it does not exist,
* it will be created. If it exists, newer files from source directories will be copied over,
* and files missing in the source directories will be deleted.
* @param {Object} [options] Optional additional parameters for the update.
* @param {string} [options.rootDir] Optional root directory (such as a project) to which target
* and source path parameters are relative; may be omitted if the paths are absolute. The
* rootDir is always omitted from any logged paths, to make the logs easier to read.
* @param {boolean} [options.all] If true, all files are copied regardless of last-modified times.
* Otherwise, a file is copied if the source's last-modified time is greather than or
* equal to the target's last-modified time, or if the file sizes are different.
* @param {string|string[]} [options.include] Optional glob string or array of glob strings that
* are tested against both target and source relative paths to determine if they are included
* in the merge-and-update. If unspecified, all items are included.
* @param {string|string[]} [options.exclude] Optional glob string or array of glob strings that
* are tested against both target and source relative paths to determine if they are excluded
* from the merge-and-update. Exclusions override inclusions. If unspecified, no items are
* excluded.
* @param {loggingCallback} [log] Optional logging callback that takes a string message
* describing any file operations that are performed.
* @return {boolean} true if any changes were made, or false if the force flag is not set
* and everything was up to date
*/
function mergeAndUpdateDir (sourceDirs, targetDir, options, log) {
if (sourceDirs && typeof sourceDirs === 'string') {
sourceDirs = [sourceDirs];
} else if (!Array.isArray(sourceDirs)) {
throw new Error('A source directory path or array of paths is required.');
}
if (!targetDir || typeof targetDir !== 'string') {
throw new Error('A target directory path is required.');
}
const rootDir = (options && options.rootDir) || '';
let include = (options && options.include) || ['**'];
if (typeof include === 'string') {
include = [include];
} else if (!Array.isArray(include)) {
throw new Error('Include parameter must be a glob string or array of glob strings.');
}
let exclude = (options && options.exclude) || [];
if (typeof exclude === 'string') {
exclude = [exclude];
} else if (!Array.isArray(exclude)) {
throw new Error('Exclude parameter must be a glob string or array of glob strings.');
}
// Scan the files in each of the source directories.
const sourceMaps = sourceDirs.map(sourceDir => {
const sourcePath = path.join(rootDir, sourceDir);
if (!fs.existsSync(sourcePath)) {
throw new Error(`Source directory does not exist: ${sourcePath}`);
}
return mapDirectory(rootDir, sourceDir, include, exclude);
});
// Scan the files in the target directory, if it exists.
const targetFullPath = path.join(rootDir, targetDir);
const targetMap = fs.existsSync(targetFullPath)
? mapDirectory(rootDir, targetDir, include, exclude)
: {};
const pathMap = mergePathMaps(sourceMaps, targetMap, targetDir);
// Iterate in sorted order for nicer logs
return Object.keys(pathMap).sort().map(subPath => {
const entry = pathMap[subPath];
return updatePathWithStats(
entry.sourcePath,
entry.sourceStats,
entry.targetPath,
entry.targetStats,
options,
log
);
}).some(updated => updated);
}
/**
* Creates a dictionary map of all files and directories under a path.
*/
function mapDirectory (rootDir, subDir, include, exclude) {
const pathToMap = path.join(rootDir, subDir);
return fastGlob.sync(include, {
fs, // we pass in fs here, to be able to mock it in our tests
dot: true,
stats: true,
onlyFiles: false,
cwd: pathToMap,
ignore: exclude
})
.map(({ path: p, stats }) => ({
[path.normalize(p)]: { subDir, stats }
}))
.reduce(
(dirMap, fragment) => Object.assign(dirMap, fragment),
{ '': { subDir, stats: fs.statSync(pathToMap) } }
);
}
/**
* Merges together multiple source maps and a target map into a single mapping from
* relative paths to objects with target and source paths and stats.
*/
function mergePathMaps (sourceMaps, targetMap, targetDir) {
// Merge multiple source maps together, along with target path info.
// Entries in later source maps override those in earlier source maps.
const sourceMap = Object.assign({}, ...sourceMaps);
const allKeys = [].concat(Object.keys(sourceMap), Object.keys(targetMap));
const pathMap = allKeys.reduce((acc, subPath) => (
Object.assign(acc, {
[subPath]: {
targetPath: path.join(targetDir, subPath),
targetStats: null,
sourcePath: null,
sourceStats: null
}
})
), {});
Object.entries(sourceMap).forEach(([subPath, { subDir, stats }]) => {
Object.assign(
pathMap[subPath],
{ sourcePath: path.join(subDir, subPath), sourceStats: stats }
);
});
// Fill in target stats for targets that exist, and create entries
// for targets that don't have any corresponding sources.
Object.entries(targetMap).forEach(([subPath, { stats }]) => {
Object.assign(pathMap[subPath], { targetStats: stats });
});
return pathMap;
}
module.exports = {
updatePath,
updatePaths,
mergeAndUpdateDir
};

256
spa/node_modules/cordova-common/src/PlatformJson.js generated vendored Normal file
View File

@@ -0,0 +1,256 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
const fs = require('fs-extra');
const path = require('path');
const endent = require('endent').default;
const mungeutil = require('./ConfigChanges/munge-util');
class PlatformJson {
constructor (filePath, platform, root) {
this.filePath = filePath;
this.platform = platform;
this.root = fix_munge(root || {});
}
static load (plugins_dir, platform) {
const filePath = path.join(plugins_dir, `${platform}.json`);
const root = fs.existsSync(filePath)
? fs.readJsonSync(filePath)
: null;
return new PlatformJson(filePath, platform, root);
}
save () {
fs.outputJsonSync(this.filePath, this.root, { spaces: 2 });
}
/**
* Indicates whether the specified plugin is installed as a top-level (not as
* dependency to others)
*
* @param {String} pluginId A plugin id to check for.
* @return {Boolean} true if plugin installed as top-level, otherwise false.
*/
isPluginTopLevel (pluginId) {
return this.root.installed_plugins[pluginId];
}
/**
* Indicates whether the specified plugin is installed as a dependency to other
* plugin.
*
* @param {String} pluginId A plugin id to check for.
* @return {Boolean} true if plugin installed as a dependency, otherwise false.
*/
isPluginDependent (pluginId) {
return this.root.dependent_plugins[pluginId];
}
/**
* Indicates whether plugin is installed either as top-level or as dependency.
*
* @param {String} pluginId A plugin id to check for.
* @return {Boolean} true if plugin installed, otherwise false.
*/
isPluginInstalled (pluginId) {
return this.isPluginTopLevel(pluginId) ||
this.isPluginDependent(pluginId);
}
addPlugin (pluginId, variables, isTopLevel) {
const pluginsList = isTopLevel
? this.root.installed_plugins
: this.root.dependent_plugins;
pluginsList[pluginId] = variables;
return this;
}
/**
* @chaining
* Generates and adds metadata for provided plugin into associated <platform>.json file
*
* @param {PluginInfo} pluginInfo A pluginInfo instance to add metadata from
* @returns {this} Current PlatformJson instance to allow calls chaining
*/
addPluginMetadata (pluginInfo) {
const installedModules = this.root.modules || [];
const installedPaths = installedModules.map(m => m.file);
const modulesToInstall = pluginInfo.getJsModules(this.platform)
.map(module => new ModuleMetadata(pluginInfo.id, module))
// Filter out modules which are already added to metadata
.filter(metadata => !installedPaths.includes(metadata.file));
this.root.modules = installedModules.concat(modulesToInstall);
this.root.plugin_metadata = this.root.plugin_metadata || {};
this.root.plugin_metadata[pluginInfo.id] = pluginInfo.version;
return this;
}
removePlugin (pluginId, isTopLevel) {
const pluginsList = isTopLevel
? this.root.installed_plugins
: this.root.dependent_plugins;
delete pluginsList[pluginId];
return this;
}
/**
* @chaining
* Removes metadata for provided plugin from associated file
*
* @param {PluginInfo} pluginInfo A PluginInfo instance to which modules' metadata
* we need to remove
*
* @returns {this} Current PlatformJson instance to allow calls chaining
*/
removePluginMetadata (pluginInfo) {
const installedModules = this.root.modules || [];
const modulesToRemove = pluginInfo.getJsModules(this.platform)
.map(jsModule => ['plugins', pluginInfo.id, jsModule.src].join('/'));
// Leave only those metadatas which 'file' is not in removed modules
this.root.modules = installedModules
.filter(m => !modulesToRemove.includes(m.file));
if (this.root.plugin_metadata) {
delete this.root.plugin_metadata[pluginInfo.id];
}
return this;
}
addInstalledPluginToPrepareQueue (pluginDirName, vars, is_top_level, force) {
this.root.prepare_queue.installed.push({ plugin: pluginDirName, vars, topLevel: is_top_level, force });
}
addUninstalledPluginToPrepareQueue (pluginId, is_top_level) {
this.root.prepare_queue.uninstalled.push({ plugin: pluginId, id: pluginId, topLevel: is_top_level });
}
/**
* Moves plugin, specified by id to top-level plugins. If plugin is top-level
* already, then does nothing.
*
* @param {String} pluginId A plugin id to make top-level.
* @return {PlatformJson} PlatformJson instance.
*/
makeTopLevel (pluginId) {
const plugin = this.root.dependent_plugins[pluginId];
if (plugin) {
delete this.root.dependent_plugins[pluginId];
this.root.installed_plugins[pluginId] = plugin;
}
return this;
}
/**
* Generates a metadata for all installed plugins and js modules. The resultant
* string is ready to be written to 'cordova_plugins.js'
*
* @returns {String} cordova_plugins.js contents
*/
generateMetadata () {
const stringify = o => JSON.stringify(o, null, 2);
return endent`
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = ${stringify(this.root.modules)};
module.exports.metadata = ${stringify(this.root.plugin_metadata)};
});
`;
}
/**
* @chaining
* Generates and then saves metadata to specified file. Doesn't check if file exists.
*
* @param {String} destination File metadata will be written to
* @return {PlatformJson} PlatformJson instance
*/
generateAndSaveMetadata (destination) {
fs.outputFileSync(destination, this.generateMetadata());
return this;
}
}
// convert a munge from the old format ([file][parent][xml] = count) to the current one
function fix_munge (root) {
root.prepare_queue = root.prepare_queue || { installed: [], uninstalled: [] };
root.config_munge = root.config_munge || { files: {} };
root.installed_plugins = root.installed_plugins || {};
root.dependent_plugins = root.dependent_plugins || {};
const munge = root.config_munge;
if (!munge.files) {
const new_munge = { files: {} };
for (const file in munge) {
for (const selector in munge[file]) {
for (const xml_child in munge[file][selector]) {
const val = parseInt(munge[file][selector][xml_child]);
for (let i = 0; i < val; i++) {
mungeutil.deep_add(new_munge, [file, selector, { xml: xml_child, count: val }]);
}
}
}
}
root.config_munge = new_munge;
}
return root;
}
class ModuleMetadata {
/**
* Creates a ModuleMetadata object that represents module entry in 'cordova_plugins.js'
* file at run time
*
* @param {String} pluginId Plugin id where this module installed from
* @param (JsModule|Object) jsModule A js-module entry from PluginInfo class to generate metadata for
*/
constructor (pluginId, jsModule) {
if (!pluginId) throw new TypeError('pluginId argument must be a valid plugin id');
if (!jsModule.src && !jsModule.name) throw new TypeError('jsModule argument must contain src or/and name properties');
this.id = `${pluginId}.${jsModule.name || jsModule.src.match(/([^/]+)\.js/)[1]}`;
this.file = ['plugins', pluginId, jsModule.src].join('/');
this.pluginId = pluginId;
if (jsModule.clobbers && jsModule.clobbers.length > 0) {
this.clobbers = jsModule.clobbers.map(o => o.target);
}
if (jsModule.merges && jsModule.merges.length > 0) {
this.merges = jsModule.merges.map(o => o.target);
}
if (jsModule.runs) {
this.runs = true;
}
}
}
module.exports = PlatformJson;

View File

@@ -0,0 +1,459 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const path = require('path');
const fs = require('fs-extra');
const { parseElementtreeSync } = require('../util/xml-helpers');
const CordovaError = require('../CordovaError');
/**
* A class for holding the information currently stored in plugin.xml
*
* It should also be able to answer questions like whether the plugin
* is compatible with a given engine version.
*/
class PluginInfo {
constructor (dirname) {
this.dir = dirname;
this.filepath = path.join(dirname, 'plugin.xml');
if (!fs.existsSync(this.filepath)) {
throw new CordovaError(`Cannot find plugin.xml for plugin "${path.basename(dirname)}". Please try adding it again.`);
}
this._et = parseElementtreeSync(this.filepath);
const root = this._et.getroot();
this.id = root.attrib.id;
this.version = root.attrib.version;
// Optional fields
const optTags = 'name description license repo issue info'.split(' ');
for (const tag of optTags) {
this[tag] = root.findtext(tag);
}
const keywordText = root.findtext('keywords');
this.keywords = keywordText && keywordText.split(',').map(s => s.trim());
}
/**
* <preference> tag
*
* Used to require a variable to be specified via --variable when installing the plugin.
*
* @example <preference name="API_KEY" />
*
* @param {string} platform
* @return {Object} { key : default | null}
*/
getPreferences (platform) {
// XML passthrough for preferences is not supported because multiple preferences will override each other.
// https://github.com/apache/cordova-common/issues/182
// return this._getTags('preference', platform).map(({ attrib }) => {
// return Object.assign({}, attrib, {
// [attrib.name.toUpperCase()]: attrib.default || null
// });
// })
return this._getTags('preference', platform).map(({ attrib }) => ({
[attrib.name.toUpperCase()]: attrib.default || null
}))
.reduce((acc, pref) => Object.assign(acc, pref), {});
}
/**
* <asset>
*
* @param {string} platform
*/
getAssets (platform) {
return this._getTags('asset', platform).map(({ attrib }) => {
const src = attrib.src;
const target = attrib.target;
if (!src || !target) {
throw new Error(`Malformed <asset> tag. Both "src" and "target" attributes must be specified in ${this.filepath}`);
}
return Object.assign({}, attrib, {
itemType: 'asset', src, target
});
});
}
/**
* <dependency>
*
* @example
* <dependency id="com.plugin.id"
* url="https://github.com/myuser/someplugin"
* commit="428931ada3891801"
* subdir="some/path/here" />
*
* @param {string} platform
*/
getDependencies (platform) {
return this._getTags('dependency', platform).map(({ attrib }) => {
if (!attrib.id) {
throw new CordovaError(`<dependency> tag is missing id attribute in ${this.filepath}`);
}
return Object.assign({}, attrib, {
id: attrib.id,
version: attrib.version || '',
url: attrib.url || '',
subdir: attrib.subdir || '',
commit: attrib.commit,
git_ref: attrib.commit
});
});
}
/**
* <config-file> tag
*
* @param {string} platform
*/
getConfigFiles (platform) {
return this._getTags('config-file', platform).map(tag => {
return Object.assign({}, tag.attrib, {
target: tag.attrib.target,
parent: tag.attrib.parent,
after: tag.attrib.after,
xmls: tag.getchildren(),
// To support demuxing via versions
versions: tag.attrib.versions,
deviceTarget: tag.attrib['device-target']
});
});
}
/**
* <edit-config> tag
*
* @param {string} platform
*/
getEditConfigs (platform) {
return this._getTags('edit-config', platform).map(tag => {
return Object.assign({}, tag.attrib, {
file: tag.attrib.file,
target: tag.attrib.target,
mode: tag.attrib.mode,
xmls: tag.getchildren()
});
});
}
/**
* <info> tags, both global and within a <platform>
*
* @param {string} platform
*/
// TODO (kamrik): Do we ever use <info> under <platform>? Example wanted.
getInfo (platform) {
return this._getTags('info', platform).map(elem => elem.text)
// Filter out any undefined or empty strings.
.filter(Boolean);
}
/**
* <source-file>
*
* @example
* <source-file src="src/ios/someLib.a" framework="true" />
* <source-file src="src/ios/someLib.a" compiler-flags="-fno-objc-arc" />
*
* @param {string} platform
*/
getSourceFiles (platform) {
return this._getTagsInPlatform('source-file', platform).map(({ attrib }) => {
return Object.assign({}, attrib, {
itemType: 'source-file',
src: attrib.src,
framework: isStrTrue(attrib.framework),
weak: isStrTrue(attrib.weak),
compilerFlags: attrib['compiler-flags'],
targetDir: attrib['target-dir']
});
});
}
/**
* <header-file>
*
* @example <header-file src="CDVFoo.h" />
*
* @param {string} platform
*/
getHeaderFiles (platform) {
return this._getTagsInPlatform('header-file', platform).map(({ attrib }) => {
return Object.assign({}, attrib, {
itemType: 'header-file',
src: attrib.src,
targetDir: attrib['target-dir'],
type: attrib.type
});
});
}
/**
* <resource-file>
*
* @example
* <resource-file
* src="FooPluginStrings.xml"
* target="res/values/FooPluginStrings.xml"
* device-target="win"
* arch="x86"
* versions=">=8.1"
* />
*
* @param {string} platform
*/
getResourceFiles (platform) {
return this._getTagsInPlatform('resource-file', platform).map(({ attrib }) => {
return Object.assign({}, attrib, {
itemType: 'resource-file',
src: attrib.src,
target: attrib.target,
versions: attrib.versions,
deviceTarget: attrib['device-target'],
arch: attrib.arch,
reference: attrib.reference
});
});
}
/**
* <lib-file>
*
* @example
* <lib-file src="src/BlackBerry10/native/device/libfoo.so" arch="device" />
*
* @param {string} platform
*/
getLibFiles (platform) {
return this._getTagsInPlatform('lib-file', platform).map(({ attrib }) => {
return Object.assign({}, attrib, {
itemType: 'lib-file',
src: attrib.src,
arch: attrib.arch,
Include: attrib.Include,
versions: attrib.versions,
deviceTarget: attrib['device-target'] || attrib.target
});
});
}
/**
* <podspec>
*
* @example
* <podspec>
* <config>
* <source url="https://github.com/brightcove/BrightcoveSpecs.git" />
* <source url="https://github.com/CocoaPods/Specs.git"/>
* </config>
* <pods use-frameworks="true" inhibit-all-warnings="true">
* <pod name="PromiseKit" />
* <pod name="Foobar1" spec="~> 2.0.0" />
* <pod name="Foobar2" git="git@github.com:hoge/foobar1.git" />
* <pod name="Foobar3" git="git@github.com:hoge/foobar2.git" branch="next" />
* <pod name="Foobar4" swift-version="4.1" />
* <pod name="Foobar5" swift-version="3.0" />
* </pods>
* </podspec>
*
* @param {string} platform
*/
getPodSpecs (platform) {
return this._getTagsInPlatform('podspec', platform).map(tag => {
const config = tag.find('config');
const pods = tag.find('pods');
const sources = config && config.findall('source')
.map(el => ({ source: el.attrib.url }))
.reduce((acc, val) => Object.assign(acc, { [val.source]: val }), {});
const declarations = pods && pods.attrib;
const libraries = pods && pods.findall('pod')
.map(t => t.attrib)
.reduce((acc, val) => Object.assign(acc, { [val.name]: val }), {});
return { declarations, sources, libraries };
});
}
/**
* <hook>
*
* @example
* <hook type="before_build" src="scripts/beforeBuild.js" />
*
* @param {string} hook
* @param {string} platforms
*/
getHookScripts (hook, platforms) {
return this._getTags('hook', platforms)
.filter(({ attrib }) =>
attrib.src && attrib.type &&
attrib.type.toLowerCase() === hook
);
}
/**
* <js-module>
*
* @param {string} platform
*/
getJsModules (platform) {
return this._getTags('js-module', platform).map(tag => {
return Object.assign({}, tag.attrib, {
itemType: 'js-module',
name: tag.attrib.name,
src: tag.attrib.src,
clobbers: tag.findall('clobbers').map(tag => ({ target: tag.attrib.target })),
merges: tag.findall('merges').map(tag => ({ target: tag.attrib.target })),
runs: tag.findall('runs').length > 0
});
});
}
getEngines () {
return this._et.findall('engines/engine').map(({ attrib }) => {
return Object.assign({}, attrib, {
name: attrib.name,
version: attrib.version,
platform: attrib.platform,
scriptSrc: attrib.scriptSrc
});
});
}
getPlatforms () {
return this._et.findall('platform').map(n => {
return Object.assign({}, n.attrib, { name: n.attrib.name });
});
}
getPlatformsArray () {
return this._et.findall('platform').map(n => n.attrib.name);
}
getFrameworks (platform, options) {
const { cli_variables = {} } = options || {};
const vars = Object.keys(cli_variables).length === 0
? this.getPreferences(platform)
: cli_variables;
const varExpansions = Object.entries(vars)
.filter(([, value]) => value)
.map(([name, value]) =>
s => s.replace(new RegExp(`\\$${name}`, 'g'), value)
);
// Replaces plugin variables in s if they exist
const expandVars = s => varExpansions.reduce((acc, fn) => fn(acc), s);
return this._getTags('framework', platform).map(({ attrib }) => {
return Object.assign({}, attrib, {
itemType: 'framework',
type: attrib.type,
parent: attrib.parent,
custom: isStrTrue(attrib.custom),
embed: isStrTrue(attrib.embed),
src: expandVars(attrib.src),
spec: attrib.spec,
weak: isStrTrue(attrib.weak),
versions: attrib.versions,
targetDir: attrib['target-dir'],
deviceTarget: attrib['device-target'] || attrib.target,
arch: attrib.arch,
implementation: attrib.implementation
});
});
}
getFilesAndFrameworks (platform, options) {
// Please avoid changing the order of the calls below, files will be
// installed in this order.
return [].concat(
this.getSourceFiles(platform),
this.getHeaderFiles(platform),
this.getResourceFiles(platform),
this.getFrameworks(platform, options),
this.getLibFiles(platform)
);
}
getKeywordsAndPlatforms () {
return (this.keywords || [])
.concat('ecosystem:cordova')
.concat(this.getPlatformsArray().map(p => `cordova-${p}`));
}
/**
* Helper method used by most of the getSomething methods of PluginInfo.
*
* Get all elements of a given name. Both in root and in platform sections
* for the given platform.
*
* @private
*
* @param {string} tag
* @param {string|string[]} platform
*/
_getTags (tag, platform) {
return this._et.findall(tag)
.concat(this._getTagsInPlatform(tag, platform));
}
/**
* Same as _getTags() but only looks inside a platform section.
*
* @private
*
* @param {string} tag
* @param {string|string[]} platform
*/
_getTagsInPlatform (tag, platform) {
const platforms = [].concat(platform);
return [].concat(...platforms.map(platform => {
const platformTag = this._et.find(`./platform[@name="${platform}"]`);
return platformTag ? platformTag.findall(tag) : [];
}));
}
}
// Check if x is a string 'true'.
function isStrTrue (x) {
return String(x).toLowerCase() === 'true';
}
module.exports = PluginInfo;
// Backwards compat:
PluginInfo.PluginInfo = PluginInfo;
PluginInfo.loadPluginsDir = dir => {
const PluginInfoProvider = require('./PluginInfoProvider');
return new PluginInfoProvider().getAllWithinSearchPath(dir);
};

View File

@@ -0,0 +1,86 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const fs = require('fs-extra');
const path = require('path');
const PluginInfo = require('./PluginInfo');
const events = require('../events');
const glob = require('glob');
class PluginInfoProvider {
constructor () {
this._cache = {};
this._getAllCache = {};
}
get (dirName) {
const absPath = path.resolve(dirName);
if (!this._cache[absPath]) {
this._cache[absPath] = new PluginInfo(dirName);
}
return this._cache[absPath];
}
// Normally you don't need to put() entries, but it's used
// when copying plugins, and in unit tests.
put (pluginInfo) {
const absPath = path.resolve(pluginInfo.dir);
this._cache[absPath] = pluginInfo;
}
// Used for plugin search path processing.
// Given a dir containing multiple plugins, create a PluginInfo object for
// each of them and return as array.
// Should load them all in parallel and return a promise, but not yet.
getAllWithinSearchPath (dirName) {
const absPath = path.resolve(dirName);
if (!this._getAllCache[absPath]) {
this._getAllCache[absPath] = getAllHelper(absPath, this);
}
return this._getAllCache[absPath];
}
}
function getAllHelper (absPath, provider) {
if (!fs.existsSync(absPath)) {
return [];
}
// If dir itself is a plugin, return it in an array with one element.
if (fs.existsSync(path.join(absPath, 'plugin.xml'))) {
return [provider.get(absPath)];
}
// Match normal and scoped plugins
const pluginXmlPaths = glob.sync('{,@*/}*/plugin.xml', {
cwd: absPath,
nodir: true,
absolute: true
}).map(path.normalize);
return pluginXmlPaths.map(pluginXmlPath => {
try {
return provider.get(path.dirname(pluginXmlPath));
} catch (err) {
events.emit('warn', `Error parsing ${pluginXmlPath}:\n${err.stack}`);
return null;
}
}).filter(p => p);
}
module.exports = PluginInfoProvider;

149
spa/node_modules/cordova-common/src/PluginManager.js generated vendored Normal file
View File

@@ -0,0 +1,149 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const fs = require('fs-extra');
const path = require('path');
const ActionStack = require('./ActionStack');
const PlatformJson = require('./PlatformJson');
const CordovaError = require('./CordovaError');
const PlatformMunger = require('./ConfigChanges/ConfigChanges').PlatformMunger;
const PluginInfoProvider = require('./PluginInfo/PluginInfoProvider');
/**
* Represents an entity for adding/removing plugins for platforms
*/
class PluginManager {
/**
* @param {String} platform Platform name
* @param {Object} locations - Platform files and directories
* @param {IDEProject} ideProject The IDE project to add/remove plugin changes to/from
*/
constructor (platform, locations, ideProject) {
this.platform = platform;
this.locations = locations;
this.project = ideProject;
const platformJson = PlatformJson.load(locations.root, platform);
this.munger = new PlatformMunger(platform, locations.root, platformJson, new PluginInfoProvider());
}
/**
* @constructs PluginManager
* A convenience shortcut to new PluginManager(...)
*
* @param {String} platform Platform name
* @param {Object} locations - Platform files and directories
* @param {IDEProject} ideProject The IDE project to add/remove plugin changes to/from
* @returns new PluginManager instance
*/
static get (platform, locations, ideProject) {
return new PluginManager(platform, locations, ideProject);
}
static get INSTALL () { return 'install'; }
static get UNINSTALL () { return 'uninstall'; }
/**
* Describes and implements common plugin installation/uninstallation routine. The flow is the following:
* * Validate and set defaults for options. Note that options are empty by default. Everything
* needed for platform IDE project must be passed from outside. Plugin variables (which
* are the part of the options) also must be already populated with 'PACKAGE_NAME' variable.
* * Collect all plugin's native and web files, get installers/uninstallers and process
* all these via ActionStack.
* * Save the IDE project, so the changes made by installers are persisted.
* * Generate config changes munge for plugin and apply it to all required files
* * Generate metadata for plugin and plugin modules and save it to 'cordova_plugins.js'
*
* @param {PluginInfo} plugin A PluginInfo structure representing plugin to install
* @param {Object} [options={}] An installation options. It is expected but is not necessary
* that options would contain 'variables' inner object with 'PACKAGE_NAME' field set by caller.
*
* @returns {Promise}
*/
doOperation (operation, plugin, options) {
if (operation !== PluginManager.INSTALL && operation !== PluginManager.UNINSTALL) { return Promise.reject(new CordovaError('The parameter is incorrect. The opeation must be either "add" or "remove"')); }
if (!plugin || plugin.constructor.name !== 'PluginInfo') { return Promise.reject(new CordovaError('The parameter is incorrect. The first parameter should be a PluginInfo instance')); }
// Set default to empty object to play safe when accesing properties
options = options || {};
const actions = new ActionStack();
// gather all files need to be handled during operation ...
plugin.getFilesAndFrameworks(this.platform, options)
.concat(plugin.getAssets(this.platform))
.concat(plugin.getJsModules(this.platform))
// ... put them into stack ...
.forEach(item => {
const installer = this.project.getInstaller(item.itemType);
const uninstaller = this.project.getUninstaller(item.itemType);
const actionArgs = [item, plugin, this.project, options];
let action;
if (operation === PluginManager.INSTALL) {
action = actions.createAction(installer, actionArgs, uninstaller, actionArgs);
} else /* op === PluginManager.UNINSTALL */{
action = actions.createAction(uninstaller, actionArgs, installer, actionArgs);
}
actions.push(action);
});
// ... and run through the action stack
return actions.process(this.platform)
.then(() => {
if (this.project.write) {
this.project.write();
}
if (operation === PluginManager.INSTALL) {
// Ignore passed `is_top_level` option since platform itself doesn't know
// anything about managing dependencies - it's responsibility of caller.
this.munger.add_plugin_changes(plugin, options.variables, /* is_top_level= */true, /* should_increment= */true, options.force);
this.munger.platformJson.addPluginMetadata(plugin);
} else {
this.munger.remove_plugin_changes(plugin, /* is_top_level= */true);
this.munger.platformJson.removePluginMetadata(plugin);
}
// Save everything (munge and plugin/modules metadata)
this.munger.save_all();
const metadata = this.munger.platformJson.generateMetadata();
fs.writeFileSync(path.join(this.locations.www, 'cordova_plugins.js'), metadata, 'utf-8');
// CB-11022 save plugin metadata to both www and platform_www if options.usePlatformWww is specified
if (options.usePlatformWww) {
fs.writeFileSync(path.join(this.locations.platformWww, 'cordova_plugins.js'), metadata, 'utf-8');
}
});
}
addPlugin (plugin, installOptions) {
return this.doOperation(PluginManager.INSTALL, plugin, installOptions);
}
removePlugin (plugin, uninstallOptions) {
return this.doOperation(PluginManager.UNINSTALL, plugin, uninstallOptions);
}
}
module.exports = PluginManager;

81
spa/node_modules/cordova-common/src/events.js generated vendored Normal file
View File

@@ -0,0 +1,81 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const EventEmitter = require('events').EventEmitter;
const MAX_LISTENERS = 20;
const INSTANCE_KEY = Symbol.for('org.apache.cordova.common.CordovaEvents');
let EVENTS_RECEIVER = null;
class CordovaEventEmitter extends EventEmitter {
/**
* Sets up current instance to forward emitted events to another EventEmitter
* instance.
*
* @param {EventEmitter} [eventEmitter] The emitter instance to forward
* events to. Falsy value, when passed, disables forwarding.
*/
forwardEventsTo (eventEmitter) {
// If no argument is specified disable events forwarding
if (!eventEmitter) {
EVENTS_RECEIVER = undefined;
return;
}
if (!(eventEmitter instanceof EventEmitter)) {
throw new Error('Cordova events can be redirected to another EventEmitter instance only');
}
// CB-10940 Skipping forwarding to this to avoid infinite recursion.
// This is the case when the modules are npm-linked.
if (this !== eventEmitter) {
EVENTS_RECEIVER = eventEmitter;
} else {
// Reset forwarding if we are subscribing to this
EVENTS_RECEIVER = undefined;
}
}
/**
* Sets up current instance to forward emitted events to another EventEmitter
* instance.
*
* @param {EventEmitter} [eventEmitter] The emitter instance to forward
* events to. Falsy value, when passed, disables forwarding.
*/
emit (eventName, ...args) {
if (EVENTS_RECEIVER) {
EVENTS_RECEIVER.emit(eventName, ...args);
}
return super.emit(eventName, ...args);
}
}
// This singleton instance pattern is based on the ideas from
// https://derickbailey.com/2016/03/09/creating-a-true-singleton-in-node-js-with-es6-symbols/
if (Object.getOwnPropertySymbols(global).indexOf(INSTANCE_KEY) === -1) {
const events = new CordovaEventEmitter();
events.setMaxListeners(MAX_LISTENERS);
global[INSTANCE_KEY] = events;
}
module.exports = global[INSTANCE_KEY];

156
spa/node_modules/cordova-common/src/superspawn.js generated vendored Normal file
View File

@@ -0,0 +1,156 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const crossSpawn = require('cross-spawn');
const fs = require('fs-extra');
const extend = require('lodash.assign');
const Q = require('q');
const events = require('./events');
const iswin32 = process.platform === 'win32';
/**
* A special implementation for child_process.spawn that handles
* Windows-specific issues with batch files and spaces in paths. Returns a
* promise that succeeds only for return code 0. It is also possible to
* subscribe on spawned process' stdout and stderr streams using progress
* handler for resultant promise.
*
* @example spawn('mycommand', [], {stdio: 'pipe'}) .progress(function (stdio){
* if (stdio.stderr) { console.error(stdio.stderr); } })
* .then(function(result){ // do other stuff })
*
* @param {String} cmd A command to spawn
* @param {String[]} [args=[]] An array of arguments, passed to spawned
* process
* @param {Object} [opts={}] A configuration object
* @param {String|String[]|Object} opts.stdio Property that configures how
* spawned process' stdio will behave. Has the same meaning and possible
* values as 'stdio' options for child_process.spawn method
* (https://nodejs.org/api/child_process.html#child_process_options_stdio).
* @param {Object} [env={}] A map of extra environment variables
* @param {String} [cwd=process.cwd()] Working directory for the command
* @param {Boolean} [chmod=false] If truthy, will attempt to set the execute
* bit before executing on non-Windows platforms
*
* @return {Promise} A promise that is either fulfilled if the spawned
* process is exited with zero error code or rejected otherwise. If the
* 'stdio' option set to 'default' or 'pipe', the promise also emits progress
* messages with the following contents:
* {
* 'stdout': ...,
* 'stderr': ...
* }
*/
exports.spawn = (cmd, args, opts) => {
args = args || [];
opts = opts || {};
const spawnOpts = {};
const d = Q.defer();
if (opts.stdio !== 'default') {
// Ignore 'default' value for stdio because it corresponds to child_process's default 'pipe' option
spawnOpts.stdio = opts.stdio;
}
if (opts.cwd) {
spawnOpts.cwd = opts.cwd;
}
if (opts.env) {
spawnOpts.env = extend(extend({}, process.env), opts.env);
}
if (opts.chmod && !iswin32) {
try {
// This fails when module is installed in a system directory (e.g. via sudo npm install)
fs.chmodSync(cmd, '755');
} catch (e) {
// If the perms weren't set right, then this will come as an error upon execution.
}
}
events.emit(opts.printCommand ? 'log' : 'verbose', `Running command: ${cmd} ${args.join(' ')}`);
// At least until Node.js 8, child_process.spawn will throw exceptions
// instead of emitting error events in certain cases (like EACCES), Thus we
// have to wrap the execution in try/catch to convert them into rejections.
let child;
try {
child = crossSpawn.spawn(cmd, args, spawnOpts);
} catch (e) {
whenDone(e);
return d.promise;
}
let capturedOut = '';
let capturedErr = '';
if (child.stdout) {
child.stdout.setEncoding('utf8');
child.stdout.on('data', data => {
capturedOut += data;
d.notify({ stdout: data });
});
}
if (child.stderr) {
child.stderr.setEncoding('utf8');
child.stderr.on('data', data => {
capturedErr += data;
d.notify({ stderr: data });
});
}
child.on('close', whenDone);
child.on('error', whenDone);
function whenDone (arg) {
if (child) {
child.removeListener('close', whenDone);
child.removeListener('error', whenDone);
}
const code = typeof arg === 'number' ? arg : arg && arg.code;
events.emit('verbose', `Command finished with error code ${code}: ${cmd} ${args}`);
if (code === 0) {
d.resolve(capturedOut.trim());
} else {
let errMsg = `${cmd}: Command failed with exit code ${code}`;
if (capturedErr) {
errMsg += ` Error output:\n${capturedErr.trim()}`;
}
const err = new Error(errMsg);
if (capturedErr) {
err.stderr = capturedErr;
}
if (capturedOut) {
err.stdout = capturedOut;
}
err.code = code;
d.reject(err);
}
}
return d.promise;
};
exports.maybeSpawn = (cmd, args, opts) => {
if (fs.existsSync(cmd)) {
return exports.spawn(cmd, args, opts);
}
return Q(null);
};

View File

@@ -0,0 +1,53 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const CordovaError = require('../CordovaError');
/**
* Formats an error for logging.
*
* @param {Error} error - The error to be formatted.
* @param {boolean} isVerbose - Whether the include additional debugging
* information when formatting the error.
*
* @returns {string} The formatted error message.
*/
module.exports = function formatError (error, isVerbose) {
let message = '';
if (error instanceof CordovaError) {
message = error.toString(isVerbose);
} else if (error instanceof Error) {
if (isVerbose) {
message = error.stack;
} else {
message = error.message;
}
} else {
// Plain text error message
message = error;
}
if (typeof message === 'string' && !message.toUpperCase().startsWith('ERROR:')) {
// Needed for backward compatibility with external tools
message = `Error: ${message}`;
}
return message;
};

View File

@@ -0,0 +1,97 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
// contains PLIST utility functions
const isObject = require('lodash.isobject');
const isDate = require('lodash.isdate');
const extend = require('lodash.assign');
const plist = require('plist');
// adds node to doc at selector
module.exports.graftPLIST = graftPLIST;
function graftPLIST (doc, xml, selector) {
const obj = plist.parse(`<plist>${xml}</plist>`);
const node = doc[selector];
if (node && Array.isArray(node) && Array.isArray(obj)) {
const isNew = item => !node.some(nodeChild => nodeEqual(item, nodeChild));
doc[selector] = node.concat(obj.filter(isNew));
} else {
// plist uses objects for <dict>. If we have two dicts we merge them instead of
// overriding the old one. See CB-6472
const isDict = o => isObject(o) && !isDate(o); // arrays checked above
if (isDict(node) && isDict(obj)) extend(obj, node);
doc[selector] = obj;
}
return true;
}
// removes node from doc at selector
module.exports.prunePLIST = prunePLIST;
function prunePLIST (doc, xml, selector) {
const obj = plist.parse(`<plist>${xml}</plist>`);
pruneObject(doc, selector, obj);
return true;
}
function pruneObject (doc, selector, fragment) {
if (Array.isArray(fragment) && Array.isArray(doc[selector])) {
let empty = true;
for (const i in fragment) {
for (const j in doc[selector]) {
empty = pruneObject(doc[selector], j, fragment[i]) && empty;
}
}
if (empty) {
delete doc[selector];
return true;
}
} else if (nodeEqual(doc[selector], fragment)) {
delete doc[selector];
return true;
}
return false;
}
function nodeEqual (node1, node2) {
if (typeof node1 !== typeof node2) {
return false;
} else if (typeof node1 === 'string') {
node2 = escapeRE(node2).replace(/\\\$\(\S+\)/gm, '(.*?)');
return new RegExp(`^${node2}$`).test(node1);
} else {
for (const key in node2) {
if (!nodeEqual(node1[key], node2[key])) return false;
}
return true;
}
}
// escape string for use in regex
function escapeRE (str) {
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
}

367
spa/node_modules/cordova-common/src/util/xml-helpers.js generated vendored Normal file
View File

@@ -0,0 +1,367 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
// @ts-check
/**
* contains XML utility functions, some of which are specific to elementtree
*/
const fs = require('fs-extra');
const path = require('path');
const extend = require('lodash.assign');
const zip = require('lodash.zip');
const et = require('elementtree');
const stripBom = require('strip-bom');
/**
* The part of the <edit-config> interface that is used here
* @typedef {{oldAttrib?: et.Attributes}} EditConfigMunge
*/
module.exports = {
/**
* Compares two et.XML nodes, see if they match.
*
* Compares tagName, text, attributes and children (recursively)
*
* @param {et.Element} one
* @param {et.Element} two
* @return {boolean} true iff one and two are equal
*/
equalNodes (one, two) {
return one.tag === two.tag &&
one.len() === two.len() &&
String(one.text).trim() === String(two.text).trim() &&
attribMatch(one, two) &&
zip(one.getchildren(), two.getchildren())
.every(([c1, c2]) => module.exports.equalNodes(c1, c2));
},
/**
* Adds node to doc at selector, creating parent if it doesn't exist
*
* @param {et.ElementTree} doc
* @param {et.Element[]} nodes
* @param {string} selector
* @param {string | undefined} [after]
* @return {boolean}
*/
graftXML (doc, nodes, selector, after) {
let parent = module.exports.resolveParent(doc, selector);
if (!parent) {
// Try to create the parent recursively if necessary
try {
const parentToCreate = et.XML(`<${path.basename(selector)}/>`);
const parentSelector = path.dirname(selector);
this.graftXML(doc, [parentToCreate], parentSelector);
} catch (e) {
return false;
}
parent = module.exports.resolveParent(doc, selector);
if (!parent) return false;
}
nodes.forEach(node => {
// skip if an equal element already exists in parent
if (findChild(node, parent)) return;
const children = parent.getchildren();
const insertIdx = after ? findInsertIdx(children, after) : children.length;
// TODO: replace with parent.insert after the bug in ElementTree is fixed
parent.getchildren().splice(insertIdx, 0, node);
});
return true;
},
/**
* Adds new attributes to doc at selector.
*
* Will only merge if attribute has not been modified already or --force is used
*
* @param {et.ElementTree} doc
* @param {et.Element[]} nodes
* @param {string} selector
* @param {EditConfigMunge} xml
* @return {boolean}
*/
graftXMLMerge (doc, nodes, selector, xml) {
return graftXMLAttrs(doc, nodes, selector, xml);
},
/**
* Overwrites all attributes to doc at selector with new attributes.
*
* Will only overwrite if attribute has not been modified already or --force is used
*
* @param {et.ElementTree} doc
* @param {et.Element[]} nodes
* @param {string} selector
* @param {EditConfigMunge} xml
* @return {boolean}
*/
graftXMLOverwrite (doc, nodes, selector, xml) {
return graftXMLAttrs(doc, nodes, selector, xml, { overwrite: true });
},
/**
* Removes node from doc at selector.
*
* @param {et.ElementTree} doc
* @param {et.Element[]} nodes
* @param {string} selector
* @return {boolean}
*/
pruneXML (doc, nodes, selector) {
const parent = module.exports.resolveParent(doc, selector);
if (!parent) return false;
nodes.forEach(node => {
const matchingKid = findChild(node, parent);
if (matchingKid) parent.remove(matchingKid);
});
return true;
},
/**
* Restores attributes from doc at selector.
*
* @param {et.ElementTree} doc
* @param {string} selector
* @param {EditConfigMunge} xml
* @return {boolean}
*/
pruneXMLRestore (doc, selector, xml) {
const target = module.exports.resolveParent(doc, selector);
if (!target) return false;
if (xml.oldAttrib) {
target.attrib = extend({}, xml.oldAttrib);
}
return true;
},
/**
* @param {et.ElementTree} doc
* @param {string} selector
* @param {et.Element[]} nodes
* @return {boolean}
*/
pruneXMLRemove (doc, selector, nodes) {
const target = module.exports.resolveParent(doc, selector);
if (!target) return false;
nodes.forEach(node => {
for (const attribute in node.attrib) {
delete target.attrib[attribute];
}
});
return true;
},
/**
* @param {string} filename
* @return {et.ElementTree}
*/
parseElementtreeSync (filename) {
return et.parse(stripBom(fs.readFileSync(filename, 'utf-8')));
},
/**
* @param {et.ElementTree} doc
* @param {string} selector
* @return {et.Element | null}
*/
resolveParent (doc, selector) {
if (!selector.startsWith('/')) return doc.find(selector);
// elementtree does not implement absolute selectors so we build an
// extended tree where we can use an equivalent relative selector
const metaRoot = et.Element('meta-root');
metaRoot.append(doc.getroot());
return metaRoot.find(`.${selector}`);
}
};
/**
* @param {et.ElementTree} doc
* @param {et.Element[]} nodes
* @param {string} selector
* @param {EditConfigMunge} xml
* @return {boolean}
*/
function graftXMLAttrs (doc, nodes, selector, xml, { overwrite = false } = {}) {
const target = module.exports.resolveParent(doc, selector);
if (!target) return false;
// saves the attributes of the original xml before making changes
xml.oldAttrib = Object.assign({}, target.attrib);
if (overwrite) target.attrib = {};
Object.assign(target.attrib, ...nodes.map(n => n.attrib));
return true;
}
/**
* @param {et.Element} node
* @param {et.Element | et.ElementTree} parent
* @return {et.Element | undefined}
*/
function findChild (node, parent) {
const matches = parent.findall(String(node.tag));
return matches.find(m => module.exports.equalNodes(node, m));
}
/**
* Find the index at which to insert an entry.
*
* @param {et.Element[]} children
* @param {string} after a ;-separated priority list of tags after which the
* insertion should be made. E.g. if we need to insert an element C, and the
* order of children has to be As, Bs, Cs then `after` will be equal to "C;B;A".
* @return {number}
*/
function findInsertIdx (children, after) {
const childrenTags = children.map(child => child.tag);
const foundIndex = after.split(';')
.map(tag => childrenTags.lastIndexOf(tag))
.find(index => index !== -1);
// add to the beginning if no matching nodes are found
return foundIndex === undefined ? 0 : foundIndex + 1;
}
const DENIED_TAGS = ['platform', 'feature', 'plugin', 'engine'];
const SINGLETONS = ['content', 'author', 'name'];
/**
* @param {et.Element} src
* @param {et.Element} dest
* @param {string} platform
* @param {boolean} clobber
*/
function mergeXml (src, dest, platform, clobber) {
// Do nothing for denied tags.
if (DENIED_TAGS.includes(String(src.tag))) return;
// Handle attributes
const omitAttrs = new Set(clobber ? [] : dest.keys());
const xferAttrs = src.keys().filter(k => !omitAttrs.has(k));
xferAttrs.forEach(attr => { dest.attrib[attr] = src.attrib[attr]; });
// Handle text
if (src.text && (clobber || !dest.text)) {
dest.text = src.text;
}
// Handle children
src.getchildren().forEach(mergeChild);
// Handle platform
if (platform) {
src.findall(`platform[@name="${platform}"]`).forEach(platformElement => {
platformElement.getchildren().forEach(mergeChild);
});
}
// Handle duplicate preference tags (by name attribute)
removeDuplicatePreferences(dest);
/** @param {et.Element} srcChild */
function mergeChild (srcChild) {
const srcTag = String(srcChild.tag);
const query = srcTag + '';
let destChild;
let shouldMerge = true;
if (DENIED_TAGS.includes(srcTag)) return;
if (SINGLETONS.includes(srcTag)) {
destChild = dest.find(query);
} else {
// Check for an exact match and if you find one don't add
destChild = dest.findall(query).find(el =>
textMatch(srcChild, el) && attribMatch(srcChild, el)
);
if (destChild) shouldMerge = false;
}
if (destChild) {
dest.remove(destChild);
} else {
destChild = et.Element(srcTag);
}
mergeXml(srcChild, destChild, platform, clobber && shouldMerge);
dest.append(destChild);
}
/** @param {et.Element} xml */
function removeDuplicatePreferences (xml) {
const prefs = xml.findall('preference[@name][@value]');
// reduce preference tags to a hashtable to remove dupes
const prefMap = new Map(
prefs.map(({ attrib: { name, value } }) => [name, value])
);
// remove all preferences
prefs.forEach(pref => xml.remove(pref));
// write new preferences
prefMap.forEach((value, name) => {
et.SubElement(xml, 'preference', { name, value });
});
}
}
// Expose for testing.
module.exports.mergeXml = mergeXml;
/**
* @param {et.Element} elm1
* @param {et.Element} elm2
* @return {boolean}
*/
function textMatch (elm1, elm2) {
/** @param {et.ElementText | null} text */
const format = text => text ? String(text).replace(/\s+/, '') : '';
const text1 = format(elm1.text);
const text2 = format(elm2.text);
return (text1 === '' || text1 === text2);
}
/**
* @param {et.Element} a
* @param {et.Element} b
* @return {boolean} true iff attributes on a and b are equal
*/
function attribMatch (a, b) {
const aKeys = a.keys();
return aKeys.length === b.keys().length &&
aKeys.every(key => a.get(key) === b.get(key));
}