pterm 0.0.13 → 0.0.15
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.
- package/README.md +1 -0
- package/index.js +21 -9
- package/package.json +1 -1
- package/util.js +52 -1
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ pterm version <type>
|
|
|
24
24
|
- `terminal`: returns the pterm version
|
|
25
25
|
- `pinokiod`: returns the pinokiod version
|
|
26
26
|
- `pinokio`: returns the pinokio version
|
|
27
|
+
- `script`: returns the valid script version for the current client. used for including in `pinokio.js`
|
|
27
28
|
|
|
28
29
|
### example
|
|
29
30
|
|
package/index.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const yargs = require('yargs/yargs')
|
|
4
4
|
const { hideBin } = require('yargs/helpers')
|
|
5
|
+
const argv = yargs(hideBin(process.argv)).parse();
|
|
5
6
|
const Script = require('./script')
|
|
6
7
|
const Util = require('./util')
|
|
7
|
-
const argv = yargs(hideBin(process.argv)).parse();
|
|
8
8
|
const script = new Script();
|
|
9
9
|
const util = new Util();
|
|
10
|
+
const isHttpUri = (value) => typeof value === "string" && /^https?:\/\//i.test(value);
|
|
10
11
|
(async () => {
|
|
11
12
|
if (argv._.length > 0) {
|
|
12
13
|
let cmd = argv._[0].toLowerCase()
|
|
@@ -53,6 +54,12 @@ const util = new Util();
|
|
|
53
54
|
await util.filepicker(argv)
|
|
54
55
|
} else if (cmd === "download") {
|
|
55
56
|
await util.download(argv)
|
|
57
|
+
} else if (cmd === "search") {
|
|
58
|
+
await util.search(argv)
|
|
59
|
+
} else if (cmd === "status") {
|
|
60
|
+
await util.status(argv)
|
|
61
|
+
} else if (cmd === "logs") {
|
|
62
|
+
await util.logs(argv)
|
|
56
63
|
} else if (cmd === "stop") {
|
|
57
64
|
await script.stop(argv)
|
|
58
65
|
} else if (cmd === "start") {
|
|
@@ -65,12 +72,13 @@ const util = new Util();
|
|
|
65
72
|
} else if (cmd === "run") {
|
|
66
73
|
if (argv._.length > 1) {
|
|
67
74
|
let _uri = argv._[1]
|
|
68
|
-
const uri = path.resolve(process.cwd(), _uri)
|
|
75
|
+
const uri = isHttpUri(_uri) ? _uri : path.resolve(process.cwd(), _uri)
|
|
69
76
|
// try downloading first
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
if (isHttpUri(uri)) {
|
|
78
|
+
await util.download({
|
|
79
|
+
...argv,
|
|
80
|
+
no_exit: true
|
|
81
|
+
})
|
|
74
82
|
}
|
|
75
83
|
while(true) {
|
|
76
84
|
let default_uri = await script.default_script(uri)
|
|
@@ -87,9 +95,13 @@ const util = new Util();
|
|
|
87
95
|
break
|
|
88
96
|
}
|
|
89
97
|
} else {
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
// default behavior is no browser side effect.
|
|
99
|
+
if (argv.open) {
|
|
100
|
+
let response = await util.open_url(default_uri)
|
|
101
|
+
console.log({ response })
|
|
102
|
+
} else {
|
|
103
|
+
console.log(default_uri)
|
|
104
|
+
}
|
|
93
105
|
break
|
|
94
106
|
}
|
|
95
107
|
} else {
|
package/package.json
CHANGED
package/util.js
CHANGED
|
@@ -3,6 +3,55 @@ const axios = require('axios')
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
const RPC = require('./rpc')
|
|
5
5
|
class Util {
|
|
6
|
+
printJson(payload) {
|
|
7
|
+
process.stdout.write(JSON.stringify(payload, null, 2))
|
|
8
|
+
process.stdout.write("\n")
|
|
9
|
+
}
|
|
10
|
+
async search(argv) {
|
|
11
|
+
const query = (argv._.slice(1).join(" ") || argv.q || "").trim()
|
|
12
|
+
const response = await axios.get("http://localhost:42000/apps/search", {
|
|
13
|
+
params: { q: query }
|
|
14
|
+
})
|
|
15
|
+
this.printJson(response.data)
|
|
16
|
+
}
|
|
17
|
+
async status(argv) {
|
|
18
|
+
if (argv._.length <= 1) {
|
|
19
|
+
console.error("required argument: <app_id>")
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
const appId = argv._[1]
|
|
23
|
+
const probe = argv.probe ? "1" : "0"
|
|
24
|
+
const timeout = argv.timeout ? Number.parseInt(String(argv.timeout), 10) : null
|
|
25
|
+
const params = new URLSearchParams()
|
|
26
|
+
params.set("probe", probe)
|
|
27
|
+
if (Number.isFinite(timeout) && timeout > 0) {
|
|
28
|
+
params.set("timeout", String(timeout))
|
|
29
|
+
}
|
|
30
|
+
const url = `http://localhost:42000/apps/status/${encodeURIComponent(appId)}?${params.toString()}`
|
|
31
|
+
const response = await axios.get(url)
|
|
32
|
+
this.printJson(response.data)
|
|
33
|
+
}
|
|
34
|
+
async logs(argv) {
|
|
35
|
+
if (argv._.length <= 1) {
|
|
36
|
+
console.error("required argument: <app_id>")
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const appId = argv._[1]
|
|
40
|
+
const params = new URLSearchParams()
|
|
41
|
+
if (argv.script) {
|
|
42
|
+
params.set("script", String(argv.script))
|
|
43
|
+
}
|
|
44
|
+
if (argv.tail) {
|
|
45
|
+
const tail = Number.parseInt(String(argv.tail), 10)
|
|
46
|
+
if (Number.isFinite(tail) && tail > 0) {
|
|
47
|
+
params.set("tail", String(tail))
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const suffix = params.toString() ? `?${params.toString()}` : ""
|
|
51
|
+
const url = `http://localhost:42000/apps/logs/${encodeURIComponent(appId)}${suffix}`
|
|
52
|
+
const response = await axios.get(url)
|
|
53
|
+
this.printJson(response.data)
|
|
54
|
+
}
|
|
6
55
|
async filepicker(argv) {
|
|
7
56
|
const rpc = new RPC("ws://localhost:42000")
|
|
8
57
|
if (argv.path) {
|
|
@@ -104,7 +153,9 @@ class Util {
|
|
|
104
153
|
}
|
|
105
154
|
})
|
|
106
155
|
}
|
|
107
|
-
|
|
156
|
+
if (!argv.no_exit) {
|
|
157
|
+
process.exit()
|
|
158
|
+
}
|
|
108
159
|
} else {
|
|
109
160
|
console.error("required argument: <uri>")
|
|
110
161
|
}
|