pear-mobile 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/index.js +24 -3
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -20,9 +20,7 @@ This boilerplate is MVP and Experimental.
|
|
|
20
20
|
const PearRuntime = require('pear-mobile')
|
|
21
21
|
const { version, upgrade, productName, name } = require('./package.json')
|
|
22
22
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const runtime = new PearRuntime({ version, upgrade, app })
|
|
23
|
+
const runtime = new PearRuntime({ version, upgrade, name: productName })
|
|
26
24
|
runtime.updater.on('updated', async () => {
|
|
27
25
|
await runtime.updater.applyUpdate()
|
|
28
26
|
conosle.log('restart for update')
|
|
@@ -52,11 +50,13 @@ Create a runtime. `opts` may include:
|
|
|
52
50
|
|
|
53
51
|
- **`dir`** Directory to store data (e.g. app data dir). Defaults to `/Documents`.
|
|
54
52
|
- **`upgrade`** – (required) Pear link for OTA updates (e.g. from `package.json` `upgrade` field).
|
|
55
|
-
- **`
|
|
56
|
-
- **`
|
|
57
|
-
- **`
|
|
58
|
-
- **`
|
|
59
|
-
- **`
|
|
53
|
+
- **`name`** - (required) The package.json prductName of the app.
|
|
54
|
+
- **`store`** - (optional) pass a [Corestore](https://github.com/holepunchto/corestore) to be used for updates. If passed `swarm` must also be passed. The `store` should be replicated over the `swarm`.
|
|
55
|
+
- **`swarm`** - (optional) pass a [Hyperswarm](https://github.com/holepunchto/hyperswarm) to be used for swarming updates. If passed `store` must also be passed. The `store` should be replicated over the `swarm`.
|
|
56
|
+
- **`app`** – (optional) The path to the local OTA react-native bundle as booted from native code. (defaults to [pear-runtime-react-native](https://github.com/holepunchto/pear-runtime-react-native) default)
|
|
57
|
+
- **`version`** – (optional) Current app version (i.e. from `package.json`); used for update checks.
|
|
58
|
+
- **`updates`** – (optional) Set to `false` to disable P2P OTA updates.
|
|
59
|
+
- **`storage`** – (optional) Saves the app storage path.
|
|
60
60
|
|
|
61
61
|
#### `pear.storage`
|
|
62
62
|
|
package/index.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
const PearRuntimeUpdater = require('pear-runtime-updater')
|
|
2
|
-
const
|
|
2
|
+
const ReadyResource = require('ready-resource')
|
|
3
|
+
const Corestore = require('corestore')
|
|
4
|
+
const Hyperswarm = require('hyperswarm')
|
|
3
5
|
const path = require('bare-path')
|
|
4
6
|
const dir = require('bare-storage')
|
|
5
7
|
const fs = require('bare-fs')
|
|
6
8
|
|
|
7
|
-
module.exports = class PearRuntime extends
|
|
9
|
+
module.exports = class PearRuntime extends ReadyResource {
|
|
8
10
|
constructor(opts = {}) {
|
|
9
11
|
super()
|
|
12
|
+
if ((!opts.store && opts.swarm) || (opts.store && !opts.swarm)) {
|
|
13
|
+
throw new Error('must pass store if passing swarm and vice versa')
|
|
14
|
+
}
|
|
10
15
|
if (!opts.dir) opts.dir = dir.persistent()
|
|
16
|
+
this.opts = opts
|
|
17
|
+
if (!opts.store) opts.store = new Corestore(path.join(opts.dir, 'pear-runtime/corestore'))
|
|
18
|
+
this.store = opts.store
|
|
11
19
|
|
|
20
|
+
this.swarm = opts.swarm || null
|
|
21
|
+
this.bootstrap = opts.bootstrap
|
|
12
22
|
this.dir = opts.dir
|
|
13
23
|
this.storage = opts.storage || path.join(this.dir, 'app-storage')
|
|
14
24
|
|
|
15
|
-
const appPath = path.join(opts.dir, 'pear-runtime', 'ota')
|
|
25
|
+
const appPath = opts.app || path.join(opts.dir, 'pear-runtime', 'ota')
|
|
16
26
|
if (!fs.existsSync(appPath)) fs.mkdirSync(appPath, { recursive: true, force: true })
|
|
17
27
|
this.updater = new PearRuntimeUpdater({ ...opts, app: appPath })
|
|
18
28
|
this.updater.on('error', (err) => this.emit('error', err))
|
|
@@ -20,9 +30,20 @@ module.exports = class PearRuntime extends ReadyResouce {
|
|
|
20
30
|
|
|
21
31
|
async _open() {
|
|
22
32
|
await this.updater.ready()
|
|
33
|
+
if (this.swarm === null) {
|
|
34
|
+
const keyPair = await this.store.createKeyPair('pear-runtime')
|
|
35
|
+
this.swarm = new Hyperswarm({ keyPair, bootstrap: this.bootstrap })
|
|
36
|
+
this.swarm.on('connection', (connection) => this.store.replicate(connection))
|
|
37
|
+
this.swarm.join(this.updater.drive.core.discoveryKey, {
|
|
38
|
+
client: true,
|
|
39
|
+
server: false
|
|
40
|
+
})
|
|
41
|
+
}
|
|
23
42
|
}
|
|
24
43
|
|
|
25
44
|
async _close() {
|
|
45
|
+
if (this.opts.swarm) await this.swarm.destroy()
|
|
26
46
|
await this.updater.close()
|
|
47
|
+
if (this.opts.store) await this.store.close()
|
|
27
48
|
}
|
|
28
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-mobile",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Embeddable Pear runtime for mobile applications",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -41,7 +41,9 @@
|
|
|
41
41
|
"bare-fs": "^4.5.5",
|
|
42
42
|
"bare-path": "^3.0.0",
|
|
43
43
|
"bare-storage": "^1.0.1",
|
|
44
|
-
"
|
|
44
|
+
"corestore": "^7.9.1",
|
|
45
|
+
"hyperswarm": "^4.17.0",
|
|
46
|
+
"pear-runtime-updater": "^3.0.0",
|
|
45
47
|
"ready-resource": "^1.2.0"
|
|
46
48
|
}
|
|
47
49
|
}
|