Skip to content

Commit 7d69362

Browse files
committed
feat: print public API to make tunnel experience easier
1 parent 47d176a commit 7d69362

File tree

3 files changed

+209
-9
lines changed

3 files changed

+209
-9
lines changed

packages/slidev/node/cli.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ cli.command(
161161
console.log(yellow('\n --remote is required for tunneling, localtunnel is not enabled.\n'))
162162
}
163163

164-
lastRemoteUrl = printInfo(options, port, remote, tunnelUrl)
164+
let publicIp: string | undefined
165+
if (remote)
166+
publicIp = await import('public-ip').then(r => r.publicIpv4())
167+
168+
lastRemoteUrl = printInfo(options, port, remote, tunnelUrl, publicIp)
165169
}
166170

167171
async function openTunnel(port: number) {
@@ -214,10 +218,13 @@ cli.command(
214218
if (!lastRemoteUrl)
215219
return
216220
await import('uqr')
217-
.then((r) => {
221+
.then(async (r) => {
218222
const code = r.renderUnicodeCompact(lastRemoteUrl!)
219223
console.log(`\n${dim(' QR Code for remote control: ')}\n ${blue(lastRemoteUrl!)}\n`)
220224
console.log(code.split('\n').map(i => ` ${i}`).join('\n'))
225+
const publicIp = await import('public-ip').then(r => r.publicIpv4())
226+
if (publicIp)
227+
console.log(`\n${dim(' Public IP: ')} ${blue(publicIp)}\n`)
221228
})
222229
},
223230
},
@@ -524,7 +531,13 @@ function exportOptions<T>(args: Argv<T>) {
524531
})
525532
}
526533

527-
function printInfo(options: ResolvedSlidevOptions, port?: number, remote?: string, tunnelUrl?: string) {
534+
function printInfo(
535+
options: ResolvedSlidevOptions,
536+
port?: number,
537+
remote?: string,
538+
tunnelUrl?: string,
539+
publicIp?: string,
540+
) {
528541
console.log()
529542
console.log()
530543
console.log(` ${cyan('●') + blue('■') + yellow('▲')}`)
@@ -560,6 +573,11 @@ function printInfo(options: ResolvedSlidevOptions, port?: number, remote?: strin
560573
console.log(`${dim(' remote control ')} > ${blue(lastRemoteUrl)}`)
561574
}))
562575

576+
if (publicIp) {
577+
lastRemoteUrl = `http://${publicIp}:${port}${entryPath}`
578+
console.log(`${dim(' remote control ')} > ${blue(lastRemoteUrl)}`)
579+
}
580+
563581
if (tunnelUrl) {
564582
lastRemoteUrl = `${tunnelUrl}${entryPath}`
565583
console.log(`${dim(' remote via tunnel')} > ${yellow(lastRemoteUrl)}`)

packages/slidev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"postcss-nested": "^6.0.1",
9191
"prismjs": "^1.29.0",
9292
"prompts": "^2.4.2",
93+
"public-ip": "^6.0.1",
9394
"resolve": "^1.22.8",
9495
"resolve-from": "^5.0.0",
9596
"resolve-global": "^1.0.0",

0 commit comments

Comments
 (0)