Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, '<') | ||
.replace(/\>/g, '>') | ||
} | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, '|') | ||
} | ||
|
||
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() |