-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Nextra docs to reflect new app structure
Build CloudFormation documentation dynamically Build Terraform documentation dynamically
- Loading branch information
Showing
28 changed files
with
834 additions
and
100 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const fs = require('fs'); | ||
const YAML = require('yaml'); | ||
const templateFile = '../sam/template.yml'; | ||
const customTags = require('./cfn-tags'); | ||
|
||
function getParameters() { | ||
const { Parameters } = getTemplate(templateFile); | ||
const result = []; | ||
for (const param in Parameters) { | ||
result.push({ Name: param, ...Parameters[param] }); | ||
} | ||
return result; | ||
} | ||
|
||
async function getPropertyList(opts = {}) { | ||
const { compileMdx } = await import('nextra/compile'); | ||
|
||
const result = getParameters(); | ||
for (const param in result) { | ||
const prop = result[param]; | ||
const mdx = await compileMdx(`${opts?.descPrefix}${prop.Description}`, { defaultShowCopyCode: true }); | ||
prop.Description = mdx.result; | ||
} | ||
return result; | ||
} | ||
|
||
function getTemplate(file) { | ||
return YAML.parse(fs.readFileSync(file).toString(), { customTags }); | ||
} | ||
|
||
module.exports = { | ||
getParameters, | ||
getPropertyList, | ||
getTemplate | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const functionTags = { | ||
'!GetAtt': { type: 'string', quoted: false }, | ||
'!Sub': { type: 'string', quoted: true }, | ||
'!Ref': { type: 'string', quoted: false } | ||
}; | ||
|
||
module.exports = Object.entries(functionTags).map(([tag, { quoted }]) => { | ||
const key = tag === '!Ref' ? 'Ref' : tag.replace(/^!/, 'Fn::'); | ||
return { | ||
tag, | ||
identify: (val) => { | ||
const isTagged = Object.keys(val)[0] === key; | ||
return isTagged; | ||
}, | ||
resolve: (val) => { | ||
return { [key]: val }; | ||
}, | ||
stringify: (val) => { | ||
const result = val.value[key]; | ||
return quoted ? `"${result}"` : result; | ||
} | ||
}; | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { getTemplate } = require('./cfn-reader'); | ||
const { fence, stringify } = require('./render'); | ||
|
||
function example(format) { | ||
const template = getTemplate('../examples/cloudformation/custom_hostname.yml'); | ||
return fence(stringify(template, format), format); | ||
} | ||
|
||
function parameterList(format = 'object') { | ||
const { Parameters } = getTemplate('../sam/template.yml'); | ||
for (const key in Parameters) { | ||
Parameters[key] = Parameters[key].Type; | ||
} | ||
|
||
const result = { | ||
Type: 'AWS::Serverless::Application', | ||
Properties: { | ||
Location: { | ||
ApplicationId: | ||
'arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif-standalone-dev', | ||
SemanticVersion: '5.0.0' | ||
}, | ||
Parameters | ||
} | ||
}; | ||
return fence(stringify(result, format), format); | ||
} | ||
|
||
module.exports = { | ||
example, | ||
parameterList | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const customTags = require('./cfn-tags'); | ||
const YAML = require('yaml'); | ||
|
||
function fence(code, format) { | ||
return '```' + `${format}\n${code}\n` + '```'; | ||
} | ||
|
||
function stringify(data, format) { | ||
switch (format) { | ||
case 'json': | ||
return JSON.stringify(data, null, 2); | ||
case 'yaml': | ||
return YAML.stringify(data, { customTags }); | ||
default: | ||
return data.toString(); | ||
} | ||
} | ||
|
||
function displayValue(v) { | ||
if (v === '') return '""'; | ||
if (v.join) return v.join(' | '); | ||
return v; | ||
} | ||
|
||
function present(v) { | ||
if (v === 0) return true; | ||
if (v === '') return true; | ||
return !!v; | ||
} | ||
|
||
function snake(str) { | ||
return str.replace(/\B([A-Z])/g, '_$1').toLowerCase(); | ||
} | ||
|
||
module.exports = { | ||
displayValue, | ||
fence, | ||
present, | ||
snake, | ||
stringify | ||
}; |
Oops, something went wrong.