pear-electron 1.0.2 → 1.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 (2) hide show
  1. package/bin.js +25 -10
  2. package/package.json +3 -4
package/bin.js CHANGED
@@ -1,28 +1,44 @@
1
1
  #!/usr/bin/env pear
2
- /* global Pear, Bare */
2
+ /* global Pear */
3
3
 
4
4
  if (!global.Pear && global.process) {
5
- const { status } = require('child_process').spawnSync('pear', process.argv.slice(1), { stdio: 'inherit' })
5
+ const { status } = require('child_process').spawnSync('pear', process.argv.slice(1), { stdio: 'inherit', shell: true })
6
6
  process.exit(status)
7
7
  }
8
8
 
9
9
  const path = require('path')
10
- const { runtimes } = global.Pear.config.entrypoint.startsWith('/node_modules/.bin/')
11
- ? require('../pear-electron/package.json').pear
12
- : require('./package.json').pear
10
+ const inDotBin = global.Pear.config.entrypoint.startsWith('/node_modules/.bin/')
11
+ const { runtimes } = inDotBin ? require('../pear-electron/package.json').pear : require('./package.json').pear
13
12
  const IPC = require('pear-ipc')
14
13
  const { encode } = require('hypercore-id-encoding')
15
14
  const { PLATFORM_LOCK, SOCKET_PATH, CONNECT_TIMEOUT } = require('pear-api/constants')
16
15
  const tryboot = require('pear-api/tryboot')
17
16
  const link = require('pear-link')()
17
+ const byteSize = require('tiny-byte-size')
18
+ const { outputter, ansi } = require('pear-api/terminal')
19
+
20
+ const output = outputter('dump', {
21
+ dumping: ({ link, dir, list }) => list > -1 ? '' : `\n${ansi.pear} Bootstrapping pear-electron runtimes from peers\n\nfrom: ${link}\ninto: ${dir}\n`,
22
+ file: ({ key, value }) => `${key}${value ? '\n' + value : ''}`,
23
+ complete: () => '\x1b[1A\nBootstrap complete\n',
24
+ stats ({ upload, download, peers }) {
25
+ const dl = download.total + download.speed === 0 ? '' : `[⬇ ${byteSize(download.total)} - ${byteSize(download.speed)}/s ]`
26
+ const ul = upload.total + upload.speed === 0 ? '' : `[⬆ ${byteSize(upload.total)} - ${byteSize(upload.speed)}/s ]`
27
+ return {
28
+ output: 'status',
29
+ message: `${dl} ${ul} [ Peers: ${peers} ]`
30
+ }
31
+ },
32
+ error: (err) => `Bootstrap Failure (code: ${err.code || 'none'}) ${err.stack}`
33
+ })
18
34
 
19
35
  async function pearElectron () {
20
36
  const { protocol, drive } = link(runtimes)
21
-
37
+ const root = new URL(Pear.config.applink).pathname
22
38
  const opts = {
23
- id: Bare.pid,
39
+ id: Pear.pid,
24
40
  link: protocol + '//' + encode(drive.key) + '/by-arch/',
25
- dir: path.join(new URL(Pear.config.applink).pathname, 'node_modules', 'pear-electron'),
41
+ dir: inDotBin ? path.join(root, 'node_modules', 'pear-electron') : root,
26
42
  // checkout: drive.length,
27
43
  force: true
28
44
 
@@ -34,8 +50,7 @@ async function pearElectron () {
34
50
  connect: tryboot
35
51
  })
36
52
  await ipc.ready()
37
- const stream = ipc.dump(opts)
38
- for await (const output of stream) console.log(output)
53
+ await output(false, ipc.dump(opts))
39
54
  await ipc.close()
40
55
  }
41
56
 
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "pear-electron",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Pear User-Interface Library for Electron",
5
5
  "main": "index.js",
6
6
  "bin": "bin.js",
7
7
  "scripts": {
8
- "archdump": "node scripts/bootstrap.js --archdump",
9
- "bootstrap": "node scripts/bootstrap.js",
8
+ "bootstrap": "pear run bin.js",
10
9
  "decal": "node scripts/decal.js",
11
10
  "bundle": "node scripts/bundle.js",
12
11
  "generate": "npm run decal && npm run bundle",
@@ -81,7 +80,7 @@
81
80
  "node-bare-bundle": "^1.4.2",
82
81
  "paparam": "^1.6.1",
83
82
  "path": "npm:bare-node-path@^1.0.1",
84
- "pear-api": "^1.1.1",
83
+ "pear-api": "^1.2.2",
85
84
  "pear-interface": "^1.0.3",
86
85
  "pear-ipc": "^3.2.0",
87
86
  "pear-link": "^2.0.6",