Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions bin/actions.js
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
};
33 changes: 33 additions & 0 deletions bin/args.js
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', {

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 -m in that scenario means "file name" but here it's actually mdx. A better structure would be to have a filename option like -s/src which takes a file of either .js(x) or .md(x). And then either infer the filetype from webpack or have a boolean flag -m/mdx which sets the filetype to md(x).

It's also weird that the default filename is hidden behind a flag. I would assume you could just run spectacle and have smart defaults like "look for slides.js and spin up webserver"

Copy link
Contributor Author

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.

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.

Copy link
Contributor Author

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.

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

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())
};
27 changes: 27 additions & 0 deletions bin/cli.js
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();
}
28 changes: 28 additions & 0 deletions examples/MDX/TestMDX.js
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;
59 changes: 59 additions & 0 deletions examples/MDX/slides.mdx
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)**

---

![datboi](https://pbs.twimg.com/media/CkjFUyTXEAEysBY.jpg)

---

###### 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>;
}
}
```
7 changes: 7 additions & 0 deletions examples/MDX/test-component.js
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;
100 changes: 0 additions & 100 deletions examples/MDX/test.mdx

This file was deleted.

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { render } from 'react-dom';

// START: test components to try rendering:
import MDXDocument from './examples/MDX/test.mdx';
import TestMDX from './examples/MDX/TestMDX';
// import TestJs from './examples/JS/TestJS.js';
// END: test components to try rendering

Expand All @@ -13,4 +13,4 @@ import MDXDocument from './examples/MDX/test.mdx';
* to hot-reload with new contents.
*/

render(<MDXDocument />, document.getElementById('root'));
render(<TestMDX />, document.getElementById('root'));
Loading