You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vitepress/bin/vitepress.js

45 lines
1.2 KiB

5 years ago
#!/usr/bin/env node
5 years ago
const chalk = require('chalk')
const argv = require('minimist')(process.argv.slice(2))
console.log(chalk.cyan(`vitepress v${require('../package.json').version}`))
5 years ago
console.log(chalk.cyan(`vite v${require('vite/package.json').version}`))
5 years ago
const command = argv._[0]
const root = argv._[command ? 1 : 0]
if (root) {
argv.root = root
}
5 years ago
if (!command || command === 'dev') {
const port = argv.port || 3000
require('../dist/node')
5 years ago
.createServer(argv)
.then((server) => {
server.listen(port, () => {
console.log(`listening at http://localhost:${port}`)
})
})
.catch((err) => {
console.error(chalk.red(`failed to start server. error:\n`), err)
process.exit(1)
5 years ago
})
5 years ago
} else if (command === 'build') {
require('../dist/node')
5 years ago
.build(argv)
.catch((err) => {
console.error(chalk.red(`build error:\n`), err)
process.exit(1)
5 years ago
})
} else if (command === 'serve') {
require('../dist/node')
.serve(argv)
.catch((err) => {
console.error(chalk.red(`failed to start server. error:\n`), err)
process.exit(1)
})
5 years ago
} else {
console.log(chalk.red(`unknown command "${command}".`))
process.exit(1)
5 years ago
}