-
Notifications
You must be signed in to change notification settings - Fork 11
/
verbfile.js
68 lines (59 loc) · 1.66 KB
/
verbfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var verb = require('verb')
var literal = require('json-literal')
var commentPatterns = require('./')
var esformatter = require('esformatter')
/**
* Pretty print an object as javascript-source code.
* @param {object} `obj` the javascript object
* @returns {string} a pretty printed markdown code-block
*/
function stringify (obj) {
var formatted = esformatter.format(literal.stringify(obj), {
indent: {
value: ' '
}
})
return '```js\n' +
formatted.replace(/^\(([\s\S]*)\)$/, '$1') +
'\n```\n'
}
// load data for templates if needed
verb.data({ 'langDB': require('./db-generated/base.js') })
/**
* Helper to call the base function of this module
*/
verb.helper('commentPatterns', function (filename) {
return stringify(commentPatterns(filename))
})
/**
* Helper to call the codeContext function of this module
*/
verb.helper('codeContext', function (filename, string, lineNr) {
var codeContext = commentPatterns.codeContext(filename).detect(string, lineNr)
return stringify(codeContext)
})
/**
* Helper to call the .regex-function of this module
*/
verb.helper('commentPatterns_regex', function (filename) {
return stringify(commentPatterns.regex(filename))
})
/**
* Helper to write a pretty-printed javascript-source of an object
*/
verb.helper('literal', stringify)
verb.task('readme', function () {
verb.src(['.verb.md'])
.pipe(verb.dest('./'))
.on('error', function (error) {
console.error(error.stack)
})
})
verb.task('docs', function () {
verb.src(['.docs/*.md'])
.pipe(verb.dest('./docs/'))
.on('error', function (error) {
console.error(error.stack)
})
})
verb.task('default', ['readme', 'docs'])