Created
March 24, 2016 15:50
-
-
Save calvinfroedge/a4ce83af3418c39de5a3 to your computer and use it in GitHub Desktop.
Use react-docgen to automatically add json to a README.md
This file contains hidden or 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
#!/usr/bin/env node | |
var sync = require('child_process').spawnSync; | |
var fs = require('fs'); | |
var START = '<!--(auto-->'; | |
var END = '<!--/auto)-->'; | |
function makeSection(file, title){ | |
var json = JSON.parse(sync('./node_modules/react-docgen/bin/react-docgen.js', ['--pretty', './'+file]).output[1].toString()); | |
var str = "## "+title+"\n\n"; | |
str = str + "```\n" + JSON.stringify(json.props, null, 2) + "\n```\n"; | |
return str; | |
} | |
function makeDocs(){ | |
var docs = fs.readFileSync('./README.md').toString(); | |
var split = docs.split(START); | |
var endAuto = split.pop(); | |
var content = split.pop(); | |
var auto = "\n\n"; | |
auto = auto + makeSection('src/modal-component.js', 'Modal') + "\n"; | |
auto = auto + makeSection('src/launch-button.js', 'Modal Launch') + "\n"; | |
var newContent = [content, auto].join(START) + END; | |
fs.writeFileSync('./README.md', newContent); | |
} | |
makeDocs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment