- format python with black

- format js with prettier

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2021-07-28 17:26:14 -07:00 committed by alexfornuto
parent d0c249bd09
commit 59baf202e7
2 changed files with 107 additions and 89 deletions

View file

@ -1,7 +1,7 @@
// generate-console-pages.js // generate-console-pages.js
const fs = require('fs'); const fs = require("fs");
const yaml = require('js-yaml'); const yaml = require("js-yaml");
/** /**
* This helper script, run by the technical writers, (re)generates markdown * This helper script, run by the technical writers, (re)generates markdown
@ -11,7 +11,6 @@ const yaml = require('js-yaml');
* running `pomerium-console gendocs. * running `pomerium-console gendocs.
*/ */
// Functions // Functions
/** /**
@ -33,24 +32,21 @@ const fromOSSettings = (name, keys) => {
result = asMap[i][j].doc.replace(fixAnchorLinksRegex, "(/reference/readme.md#").replace(fixHTMLLinksRegex, "(/$1.md") result = asMap[i][j].doc.replace(fixAnchorLinksRegex, "(/reference/readme.md#").replace(fixHTMLLinksRegex, "(/$1.md")
} }
else if (keys !== null && asMap[i][j].keys && keys.some( key => asMap[i][j].keys.indexOf(key) >= 0)) { else if (keys !== null && asMap[i][j].keys && keys.some( key => asMap[i][j].keys.indexOf(key) >= 0)) {
result = asMap[i][j].doc.replace(fixAnchorLinksRegex, "(/reference/readme.md#").replace(fixHTMLLinksRegex, "(/$1.md") result = asMap[i][j].doc.replace(fixAnchorLinksRegex, "(/reference/readme.md#").replace(fixHTMLLinksRegex, "(/$1.md")
} }
} }
} }
return result return result;
} }
/** /**
* Import console environment/config options from `pomerium-console_serve.yaml` * Import console environment/config options from `pomerium-console_serve.yaml`
*/ */
const writeConfigPage = (src) => { const writeConfigPage = (src) => {
//console.log(`keys from src file: ` + JSON.stringify(src)) // For Debugging //console.log(`keys from src file: ` + JSON.stringify(src)) // For Debugging
let path = './docs/enterprise/reference/config.md' let path = "./docs/enterprise/reference/config.md";
console.log(`Generating environment variable docs...\n`) console.log(`Generating environment variable docs...\n`);
let frontmatter = let frontmatter = `---
`---
title: Environment Variables title: Environment Variables
lang: en-US lang: en-US
meta: meta:
@ -62,33 +58,34 @@ meta:
The keys listed below can be applied in Pomerium Console's \`config.yaml\` file, or applied as environment variables (in uppercase, replacing \`-\` with \`_\`). The keys listed below can be applied in Pomerium Console's \`config.yaml\` file, or applied as environment variables (in uppercase, replacing \`-\` with \`_\`).
` `;
const keySection = (obj) => { const keySection = (obj) => {
//console.log(JSON.stringify(obj.name)) // For Debugging //console.log(JSON.stringify(obj.name)) // For Debugging
let header = `## ` + obj.name + '\n\n' let header = `## ` + obj.name + "\n\n";
let body = let body = `${obj.usage}
`${obj.usage}
**Default value:** \`${obj.default_value ? obj.default_value : `none`}\` **Default value:** \`${obj.default_value ? obj.default_value : `none`}\`
` `;
return header + body return header + body;
} };
let content = frontmatter + src.options.map(section => keySection(section)).join('\n')
fs.writeFileSync(path, content)
}
let content =
frontmatter + src.options.map((section) => keySection(section)).join("\n");
fs.writeFileSync(path, content);
};
/** /**
* Read `console-settings.yaml` and write * Read `console-settings.yaml` and write
* markdown pages under `docs/enterprise/reference`. * markdown pages under `docs/enterprise/reference`.
*/ */
const writePage = (setting) => { const writePage = (setting) => {
let path = './docs/enterprise/reference/' + setting.name.replace(/\s/g, '-').toLowerCase() + ".md" let path =
console.log('Generating', path, "page") "./docs/enterprise/reference/" +
setting.name.replace(/\s/g, "-").toLowerCase() +
".md";
console.log("Generating", path, "page");
let frontmatter = let frontmatter = `---
`---
title: ${setting.name} title: ${setting.name}
lang: en-US lang: en-US
sidebarDepth: 2 sidebarDepth: 2
@ -97,50 +94,68 @@ meta:
content: configuration options settings Pomerium enterprise console content: configuration options settings Pomerium enterprise console
--- ---
` `;
let header = '# ' + setting.name + '\n' + '\n' let header = "# " + setting.name + "\n" + "\n";
let body = setting.doc ? setting.doc.toString() + '\n' : '' let body = setting.doc ? setting.doc.toString() + "\n" : "";
let moreBody = setting.settings ? setting.settings.map(subsection => writeSubsection(subsection, 2)).join('') : '' let moreBody = setting.settings
let content = frontmatter + header + body + moreBody ? setting.settings
.map((subsection) => writeSubsection(subsection, 2))
.join("")
: "";
let content = frontmatter + header + body + moreBody;
fs.writeFileSync(path, content) fs.writeFileSync(path, content);
};
}
/** /**
* Called by writePage, this function * Called by writePage, this function
* handles nested settings objects. * handles nested settings objects.
*/ */
const writeSubsection = (subsection, depth) => { const writeSubsection = (subsection, depth) => {
let subContent = '' let subContent = "";
if (!subsection.name) { if (!subsection.name) {
return return;
} }
if (!subsection.doc) { if (!subsection.doc) {
//console.log(subsection) //console.log(subsection)
//console.log(subsection.keys || "no key") //console.log(subsection.keys || "no key")
subContent = fromOSSettings(subsection.name, subsection.keys || null) + '\n' subContent =
fromOSSettings(subsection.name, subsection.keys || null) + "\n";
} }
let header = '#'.repeat(depth) + ' ' + subsection.name + '\n' + '\n' let header = "#".repeat(depth) + " " + subsection.name + "\n" + "\n";
subContent = subContent + (subsection.doc ? subsection.doc.toString() + '\n\n' : '') subContent =
subsection.attributes ? subContent = subContent + subsection.attributes.toString() : null subContent + (subsection.doc ? subsection.doc.toString() + "\n\n" : "");
subsection.settings ? subContent = subContent + subsection.settings.map(turtles => writeSubsection(turtles, depth + 1)).join('') : '' subsection.attributes
return header + subContent ? (subContent = subContent + subsection.attributes.toString())
} : null;
subsection.settings
? (subContent =
subContent +
subsection.settings
.map((turtles) => writeSubsection(turtles, depth + 1))
.join(""))
: "";
return header + subContent;
};
// Main // Main
console.log("Reading console-settings.yaml") console.log("Reading console-settings.yaml");
let docs = yaml.load(fs.readFileSync('./docs/enterprise/console-settings.yaml', 'utf8')) let docs = yaml.load(
let keysFile = yaml.load(fs.readFileSync('./docs/enterprise/pomerium-console_serve.yaml', 'utf8')) fs.readFileSync("./docs/enterprise/console-settings.yaml", "utf8")
let OSSettings = yaml.load(fs.readFileSync('./docs/reference/settings.yaml', 'utf8')) );
//console.log(`OSSettings: ${JSON.stringify(OSSettings)}`) // For Debugging let keysFile = yaml.load(
fs.readFileSync("./docs/enterprise/pomerium-console_serve.yaml", "utf8")
);
let OSSettings = yaml.load(
fs.readFileSync("./docs/reference/settings.yaml", "utf8")
);
//console.log(`OSSettings: ${JSON.stringify(OSSettings)}`) // For Debugging
writeConfigPage(keysFile) writeConfigPage(keysFile);
docs.settings.map( setting => {
writePage(setting)
})
docs.settings.map((setting) => {
writePage(setting);
});

View file

@ -5,8 +5,7 @@ import yaml
def main(): def main():
d = os.path.join(os.path.dirname(__file__), d = os.path.join(os.path.dirname(__file__), "..", "docs", "enterprise")
"..", "docs", "enterprise")
d = os.path.normpath(d) d = os.path.normpath(d)
print(f"generating {d}/reference.md") print(f"generating {d}/reference.md")
@ -14,8 +13,12 @@ def main():
doc = yaml.full_load(f) doc = yaml.full_load(f)
f.close() f.close()
f = open(os.path.join(os.path.dirname(__file__), f = open(
"..", "docs", "enterprise", "reference.md"), "w") os.path.join(
os.path.dirname(__file__), "..", "docs", "enterprise", "reference.md"
),
"w",
)
f.write(f"{doc['preamble']}\n") f.write(f"{doc['preamble']}\n")
write_setting(f, 1, doc) write_setting(f, 1, doc)
f.write(f"{doc['postamble']}") f.write(f"{doc['postamble']}")
@ -23,19 +26,19 @@ def main():
def write_setting(w, depth, setting): def write_setting(w, depth, setting):
if 'name' in setting: if "name" in setting:
w.write(f"{'#' * depth} {setting.get('name', '')}\n") w.write(f"{'#' * depth} {setting.get('name', '')}\n")
if 'attributes' in setting: if "attributes" in setting:
w.write(f"{setting.get('attributes','')}\n") w.write(f"{setting.get('attributes','')}\n")
if 'doc' in setting: if "doc" in setting:
w.write(f"{setting.get('doc', '')}\n") w.write(f"{setting.get('doc', '')}\n")
w.write("\n") w.write("\n")
for subsetting in setting.get('settings', []): for subsetting in setting.get("settings", []):
write_setting(w, depth+1, subsetting) write_setting(w, depth + 1, subsetting)
if __name__ == "__main__": if __name__ == "__main__":