From 81257e1e771d9d6121273ae9551b3da73aae56bf Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 14 May 2019 14:20:34 +0900 Subject: [PATCH] feat: add --dest, --out, --port options (#14) --- README.md | 2 ++ assets/help-message.txt | 3 +++ index.js | 32 ++++++++++++++++++-------------- test.js | 26 +++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ef07928..f495ec9 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Default settings are as follows: ```yml port: 6275 dest: build +out: index.html source: slides.md title: '' assets: ['assets'] @@ -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. diff --git a/assets/help-message.txt b/assets/help-message.txt index cb2ecb4..3521cab 100755 --- a/assets/help-message.txt +++ b/assets/help-message.txt @@ -8,5 +8,8 @@ Options: -v, --version Shows the version number and exits -s, --source Specifies the slide's markdown file. This overrides 'source' property of the config file. + -o, --out The output filename of the slides. Default is index.html. + -d, --dest The destination directory for built slides. + -p, --port The port number for dev server. See https://npm.im/remarker for more details. diff --git a/index.js b/index.js index ca42e16..d64c637 100755 --- a/index.js +++ b/index.js @@ -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') @@ -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: { @@ -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' } }) ) diff --git a/test.js b/test.js index 0efd081..6851c40 100644 --- a/test.js +++ b/test.js @@ -25,7 +25,7 @@ before(done => { after(done => { processes.forEach(child => child.kill()) - rimraf('examples/*/build', done) + rimraf('examples/*/{build,build2}', done) }) describe('remarker', () => { @@ -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 })