pear-install 1.0.5 → 1.0.6

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 (4) hide show
  1. package/README.md +8 -2
  2. package/bin.js +2 -16
  3. package/cmd.js +17 -0
  4. package/package.json +3 -2
package/README.md CHANGED
@@ -72,7 +72,7 @@ await corestore.close()
72
72
  - `stats` → `{ download, upload, peers }`
73
73
  - `final` → `{ success, installed, exists }`
74
74
 
75
- ## CMD
75
+ ## Command Integration: `/cmd`
76
76
 
77
77
  For embedding in another CLI. Wraps `Install` as a `pear-opstream` of `{ tag, data }` records with stdout formatters.
78
78
 
@@ -91,7 +91,7 @@ await InstallCmd.output(json, stream)
91
91
  - `error` → `{ code, message, stack, info, success: false }`
92
92
  - `final` → `{ success, installed, exists }`
93
93
 
94
- ### `InstallCmd.output(json, stream)`
94
+ ### `await InstallCmd.output(json, stream)`
95
95
 
96
96
  Drains `stream` to STDOUT.
97
97
 
@@ -100,6 +100,12 @@ Drains `stream` to STDOUT.
100
100
 
101
101
  Returns the `final` record.
102
102
 
103
+ ### `await InstallCmd.runner(cmd)`
104
+
105
+ Pass directly as a [paparam](https://github.com/holepunchto/paparam) command runner. Creates `InstallCmd` instance and passes it to `InstallCmd.output`
106
+
107
+ - `cmd` is a [paparam](https://github.com/holepunchto/paparam) `cmd` instance
108
+
103
109
  ## License
104
110
 
105
111
  Apache-2.0
package/bin.js CHANGED
@@ -2,26 +2,12 @@
2
2
  const pkg = require('./package.json')
3
3
  const { isWindows } = require('which-runtime')
4
4
  const { command, arg, bail } = require('paparam')
5
- const InstallCmd = require('./cmd')
5
+ const { runner } = require('./cmd')
6
6
 
7
7
  const program = command(
8
8
  'install',
9
9
  arg('[link]', 'Pear link origin to install from'),
10
- async (cmd) => {
11
- const { json, only, to, dhtBootstrap } = cmd.flags
12
- const timeout = (cmd.flags.timeout || 30) * 1000
13
- const link = cmd.args.link ?? pkg.pear.platform.key
14
- const bootstrap = dhtBootstrap
15
- ? dhtBootstrap.split(',').map((tuple) => {
16
- const [host, port] = tuple.split(':')
17
- const int = +port
18
- if (Number.isInteger(int) === false) throw new Error(`Invalid port: ${port}`)
19
- return { host, port: int }
20
- })
21
- : undefined
22
- const stream = new InstallCmd({ link, only, to, bootstrap, timeout })
23
- await InstallCmd.output(json, stream)
24
- },
10
+ runner,
25
11
  pkg.command,
26
12
  bail((info = {}) => {
27
13
  process.exitCode = 1
package/cmd.js CHANGED
@@ -3,6 +3,7 @@ const process = require('process')
3
3
  const Opstream = require('pear-opstream')
4
4
  const byteSize = require('tiny-byte-size')
5
5
  const { isWindows } = require('which-runtime')
6
+ const pkg = require('./package.json')
6
7
  const Install = require('.')
7
8
 
8
9
  const down = isWindows ? '↓' : '⬇'
@@ -46,6 +47,22 @@ class InstallCmd extends Opstream {
46
47
  }
47
48
  }
48
49
 
50
+ static async runner(cmd) {
51
+ const { json, only, to, dhtBootstrap } = cmd.flags
52
+ const timeout = (cmd.flags.timeout || 30) * 1000
53
+ const link = cmd.args.link ?? pkg.pear.platform.key
54
+ const bootstrap = dhtBootstrap
55
+ ? dhtBootstrap.split(',').map((tuple) => {
56
+ const [host, port] = tuple.split(':')
57
+ const int = +port
58
+ if (Number.isInteger(int) === false) throw new Error(`Invalid port: ${port}`)
59
+ return { host, port: int }
60
+ })
61
+ : undefined
62
+ const stream = new InstallCmd({ link, only, to, bootstrap, timeout })
63
+ await InstallCmd.output(json, stream)
64
+ }
65
+
49
66
  constructor(params) {
50
67
  super((...args) => this.#op(...args), params)
51
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-install",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "type": "commonjs",
6
6
  "description": "Install Pear and Pear Applications",
@@ -12,7 +12,8 @@
12
12
  "bin": "bin.js",
13
13
  "exports": {
14
14
  ".": "./index.js",
15
- "./cmd": "./cmd.js"
15
+ "./cmd": "./cmd.js",
16
+ "./package.json": "./package.json"
16
17
  },
17
18
  "imports": {
18
19
  "process": {