@byaga/cdk-patterns 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ import {Stack} from 'aws-cdk-lib';
2
+ import {IStackArguments} from './IStackArguments'
3
+ import {IConstruct} from "constructs";
4
+
5
+ export class IDeployStack extends Stack {
6
+ registry: { [t: string]: { [n: string]: any } } = {}
7
+ stage: string
8
+ name: string
9
+
10
+ genName(...name: string[]): string {
11
+ return IDeployStack.genStackResourceName(this.name, this.stage, name.filter(n => !!n).join('-'))
12
+ }
13
+
14
+ genId(...name: string[]): string {
15
+ return IDeployStack.genStackResourceId(this.name, this.stage, name.filter(n => !!n).join('-'))
16
+ }
17
+
18
+ static genStackResourceName(stackName: string, resource: string, stage = 'develop') {
19
+ let name = stackName[0].toLowerCase() + stackName.substr(1)
20
+ name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase())
21
+ return `${name}-${resource}-${stage}`.toLowerCase()
22
+ }
23
+
24
+ static genStackResourceId(stackName: string, resource: string, stage = 'develop') {
25
+ const constructName = `${stackName}-${resource}-${stage}`
26
+ return constructName[0].toUpperCase() + constructName.substr(1).replace(/-./g, v => (v[1] || '').toUpperCase())
27
+ }
28
+
29
+ constructor(scope: IConstruct, props: IStackArguments) {
30
+ const options = (props || {}) as IStackArguments
31
+ const {stage = 'develop'} = options
32
+ super(scope, props.stackName + '-' + stage, {
33
+ ...props,
34
+ stackName: props.stackName + '-' + stage
35
+ });
36
+ const stack = this;
37
+ stack.name = props.stackName || '';
38
+
39
+ stack.stage = stage;
40
+
41
+ stack.tags.setTag('Stage', stage);
42
+ stack.tags.setTag('Stack', this.genName('ui-stack'));
43
+ }
44
+
45
+ get(type: string, name: string) {
46
+ const items = this.registry[type]
47
+ return (items && items[name]) || null
48
+ }
49
+
50
+ set(type: string, name: string, instance: any) {
51
+ this.registry[type] = this.registry[type] || {};
52
+ this.registry[type][name] = instance;
53
+ return instance;
54
+ }
55
+ }
@@ -0,0 +1,7 @@
1
+ import {StackProps} from '@aws-cdk/core';
2
+
3
+ export interface IStackArguments extends StackProps {
4
+ stage: string,
5
+ project: string,
6
+ owner: string
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byaga/cdk-patterns",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
5
5
  "main": " ",
6
6
  "scripts": {
@@ -12,5 +12,12 @@
12
12
  "AWS"
13
13
  ],
14
14
  "author": "VeryFineHat",
15
- "license": "MIT"
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "aws-cdk-lib": "^2.92.0",
18
+ "constructs": "^10.2.69",
19
+ "fs-extra": "^11.1.1",
20
+ "glob": "^10.3.3",
21
+ "js-yaml": "^4.1.0"
22
+ }
16
23
  }
package/cdk-patterns.iml DELETED
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="inheritedJdk" />
7
- <orderEntry type="sourceFolder" forTests="false" />
8
- </component>
9
- </module>