# cordova-browsersync-primitives

> Various tweaks needed to enable browsersync for cordova apps

Latest version **1.3.0** (published 2017-04-12) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install cordova-browsersync-primitives
pnpm add cordova-browsersync-primitives
yarn add cordova-browsersync-primitives
bun add cordova-browsersync-primitives
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2017-04-12 |
| First published | 2016-02-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Andre Asselin |
| Maintainers | asselin, pointsource |
| Keywords | cordova, ecosystem:cordova, cordova-android, cordova-ios, browser sync |

## Links

- npm: https://www.npmjs.com/package/cordova-browsersync-primitives
- Repository: https://github.com/pointsource/cordova-browsersync-primitives
- Homepage: https://github.com/pointsource/cordova-browsersync-primitives#readme
- Issues: https://github.com/pointsource/cordova-browsersync-primitives/issues
- npm.io page: https://npm.io/package/cordova-browsersync-primitives

## Dependencies (5)

- [plist](https://npm.io/package/plist.md) 1.x
- [cheerio](https://npm.io/package/cheerio.md) 0.x
- [csp-parse](https://npm.io/package/csp-parse.md) 0.x
- [elementtree](https://npm.io/package/elementtree.md) 0.x
- [browser-sync](https://npm.io/package/browser-sync.md) >=2.11

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2017-04-12
- 1.2.0 — 2017-04-04
- 1.1.1 — 2016-02-23
- 1.1.0 — 2016-02-17
- 1.0.0 — 2016-02-10

## README

# cordova-browsersync-primitives

This npm package contains common code used to implement browsersync with cordova.  It exports the following APIs:

## addCSP(filename)

###Parameters
* String filename - name of the HTML file to update.
  
###Returns
* Nothing.

### Description
Reads the HTML file specified by `filename`, updates the Content-Security-Policy, and saves the file in place.

## createIndexHtml(servers, platform, cordovaDir, [dest])

###Parameters
* Object servers - The list of IP addresses supplied by browsersync that it is listening on.  
* String platform - Which platform (`android` or `ios`) the page should be built for.  Affects the URLs embedded in the generated HTML file.
* String cordovaDir - Base directory of the cordova project.
* String dest (optional) - Location to save the start page.  If not specified, defaults to `<cordovaDir>/www/index.html`.

###Returns
* Nothing.

### Description

Creates an HTML page that is embedded inside the application's APK or IPA file.  When loaded, the HTML page redirects to the index.html served by browsersync.

This function embeds the IP addresses that the browsersync server is listening on into the HTML file that is built. 

## fixATS(cordovaDir, projectName)

###Parameters
* String cordovaDir - Base directory of the cordova project.
* String projectName - The name given to the cordova project at creation i.e. `cordova create <PATH> <ID> <NAME>`
  
###Returns
* Nothing.

### Description
Updates the iOS platform's `<projectName>-Info.plist` file to disable AppTransportSecurity, and allow loading external HTTP files.

## startBrowserSync(cordovaDir, platforms, opts, cb)

###Parameters
* String cordovaDir - Base directory of the cordova project.
* String[] platforms - Array of strings, each of which is a Cordova platform name to serve.
* Object | Function opts - Options object to be passed to browserSync. If this is a function, the function is called with default values and should return the final options to be passed to browser-sync.
* Function(err, browserSyncInfo) cb - A callback when server is ready.
  
###Returns
* Object - The browsersync instance created.

### Description

Creates and initializes a browsersync instance.  When the instance is ready, `cb` is called. `cb` will be passed 2 parameters:
* Object err - An error object given by browsersync.
* Object browserSyncInfo - Info about the browsersync instance.  Format:

````
Object {
	Object bsInstance - The browsersync instance.
	Object servers {
		String local (optional) - Base URL to localhost.  Example: http://localhost:3000
		String external (optional) - Base URL for external address.  Example: http://10.128.64.174:3000
	}
}
````

## getWWWFolder(platform)

###Parameters
* String platform - Specifies which platform's path (`android` or `ios`) is desired.

###Returns
* String - The path of the platform www directory.  **Note:** This path *always* uses `/` delimiters.

### Description

Returns the path of `platform`'s www directory relative to the cordova root directory.  For example: `platforms/android/assets/www`.

## updateConfigXml(cordovaDir, platform, projectName, hostedPage)

###Parameters
* String cordovaDir - Base directory of the cordova project.
* String platform - Specifies which platform's config.xml file (`android` or `ios`) should be updated.
* String projectName - The name given to the cordova project at creation i.e. `cordova create <PATH> <ID> <NAME>`
* String hostedPage - Name of the starting HTML file that is embedded in the APK or IPA file. 
   
###Returns
* Nothing.

### Description

Updates `platform`'s config.xml file.  Two things are changed:
1. The starting page is changed to `hostedPage` (`<content src='...'>`).
2. An `<allow-navigation href="*" />` element is added to allow the app to navigate to http URLs inside the embedded web view. 

## isPlatformSupported(platform)

###Parameters
* String platform - Specifies the name of the platform to test for support.
  
###Returns
* Boolean - Returns true if the platform is supported; false otherwise.

### Description
Returns true if a supported platform (`android` or `ios`) is passed in `platform`; false otherwise.

---
_Source: https://npm.io/package/cordova-browsersync-primitives · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
