@openmrs/config-cli
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -31,4 +31,4 @@ import { execSync } from "child_process"; | ||
it("includes out of the box validators", () => { | ||
expect(result).toMatch(/- must be a string/i); | ||
expect(result).toMatch(/- must be a boolean/i); | ||
expect(result).toMatch(/must be a string\./i); | ||
expect(result).toMatch(/must be a boolean\./i); | ||
}); | ||
@@ -40,3 +40,14 @@ | ||
test.todo("includes 'description' key"); | ||
it("includes higher-level validators", () => { | ||
expect(result).toMatch(/bar[\s\S]*higher-level validator/); | ||
}); | ||
it("includes 'description' key", () => { | ||
expect(result).toMatch("The most beautiful string you can think of"); | ||
}); | ||
it("includes higher-level descriptions", () => { | ||
expect(result).toMatch(/bar[\s\S]*higher-level description/); | ||
}); | ||
test.todo("reasonable formatting for default arrays"); | ||
@@ -66,3 +77,3 @@ }); | ||
// we modify the config schema a little bit | ||
execSync('sed -i "s/foo/bar/" ' + fixture); | ||
execSync('sed -i "s/foo/doof/" ' + fixture); | ||
try { | ||
@@ -73,3 +84,3 @@ execSync(`./bin/cli.js -e ${fixture} -o ${readmePath}`, { | ||
const result = fs.readFileSync(readmePath, "utf-8"); | ||
const expectedBar = new RegExp(initialReadme + "[\\s\\S]*" + "bar.*tsx"); | ||
const expectedBar = new RegExp(initialReadme + "[\\s\\S]*" + "doof.*tsx"); | ||
expect(result).toMatch(expectedBar); | ||
@@ -79,3 +90,3 @@ expect(result).not.toMatch(expectedFoo); | ||
// we change it back | ||
execSync('sed -i "s/bar/foo/" ' + fixture); | ||
execSync('sed -i "s/doof/foo/" ' + fixture); | ||
} | ||
@@ -82,0 +93,0 @@ }); |
@@ -11,6 +11,4 @@ # My Module | ||
- **foo** *(default: tsx)* | ||
- must be a string | ||
- must be a boolean | ||
- it's ok | ||
- **foo** *(default: tsx)*\ | ||
*must be a string. must be a boolean. it's ok.* | ||
<!-- END OF GENERATED --> |
@@ -28,16 +28,16 @@ var fs = require("fs"); | ||
for (let key of Object.keys(schema)) { | ||
const thisKeyPath = keyPath.concat([key]); | ||
const indents = " ".repeat(keyPath.length); | ||
const startStr = "\n" + indents + "- "; | ||
if (schema[key].hasOwnProperty("default")) { | ||
if ( | ||
!["default", "description", "validators"].includes(key) && | ||
isOrdinaryObject(schema[key]) | ||
) { | ||
const thisKeyPath = keyPath.concat([key]); | ||
const indents = " ".repeat(keyPath.length); | ||
const startStr = "\n" + indents + "- "; | ||
const isLeaf = schema[key].hasOwnProperty("default"); | ||
doc += | ||
startStr + | ||
"**" + | ||
key + | ||
"**" + | ||
documentationForKey(schema[key], indents); | ||
} else { | ||
// recurse for nested keys | ||
doc += startStr + key; | ||
doc += generateDocFromSchema(schema[key], thisKeyPath); | ||
(isLeaf ? "**" + key + "**" + defaultText(schema[key].default) : key); | ||
doc += descriptionText(schema[key].description, indents); | ||
doc += generateDocFromSchema(schema[key], thisKeyPath); // recurse | ||
doc += validatorText(schema[key].validators, indents); | ||
} | ||
@@ -48,13 +48,16 @@ } | ||
function documentationForKey(keySchema, indents) { | ||
const defaultStr = " *(default: " + keySchema.default + ")*"; | ||
let validatorStrings = ""; | ||
if (keySchema.validators) { | ||
const validatorPrefix = "\n " + indents + "- "; | ||
validatorStrings = | ||
validatorPrefix + keySchema.validators.join(validatorPrefix); | ||
} | ||
return defaultStr + validatorStrings; | ||
function defaultText(defaultStr) { | ||
return " *(default: " + defaultStr + ")*"; | ||
} | ||
function descriptionText(description, indents) { | ||
return description ? "\\\n " + indents + description : ""; | ||
} | ||
function validatorText(validators, indents) { | ||
return validators | ||
? "\\\n " + indents + "*" + validators.join(". ") + ".*" | ||
: ""; | ||
} | ||
function appendOrReplaceDocstring(outfile, docString) { | ||
@@ -80,1 +83,5 @@ const inputString = fs.readFileSync(outfile, "utf8"); | ||
} | ||
function isOrdinaryObject(value) { | ||
return typeof value === "object" && !Array.isArray(value) && value !== null; | ||
} |
{ | ||
"name": "@openmrs/config-cli", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Generates documentation about module configurability", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15012
394