UNPKG

@nolanrigo/cloudformation

Version:

TypeScript-based imperative way to define AWS CloudFormation templates

68 lines (57 loc) 1.71 kB
#!/usr/bin/env node const { resolve } = require("path"); const tsNode = require("ts-node"); const arg = require("arg"); const color = require("chalk"); const minifyjson = require("jsonminify"); const { _: [path], "--help": showHelp = false, "--version": showVersion = false, "--minify": minify = false, } = arg({ // Types "--help": Boolean, "--version": Boolean, "--minify": Boolean, // Aliases "-h": "--help", "-v": "--version", "-m": "--minify", }); if (showVersion) { console.warn(`Show versions (WIP)`); process.exit(1); } if (showHelp || !path) { console.warn(`${color.bold.white( "cloudformation - TypeScript-based imperative way to define AWS CloudFormation templates", )} usage: cloudformation [-m|--minify] <path> <path> should point to the TypeScript file containing entrypoint of the CloudFormation definition options: -m, --minify Minify JSON output, default: false -h, --help Show the help menu (this one) -v, --version Show the version of the cli and the versions of schemas used ${color.green("- Generate cloudformation template")} ${color.red( `cloudformation ${color.blue("aws/template.ts")} > ${color.blue( "generated.template", )}`, )} ${color.green("- Generate minifed cloudformation template")} ${color.red( `cloudformation -m ${color.blue("aws/template.ts")} > ${color.blue( "generated.template", )}`, )} ${color.green("- Print cloudformation versions")} ${color.red("cloudformation -v")} `); process.exit(1); } (async function () { tsNode.register(); const { default: template } = await require(resolve(path)); console.log(minify ? minifyjson(template) : template); })();