@zjy4fun/json-open 0.1.1 → 0.1.3
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 +8 -1
- package/README.zh-CN.md +7 -0
- package/bin/json.js +40 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,9 +107,16 @@ Input source:
|
|
|
107
107
|
- stdin (pipe)
|
|
108
108
|
- inline argument JSON string
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Options:
|
|
111
|
+
|
|
112
|
+
- `-h, --help` show help
|
|
113
|
+
- `-v, --version` show CLI version
|
|
114
|
+
|
|
115
|
+
Examples:
|
|
111
116
|
|
|
112
117
|
```bash
|
|
118
|
+
json --help
|
|
119
|
+
json --version
|
|
113
120
|
json '{"ok":true}'
|
|
114
121
|
```
|
|
115
122
|
|
package/README.zh-CN.md
CHANGED
package/bin/json.js
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from 'node:fs/promises'
|
|
3
|
+
import fsSync from 'node:fs'
|
|
3
4
|
import os from 'node:os'
|
|
4
5
|
import path from 'node:path'
|
|
5
6
|
import { spawn } from 'node:child_process'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
function getCliVersion() {
|
|
10
|
+
try {
|
|
11
|
+
const currentFile = fileURLToPath(import.meta.url)
|
|
12
|
+
const packageJsonPath = path.resolve(path.dirname(currentFile), '..', 'package.json')
|
|
13
|
+
const packageJson = JSON.parse(fsSync.readFileSync(packageJsonPath, 'utf8'))
|
|
14
|
+
return packageJson.version
|
|
15
|
+
} catch {
|
|
16
|
+
return 'unknown'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function printHelp() {
|
|
21
|
+
console.log(`json-open
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
json <json-string>
|
|
25
|
+
cat data.json | json
|
|
26
|
+
curl https://example.com/api | json
|
|
27
|
+
|
|
28
|
+
Options:
|
|
29
|
+
-h, --help Show help
|
|
30
|
+
-v, --version Show version`)
|
|
31
|
+
}
|
|
6
32
|
|
|
7
33
|
function readStdin() {
|
|
8
34
|
return new Promise((resolve, reject) => {
|
|
@@ -178,10 +204,22 @@ function openInBrowser(filePath) {
|
|
|
178
204
|
}
|
|
179
205
|
|
|
180
206
|
async function main() {
|
|
181
|
-
const
|
|
207
|
+
const args = process.argv.slice(2)
|
|
208
|
+
|
|
209
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
210
|
+
printHelp()
|
|
211
|
+
process.exit(0)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (args.includes('-v') || args.includes('--version')) {
|
|
215
|
+
console.log(getCliVersion())
|
|
216
|
+
process.exit(0)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const inlineInput = args.join(' ').trim()
|
|
182
220
|
|
|
183
221
|
if (!inlineInput && process.stdin.isTTY) {
|
|
184
|
-
|
|
222
|
+
printHelp()
|
|
185
223
|
process.exit(1)
|
|
186
224
|
}
|
|
187
225
|
|