poloczek 0.0.1
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 +0 -0
- package/bin/cli.js +87 -0
- package/package.json +27 -0
package/README.md
ADDED
|
File without changes
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// poloczek — a tiny "family TLD" CLI.
|
|
3
|
+
//
|
|
4
|
+
// npx poloczek list the family and how to call it
|
|
5
|
+
// npx poloczek <name> open that family member's page in your browser
|
|
6
|
+
//
|
|
7
|
+
// Add a relative by dropping another entry into MEMBERS below.
|
|
8
|
+
|
|
9
|
+
import { spawn } from 'node:child_process'
|
|
10
|
+
|
|
11
|
+
const MEMBERS = {
|
|
12
|
+
philip: { name: 'Philip', url: 'https://peetzweg.com' },
|
|
13
|
+
jendrik: { name: 'Jendrik', url: 'https://madewithtea.com' },
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Open a URL in the user's default browser, cross-platform.
|
|
17
|
+
function openURL(url) {
|
|
18
|
+
const platform = process.platform
|
|
19
|
+
let cmd, args
|
|
20
|
+
if (platform === 'darwin') {
|
|
21
|
+
cmd = 'open'
|
|
22
|
+
args = [url]
|
|
23
|
+
} else if (platform === 'win32') {
|
|
24
|
+
// `start` is a cmd builtin; the empty "" is the window-title placeholder.
|
|
25
|
+
cmd = 'cmd'
|
|
26
|
+
args = ['/c', 'start', '', url]
|
|
27
|
+
} else {
|
|
28
|
+
cmd = 'xdg-open'
|
|
29
|
+
args = [url]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const child = spawn(cmd, args, { stdio: 'ignore', detached: true })
|
|
33
|
+
child.on('error', () => {
|
|
34
|
+
console.error(`Couldn't launch a browser. Open this yourself:\n ${url}`)
|
|
35
|
+
process.exitCode = 1
|
|
36
|
+
})
|
|
37
|
+
child.unref()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const B = '\x1b[1m'
|
|
41
|
+
const DIM = '\x1b[2m'
|
|
42
|
+
const CYAN = '\x1b[36m'
|
|
43
|
+
const R = '\x1b[0m'
|
|
44
|
+
const color = process.stdout.isTTY
|
|
45
|
+
|
|
46
|
+
function paint(code, s) {
|
|
47
|
+
return color ? code + s + R : s
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function printHelp() {
|
|
51
|
+
const names = Object.keys(MEMBERS)
|
|
52
|
+
const pad = Math.max(...names.map((n) => n.length))
|
|
53
|
+
|
|
54
|
+
console.log('')
|
|
55
|
+
console.log(paint(B, 'poloczek') + ' — the Poloczek family CLI')
|
|
56
|
+
console.log('')
|
|
57
|
+
console.log(paint(DIM, 'Usage:'))
|
|
58
|
+
console.log(` npx poloczek ${paint(CYAN, '<name>')} open that family member's page`)
|
|
59
|
+
console.log(' npx poloczek show this help')
|
|
60
|
+
console.log('')
|
|
61
|
+
console.log(paint(DIM, 'Family:'))
|
|
62
|
+
for (const key of names) {
|
|
63
|
+
const m = MEMBERS[key]
|
|
64
|
+
console.log(
|
|
65
|
+
` ${paint(CYAN, key.padEnd(pad))} ${m.name} ${paint(DIM, '→ ' + m.url)}`,
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
console.log('')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const arg = (process.argv[2] || '').toLowerCase().replace(/^-+/, '')
|
|
72
|
+
|
|
73
|
+
if (!arg || arg === 'help' || arg === 'h') {
|
|
74
|
+
printHelp()
|
|
75
|
+
process.exit(0)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const member = MEMBERS[arg]
|
|
79
|
+
if (!member) {
|
|
80
|
+
console.error(`Unknown family member: ${paint(B, arg)}`)
|
|
81
|
+
console.error(`Known: ${Object.keys(MEMBERS).join(', ')}`)
|
|
82
|
+
console.error('Run `npx poloczek` to see the list.')
|
|
83
|
+
process.exit(1)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(`Opening ${paint(B, member.name)} → ${member.url}`)
|
|
87
|
+
openURL(member.url)
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "poloczek",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The Poloczek family CLI — `npx poloczek <name>` opens that family member's page.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"poloczek": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "peetzweg",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/peetzweg/poloczek.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/peetzweg/poloczek/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/peetzweg/poloczek#readme",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"poloczek",
|
|
24
|
+
"family",
|
|
25
|
+
"cli"
|
|
26
|
+
]
|
|
27
|
+
}
|