Skip to content

Commit

Permalink
feat(docs): add format flag to which selects docs output formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gierth authored and dignifiedquire committed Nov 21, 2017
1 parent 0a847e1 commit 456858f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
7 changes: 7 additions & 0 deletions cmds/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ module.exports = {
alias: 'p',
describe: 'Publish to GitHub Pages',
default: false
},
docsFormats: {
alias: 'd',
describe: 'Which documentation formats to build',
type: 'array',
choices: ['html', 'md'],
default: ['html']
}
},
handler (argv) {
Expand Down
7 changes: 7 additions & 0 deletions cmds/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ module.exports = {
choices: ['node', 'browser', 'webworker'],
default: ['node', 'browser', 'webworker']
},
docsFormats: {
alias: 'd',
describe: 'Which documentation formats to build',
type: 'array',
choices: ['html', 'md'],
default: ['html']
},
build: {
describe: 'Run build tasks before release',
default: true
Expand Down
29 changes: 22 additions & 7 deletions src/docs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ function writeDocs (output) {
}))
}

function writeMdDocs (output) {
const docsPath = utils.getPathToDocs()
return fs.ensureDir(docsPath)
.then(() => fs.writeFileSync(utils.getPathToDocsMdFile(), output))
}

function build (ctx) {
return Promise.all([
utils.getPkg(),
Expand All @@ -60,13 +66,22 @@ function build (ctx) {
const pkg = res[0]
const files = res[1]

return documentation.build(files, getOpts(pkg))
.then((docs) => documentation.formats.html(docs, {
theme: require.resolve('clean-documentation-theme'),
version: pkg.version,
name: pkg.name
}))
.then(writeDocs)
return Promise.all(ctx.docsFormats.map((fmt) => {
if (fmt === 'md') {
return documentation.build(files, getOpts(pkg))
.then((docs) => documentation.formats.md(docs))
.then(writeMdDocs)
}
if (fmt === 'html') {
return documentation.build(files, getOpts(pkg))
.then((docs) => documentation.formats.html(docs, {
theme: require.resolve('clean-documentation-theme'),
version: pkg.version,
name: pkg.name
}))
.then(writeDocs)
}
}))
})
}

Expand Down
9 changes: 9 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ exports.getPathToDocsFile = () => {
return path.join(exports.getPathToDocs(), 'index.html')
}

/**
* Path to documentation index.md.
*
* @returns {string}
*/
exports.getPathToDocsMdFile = () => {
return path.join(exports.getPathToDocs(), 'index.md')
}

exports.hook = (env, key) => (ctx) => {
if (ctx && ctx.hooks) {
if (ctx.hooks[env] && ctx.hooks[env][key]) {
Expand Down

0 comments on commit 456858f

Please sign in to comment.