Add 20 Pear/Bare platform modules replacing deprecated pear run.
Introduces hyper-bare-entry-runner, pear-runtime embed/link/config stack, and scaffold helpers for argv, storage, OTA, Electron, and headless UI. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 0.0.0-scaffold
|
||||
|
||||
- Initial Pear platform module.
|
||||
@@ -0,0 +1,9 @@
|
||||
# hyper-pear-preflight-sync
|
||||
|
||||
**Protocol:** `pear-preflight-sync/v1`
|
||||
|
||||
Preflight asset warmup before app run. See [`docs/api.md`](docs/api.md).
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
# API: hyper-pear-preflight-sync
|
||||
|
||||
**Protocol:** `pear-preflight-sync/v1` · **Export:** `{ HyperPearPreflightSync, PROTOCOL }`
|
||||
|
||||
See [`index.js`](../index.js) for methods and `getStats()`.
|
||||
@@ -0,0 +1,3 @@
|
||||
# Architecture: hyper-pear-preflight-sync
|
||||
|
||||
Pear/Bare platform module. Replaces or complements deprecated `pear run` flows via embeddable `pear-runtime`.
|
||||
@@ -0,0 +1,9 @@
|
||||
require('bare-process/global')
|
||||
const { HyperPearPreflightSync } = require('../index.js')
|
||||
async function main () {
|
||||
const m = new HyperPearPreflightSync()
|
||||
await m.ready()
|
||||
console.log(m.getStats())
|
||||
await m.close()
|
||||
}
|
||||
main().catch((e) => { console.error(e); process.exit(1) })
|
||||
@@ -0,0 +1,62 @@
|
||||
require('bare-process/global')
|
||||
const EventEmitter = require('bare-events')
|
||||
const { assertId, platformStats } = require('../../_shared/pear-platform-base.js')
|
||||
|
||||
const PROTOCOL = 'pear-preflight-sync/v1'
|
||||
|
||||
class HyperPearPreflightSync extends EventEmitter {
|
||||
constructor (opts = {}) {
|
||||
super()
|
||||
this.warmupTimeoutMs = opts.warmupTimeoutMs ?? 30000
|
||||
this._jobs = new Map()
|
||||
this._stats = { started: 0, done: 0 }
|
||||
}
|
||||
|
||||
start (target, meta = {}) {
|
||||
const id = assertId(meta.id || String(Date.now()), 'id')
|
||||
const job = {
|
||||
id,
|
||||
target: String(target),
|
||||
status: 'syncing',
|
||||
assets: 0,
|
||||
startedAt: Date.now(),
|
||||
endedAt: null
|
||||
}
|
||||
this._jobs.set(id, job)
|
||||
this._stats.started++
|
||||
this.emit('start', job)
|
||||
return job
|
||||
}
|
||||
|
||||
recordAsset (id, name) {
|
||||
const job = this._jobs.get(assertId(id))
|
||||
if (!job) return false
|
||||
job.assets++
|
||||
this.emit('asset', { id, name })
|
||||
return true
|
||||
}
|
||||
|
||||
complete (id, ok = true) {
|
||||
const job = this._jobs.get(assertId(id))
|
||||
if (!job) return false
|
||||
job.status = ok ? 'ready' : 'failed'
|
||||
job.endedAt = Date.now()
|
||||
this._stats.done++
|
||||
this.emit('complete', job)
|
||||
return true
|
||||
}
|
||||
|
||||
isReady (id) {
|
||||
const job = this._jobs.get(assertId(id))
|
||||
return job ? job.status === 'ready' : false
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return platformStats(this._stats, PROTOCOL, { jobs: this._jobs.size })
|
||||
}
|
||||
|
||||
async ready () { return this }
|
||||
async close () { this._jobs.clear(); this.emit('closed') }
|
||||
}
|
||||
|
||||
module.exports = { HyperPearPreflightSync, HyperP2PPearPreflightSync: HyperPearPreflightSync, PROTOCOL }
|
||||
+1286
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "hyper-pear-preflight-sync",
|
||||
"version": "0.0.0-scaffold",
|
||||
"description": "Preflight asset warmup before app run.",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
"license": "Apache-2.0",
|
||||
"scripts": { "test": "brittle-bare test/test.js" },
|
||||
"dependencies": {
|
||||
"bare-events": "^2.8.0",
|
||||
"bare-process": "^4.4.0",
|
||||
"b4a": "^1.6.7",
|
||||
"hypercore-crypto": "^3.0.0"
|
||||
},
|
||||
"peerDependencies": { "bare": ">=1.0.0" },
|
||||
"devDependencies": { "brittle": "^3.0.0" },
|
||||
"imports": {
|
||||
"process": { "bare": "bare-process", "default": "process" },
|
||||
"events": { "bare": "bare-events", "default": "events" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperPearPreflightSync, PROTOCOL } = require('../index.js')
|
||||
|
||||
test('preflight job', async (t) => {
|
||||
const p = new HyperPearPreflightSync()
|
||||
const j = p.start('pear://app', { id: 'j1' })
|
||||
p.recordAsset('j1', 'a.js')
|
||||
t.ok(p.complete('j1'))
|
||||
t.ok(p.isReady('j1'))
|
||||
await p.close()
|
||||
})
|
||||
Reference in New Issue
Block a user