Skip to content

Commit

Permalink
autogen(docs): generate cli docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Feb 2, 2022
1 parent 4e6897f commit 9ce2b9e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 100 deletions.
3 changes: 1 addition & 2 deletions docs/docs/self-service/flows/code/registration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export const getFlowMethodOidcWithCompletion = {
browser: {
label: 'Browser UI',
image: require('./images/browser-oidc-invalid.png').default,
alt:
'User Registration HTML Form with missing or invalid fields when performing an OpenID Connect flow'
alt: 'User Registration HTML Form with missing or invalid fields when performing an OpenID Connect flow'
},
missing: {
label: 'Missing Website',
Expand Down
12 changes: 4 additions & 8 deletions docs/docs/self-service/flows/code/verification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ export const getFlowMethodLinkWithErrors = {
browser: {
label: 'Browser UI',
image: require('./images/browser-missing.png').default,
alt:
'Email Verification and Account Activation HTML Form with validation errors'
alt: 'Email Verification and Account Activation HTML Form with validation errors'
},
missing: {
label: 'Missing Email',
Expand All @@ -16,8 +15,7 @@ export const getFlowMethodLinkSuccess = {
browser: {
label: 'Browser UI',
image: require('./images/browser-success.png').default,
alt:
'Email Verification and Account Activation HTML Form with success message'
alt: 'Email Verification and Account Activation HTML Form with success message'
},
missing: {
label: 'Email Sent',
Expand All @@ -30,8 +28,7 @@ export const getFlowMethodLinkInvalidChallenge = {
browser: {
label: 'Browser UI',
image: require('./images/browser-invalid-challenge.png').default,
alt:
'Email Verification and Account Activation HTML Form with an invalid challenge'
alt: 'Email Verification and Account Activation HTML Form with an invalid challenge'
},
missing: {
label: 'Invalid Challenge',
Expand All @@ -44,8 +41,7 @@ export const getFlowMethodLinkChallengeDone = {
browser: {
label: 'Browser UI',
image: require('./images/browser-challenge-completed.png').default,
alt:
'Email Verification and Account Activation HTML Form with an invalid challenge'
alt: 'Email Verification and Account Activation HTML Form with an invalid challenge'
},
missing: {
label: 'Success State',
Expand Down
156 changes: 79 additions & 77 deletions docs/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,98 +45,100 @@ if (process.argv.length !== 3 || process.argv[1] === 'help') {

const config = require(path.resolve(process.argv[2]))

const enhance = (schema, parents = []) => (item) => {
const key = item.key.value

const path = [
...parents.map((parent) => ['properties', parent]),
['properties', key]
].flat()

if (['title', 'description'].find((f) => path[path.length - 1] === f)) {
return
}
const enhance =
(schema, parents = []) =>
(item) => {
const key = item.key.value

const path = [
...parents.map((parent) => ['properties', parent]),
['properties', key]
].flat()

if (['title', 'description'].find((f) => path[path.length - 1] === f)) {
return
}

const comments = [`# ${pathOr(key, [...path, 'title'], schema)} ##`, '']
const comments = [`# ${pathOr(key, [...path, 'title'], schema)} ##`, '']

const description = pathOr('', [...path, 'description'], schema)
if (description) {
comments.push(' ' + description.split('\n').join('\n '), '')
}
const description = pathOr('', [...path, 'description'], schema)
if (description) {
comments.push(' ' + description.split('\n').join('\n '), '')
}

const defaultValue = pathOr('', [...path, 'default'], schema)
if (defaultValue || defaultValue === false) {
comments.push(' Default value: ' + defaultValue, '')
}
const defaultValue = pathOr('', [...path, 'default'], schema)
if (defaultValue || defaultValue === false) {
comments.push(' Default value: ' + defaultValue, '')
}

const enums = pathOr('', [...path, 'enum'], schema)
if (enums && Array.isArray(enums)) {
comments.push(
' One of:',
...YAML.stringify(enums)
.split('\n')
.map((i) => ` ${i}`)
) // split always returns one empty object so no need for newline
}
const enums = pathOr('', [...path, 'enum'], schema)
if (enums && Array.isArray(enums)) {
comments.push(
' One of:',
...YAML.stringify(enums)
.split('\n')
.map((i) => ` ${i}`)
) // split always returns one empty object so no need for newline
}

const min = pathOr('', [...path, 'minimum'], schema)
if (min || min === 0) {
comments.push(` Minimum value: ${min}`, '')
}
const min = pathOr('', [...path, 'minimum'], schema)
if (min || min === 0) {
comments.push(` Minimum value: ${min}`, '')
}

const max = pathOr('', [...path, 'maximum'], schema)
if (max || max === 0) {
comments.push(` Maximum value: ${max}`, '')
}
const max = pathOr('', [...path, 'maximum'], schema)
if (max || max === 0) {
comments.push(` Maximum value: ${max}`, '')
}

const examples = pathOr('', [...path, 'examples'], schema)
if (examples) {
comments.push(
' Examples:',
...YAML.stringify(examples)
.split('\n')
.map((i) => ` ${i}`)
) // split always returns one empty object so no need for newline
}
const examples = pathOr('', [...path, 'examples'], schema)
if (examples) {
comments.push(
' Examples:',
...YAML.stringify(examples)
.split('\n')
.map((i) => ` ${i}`)
) // split always returns one empty object so no need for newline
}

let hasChildren
if (item.value.items) {
item.value.items.forEach((item) => {
if (item.key) {
enhance(schema, [...parents, key])(item)
hasChildren = true
}
})
}
let hasChildren
if (item.value.items) {
item.value.items.forEach((item) => {
if (item.key) {
enhance(schema, [...parents, key])(item)
hasChildren = true
}
})
}

const showEnvVarBlockForObject = pathOr(
'',
[...path, 'showEnvVarBlockForObject'],
schema
)
if (!hasChildren || showEnvVarBlockForObject) {
const env = [...parents, key].map((i) => i.toUpperCase()).join('_')
comments.push(
' Set this value using environment variables on',
' - Linux/macOS:',
` $ export ${env}=<value>`,
' - Windows Command Line (CMD):',
` > set ${env}=<value>`,
''
const showEnvVarBlockForObject = pathOr(
'',
[...path, 'showEnvVarBlockForObject'],
schema
)

// Show this if the config property is an object, to call out how to specify the env var
if (hasChildren) {
if (!hasChildren || showEnvVarBlockForObject) {
const env = [...parents, key].map((i) => i.toUpperCase()).join('_')
comments.push(
' This can be set as an environment variable by supplying it as a JSON object.',
' Set this value using environment variables on',
' - Linux/macOS:',
` $ export ${env}=<value>`,
' - Windows Command Line (CMD):',
` > set ${env}=<value>`,
''
)

// Show this if the config property is an object, to call out how to specify the env var
if (hasChildren) {
comments.push(
' This can be set as an environment variable by supplying it as a JSON object.',
''
)
}
}
}

item.commentBefore = comments.join('\n')
item.spaceBefore = true
}
item.commentBefore = comments.join('\n')
item.spaceBefore = true
}

new Promise((resolve, reject) => {
parser.dereference(
Expand Down
26 changes: 14 additions & 12 deletions docs/src/theme/CodeFromRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,23 @@ const findLine = (needle, haystack) => {
return index
}

const transform = ({ startAt, endAt }) => (content) => {
let lines = content.split('\n')
const transform =
({ startAt, endAt }) =>
(content) => {
let lines = content.split('\n')

const startIndex = findLine(startAt, lines)
if (startIndex > 0) {
lines = ['// ...', ...lines.slice(startIndex, -1)]
}
const startIndex = findLine(startAt, lines)
if (startIndex > 0) {
lines = ['// ...', ...lines.slice(startIndex, -1)]
}

const endIndex = findLine(endAt, lines)
if (endIndex > 0) {
lines = [...lines.slice(0, endIndex + 1), '// ...']
}
const endIndex = findLine(endAt, lines)
if (endIndex > 0) {
lines = [...lines.slice(0, endIndex + 1), '// ...']
}

return lines.join('\n')
}
return lines.join('\n')
}

const CodeFromRemote = (props) => {
const { src, title } = props
Expand Down
3 changes: 2 additions & 1 deletion docs/src/theme/ketoRelationTuplesPrism.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default (prism) =>
(prism.languages['keto-relation-tuples'] = {
comment: /\/\/.*(\n|$)/,
'relation-tuple': {
pattern: /([^:#@()\n]+:)?([^:#@()\n]+)#([^:#@()\n]+)@?((\(([^:#@()\n]+:)?([^:#@()\n]+)#([^:#@()\n]*)\))|([^:#@()\n]+))/,
pattern:
/([^:#@()\n]+:)?([^:#@()\n]+)#([^:#@()\n]+)@?((\(([^:#@()\n]+:)?([^:#@()\n]+)#([^:#@()\n]*)\))|([^:#@()\n]+))/,
inside: {
namespace,
object,
Expand Down

0 comments on commit 9ce2b9e

Please sign in to comment.