diff --git a/API.md b/API.md
index 7b2046f..70be2dd 100644
--- a/API.md
+++ b/API.md
@@ -4,6 +4,8 @@
### AccountWrapper
+Wrapper for account-level stacks.
+
#### Initializers
```typescript
@@ -89,6 +91,8 @@ The tree node.
### EnvironmentWrapper
+Wrapper for environmental stacks.
+
#### Initializers
```typescript
@@ -1461,6 +1465,8 @@ public readonly config: {[ key: string ]: any};
### AccountStrategyOneProps
+Props `AccountStrategy.one`.
+
#### Initializer
```typescript
@@ -1500,6 +1506,8 @@ public readonly mock: AccountConfiguration;
### AccountStrategyThreeProps
+Props `AccountStrategy.three`.
+
#### Initializer
```typescript
@@ -1561,6 +1569,8 @@ public readonly mock: AccountConfiguration;
### AccountStrategyTwoProps
+Props `AccountStrategy.two`.
+
#### Initializer
```typescript
diff --git a/src/smartstack/name/index.test.ts b/src/smartstack/name/index.test.ts
index 5a4d835..8e9a0b7 100644
--- a/src/smartstack/name/index.test.ts
+++ b/src/smartstack/name/index.test.ts
@@ -42,7 +42,7 @@ describe('SmartStack', () => {
environmentType: 'testing',
stackId: 'my-stack',
},
- expected: 'MyProject-Testing-Environment-MyStack',
+ expected: 'MyProject-Environment-Testing-MyStack',
},
{
name: 'environmentType missing',
@@ -88,7 +88,7 @@ describe('SmartStack', () => {
environmentType: 'testing',
stackId: 'n'.repeat(49),
},
- expected: 'MyProject-Testing-Environment-'+capitalizeFirstLetter('n'.repeat(48)),
+ expected: 'MyProject-Environment-Testing-'+capitalizeFirstLetter('n'.repeat(48)),
},
{
name: 'too long project name',
@@ -98,7 +98,7 @@ describe('SmartStack', () => {
environmentType: 'testing',
stackId: 'my-stack',
},
- expected: capitalizeFirstLetter('n'.repeat(32))+'-Testing-Environment-MyStack',
+ expected: capitalizeFirstLetter('n'.repeat(32))+'-Environment-Testing-MyStack',
},
{
name: 'too long accountType name',
@@ -118,7 +118,7 @@ describe('SmartStack', () => {
environmentType: 'n'.repeat(33),
stackId: 'my-stack',
},
- expected: 'MyProject-'+capitalizeFirstLetter('n'.repeat(32))+'-Environment-MyStack',
+ expected: 'MyProject-Environment-'+capitalizeFirstLetter('n'.repeat(32))+'-MyStack',
},
{
name: 'everything too long',
@@ -128,8 +128,8 @@ describe('SmartStack', () => {
environmentType: 'n'.repeat(33),
stackId: 'n'.repeat(49),
},
- expected: capitalizeFirstLetter('n'.repeat(32))+'-'+capitalizeFirstLetter('n'.repeat(32))+'-Environment-'+capitalizeFirstLetter('n'.repeat(48)),
+ expected: capitalizeFirstLetter('n'.repeat(32))+'-Environment-'+capitalizeFirstLetter('n'.repeat(32))+'-'+capitalizeFirstLetter('n'.repeat(48)),
},
].map(runTest);
});
-});
\ No newline at end of file
+});
diff --git a/src/smartstack/name/index.ts b/src/smartstack/name/index.ts
index f5fb840..a914599 100644
--- a/src/smartstack/name/index.ts
+++ b/src/smartstack/name/index.ts
@@ -1,38 +1,38 @@
import { renderTemplate, TemplateContext } from '../../template';
import { isSet } from '../../utils/isSet';
-const template = `{#
+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:
+
+ - No Environment or Account present:
32+1+48 = 81
-
+
- Environment present:
32+1+32+13+48 = 126
-
- - Account present:
+
+ - 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 %}{#
+ #}{{ projectName | pascal | truncate(32, true, "") | append("-") }}{#
+
+ #}{% if environment | notEmpty %}{#
+ "Environment-Staging-"
+ #}{{ environment | pascal | stripUnderscore | truncate(32, true, "") | prepend("Environment-") | append("-") }}{#
+
+ #}{% elif account | notEmpty %}{#
"Dev-Account-"
- #}{{ account | pascal| truncate(32, true, "") | append("-Account-") }}{#
-
- #}{% endif %}{#
-
+ #}{{ account | pascal| truncate(32, true, "") | append("-Account-") }}{#
+
+ #}{% endif %}{#
+
"MyStack"
#}{{ stackId | pascal | truncate(48, true, "")}}`;
@@ -63,4 +63,4 @@ export function formatName(props: NameProps): string {
account: props.accountType,
environment: props.environmentType,
});
-}
\ No newline at end of file
+}
diff --git a/src/template/index.ts b/src/template/index.ts
index b37e91a..9a2bd3b 100644
--- a/src/template/index.ts
+++ b/src/template/index.ts
@@ -15,6 +15,10 @@ env.addFilter('notEmpty', function(str: string) {
return typeof str === 'string' && str.length > 0;
});
+env.addFilter('prepend', function(str: string, leader: string) {
+ return `${leader}${str}`;
+});
+
env.addFilter('append', function(str: string, trailer: string) {
return `${str}${trailer}`;
});
@@ -24,4 +28,4 @@ export type TemplateContext = Record;
export function renderTemplate(template: string, context: T): string {
return env.renderString(template, context);
-}
\ No newline at end of file
+}
diff --git a/test/integration.test.ts b/test/integration.test.ts
index 1709f3c..87a4eca 100644
--- a/test/integration.test.ts
+++ b/test/integration.test.ts
@@ -44,7 +44,7 @@ describe('Integration', () => {
},
});
- expect(stack.stackName).toBe('MyCoolProject-Development-Environment-TestStack');
+ expect(stack.stackName).toBe('MyCoolProject-Environment-Development-TestStack');
expect(stack.terminationProtection).toBeFalsy();
expect(stack.region).toBe('eu-west-1');
@@ -124,7 +124,7 @@ describe('Integration', () => {
},
});
- expect(stack.stackName).toBe('MyCoolProject-FeatureAbc123-Environment-TestStack');
+ expect(stack.stackName).toBe('MyCoolProject-Environment-FeatureAbc123-TestStack');
expect(stack.terminationProtection).toBeFalsy();
expect(stack.region).toBe('eu-west-1');
@@ -204,7 +204,7 @@ describe('Integration', () => {
},
});
- expect(stack.stackName).toBe('MyCoolProject-Production-Environment-TestStack');
+ expect(stack.stackName).toBe('MyCoolProject-Environment-Production-TestStack');
expect(stack.terminationProtection).toBeTruthy();
expect(stack.region).toBe('eu-west-1');