pear-mobile 0.0.2 → 0.0.4

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.
Files changed (3) hide show
  1. package/README.md +77 -36
  2. package/index.js +4 -1
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -6,76 +6,117 @@ Embeddable Pear runtime for mobile applications. Provides storage path and bare
6
6
  npm install pear-mobile
7
7
  ```
8
8
 
9
- ```sh
10
- npm install react-native-bare-kit --save
11
- ```
9
+ This module integrates Pear into React-Native-based Mobile applications.
12
10
 
13
- Requires `react-native-bare-kit` to be listed in project dependencies.
11
+ See [pear-runtime](https://github.com/holepunchto/pear-runtime) for Pear's embeddable runtime module for Desktop Devices.
14
12
 
15
- ## Usage
13
+ ## MVP - EXPERIMENTAL
16
14
 
17
- ```js
18
- /* React Native */
19
- import PearRuntime from 'pear-mobile'
20
- import bundle from './worker.bundle.js'
21
- import { version, upgrade } from './package.json'
15
+ This boilerplate is MVP and Experimental.
22
16
 
23
- const runtime = new PearRuntime()
24
- const IPC = runtime.run('/worker.bundle', bundle, [runtime.dir])
17
+ ## Usage
25
18
 
26
- /* Bare Worklet */
27
- const PearRuntime = require('pear-runtime')
19
+ ```js
20
+ const PearRuntime = require('pear-mobile')
28
21
  const { version, upgrade } = require('./package.json')
29
22
 
30
- const dir = Bare.argv[0]
23
+ const dir = Bare.argv[0] // pass the /Documents storage dir
31
24
 
32
25
  const runtime = new PearRuntime({ version, upgrade, dir })
33
- runtime.on('updated', () => {
34
- runtime.applyUpdate()
26
+ runtime.on('updated', async () => {
27
+ await runtime.applyUpdate()
35
28
  conosle.log('restart for update')
36
29
  })
37
30
  ```
38
31
 
