1 | const parseMarkdown = require('./parseMarkdown')
|
2 | const loadFile = require('./loadFile')
|
3 | const execa = require('execa')
|
4 | const prependFile = require('prepend-file')
|
5 |
|
6 | const exec = command => {
|
7 | execa.shell(command)
|
8 | //const output =
|
9 | // output.stdout.pipe(process.stdout)
|
10 | // output.stderr.pipe(process.stderr)
|
11 | }
|
12 |
|
13 | module.exports = async section => {
|
14 | const { path: filepath, data } = loadFile.loadSync([
|
15 | 'FcScripts.md',
|
16 | 'contributing.md',
|
17 | 'CONTRIBUTING.md',
|
18 | 'README.md',
|
19 | 'readme.md'
|
20 | ])
|
21 | if (!filepath) return null
|
22 | // toc.insert(filepath)
|
23 | if (data.indexOf('<!-- toc -->') === -1) {
|
24 | prependFile.sync(filepath, '<!-- toc -->')
|
25 | }
|
26 | exec('npx markdown-toc FcScripts.md -i')
|
27 | let newContent = data.replace(/(<!-- toc -->(\s|\S)*?<!-- tocstop -->)/g, '')
|
28 | return parseMarkdown(newContent, { section, filepath })
|
29 | }
|
30 | //const parseMarkdown = require('./parseMarkdown')
|
31 | // const fs = require('fs')
|
32 | // const path = require('path')
|
33 | // const flp = path.resolve(process.cwd(), '/FcScripts.md')
|
34 | // const loadFile = require('./loadFile')
|
35 | //
|
36 | // module.exports = section => {
|
37 | // const { path: filepath, data } = loadFile.loadSync([
|
38 | // 'FcScripts.md',
|
39 | // 'contributing.md',
|
40 | // 'CONTRIBUTING.md',
|
41 | // 'README.md',
|
42 | // 'readme.md'
|
43 | // ])
|
44 | // if (!filepath) return null
|
45 | // console.warn('-- Console fil', filepath, data)
|
46 | // let contents = fs.readFileSync(filepath, 'utf8')
|
47 | //
|
48 | // // fs.readFile(, 'utf8', function(
|
49 | // // err,
|
50 | // // contents
|
51 | // // ) {
|
52 | // // console.log(contents)
|
53 | // return parseMarkdown(data, { section, filepath })
|
54 | // // })
|
55 | // // console.warn(data);
|
56 | // }
|