-
Notifications
You must be signed in to change notification settings - Fork 700
MDX Slide Parsing and CLI #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
020ca06
custom MDX webpack loader + example usage
SunburtReynolds 932285b
WIP - added spectacle cli
SunburtReynolds cecb28b
CLI is working! Using resolved paths for wp deps
SunburtReynolds 2eed94c
use kebab-case on new file
SunburtReynolds b737840
use kebab-case consistently throughout project
SunburtReynolds a9d7c2a
pass linting & prettier
SunburtReynolds d8da41c
Merge branch 'rewrite/mdx-cli' into rewrite/kebab-case
SunburtReynolds 726c483
remove two errant auto-imports
SunburtReynolds 90b718f
improve the CLI API design; better defaults
SunburtReynolds 3d6353f
use git mv to recognize capilatization change
SunburtReynolds 36bf44a
kebab-case: rename deck and slide as well
SunburtReynolds d2d5aac
Merge branch 'rewrite/mdx-cli' into rewrite/kebab-case
SunburtReynolds 644ffa5
Merge pull request #705 from FormidableLabs/rewrite/kebab-case
SunburtReynolds 34420b5
support code blocks and inline code in WP loader
SunburtReynolds 8c11803
Fix self-referencing note in loader
SunburtReynolds 7762b13
use a better regex to support code snippets
SunburtReynolds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| const webpack = require('webpack'); | ||
| const WebpackDevServer = require('webpack-dev-server'); | ||
| const path = require('path'); | ||
| const config = require('../webpack.config'); | ||
|
|
||
| const port = 3000; | ||
|
|
||
| const options = { | ||
| hot: true | ||
| }; | ||
|
|
||
| const launchServer = (configUpdates = {}) => { | ||
| const customConfig = { ...config, ...configUpdates }; | ||
| const server = new WebpackDevServer(webpack(customConfig), options); | ||
|
|
||
| server.listen(port, 'localhost', function(err) { | ||
| if (err) { | ||
| console.log(err); | ||
| } | ||
| console.log('WebpackDevServer listening at localhost:', port); | ||
| }); | ||
| }; | ||
|
|
||
| const launchMDXServer = mdxFilePath => { | ||
| if (!mdxFilePath) { | ||
| // developer error - must supply an entry file path | ||
| throw new Error('MDX file path must be provided.'); | ||
| } | ||
|
|
||
| const cliRoot = path.resolve(__dirname, '..'); | ||
| const absoluteMdxFilePath = path.resolve(mdxFilePath); | ||
| const nodeModules = path.resolve(__dirname, '../node_modules'); | ||
|
|
||
| const configUpdates = { | ||
| mode: 'development', | ||
| context: cliRoot, | ||
| entry: './mdx-slides/index.js', | ||
| resolve: { | ||
| alias: { | ||
| 'spectacle-user-mdx': absoluteMdxFilePath | ||
| }, | ||
| modules: [nodeModules] | ||
| } | ||
| }; | ||
|
|
||
| launchServer(configUpdates); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| launchMDXServer | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| const yargs = require('yargs'); | ||
|
|
||
| // Validate and normalize. | ||
| const validate = parser => { | ||
| const { argv } = parser; | ||
| const { mdx } = argv; | ||
|
|
||
| return Promise.resolve({ mdx }); | ||
| }; | ||
|
|
||
| const args = () => | ||
| yargs | ||
| .usage(`Usage: spectacle -m <file>`) | ||
|
|
||
| // MDX File | ||
| .option('mdx', { | ||
| alias: 'm', | ||
| describe: 'Path to mdx file from which a presentation will be generated.', | ||
| default: 'slides.mdx', | ||
| required: false, | ||
| type: 'string' | ||
| }) | ||
|
|
||
| // Logistical | ||
| .help() | ||
| .alias('help', 'h') | ||
| .version() | ||
| .alias('version', 'v') | ||
| .strict(); | ||
|
|
||
| module.exports = { | ||
| parse: () => validate(args()) | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const args = require('./args'); | ||
| const actions = require('./actions'); | ||
| var path = require('path'); | ||
|
|
||
| const main = () => | ||
| Promise.resolve() | ||
| // Parse arguments. | ||
| .then(args.parse) | ||
| .then(parsedInput => { | ||
| const mdxFilePath = parsedInput.mdx; | ||
| if (mdxFilePath) { | ||
| actions.launchMDXServer(mdxFilePath); | ||
| } else { | ||
| throw new Error('Unsupported action.'); | ||
| } | ||
| }) | ||
| .catch(err => { | ||
| // Try to get full stack, then full string if not. | ||
| console.error(err.stack || err.toString()); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| if (require.main === module) { | ||
| main(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React from 'react'; | ||
| import slides from './slides.mdx'; | ||
| import Deck from '../../src/components/Deck'; | ||
| import Slide from '../../src/components/Slide'; | ||
|
|
||
| import { MDXProvider } from '@mdx-js/react'; | ||
|
|
||
| /* | ||
| * Note: you can add mappings here to customize how | ||
| * MDX will render standard markdown tags | ||
| */ | ||
| const components = { | ||
| // h5: MyH5Component | ||
| }; | ||
|
|
||
| const MDXTest = () => ( | ||
| <MDXProvider components={components}> | ||
| <Deck loop> | ||
| {slides.map((S, i) => ( | ||
| <Slide key={`slide-${i}`} slideNum={i}> | ||
| <S /> | ||
| </Slide> | ||
| ))} | ||
| </Deck> | ||
| </MDXProvider> | ||
| ); | ||
|
|
||
| export default MDXTest; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import Test from './test-component'; | ||
| export const testProp = 50; | ||
|
|
||
| # Hello World 👋 | ||
|
|
||
| - one | ||
| - two | ||
| - three | ||
|
|
||
| --- | ||
|
|
||
| ## Next | ||
|
|
||
| <Test height={testProp} /> | ||
|
|
||
| --- | ||
|
|
||
| # Write your Spectacle Presentations in Markdown | ||
|
|
||
| ## And seamlessly use React Components | ||
|
|
||
| **How sweet is that** | ||
| **(super sweet)** | ||
|
|
||
| --- | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ###### Typography | ||
|
|
||
| # Heading 1 | ||
|
|
||
| ## Heading 2 | ||
|
|
||
| ### Heading 3 | ||
|
|
||
| #### Heading 4 | ||
|
|
||
| ##### Heading 5 | ||
|
|
||
| ###### Heading 6 | ||
|
|
||
| Standard Text | ||
|
|
||
| --- | ||
|
|
||
| > Example Quote | ||
|
|
||
| --- | ||
|
|
||
| ```javascript | ||
| class SuperCoolComponent extends React.Component { | ||
| render() { | ||
| return <p>code slide works in markdown too whaaaaat</p>; | ||
| } | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import React from 'react'; | ||
|
|
||
| const Test = ({ height }) => { | ||
| return <div style={{ height, width: '100%', backgroundColor: 'yellow' }} />; | ||
| }; | ||
|
|
||
| export default Test; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks funky to me -
Usage: spectacle -m <file>. As a spectacle consumer, I would assume that-min that scenario means "file name" but here it's actuallymdx. A better structure would be to have a filename option like-s/srcwhich takes a file of either.js(x)or.md(x). And then either infer the filetype from webpack or have a boolean flag-m/mdxwhich sets the filetype tomd(x).It's also weird that the default filename is hidden behind a flag. I would assume you could just run
spectacleand have smart defaults like "look for slides.js and spin up webserver"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you expect
spectacle -s <jsx file name here>to do? AFAIK that's undefined behavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run a slideshow from JSX slides. It's currently undefined yes. I think the main point is that the slide file is separate from "is this mdx". And that decision can happen from a user supplied flag, OR we might be able to infer it based on the source file type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. Here's the decision tree I've got in mind:
Did the user supply a file?
If no, default to (?)
slides.mdx.If yes, what kind of file did they supply an mdx file or a jsx file?
If mdx, boot up the presentation.
If jsx (or other), console log about currently unsupported behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable, though I'd eventually expect the default to be
slides.jsx