diff --git a/.commitlintrc.yml b/.commitlintrc.yml deleted file mode 100644 index 9f17590d..00000000 --- a/.commitlintrc.yml +++ /dev/null @@ -1,4 +0,0 @@ -extends: - - '@commitlint/config-angular' -rules: - 'header-max-length': [2, 'always', 100] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e52ddc27..db5df0a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,10 +41,11 @@ jobs: if: needs.checkExecution.outputs.shouldExecute == 'true' strategy: matrix: - # Test with Node.js v20 and v22 + # Test with Node.js 22, 24 and v25 node: - - 20 - 22 + - 24 + - 25 name: Node.js v${{ matrix.node }} steps: # checkout branch @@ -69,6 +70,9 @@ jobs: run: npm run test:ci build: runs-on: ubuntu-latest + permissions: + contents: read + packages: write needs: [checkExecution, test] # only execute if not skipped by commit message if: needs.checkExecution.outputs.shouldExecute == 'true' @@ -112,4 +116,4 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GH_TOKEN: ${{ secrets.GH_TOKEN_PUBLIC_REPO }} # necessary for publish-libs script + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # necessary for publish-libs script diff --git a/.lintstagedrc.yml b/.lintstagedrc.yml deleted file mode 100644 index 5c35b407..00000000 --- a/.lintstagedrc.yml +++ /dev/null @@ -1,5 +0,0 @@ -./package.json: - - npx sort-package-json - -'*': - - npm run format:staged diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 849ddff3..00000000 --- a/.prettierignore +++ /dev/null @@ -1 +0,0 @@ -dist/ diff --git a/.prettierrc.yml b/.prettierrc.yml deleted file mode 100644 index d86a7056..00000000 --- a/.prettierrc.yml +++ /dev/null @@ -1,5 +0,0 @@ -# https://github.com/prettier/prettier/blob/master/docs/options.md -printWidth: 120 -singleQuote: true -semi: false -trailingComma: all diff --git a/README.md b/README.md index 1a0e7ee3..8d3ba9ae 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,43 @@ Public helper packages with commonly used utilities / helpers. +
= {
+ [Key in keyof P]: P[Key] extends ProdSwitchable = {
+ [Key in keyof P]: P[Key] extends StageSwitchable {
+ readonly props: P
+ readonly configService: IacStackConfigService
+
+ getProdDependantProp [K]
+
+ getStageDependantProp [K]
+}
+
+/** the IacUtils constructable type used as return type when calling the {@link extendWithIacUtils} function */
+export type IacUtilsConstructable any> = new (
+ superArgs: ConstructorParameters
+
+/** the actual Utilities function which takes any class to extend */
+export function extendWithIacUtils any>(clazz: T): IacUtilsConstructable {
+ // The Utilities class which implements the Utilities interface */
+ class IacUtilsClazz extends ( {
+ constructor(
+ superArgs: ConstructorParameters [K] {
+ return this.configService.switchProdDependant( [K] {
+ return this.configService.switchStageDependant(
+}
diff --git a/packages/iac-utilities/src/base/utils/iac-stack-config.service.ts b/packages/iac-utilities/src/base/utils/iac-stack-config.service.ts
new file mode 100644
index 00000000..223c6d8c
--- /dev/null
+++ b/packages/iac-utilities/src/base/utils/iac-stack-config.service.ts
@@ -0,0 +1,134 @@
+import { StageInfo } from '@shiftcode/branch-utilities'
+
+import { IacStackNameStrategy } from '../commons/iac-stack-name-strategy.enum.js'
+import { ProdSwitchable } from '../commons/prod-switchable.model.js'
+import { StageSwitchable } from '../commons/stage-switchable.model.js'
+import { BaseRuntimeConfig } from './base-runtime-config.type.js'
+
+export type BaseRuntimeConfigProviderFn = () => BaseRuntimeConfig
+
+export class IacStackConfigService {
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
+ static readonly envBaseRuntimeConfig = 'SC_BASE_RUNTIME_CONFIG'
+
+ readonly stackName: string
+
+ constructor(
+ readonly stackBaseName: string,
+ private readonly nameStrategy: IacStackNameStrategy,
+ readonly stageInfo: StageInfo,
+ readonly region: string,
+ ) {
+ this.stackName = this.nameByStrategy(stackBaseName)
+ }
+
+ /**
+ * concatenates given propertyToName according to defined nameStrategy.
+ * default mode is 'append'
+ */
+ nameByStrategy(propertyToName: string, mode: 'append' | 'prepend' = 'append') {
+ switch (this.nameStrategy) {
+ case IacStackNameStrategy.PROD_DEPENDANT:
+ return this.prodDependantNaming('master', propertyToName, mode)
+ case IacStackNameStrategy.PROD_DEPENDANT_MAIN:
+ return this.prodDependantNaming('main', propertyToName, mode)
+ case IacStackNameStrategy.STAGE_DEPENDANT:
+ return this.stageDependantNaming(propertyToName, mode)
+ default:
+ throw new Error('Unsupported enum value for IacStackNameStrategy')
+ }
+ }
+
+ /**
+ * create name by defined {@link nameByStrategy} and given region
+ * mode defaults to append
+ * @example
+ * nameByStrategyAndRegion('abc') =>
+ */
+ nameByStrategyAndRegion(propertyToName: string, mode: 'append' | 'prepend' = 'append') {
+ switch (this.nameStrategy) {
+ case IacStackNameStrategy.PROD_DEPENDANT:
+ return this.prodDependantNaming('master', this.regionDependantNaming(propertyToName, mode), mode)
+ case IacStackNameStrategy.PROD_DEPENDANT_MAIN:
+ return this.prodDependantNaming('main', this.regionDependantNaming(propertyToName, mode), mode)
+ case IacStackNameStrategy.STAGE_DEPENDANT:
+ return this.stageDependantNaming(this.regionDependantNaming(propertyToName, mode), mode)
+ default:
+ throw new Error('Unsupported enum value for IacStackNameStrategy')
+ }
+ }
+
+ /** prepends the {@link stackName} to proveided propertyName */
+ stackDependantNaming(propertyToName: string) {
+ return `${this.stackName}-${propertyToName}`
+ }
+
+ /**
+ * get prod or nonProd value of a prodSwitchable property
+ */
+ switchProdDependant