1 | const fs = require('fs')
|
2 | const path = require('path')
|
3 | const execSync = require('child_process').execSync
|
4 | const markdownMagic = require('../index')
|
5 |
|
6 | const config = {
|
7 | matchWord: 'MD-MAGIC-EXAMPLE',
|
8 | transforms: {
|
9 |
|
10 | customTransform(content, options) {
|
11 | console.log('original content in comment block', content)
|
12 | console.log('options defined on transform', options)
|
13 |
|
14 | return `This will replace all the contents of inside the comment ${options.optionOne}`
|
15 | },
|
16 |
|
17 | RENDERDOCS(content, options) {
|
18 | const fileContents = fs.readFileSync(options.path, 'utf8')
|
19 | const docBlocs = require('dox').parseComments(fileContents, { raw: true, skipSingleStar: true })
|
20 | let updatedContent = ''
|
21 | docBlocs.forEach((data) => {
|
22 | updatedContent += `${data.description.full}\n\n`
|
23 | })
|
24 | return updatedContent.replace(/^\s+|\s+$/g, '')
|
25 | },
|
26 |
|
27 | pluginExample: require('./plugin-example')({ addNewLine: true }),
|
28 |
|
29 |
|
30 |
|
31 | }
|
32 | }
|
33 |
|
34 |
|
35 | const callback = function autoGitCommit(err, output) {
|
36 |
|
37 | output.forEach(function(data) {
|
38 | const mdPath = data.outputFilePath
|
39 | if(!mdPath) return false
|
40 | const gitAdd = execSync(`git add ${mdPath}`, {}, (error) => {
|
41 | if (error) console.warn(error)
|
42 | const msg = `${mdPath} automatically updated by markdown-magic`
|
43 | const gitCommitCommand = `git commit -m '${msg}' --no-verify`
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | })
|
49 | })
|
50 | }
|
51 |
|
52 | const markdownPath = path.join(__dirname, '..', 'README.md')
|
53 | markdownMagic(markdownPath, config, callback)
|