diff --git a/src/smartstack/name/index.ts b/src/smartstack/name/index.ts index 26b878f..f5fb840 100644 --- a/src/smartstack/name/index.ts +++ b/src/smartstack/name/index.ts @@ -1,7 +1,40 @@ -import * as path from 'path'; -import { loadTemplate, renderTemplate, TemplateContext } from '../../template'; +import { renderTemplate, TemplateContext } from '../../template'; import { isSet } from '../../utils/isSet'; -const template = loadTemplate(path.join(__dirname, 'name.njk')); + +const template = `{# + Template for Stack Name prop + -------------------------------------------------------------------------------- + AWS CloudFormation stack names have a maximum length of 128 characters. + This template truncates various values if they exceed their limit: + + Max Lenghts: + + - No Environment or Account present: + 32+1+48 = 81 + + - Environment present: + 32+1+32+13+48 = 126 + + - Account present: + 32+1+32+9+48 = 122 + + #}{# + + "MyProject-" + #}{{ projectName | pascal | truncate(32, true, "") | append("-") }}{# + + #}{% if environment | notEmpty %}{# + "Staging-Environment-" + #}{{ environment | pascal | stripUnderscore | truncate(32, true, "") | append("-Environment-") }}{# + + #}{% elif account | notEmpty %}{# + "Dev-Account-" + #}{{ account | pascal| truncate(32, true, "") | append("-Account-") }}{# + + #}{% endif %}{# + + "MyStack" + #}{{ stackId | pascal | truncate(48, true, "")}}`; interface TemplateProps extends TemplateContext { stackId: string; diff --git a/src/smartstack/name/name.njk b/src/smartstack/name/name.njk deleted file mode 100644 index b95f8bc..0000000 --- a/src/smartstack/name/name.njk +++ /dev/null @@ -1,34 +0,0 @@ -{# -Template for Stack Name prop --------------------------------------------------------------------------------- -AWS CloudFormation stack names have a maximum length of 128 characters. -This template truncates various values if they exceed their limit: - -Max Lenghts: - -- No Environment or Account present: - 32+1+48 = 81 - -- Environment present: - 32+1+32+13+48 = 126 - -- Account present: - 32+1+32+9+48 = 122 - -#}{# - -"MyProject-" -#}{{ projectName | pascal | truncate(32, true, "") | append("-") }}{# - -#}{% if environment | notEmpty %}{# - "Staging-Environment-" - #}{{ environment | pascal | stripUnderscore | truncate(32, true, "") | append("-Environment-") }}{# - -#}{% elif account | notEmpty %}{# - "Dev-Account-" - #}{{ account | pascal| truncate(32, true, "") | append("-Account-") }}{# - -#}{% endif %}{# - -"MyStack" -#}{{ stackId | pascal | truncate(48, true, "")}} \ No newline at end of file diff --git a/src/template/index.ts b/src/template/index.ts index f54ff53..b37e91a 100644 --- a/src/template/index.ts +++ b/src/template/index.ts @@ -1,4 +1,3 @@ -import { readFileSync } from 'fs'; import { pascalCase } from 'change-case'; import { Environment } from 'nunjucks'; @@ -20,11 +19,6 @@ env.addFilter('append', function(str: string, trailer: string) { return `${str}${trailer}`; }); - -export function loadTemplate(path: string): string { - return readFileSync(path, 'utf-8').trim(); -} - type TemplateContextValue = string | undefined; export type TemplateContext = Record;