Skip to content

Commit

Permalink
fix(gitignore): add all source files
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jul 8, 2017
1 parent 3757c2b commit 61ee9f4
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
coverage/
dist
docs
/coverage
/dist
/docs
*.log
73 changes: 73 additions & 0 deletions src/docs/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict'

const documentation = require('documentation')
const glob = require('glob')
const fs = require('fs-extra')
const pify = require('pify')
const chalk = require('chalk')
const vinyl = require('vinyl-fs')
const streamArray = require('stream-array')

const utils = require('../utils')
const introTmpl = require('../config/intro-template.md')

function generateDescription (pkg) {
let example
try {
example = fs.readFileSync(utils.getPathToExample())
} catch (err) {
console.log(chalk.yellow('Warning: No `example.js` found in the root directory.'))
}

return introTmpl(pkg.name, pkg.repository.url, example)
}

function getOpts (pkg) {
const opts = {
github: true
}
const configFile = utils.getPathToDocsConfig()
if (fs.existsSync(configFile)) {
opts.config = configFile
} else {
opts.toc = [{
name: 'Intro',
description: generateDescription(pkg)
}]
}

return opts
}

function writeDocs (output) {
const docsPath = utils.getPathToDocs()
return fs.ensureDir(docsPath)
.then(() => new Promise((resolve, reject) => {
streamArray(output)
.pipe(vinyl.dest(docsPath))
.once('error', reject)
.once('end', resolve)
}))
}

function build (ctx) {
return Promise.all([
utils.getPkg(),
pify(glob)('./src/**/*.js', {
cwd: process.cwd()
})
]).then((res) => {
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)
})
}

module.exports = build
22 changes: 22 additions & 0 deletions src/docs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const Listr = require('listr')

const utils = require('../utils')
const clean = require('../clean')
const publish = require('./publish')
const build = require('./build')

const TASKS = new Listr([{
title: 'Clean ./docs',
task: () => clean('docs')
}, {
title: 'Generating documentation',
task: build
}, {
title: 'Publish to GitHub Pages',
task: publish,
enabled: (ctx) => ctx.publish
}], utils.getListrConfig())

module.exports = TASKS
19 changes: 19 additions & 0 deletions src/docs/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const ghPages = require('gh-pages')
const pify = require('pify')
const os = require('os')
const path = require('path')

const utils = require('../utils')

function publish (ctx) {
return utils.getPkg().then((pkg) => {
return pify(ghPages.publish.bind(ghPages))('docs', {
message: 'chore: update documentation',
clone: path.join(os.tmpdir(), 'aegir-gh-pages-cache', pkg.name)
})
})
}

module.exports = publish

0 comments on commit 61ee9f4

Please # to comment.