pterm 0.0.23 → 0.0.24

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 +36 -0
  2. package/index.js +1 -1
  3. package/package.json +1 -1
  4. package/util.js +52 -0
package/README.md CHANGED
@@ -149,6 +149,42 @@ Launch a script directly with query parameters. Query parameters are passed thro
149
149
  pterm start 'run.js?mode=Default'
150
150
  ```
151
151
 
152
+ ## download
153
+
154
+ Clone an app repo into Pinokio's app directory without launching it.
155
+
156
+ ### syntax
157
+
158
+ ```
159
+ pterm download <uri> [name] [--branch=<branch>]
160
+ pterm download <uri> [name] -b <branch>
161
+ ```
162
+
163
+ - `uri`: required git repository URI
164
+ - `name`: (optional) target folder name under `PINOKIO_HOME/api`
165
+ - `--branch` / `-b`: (optional) clone a specific branch
166
+
167
+ Behavior:
168
+
169
+ - if `name` is omitted, Pinokio uses the same default destination folder naming as `git clone <uri>`
170
+ - if `name` is provided, Pinokio clones into `PINOKIO_HOME/api/<name>`
171
+ - if the target folder already exists, the command fails with `already exists`
172
+ - the command does not dedupe by repo URL
173
+
174
+ ### examples
175
+
176
+ ```
177
+ pterm download https://github.com/example/my-launcher.git
178
+ ```
179
+
180
+ ```
181
+ pterm download https://github.com/example/my-launcher.git my-launcher-dev
182
+ ```
183
+
184
+ ```
185
+ pterm download https://github.com/example/my-launcher.git my-launcher-dev --branch=feature-x
186
+ ```
187
+
152
188
  ## search
153
189
 
154
190
  Search installed or available apps.
package/index.js CHANGED
@@ -58,7 +58,7 @@ const isHttpUri = (value) => typeof value === "string" && /^https?:\/\//i.test(v
58
58
  } else if (cmd === "filepicker") {
59
59
  await util.filepicker(argv)
60
60
  } else if (cmd === "download") {
61
- await util.download(argv)
61
+ await util.appDownload(argv)
62
62
  } else if (cmd === "registry") {
63
63
  const subcmd = argv._.length > 1 ? String(argv._[1]).toLowerCase() : ""
64
64
  if (subcmd === "search") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pterm",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/util.js CHANGED
@@ -7,6 +7,13 @@ class Util {
7
7
  process.stdout.write(JSON.stringify(payload, null, 2))
8
8
  process.stdout.write("\n")
9
9
  }
10
+ formatRpcError(payload) {
11
+ if (typeof payload !== "string") {
12
+ return JSON.stringify(payload)
13
+ }
14
+ const [firstLine] = payload.split(/\r?\n/)
15
+ return firstLine || payload
16
+ }
10
17
  registryBase() {
11
18
  const value = String(process.env.PINOKIO_REGISTRY_API_BASE || "https://api.pinokio.co").trim()
12
19
  return value.replace(/\/$/, "")
@@ -249,6 +256,51 @@ class Util {
249
256
  let response = await axios.post("http://localhost:42000/go", { url })
250
257
  return response
251
258
  }
259
+ async appDownload(argv) {
260
+ if (argv._.length <= 1) {
261
+ console.error("required argument: <uri>")
262
+ process.exitCode = 1
263
+ return
264
+ }
265
+ const uri = String(argv._[1]).trim()
266
+ const name = argv._.length > 2 ? String(argv._[2]).trim() : ""
267
+ const branch = typeof argv.b === "string"
268
+ ? argv.b.trim()
269
+ : (typeof argv.branch === "string" ? argv.branch.trim() : "")
270
+ const rpc = new RPC("ws://localhost:42000")
271
+ let exitCode = 0
272
+ await rpc.run({
273
+ method: "app.download",
274
+ params: {
275
+ uri,
276
+ ...(name ? { name } : {}),
277
+ ...(branch ? { branch } : {})
278
+ }
279
+ }, (packet) => {
280
+ if (packet.type === "result") {
281
+ if (!packet.data || packet.data.ok === false) {
282
+ exitCode = 1
283
+ const message = packet.data && packet.data.error ? packet.data.error : "download failed"
284
+ if (packet.data && packet.data.path) {
285
+ console.error(`${message}: ${packet.data.path}`)
286
+ } else {
287
+ console.error(message)
288
+ }
289
+ }
290
+ rpc.close()
291
+ } else if (packet.type === "stream") {
292
+ process.stdout.write(packet.data.raw)
293
+ } else if (packet.type === "error") {
294
+ exitCode = 1
295
+ console.error(this.formatRpcError(packet.data))
296
+ rpc.close()
297
+ }
298
+ })
299
+ if (exitCode !== 0) {
300
+ process.exitCode = exitCode
301
+ }
302
+ }
303
+ // Keep the legacy URL download flow for `pterm run <url>`.
252
304
  async download(argv) {
253
305
  if (argv._.length > 1) {
254
306
  let uri = argv._[1]