Skip to content

Commit

Permalink
Adding new flag for excluding resource types when in CI mode. Updates…
Browse files Browse the repository at this point in the history
… to README (#31)

Co-authored-by: Helton, Allen <[email protected]>
  • Loading branch information
allenheltondev and allenheltondev authored Mar 11, 2021
1 parent 6c2b11d commit f07282e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6,157 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,30 @@ CLI tool to visualise CloudFormation/SAM/CDK templates as diagrams.
Usage: cfn-dia [options] [command]
Options:
-v, --vers output the current version
-h, --help display help for command
-v, --vers Output the current version
-h, --help Display help for command
Commands:
Commands:
draw.io|d [options] Generates a draw.io diagram from a CloudFormation template
html|h [options] Generates a vis.js diagram from a CloudFormation template
browse|b [options] Browses and generates diagrams from your deployed templates
help [command] display help for command
```
draw.io|d [options] Generates a draw.io diagram from a CloudFormation template
html|h [options] Generates a vis.js diagram from a CloudFormation template
browse|b [options] Browses and generates diagrams from your deployed templates
help [command] Display help for command
Draw.io Options:
-t, --template-file [templateFile] Path to template or cdk.json file
-c, --ci-mode Disable terminal/console interactivity
-o, --output-file [outputFile] Name of output file
-co, --cdk-output [outputPath] CDK synth output path
-s, --skip-synth Skips CDK synth
-e, --exclude-types [excludeTypes] List of resource types to exclude when using CI mode
Html Options:
-t, --template-file [templateFile] Path to template or cdk.json file
-c, --ci-mode Disable terminal/console interactivity
-o, --output-path [outputPath] Name of output file
-co, --cdk-output [outputPath] CDK synth output path
-s, --skip-synth Skips CDK synth
```

## Output formats

Expand Down
8 changes: 6 additions & 2 deletions commands/draw.io/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ program
)
.option(
"-c, --ci-mode",
"Disable interactivity",
"Disable terminal/console interactivity",
false
)
.option("-o, --output-file [outputFile]", "Output file", "template.drawio")
.option("-o, --output-file [outputFile]", "Name of output file", "template.drawio")
.option(
"-co, --cdk-output [outputPath]",
"CDK synth output path",
Expand All @@ -27,6 +27,10 @@ program
"Skips CDK synth",
false
)
.option(
"-e, --exclude-types [excludeTypes...]",
"List of resource types to exclude when using CI mode"
)
.description("Generates a draw.io diagram from a CloudFormation template")
.action(async (cmd) => {
await mxGenerator.generate(cmd);
Expand Down
4 changes: 2 additions & 2 deletions commands/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ program
"Path to template or cdk.json file",
"template.yaml or cdk.json"
)
.option("-c, --ci-mode", "Disable interactivity", false)
.option("-c, --ci-mode", "Disable terminal/console interactivity", false)
.option(
"-o, --output-path [outputPath]",
"Output file",
"Name of output file",
`${path.join(tempDirectory, "cfn-diagram")}`
)
.option("-co, --cdk-output [outputPath]", "CDK synth output path", `cdk.out`)
Expand Down
12 changes: 12 additions & 0 deletions graph/MxGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ async function generate(cmd, template) {
}

if (ciMode) {
if(cmd.excludeTypes && Array.isArray(cmd.excludeTypes)){
const filteredTypes = filterConfig.resourceTypesToInclude.filter(type => shouldFilterFromCiTypeList(type, cmd.excludeTypes));
filterConfig.resourceTypesToInclude = filteredTypes;
}
const xml = renderTemplate(template);
fs.writeFileSync(cmd.outputFile, xml);
return;
Expand Down Expand Up @@ -362,6 +366,14 @@ function addTypesToShow(resources, types, template) {
}
}

function shouldFilterFromCiTypeList(type, excludeList) {
type = type.toLowerCase();
const isInExcludeList = excludeList.find(exclude => exclude.toLowerCase() == type
|| (type.startsWith('external resource') && type.includes(exclude)));

return !isInExcludeList;
}

module.exports = {
renderTemplate,
layouts,
Expand Down
Loading

0 comments on commit f07282e

Please sign in to comment.