1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-30 00:44:20 +03:00
mdx-deck/cli.js

66 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-07-28 21:21:36 +03:00
#!/usr/bin/env node
2018-07-29 01:32:05 +03:00
const meow = require('meow')
2018-07-28 21:21:36 +03:00
const open = require('react-dev-utils/openBrowser')
2018-07-29 01:32:05 +03:00
const chalk = require('chalk')
2018-07-28 21:21:36 +03:00
const dev = require('./lib/dev')
2018-07-29 01:32:05 +03:00
const config = require('pkg-conf').sync('mdx-deck')
const log = (...args) => {
console.log(
chalk.magenta('[mdx-deck]'),
...args
)
2018-07-28 21:21:36 +03:00
}
2018-07-29 01:32:05 +03:00
log.error = (...args) => {
console.log(
chalk.red('[err]'),
...args
)
}
const cli = meow(`
Usage
$ mdx-deck deck.mdx
$ mdx-deck build deck.mdx
Options
-p --port Dev server port
--no-open Prevent from opening in default browser
`, {
flags: {
port: {
type: 'string',
alias: 'p'
},
open: {
type: 'boolean',
alias: 'o',
default: true
}
}
})
const [ entry ] = cli.input
if (!entry) cli.showHelp(0)
const opts = Object.assign({
entry,
}, config, cli.flags)
2018-07-28 21:21:36 +03:00
dev(opts)
.then(res => {
const url = 'http://localhost:' + res.port
open(url)
2018-07-29 01:32:05 +03:00
log('listening on', chalk.magenta(url))
2018-07-28 21:21:36 +03:00
})
.catch(err => {
console.error(err)
})