From 5d89427fbd96f273c95eab7d872634712148f83e Mon Sep 17 00:00:00 2001 From: Bruno Skvorc Date: Fri, 16 Aug 2019 13:51:12 +0200 Subject: [PATCH] API ref now has bootstrap --- README.md | 7 +++++-- docgen/.vuepress/docgen/plugin.js | 24 ++++++++++++------------ docgen/config.json | 6 ++++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 11e1ba3..4fd32e0 100644 --- a/README.md +++ b/README.md @@ -79,11 +79,14 @@ Generating an API reference for a library is a heavy and slow operation, so it n "apiref": { "lang": "nim", "mainfile": "nimcrypto.nim", - "subfolder": "nimcrypto" + "subfolder": "nimcrypto", + "bootstrap": "nimble install -y" // <-- OPTIONAL }, ``` -The only supported language is currently `nim` and it requires the `0.20.0` devel version! The mainfile is the entry file through which the generator starts generating the doc, this might be language specific like in the case of Nim. In Nim's case, the JSON is generated in a subfolder, which is specified in the `subfolder` value. For Nim, all three values are required. +The only supported language is currently `nim` and it requires a version at or above 0.19.6! The mainfile is the entry file through which the generator starts generating the doc, this might be language specific like in the case of Nim. In Nim's case, the JSON is generated in a subfolder, which is specified in the `subfolder` value. For Nim, all three values are required. + +If the `bootstrap` option is provided, the generator will run this command verbatim inside the folder of the cloned repo. This is useful for installing dependencies or pre-generating things inside the folder of the lib itself. **Note that if your bootstrap is something like `nimble install -y`, your global nimble folder will be updated! Back it up before launching the generator and then go [yell at @dom96](https://github.com/nim-lang/nimble).** ## Enhancing the docs further diff --git a/docgen/.vuepress/docgen/plugin.js b/docgen/.vuepress/docgen/plugin.js index 53dab3f..909991d 100644 --- a/docgen/.vuepress/docgen/plugin.js +++ b/docgen/.vuepress/docgen/plugin.js @@ -122,15 +122,14 @@ module.exports = { const apiRefTemplateNim = "#### {name} \n\n {description} \n\n```nim{code}\n```\n\n"; console.log("Starting nimdoc generation for repo " + repos[i].label); - execSync('git clone ' + repos[i].location + " " + repos[i].name, (err, stdout, stderr) => { - if (err) { - console.error("Could not launch git clone"); - return; - } - - console.log(`stdout: ${stdout}`); - console.log(`stderr: ${stderr}`); - }); + execSync('git clone ' + repos[i].location + " " + repos[i].name); + + // Bootstrap if needed + if (repos[i].apiref.bootstrap !== undefined) { + process.chdir(repos[i].name); + console.log(execSync(repos[i].apiref.bootstrap).toString()); + process.chdir('..'); + } // Two passes because jsondoc is kinda broken // Bug: https://github.com/nim-lang/Nim/issues/11953 @@ -143,14 +142,15 @@ module.exports = { let dir = repos[i].name + '/' + repos[i].apiref.subfolder; - let jsonFiles = []; + let extension = '.json'; + let jsonFiles = []; // Consume main file - jsonFiles.push(JSON.parse(fs.readFileSync(dir + "/" + repos[i].apiref.mainfile.split(".nim")[0] + ".json"))); + jsonFiles.push(JSON.parse(fs.readFileSync(dir + "/" + repos[i].apiref.mainfile.split(".nim")[0] + extension))); // Consume all other files let subdir = dir + "/" + repos[i].apiref.mainfile.split(".nim")[0]; let files = fs.readdirSync(subdir); files.forEach(file => { - if(/\.json$/.test(file)) { + if(file.indexOf(extension ) > -1) { let jsonContent = fs.readFileSync(subdir + "/" + file); jsonFiles.push( JSON.parse(jsonContent) diff --git a/docgen/config.json b/docgen/config.json index ea2518f..5115912 100644 --- a/docgen/config.json +++ b/docgen/config.json @@ -5,6 +5,12 @@ "label": "Chronicles", "location": "https://github.com/status-im/nim-chronicles", "update": true, + "apiref": { + "lang": "nim", + "mainfile": "chronicles.nim", + "subfolder": "htmldocs", + "bootstrap": "nimble install -y" + }, "frontMatter": { "sidebar": "auto" },