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-bare-headless-ui
|
||||
|
||||
**Protocol:** `bare-headless-ui/v1`
|
||||
|
||||
Headless Pearend with optional UI worker. See [`docs/api.md`](docs/api.md).
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
# API: hyper-bare-headless-ui
|
||||
|
||||
**Protocol:** `bare-headless-ui/v1` · **Export:** `{ HyperBareHeadlessUi, PROTOCOL }`
|
||||
|
||||
See [`index.js`](../index.js) for methods and `getStats()`.
|
||||
@@ -0,0 +1,3 @@
|
||||
# Architecture: hyper-bare-headless-ui
|
||||
|
||||
Pear/Bare platform module. Replaces or complements deprecated `pear run` flows via embeddable `pear-runtime`.
|
||||
@@ -0,0 +1,9 @@
|
||||
require('bare-process/global')
|
||||
const { HyperBareHeadlessUi } = require('../index.js')
|
||||
async function main () {
|
||||
const m = new HyperBareHeadlessUi()
|
||||
await m.ready()
|
||||
console.log(m.getStats())
|
||||
await m.close()
|
||||
}
|
||||
main().catch((e) => { console.error(e); process.exit(1) })
|
||||
@@ -0,0 +1,84 @@
|
||||
require('bare-process/global')
|
||||
const EventEmitter = require('bare-events')
|
||||
const { assertId, platformStats } = require('../../_shared/pear-platform-base.js')
|
||||
|
||||
const PROTOCOL = 'bare-headless-ui/v1'
|
||||
|
||||
/**
|
||||
* Models Pear's headless Pearend + optional UI worker architecture
|
||||
* (entrypoint spawns UI over pipe when configured).
|
||||
*/
|
||||
class HyperBareHeadlessUi extends EventEmitter {
|
||||
constructor (opts = {}) {
|
||||
super()
|
||||
this.uiEnabled = opts.uiEnabled === true
|
||||
this._backend = null
|
||||
this._ui = null
|
||||
this._pipe = null
|
||||
this._stats = { starts: 0, uiSpawns: 0 }
|
||||
}
|
||||
|
||||
startBackend (entrypoint, meta = {}) {
|
||||
this._backend = {
|
||||
entrypoint: String(entrypoint),
|
||||
meta: meta || {},
|
||||
startedAt: Date.now(),
|
||||
role: 'pearend'
|
||||
}
|
||||
this._stats.starts++
|
||||
this.emit('backend', this._backend)
|
||||
return this._backend
|
||||
}
|
||||
|
||||
attachUi (uiEntry, opts = {}) {
|
||||
if (!this._backend) throw new Error('startBackend first')
|
||||
this._ui = {
|
||||
entrypoint: String(uiEntry),
|
||||
opts: opts || {},
|
||||
role: 'ui',
|
||||
spawnedAt: Date.now()
|
||||
}
|
||||
this._pipe = { id: String(Date.now()), open: true }
|
||||
this._stats.uiSpawns++
|
||||
this.emit('ui-spawn', { backend: this._backend.entrypoint, ui: this._ui.entrypoint })
|
||||
return { backend: this._backend, ui: this._ui, pipe: this._pipe }
|
||||
}
|
||||
|
||||
sendToUi (channel, payload) {
|
||||
if (!this._pipe || !this._pipe.open) return false
|
||||
this.emit('to-ui', { channel, payload })
|
||||
return true
|
||||
}
|
||||
|
||||
sendToBackend (channel, payload) {
|
||||
if (!this._pipe || !this._pipe.open) return false
|
||||
this.emit('to-backend', { channel, payload })
|
||||
return true
|
||||
}
|
||||
|
||||
teardown () {
|
||||
if (this._pipe) this._pipe.open = false
|
||||
this._ui = null
|
||||
this._backend = null
|
||||
this._pipe = null
|
||||
this.emit('teardown')
|
||||
}
|
||||
|
||||
snapshot () {
|
||||
return {
|
||||
uiEnabled: this.uiEnabled,
|
||||
backend: this._backend,
|
||||
ui: this._ui,
|
||||
pipeOpen: !!(this._pipe && this._pipe.open)
|
||||
}
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return platformStats(this._stats, PROTOCOL, this.snapshot())
|
||||
}
|
||||
|
||||
async ready () { return this }
|
||||
async close () { this.teardown(); this.emit('closed') }
|
||||
}
|
||||
|
||||
module.exports = { HyperBareHeadlessUi, HyperP2PBareHeadlessUi: HyperBareHeadlessUi, PROTOCOL }
|
||||
+1286
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "hyper-bare-headless-ui",
|
||||
"version": "0.0.0-scaffold",
|
||||
"description": "Headless Pearend with optional UI worker.",
|
||||
"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 { HyperBareHeadlessUi } = require('../index.js')
|
||||
|
||||
test('backend and ui pipe', async (t) => {
|
||||
const h = new HyperBareHeadlessUi({ uiEnabled: true })
|
||||
h.startBackend('index.js')
|
||||
h.attachUi('ui.js')
|
||||
t.ok(h.sendToUi('ready', {}))
|
||||
h.teardown()
|
||||
await h.close()
|
||||
})
|
||||
Reference in New Issue
Block a user