32
+ ## Quick Starts
33
+
34
+ ### Expo
35
+
36
+ ```sh
37
+ git clone https://github.com/holepunchto/hello-pear-react-native
38
+ ```
39
+
40
+ 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`.
41
+
42
+ ## Features
43
+
44
+ - Peer-to-Peer Over-the-Air (P2P OTA) updates (via [pear-runtime-updater](https://www.github.com/holepunchto/pear-runtime-updater))
45
+ - Application storage management
46
+
39
47
  ## API
40
48
 
41
- #### `const runtime = new PearRuntime(...)`
49
+ Inherits from [pear-runtime-updater]{https://www.github.com/holepunchto/pear-runtime-updater}
50
+
51
+ #### `const runtime = new PearRuntime(opts)`
42
52
 
43
- Create a runtime.
53
+ Create a runtime. `opts` may include:
54
+
55
+ - **`dir`** (required) Directory to store data (e.g. app data dir).
56
+ - **`upgrade`** – (required) Pear link for OTA updates (e.g. from `package.json` `upgrade` field).
57
+ - **`version`** – Current app version (e.g. from `package.json`); used for update checks.
58
+ - **`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`
59
+ - **`updates`** – Set to `false` to disable P2P OTA updates.
60
+ - **`storage`** – Saves the app storage path.
44
61
 
45
62
  #### `runtime.storage`
46
63
 
47
- Absolute path to the runtime app storage directory.
64
+ Suggested storage folder for app storage.
65
+
66
+ #### `pear.storage`
67
+
68
+ Suggested storage folder for app storage.
69
+
70
+ #### `pear.on('updating')`
48
71
 
49
- #### `runtime.on(event, callback)`
72
+ Emitted when an update is in progress
50
73
 
51
- Subscribe to an event. Returns `runtime` for chaining.
74
+ #### `updater.on('updating-delta', data)`
52
75
 
53
- #### `runtime.off(event, callback?)`
76
+ Emitted with progress data while mirroring the update.
54
77
 
55
- Unsubscribe: remove `callback` for `event`, or remove all listeners for `event` if `callback` is omitted. Returns `runtime`.
78
+ #### `pear.on('updated')`
56
79
 
57
- #### `runtime.once(event, callback)`
80
+ Emitted when an update is done
58
81
 
59
- Subscribe to an event once; listener is removed after the first emit. Returns `runtime`.
82
+ #### `await pear.applyUpdate()`
60
83
 
61
- #### `const IPC <stream.Duplex> = runtime.run(filename, bundle, argv)`
84
+ Apply the update. Only valid post `updated`. On next app restart the new update is in effect.
62
85
 
63
- Start a bare worker (worklet). Returns an IPC duplex stream. `filename` is a virtual path, `bundle` is the worklet bundle, `argv` is an array of string arguments.
86
+ #### `await pear.close()`
64
87
 
65
- `Bare.argv` in worker to access `argv`.
66
- `Bare.IPC` in worker to access stream.
88
+ Shut it down. You should do this when closing your app for best performance.
67
89
 
68
- #### `runtime.ready()`
90
+ ## Making updates
69
91
 
70
- Returns a Promise. No-op on mobile; for API compatibility.
92
+ VERY EXPERIMENTAL, MOST DEFINITELY WILL CHANGE.
71
93
 
72
- #### `runtime.close()`
94
+ Update listening and apply logic lives in [pear-runtime-updater](https://www.github.com/holepunchto/pear-runtime-updater).
95
+
96
+ First allocate a pear link if you haven't using [`pear`](https://github.com/holepunchto/pear):
97
+
98
+ ```sh
99
+ pear touch
100
+ ```
73
101
 
74
- Returns a Promise. No-op on mobile; for API compatibility.
102
+ Store this link in the `package.json` `upgrade` field of a project.
75
103
 
76
- #### `runtime.applyUpdate()`
104
+ bundle your JS frontend. Take the distributable (e.g react-native bundle and assets) produced and make a deployment folder with the following structure:
105
+
106
+ ```
107
+ /package.json
108
+ /by-arch
109
+ /[...platform-arch]
110
+ /app
111
+ ```
112
+
113
+ Now go to this folder and stage this onto the link with `pear stage`
114
+
115
+ ```sh
116
+ pear stage {link-from-touch}
117
+ ```
77
118
 
78
- Returns a Promise. On mobile this is not supported and only logs a warning; for API compatibility.
119
+ Now seed it. Any build out there on a lower version will trigger the update flow.
79
120
 
80
121
  ## LICENSE
81
122
 
package/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  const PearRuntimeUpdater = require('pear-runtime-updater')
2
2
  const path = require('bare-path')
3
3
  const fs = require('bare-fs')
4
+ const dir = require('bare-storage')
4
5
 
5
6
  module.exports = class PearRuntime extends PearRuntimeUpdater {
6
7
  constructor(opts = {}) {
7
- const appPath = opts.app || path.join(opts.dir, 'pear-runtime/upgrade')
8
+ if (!opts.dir) opts.dir = dir.persistent()
9
+ const appPath = opts.app || path.join(opts.dir, 'pear-runtime', 'upgrade')
8
10
  if (!fs.existsSync(appPath)) fs.mkdirSync(appPath, { recursive: true, force: true })
9
11
  if (fs.existsSync(path.join(appPath, 'package.json'))) {
10
12
  const manifest = fs.readFileSync(path.join(appPath, 'package.json'))
@@ -12,5 +14,6 @@ module.exports = class PearRuntime extends PearRuntimeUpdater {
12
14
  }
13
15
  opts = { app: appPath, ...opts }
14
16
  super(opts)
17
+ this.storage = opts.storage || path.join(this.dir, 'app-storage')
15
18
  }
16
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-mobile",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Embeddable Pear runtime for mobile applications",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -40,6 +40,7 @@
40
40
  "dependencies": {
41
41
  "bare-fs": "^4.5.4",
42
42
  "bare-path": "^3.0.0",
43
- "pear-runtime-updater": "^0.0.10"
43
+ "bare-storage": "^1.0.1",
44
+ "pear-runtime-updater": "^0.0.11"
44
45
  }
45
46
  }