feat: add easy-slides CLI
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'dotenv/config'
|
||||
import { networkInterfaces } from 'node:os'
|
||||
import qrcode from 'qrcode-terminal'
|
||||
import { loadProjectConfig } from './lib/config.ts'
|
||||
import { resolveDeck } from './lib/content.ts'
|
||||
import { runSlidev } from './lib/run-slidev.ts'
|
||||
import { resolveTheme } from './lib/theme.ts'
|
||||
|
||||
const input = process.argv.slice(2).find(argument => !argument.startsWith('-'))
|
||||
const config = await loadProjectConfig()
|
||||
const deck = await resolveDeck(input, process.cwd(), config.slidesDir)
|
||||
const port = process.env.PORT || '3030'
|
||||
const address = firstLanAddress()
|
||||
const remoteToken = process.env.SLIDEV_REMOTE_TOKEN || 'easy-slides-local'
|
||||
const remotePassword = encodeURIComponent(remoteToken)
|
||||
const presenterUrl = `http://${address}:${port}/presenter/?password=${remotePassword}`
|
||||
const remoteUrl = `http://${address}:${port}/entry?password=${remotePassword}`
|
||||
|
||||
console.log(`\n观众视图:http://${address}:${port}/`)
|
||||
console.log(`演示者视图:${presenterUrl}`)
|
||||
console.log(`手机遥控器:${remoteUrl}`)
|
||||
qrcode.generate(presenterUrl, { small: true })
|
||||
|
||||
await runSlidev([
|
||||
deck.entry,
|
||||
'--theme',
|
||||
resolveTheme(config.theme),
|
||||
'--port',
|
||||
port,
|
||||
'--remote',
|
||||
remoteToken,
|
||||
'--bind',
|
||||
'0.0.0.0',
|
||||
])
|
||||
|
||||
function firstLanAddress() {
|
||||
for (const entries of Object.values(networkInterfaces())) {
|
||||
for (const entry of entries ?? []) {
|
||||
if (entry.family === 'IPv4' && !entry.internal)
|
||||
return entry.address
|
||||
}
|
||||
}
|
||||
return 'localhost'
|
||||
}
|
||||
Reference in New Issue
Block a user