pear-mobile 0.0.2 → 0.0.3
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 +54 -37
- package/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,76 +6,93 @@ Embeddable Pear runtime for mobile applications. Provides storage path and bare
|
|
|
6
6
|
npm install pear-mobile
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
npm install react-native-bare-kit --save
|
|
11
|
-
```
|
|
9
|
+
This module integrates Pear into React-Native-based Mobile applications.
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
See [pear-runtime](https://github.com/holepunchto/pear-runtime) for Pear's embeddable runtime module for Desktop Devices.
|
|
14
12
|
|
|
15
13
|
## Usage
|
|
16
14
|
|
|
17
15
|
```js
|
|
18
|
-
|
|
19
|
-
import PearRuntime from 'pear-mobile'
|
|
20
|
-
import bundle from './worker.bundle.js'
|
|
21
|
-
import { version, upgrade } from './package.json'
|
|
22
|
-
|
|
23
|
-
const runtime = new PearRuntime()
|
|
24
|
-
const IPC = runtime.run('/worker.bundle', bundle, [runtime.dir])
|
|
25
|
-
|
|
26
|
-
/* Bare Worklet */
|
|
27
|
-
const PearRuntime = require('pear-runtime')
|
|
16
|
+
const PearRuntime = require('pear-mobile')
|
|
28
17
|
const { version, upgrade } = require('./package.json')
|
|
29
18
|
|
|
30
|
-
const dir = Bare.argv[0]
|
|
19
|
+
const dir = Bare.argv[0] // pass the /Documents storage dir
|
|
31
20
|
|
|
32
21
|
const runtime = new PearRuntime({ version, upgrade, dir })
|
|
33
|
-
runtime.on('updated', () => {
|
|
34
|
-
runtime.applyUpdate()
|
|
22
|
+
runtime.on('updated', async () => {
|
|
23
|
+
await runtime.applyUpdate()
|
|
35
24
|
conosle.log('restart for update')
|
|
36
25
|
})
|
|
37
26
|
```
|
|
38
27
|
|
|
28
|
+
## Quick Starts
|
|
29
|
+
|
|
30
|
+
### Expo
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
git clone https://github.com/holepunchto/hello-pear-react-native
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For end-to-end instructions from building to deploying with [Pear](https://docs.pears.com) see [hello-pear-react-native](https://github.com/holepunchto/hello-pear-react-native) `README.md`.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- Peer-to-Peer Over-the-Air (P2P OTA) updates (via [pear-runtime-updater](https://www.github.com/holepunchto/pear-runtime-updater))
|
|
41
|
+
- Application storage management
|
|
42
|
+
|
|
39
43
|
## API
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
Inherits from [pear-runtime-updater]{https://www.github.com/holepunchto/pear-runtime-updater}
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
#### `const runtime = new PearRuntime(opts)`
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
Create a runtime. `opts` may include:
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
- **`dir`** (required) – Base directory for runtime data and app storage.
|
|
52
|
+
- **`version`** – Current app version (e.g. from `package.json`); used for update checks.
|
|
53
|
+
- **`upgrade`** – Pear link for OTA updates (e.g. from `package.json` `upgrade` field).
|
|
54
|
+
- **`app`** – Path to the native boot bundle override; required for `applyUpdate()` to swap in the new build. Defaults to `path/to/Documents/pear-runtime/upgrades`
|
|
55
|
+
- **`updates`** – Set to `false` to disable P2P OTA updates.
|
|
56
|
+
- **`storage`** – Saves the app storage path.
|
|
48
57
|
|
|
49
|
-
#### `runtime.
|
|
58
|
+
#### `runtime.storage`
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
Suggested storage folder for app storage.
|
|
52
61
|
|
|
53
|
-
#### `runtime.
|
|
62
|
+
#### `await runtime.close()`
|
|
54
63
|
|
|
55
|
-
|
|
64
|
+
Shut it down. You should do this when closing your app for best performance.
|
|
56
65
|
|
|
57
|
-
|
|
66
|
+
## Making updates
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
VERY EXPERIMENTAL, MOST DEFINITELY WILL CHANGE.
|
|
60
69
|
|
|
61
|
-
|
|
70
|
+
Update listening and apply logic lives in [pear-runtime-updater](https://www.github.com/holepunchto/pear-runtime-updater).
|
|
62
71
|
|
|
63
|
-
|
|
72
|
+
First allocate a pear link if you haven't using [`pear`](https://github.com/holepunchto/pear):
|
|
64
73
|
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
```sh
|
|
75
|
+
pear touch
|
|
76
|
+
```
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
Store this link in the `package.json` `upgrade` field of a project. See [example](./example/package.json).
|
|
69
79
|
|
|
70
|
-
|
|
80
|
+
bundle your JS frontend. Take the distributable (e.g react-native bundle and assets) produced and make a deployment folder with the following structure:
|
|
71
81
|
|
|
72
|
-
|
|
82
|
+
```
|
|
83
|
+
/package.json
|
|
84
|
+
/by-arch
|
|
85
|
+
/[...platform-arch]
|
|
86
|
+
/app
|
|
87
|
+
```
|
|
73
88
|
|
|
74
|
-
|
|
89
|
+
Now go to this folder and stage this onto the link with `pear stage`
|
|
75
90
|
|
|
76
|
-
|
|
91
|
+
```sh
|
|
92
|
+
pear stage {link-from-touch}
|
|
93
|
+
```
|
|
77
94
|
|
|
78
|
-
|
|
95
|
+
Now seed it. Any build out there on a lower version will trigger the update flow.
|
|
79
96
|
|
|
80
97
|
## LICENSE
|
|
81
98
|
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const fs = require('bare-fs')
|
|
|
4
4
|
|
|
5
5
|
module.exports = class PearRuntime extends PearRuntimeUpdater {
|
|
6
6
|
constructor(opts = {}) {
|
|
7
|
-
const appPath = opts.app || path.join(opts.dir, 'pear-runtime
|
|
7
|
+
const appPath = opts.app || path.join(opts.dir, 'pear-runtime', 'upgrade')
|
|
8
8
|
if (!fs.existsSync(appPath)) fs.mkdirSync(appPath, { recursive: true, force: true })
|
|
9
9
|
if (fs.existsSync(path.join(appPath, 'package.json'))) {
|
|
10
10
|
const manifest = fs.readFileSync(path.join(appPath, 'package.json'))
|
|
@@ -12,5 +12,6 @@ module.exports = class PearRuntime extends PearRuntimeUpdater {
|
|
|
12
12
|
}
|
|
13
13
|
opts = { app: appPath, ...opts }
|
|
14
14
|
super(opts)
|
|
15
|
+
this.storage = opts.storage || path.join(this.dir, 'app-storage')
|
|
15
16
|
}
|
|
16
17
|
}
|