Skip to content

Commit

Permalink
add ref generators
Browse files Browse the repository at this point in the history
  • Loading branch information
rmonnier9 committed Jun 7, 2018
1 parent 228a1db commit 8532d00
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
68 changes: 68 additions & 0 deletions misc/cli-parser.js
@@ -0,0 +1,68 @@
const fs = require('fs')

// const { exec } = require('child_process')
// const pm2Help = exec('pm2', ['-h'])

// let stream = fs.createWriteStream('./pm2Help')

// pm2Help.stdout.on('data', (data) => {
// stream.write(data)
// console.log(data)
// })

// pm2Help.stderr.on('data', (data) => {
// console.log(`stderr: ${data}`)
// })

// pm2Help.on('close', (code) => {
// console.log(`child process exited with code ${code}`)
// stream.end()
// })

const escapeSpecialChar = (str) => {
if (typeof str !== typeof '') { return str }
return str.replace(/\|/g, '|')
.replace(/\</g, '&lt;')
.replace(/\>/g, '&gt;')
}

const schema = fs.readFileSync('./pm2Help').toString()
// console.log(schema)
const tab = schema.split('\n')
stream = fs.createWriteStream('./cli.md')

stream.write('# CLI reference')
stream.write('\n\n### pm2 Flags\n\n')
stream.write('Flag name|Description\n')
stream.write('---|---\n')

let i = 0;
while (!tab[i].match(/Options/)) {
i++
}
i = i + 2
while (tab[i].length) {
const flag = tab[i].split(/ {2,}/).filter((entry) => { return entry.trim() != '' })
const flagName = escapeSpecialChar(flag[0])
const flagDescription = escapeSpecialChar(flag[1])
stream.write(`${flagName}|${flagDescription}\n`)
i++
}
while (!tab[i].match(/Commands/)) {
i++
}
i = i + 2

stream.write('\n\n### pm2 Commands\n\n')
stream.write('Command name|Description\n')
stream.write('---|---\n')
while (i < tab.length) {
// console.log(tab[i])
const flag = tab[i].split(/ {2,}/).filter((entry) => { return entry.trim() != '' })
const flagName = escapeSpecialChar(flag[0])
const flagDescription = escapeSpecialChar(flag[1])
stream.write(`${flagName}|${flagDescription}\n`)
i++
}

stream.end()
26 changes: 26 additions & 0 deletions misc/ecosystem-parser.js
@@ -0,0 +1,26 @@
const axios = require('axios')
const fs = require('fs')

// const schema = axios.get('https://raw.githubusercontent.com/Unitech/pm2/master/lib/API/schema.json')
// .then(res => { return res.data })
const schema = JSON.parse(fs.readFileSync('./schema.json'))

const escapeVerticalBar = (str) => {
if (typeof str !== typeof '') { return str }
return str.replace(/\|/g, '&#124;')
}

const stream = fs.createWriteStream('./ecosystem.md')

stream.write('# Ecosystem file reference\n\n')
stream.write('Entry name|Description|Type|Default\n')
stream.write('---|---|---|---\n')

for (let key of Object.keys(schema)) {
const description = escapeVerticalBar(schema[key].description)
const type = escapeVerticalBar(schema[key].type)
const defaultValue = escapeVerticalBar(schema[key].default)

stream.write(`${key}|${description || ''}|${type || ''}|${defaultValue || ''}\n`)
}
stream.end()

0 comments on commit 8532d00

Please sign in to comment.