mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-26 00:35:02 +03:00
Adjust parsing in loader
This commit is contained in:
parent
b0b00eeb5f
commit
1db1973071
54
cli.js
54
cli.js
@ -1,16 +1,64 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
const meow = require('meow')
|
||||||
const open = require('react-dev-utils/openBrowser')
|
const open = require('react-dev-utils/openBrowser')
|
||||||
|
const chalk = require('chalk')
|
||||||
const dev = require('./lib/dev')
|
const dev = require('./lib/dev')
|
||||||
|
|
||||||
const opts = {
|
const config = require('pkg-conf').sync('mdx-deck')
|
||||||
|
|
||||||
|
const log = (...args) => {
|
||||||
|
console.log(
|
||||||
|
chalk.magenta('[mdx-deck]'),
|
||||||
|
...args
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
|
|
||||||
dev(opts)
|
dev(opts)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const url = 'http://localhost:' + res.port
|
const url = 'http://localhost:' + res.port
|
||||||
open(url)
|
open(url)
|
||||||
console.log(url)
|
log('listening on', chalk.magenta(url))
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
1
docs/Layout.js
Normal file
1
docs/Layout.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
import React from 'react'
|
@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { MDXProvider } from '@mdx-js/tag'
|
import { MDXProvider } from '@mdx-js/tag'
|
||||||
import styled, { ThemeProvider } from 'styled-components'
|
import styled, { ThemeProvider } from 'styled-components'
|
||||||
import { color } from 'styled-system'
|
import { width, height, color } from 'styled-system'
|
||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
|
|
||||||
import defaultTheme from './theme'
|
import defaultTheme from './theme'
|
||||||
@ -16,7 +16,8 @@ export const dec = state => state.index > 0
|
|||||||
const CarouselRoot = styled.div([], {
|
const CarouselRoot = styled.div([], {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
overflowX: 'auto',
|
overflowX: 'auto',
|
||||||
width: '100vw',
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
scrollSnapType: 'mandatory',
|
scrollSnapType: 'mandatory',
|
||||||
'::-webkit-scrollbar': {
|
'::-webkit-scrollbar': {
|
||||||
display: 'none'
|
display: 'none'
|
||||||
@ -78,8 +79,8 @@ export const Slide = styled.div([], {
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
width: '100vw',
|
width: '100%',
|
||||||
height: '90vh'
|
height: '100%'
|
||||||
}, color)
|
}, color)
|
||||||
|
|
||||||
Slide.defaultProps = {
|
Slide.defaultProps = {
|
||||||
@ -87,6 +88,8 @@ Slide.defaultProps = {
|
|||||||
bg: 'background'
|
bg: 'background'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Root = styled.div([], { backgroundColor: 'tomato' }, width, height)
|
||||||
|
|
||||||
export default class SlideDeck extends React.Component {
|
export default class SlideDeck extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
slides: PropTypes.array.isRequired,
|
slides: PropTypes.array.isRequired,
|
||||||
@ -95,7 +98,9 @@ export default class SlideDeck extends React.Component {
|
|||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
slides: [],
|
slides: [],
|
||||||
theme: defaultTheme,
|
theme: defaultTheme,
|
||||||
components: defaultComponents
|
components: defaultComponents,
|
||||||
|
width: '100vw',
|
||||||
|
height: '100vh',
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -106,7 +111,6 @@ export default class SlideDeck extends React.Component {
|
|||||||
update = fn => this.setState(fn)
|
update = fn => this.setState(fn)
|
||||||
|
|
||||||
handleKeyDown = e => {
|
handleKeyDown = e => {
|
||||||
console.log(e)
|
|
||||||
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
|
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case 'ArrowRight':
|
case 'ArrowRight':
|
||||||
@ -133,14 +137,19 @@ export default class SlideDeck extends React.Component {
|
|||||||
const {
|
const {
|
||||||
slides,
|
slides,
|
||||||
theme,
|
theme,
|
||||||
components
|
components,
|
||||||
|
width,
|
||||||
|
height
|
||||||
} = this.props
|
} = this.props
|
||||||
const { index } = this.state
|
const { index } = this.state
|
||||||
|
console.log(slides.map(Slide => {
|
||||||
|
return <Slide />
|
||||||
|
}))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
<MDXProvider components={components}>
|
<MDXProvider components={components}>
|
||||||
<div>
|
<Root width={width} height={height}>
|
||||||
<Carousel
|
<Carousel
|
||||||
index={index}
|
index={index}
|
||||||
onScroll={index => {
|
onScroll={index => {
|
||||||
@ -155,7 +164,7 @@ export default class SlideDeck extends React.Component {
|
|||||||
<samp>{this.state.index + 1}/{this.state.length}</samp>
|
<samp>{this.state.index + 1}/{this.state.length}</samp>
|
||||||
<button onClick={e => this.update(dec)}>previous</button>
|
<button onClick={e => this.update(dec)}>previous</button>
|
||||||
<button onClick={e => this.update(inc)}>next</button>
|
<button onClick={e => this.update(inc)}>next</button>
|
||||||
</div>
|
</Root>
|
||||||
</MDXProvider>
|
</MDXProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
|
@ -116,7 +116,7 @@ const start = async (opts = {}) => {
|
|||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
OPTIONS: JSON.stringify(opts),
|
OPTIONS: JSON.stringify(opts),
|
||||||
// APP_FILENAME: JSON.stringify(opts.entry),
|
APP_FILENAME: JSON.stringify(opts.entry),
|
||||||
HOT_PORT: JSON.stringify(hotPort)
|
HOT_PORT: JSON.stringify(hotPort)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,6 @@ import slides, {
|
|||||||
meta
|
meta
|
||||||
} from '../docs/index.mdx'
|
} from '../docs/index.mdx'
|
||||||
|
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const {
|
const {
|
||||||
@ -24,6 +23,7 @@ class App extends React.Component {
|
|||||||
slides={slides}
|
slides={slides}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
components={components}
|
components={components}
|
||||||
|
height='100vh'
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,13 @@ module.exports = async function (src) {
|
|||||||
.map(str => str.trim())
|
.map(str => str.trim())
|
||||||
.map(str => str.replace(EXREG, ''))
|
.map(str => str.replace(EXREG, ''))
|
||||||
.map(str => {
|
.map(str => {
|
||||||
const lines = str.split('\n\n')
|
const lines = str.split('\n')
|
||||||
inlineModules.push(
|
inlineModules.push(
|
||||||
...lines.filter(str => MODREG.test(str))
|
...lines.filter(str => MODREG.test(str))
|
||||||
)
|
)
|
||||||
return lines.filter(str => !MODREG.test(str))
|
return lines.filter(str => !MODREG.test(str))
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n')
|
||||||
})
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -37,7 +39,6 @@ export const meta = ${stringifyObject(data)}
|
|||||||
export default [
|
export default [
|
||||||
${slides.join(',\n\n')}
|
${slides.join(',\n\n')}
|
||||||
]`
|
]`
|
||||||
// console.log(code)
|
|
||||||
|
|
||||||
return callback(null, code)
|
return callback(null, code)
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
"version": "1.0.0-0",
|
"version": "1.0.0-0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
"bin": {
|
||||||
|
"mdx-deck": "./cli.js"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "./cli.js"
|
"start": "./cli.js docs/index.mdx"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Brent Jackson",
|
"author": "Brent Jackson",
|
||||||
@ -12,14 +15,17 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mdx-js/tag": "^0.14.1",
|
"@mdx-js/tag": "^0.14.1",
|
||||||
"chalk": "^2.4.1",
|
"chalk": "^2.4.1",
|
||||||
|
"clipboardy": "^1.2.3",
|
||||||
"debounce": "^1.1.0",
|
"debounce": "^1.1.0",
|
||||||
"get-port": "^4.0.0",
|
"get-port": "^4.0.0",
|
||||||
"gray-matter": "^4.0.1",
|
"gray-matter": "^4.0.1",
|
||||||
"koa": "^2.5.2",
|
"koa": "^2.5.2",
|
||||||
"koa-webpack": "^5.1.0",
|
"koa-webpack": "^5.1.0",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
|
"meow": "^5.0.0",
|
||||||
"mini-html-webpack-plugin": "^0.2.3",
|
"mini-html-webpack-plugin": "^0.2.3",
|
||||||
"ok-cli": "^2.0.9",
|
"ok-cli": "^2.0.9",
|
||||||
|
"pkg-conf": "^2.1.0",
|
||||||
"progress-bar-webpack-plugin": "^1.11.0",
|
"progress-bar-webpack-plugin": "^1.11.0",
|
||||||
"prop-types": "^15.6.2",
|
"prop-types": "^15.6.2",
|
||||||
"react-dev-utils": "^5.0.1",
|
"react-dev-utils": "^5.0.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user