Skip to content

Commit

Permalink
feat: add --dest, --out, --port options (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed May 14, 2019
1 parent c5d344d commit 81257e1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Default settings are as follows:
```yml
port: 6275
dest: build
out: index.html
source: slides.md
title: ''
assets: ['assets']
Expand All @@ -100,6 +101,7 @@ livereloadPort: 35729

- `port` is the port number of remarker server. Default is `6275`.
- `dest` is the destination of `remarker build` command. Default is `build`
- `out` is the filename of the result html page. Default is `index.html`
- `source` is the source markdown filename. Default is `slides.md`.
- `title` is the page title of the slides. Default is an empty string.
- `css` is css text you want to add to slides' html page.
Expand Down
3 changes: 3 additions & 0 deletions assets/help-message.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ Options:
-v, --version Shows the version number and exits
-s, --source <path> Specifies the slide's markdown file.
This overrides 'source' property of the config file.
-o, --out <filename> The output filename of the slides. Default is index.html.
-d, --dest <path> The destination directory for built slides.
-p, --port <number> The port number for dev server.

See https://npm.im/remarker for more details.
32 changes: 18 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ const defaultCss = read('assets/default.css')
const defaultAssetsPath = 'assets'

const defaultConfig = {
title: '',
port: 6275,
title: '', // The page title of the result html
port: 6275, // The port number of dev server
livereload: true,
livereloadPort: 35729,
dest: 'build',
source: 'slides.md',
css: defaultCss,
cssFiles: [],
script: '',
scriptFiles: [],
remarkConfig: {},
remarkPath: join(__dirname, 'vendor', 'remark.js'),
assets: [defaultAssetsPath]
dest: 'build', // The destination directory of built assets
out: 'index.html', // The result html filename of the slides
source: 'slides.md', // The source of the slides
css: defaultCss, // The additional css for the slides
cssFiles: [], // The additional css files
script: '', // The additional script for the slides
scriptFiles: [], // The additional script files
remarkConfig: {}, // The config object passed to remark
remarkPath: join(__dirname, 'vendor', 'remark.js'), // The remark path
assets: [defaultAssetsPath] // The asset paths
}

name('remarker')
Expand All @@ -72,7 +73,7 @@ const onConfig = (config, argv) => {

const slidePipeline = asset(config.source)
.pipe(emojify())
.pipe(rename({ basename: 'index', extname: '.html' }))
.pipe(rename(config.out))
.pipe(
layout1.nunjucks(layoutFilename, {
data: {
Expand Down Expand Up @@ -153,9 +154,12 @@ const onLivereloadConfig = (slidePipeline, config) => {

on('config', config =>
minimisted(argv => onConfig(config, argv), {
string: ['source'],
string: ['source', 'out', 'dest', 'port'],
alias: {
s: 'source'
s: 'source',
o: 'out',
p: 'port',
d: 'dest'
}
})
)
26 changes: 25 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ before(done => {

after(done => {
processes.forEach(child => child.kill())
rimraf('examples/*/build', done)
rimraf('examples/*/{build,build2}', done)
})

describe('remarker', () => {
Expand Down Expand Up @@ -100,6 +100,30 @@ describe('remarker', () => {
})
})

describe('-d, --dest option', () => {
it('specifies destination directory', () => {
execSync('node ../../index.js build --dest build2', {
cwd: examples.simple
})

expect(
readFileSync(join(examples.simple, 'build2', 'index.html')).toString()
).to.include('My Awesome Presentation')
})
})

describe('-o, --out option', () => {
it('specifies destination directory', () => {
execSync('node ../../index.js build --out slides.html', {
cwd: examples.simple
})

expect(
readFileSync(join(examples.simple, 'build', 'slides.html')).toString()
).to.include('My Awesome Presentation')
})
})

describe('contents in assets directory', () => {
it('are copied to build directory', () => {
execSync('node ../../index.js build', { cwd: examples.hasAssets })
Expand Down

0 comments on commit 81257e1

Please sign in to comment.