declapract-typescript-ehmpathy 0.22.8 → 0.23.2

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.
Files changed (39) hide show
  1. package/dist/practices/{cicd-integrate → cicd-common}/best-practice/.github/workflows/.test.yml +10 -6
  2. package/dist/practices/{cicd-deploy-package → cicd-package}/best-practice/.github/workflows/.publish-npm.yml +4 -9
  3. package/dist/practices/cicd-package/best-practice/.github/workflows/publish.yml +15 -0
  4. package/dist/practices/cicd-package/best-practice/.github/workflows/test.yml +13 -0
  5. package/dist/practices/cicd-package/best-practice/package.json +6 -0
  6. package/dist/practices/cicd-package/best-practice/package.json.declapract.ts +4 -0
  7. package/dist/practices/config/bad-practices/divergent-config-shapes/config/dev.json.declapract.ts +1 -4
  8. package/dist/practices/config/bad-practices/divergent-config-shapes/config/prod.json.declapract.ts +1 -4
  9. package/dist/practices/format/best-practice/package.json.declapract.ts +31 -2
  10. package/dist/practices/git/best-practice/.gitignore.declapract.ts +1 -0
  11. package/dist/practices/terraform/best-practice/provision/aws/product/variables.tf +7 -0
  12. package/dist/practices/testing/best-practice/jest.unit.env.ts.declapract.ts +33 -0
  13. package/dist/useCases.yml +3 -3
  14. package/dist/utils/readFile.ts +5 -0
  15. package/package.json +2 -2
  16. package/dist/practices/cicd-deploy-package/best-practice/.github/workflows/publish.yml +0 -21
  17. package/dist/practices/format/best-practice/package.json +0 -6
  18. /package/dist/practices/{cicd-integrate → cicd-common}/bad-practices/old-names/.github/workflows/ci-on-commit.yml.declapract.ts +0 -0
  19. /package/dist/practices/{cicd-integrate → cicd-common}/bad-practices/old-names/.github/workflows/ci_on_commit.yml.declapract.ts +0 -0
  20. /package/dist/practices/{cicd-integrate → cicd-common}/bad-practices/old-names/.github/workflows/pr-release-on-main.yml.declapract.ts +0 -0
  21. /package/dist/practices/{cicd-integrate → cicd-common}/bad-practices/old-names/.github/workflows/test-on-commit.yml.declapract.ts +0 -0
  22. /package/dist/practices/{cicd-integrate → cicd-common}/bad-practices/old-names/.github/workflows/test_on_commit.yml.declapract.ts +0 -0
  23. /package/dist/practices/{cicd-integrate → cicd-common}/best-practice/.declapract.readme.md +0 -0
  24. /package/dist/practices/{cicd-integrate → cicd-common}/best-practice/.github/workflows/release.yml +0 -0
  25. /package/dist/practices/{cicd-deploy-package → cicd-package}/bad-practices/old-names/.github/workflows/publish_on_tag.yml.declapract.ts +0 -0
  26. /package/dist/practices/{cicd-deploy-package → cicd-package}/best-practice/.declapract.readme.md +0 -0
  27. /package/dist/practices/{cicd-deploy-service → cicd-service}/bad-practices/old-names/.github/workflows/deploy-dev-on-main.yml.declapract.ts +0 -0
  28. /package/dist/practices/{cicd-deploy-service → cicd-service}/bad-practices/old-names/.github/workflows/deploy-prod-on-tag.yml.declapract.ts +0 -0
  29. /package/dist/practices/{cicd-deploy-service → cicd-service}/bad-practices/old-names/.github/workflows/deploy_dev_on_main.yml.declapract.ts +0 -0
  30. /package/dist/practices/{cicd-deploy-service → cicd-service}/bad-practices/old-names/.github/workflows/deploy_dev_on_master.yml.declapract.ts +0 -0
  31. /package/dist/practices/{cicd-deploy-service → cicd-service}/bad-practices/old-names/.github/workflows/deploy_on_tag.yml.declapract.ts +0 -0
  32. /package/dist/practices/{cicd-deploy-service → cicd-service}/bad-practices/old-names/.github/workflows/deploy_prod_on_tag.yml.declapract.ts +0 -0
  33. /package/dist/practices/{cicd-deploy-service → cicd-service}/best-practice/.declapract.readme.md +0 -0
  34. /package/dist/practices/{cicd-deploy-service → cicd-service}/best-practice/.github/workflows/.deploy-sls.yml +0 -0
  35. /package/dist/practices/{cicd-deploy-service → cicd-service}/best-practice/.github/workflows/.sql-schema-control.yml +0 -0
  36. /package/dist/practices/{cicd-deploy-service → cicd-service}/best-practice/.github/workflows/.terraform.yml +0 -0
  37. /package/dist/practices/{cicd-deploy-service → cicd-service}/best-practice/.github/workflows/deploy.yml +0 -0
  38. /package/dist/practices/{cicd-deploy-service → cicd-service}/best-practice/.github/workflows/provision.yml +0 -0
  39. /package/dist/practices/{cicd-integrate → cicd-service}/best-practice/.github/workflows/test.yml +0 -0
@@ -6,17 +6,17 @@ on:
6
6
  aws-region:
7
7
  type: string
8
8
  description: the aws region within which we should run the tests
9
- required: true
9
+ required: false
10
10
  aws-account-id:
11
11
  type: string
12
12
  description: the id of the account the credentials are expected to access
13
- required: true
13
+ required: false
14
14
  secrets:
15
15
  aws-access-key-id:
16
- required: true
16
+ required: false
17
17
  description: required credentials to authenticate with aws the aws account against which to run the tests
18
18
  aws-secret-access-key:
19
- required: true
19
+ required: false
20
20
  description: required credentials to authenticate with aws the aws account against which to run the tests
21
21
 
22
22
  jobs:
@@ -174,14 +174,16 @@ jobs:
174
174
  key: ${{ runner.os }}-node-${{ github.sha }}
175
175
 
176
176
  - name: configure aws credentials
177
+ if: "${{ inputs.aws-account-id != '' }}"
177
178
  uses: aws-actions/configure-aws-credentials@v1
178
179
  id: credentials
179
180
  with:
180
181
  aws-access-key-id: ${{ secrets.aws-access-key-id }}
181
182
  aws-secret-access-key: ${{ secrets.aws-secret-access-key }}
182
- aws-region: us-east-1
183
+ aws-region: ${{ inputs.aws-region }}
183
184
 
184
185
  - name: confirm aws credentials
186
+ if: "${{ inputs.aws-account-id != '' }}"
185
187
  run: |
186
188
  [[ ${{steps.credentials.outputs.aws-account-id}} != ${{ inputs.aws-account-id }} ]] \
187
189
  && echo 'wrong aws account' && exit 1 \
@@ -213,14 +215,16 @@ jobs:
213
215
  key: ${{ runner.os }}-node-${{ github.sha }}
214
216
 
215
217
  - name: configure aws credentials
218
+ if: "${{ inputs.aws-account-id != '' }}"
216
219
  uses: aws-actions/configure-aws-credentials@v1
217
220
  id: credentials
218
221
  with:
219
222
  aws-access-key-id: ${{ secrets.aws-access-key-id }}
220
223
  aws-secret-access-key: ${{ secrets.aws-secret-access-key }}
221
- aws-region: us-east-1
224
+ aws-region: ${{ inputs.aws-region }}
222
225
 
223
226
  - name: confirm aws credentials
227
+ if: "${{ inputs.aws-account-id != '' }}"
224
228
  run: |
225
229
  [[ ${{steps.credentials.outputs.aws-account-id}} != ${{ inputs.aws-account-id }} ]] \
226
230
  && echo 'wrong aws account' && exit 1 \
@@ -12,17 +12,12 @@ jobs:
12
12
  runs-on: ubuntu-20.04
13
13
  steps:
14
14
  - name: checkout
15
- uses: actions/checkout@v2
15
+ uses: actions/checkout@v3
16
16
 
17
- - name: read nvmrc
18
- id: nvmrc
19
- run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
20
-
21
- - name: setup node
22
- uses: actions/setup-node@v2
17
+ - name: set node version
18
+ uses: actions/setup-node@v3
23
19
  with:
24
- node-version: ${{ steps.nvmrc.outputs.NODE_VERSION }}
25
- registry-url: 'https://registry.npmjs.org'
20
+ node-version-file: '.nvmrc'
26
21
  cache: 'npm'
27
22
 
28
23
  - name: install
@@ -0,0 +1,15 @@
1
+ name: publish
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v*
7
+
8
+ jobs:
9
+ test:
10
+ uses: ./.github/workflows/.test.yml
11
+
12
+ publish:
13
+ uses: ./.github/workflows/.publish-npm.yml
14
+ secrets:
15
+ npm-auth-token: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,13 @@
1
+ name: test
2
+
3
+ on:
4
+ workflow_call:
5
+ push:
6
+ branches-ignore:
7
+ - 'main' # exclude main branch, since deploy workflow triggers on main, and calls the test workflow inside of it already
8
+ tags-ignore:
9
+ - v* # exclude tags, since deploy workflow triggers on tags, and calls the test workflow inside of it already
10
+
11
+ jobs:
12
+ suite:
13
+ uses: ./.github/workflows/.test.yml
@@ -0,0 +1,6 @@
1
+ {
2
+ "scripts": {
3
+ "fix:format:terraform": "echo 'terraform not used'",
4
+ "test:format:terraform": "echo 'terraform not used'"
5
+ }
6
+ }
@@ -0,0 +1,4 @@
1
+ import { FileCheckType } from 'declapract';
2
+
3
+ // TODO: move this check out into the function that defines `fix:format`, and have it check whether it should include terraform instead
4
+ export const check = FileCheckType.CONTAINS;
@@ -1,10 +1,7 @@
1
1
  import { FileCheckFunction } from 'declapract';
2
2
  import flatten from 'flat';
3
- import fs from 'fs';
4
- import util from 'util';
5
3
 
6
- export const readFile = async (filePath: string) =>
7
- util.promisify(fs.readFile)(filePath, 'utf-8');
4
+ import { readFile } from '../../../../../utils/readFile';
8
5
 
9
6
  export const check: FileCheckFunction = async (contents, context) => {
10
7
  if (!contents) throw new Error('its fine'); // ... yeah, i know, todo: eliminate this weird "throw an error if its fine" pattern
@@ -1,10 +1,7 @@
1
1
  import { FileCheckFunction } from 'declapract';
2
2
  import flatten from 'flat';
3
- import fs from 'fs';
4
- import util from 'util';
5
3
 
6
- export const readFile = async (filePath: string) =>
7
- util.promisify(fs.readFile)(filePath, 'utf-8');
4
+ import { readFile } from '../../../../../utils/readFile';
8
5
 
9
6
  export const check: FileCheckFunction = async (contents, context) => {
10
7
  if (!contents) throw new Error('its fine'); // ... yeah, i know, todo: eliminate this weird "throw an error if its fine" pattern
@@ -1,3 +1,32 @@
1
- import { FileCheckType } from 'declapract';
1
+ import { FileCheckType, FileContentsFunction } from 'declapract/dist/domain';
2
+ import { isPresent } from 'type-fns';
2
3
 
3
- export const check = FileCheckType.CONTAINS;
4
+ /**
5
+ * declare the expected contents
6
+ */
7
+ export const contents: FileContentsFunction = (context) => {
8
+ const formatters = [
9
+ 'prettier',
10
+ context.projectPractices.includes('terraform') ? 'terraform' : null, // only include the terraform formatter if terraform practice is used
11
+ ].filter(isPresent);
12
+
13
+ return JSON.stringify(
14
+ {
15
+ scripts: {
16
+ 'fix:format': formatters
17
+ .map((formatter) => `npm run fix:format:${formatter}`)
18
+ .join(' && '),
19
+ 'test:format': formatters
20
+ .map((formatter) => `npm run test:format:${formatter}`)
21
+ .join(' && '),
22
+ },
23
+ },
24
+ null,
25
+ 2,
26
+ );
27
+ };
28
+
29
+ /**
30
+ * check that they're contained in the file
31
+ */
32
+ export const check: FileCheckType = FileCheckType.CONTAINS;
@@ -3,6 +3,7 @@ import expect from 'expect';
3
3
  import uniq from 'lodash.uniq';
4
4
 
5
5
  const expectedIgnores = [
6
+ '*.log',
6
7
  '.artifact', // deployment artifacts from `simple-artifact-builder` are produced here
7
8
  '.env',
8
9
  '.serverless',
@@ -12,3 +12,10 @@ locals {
12
12
  product = local.service
13
13
  }
14
14
  }
15
+
16
+ data "aws_caller_identity" "current" {}
17
+ data "aws_region" "current" {}
18
+ locals {
19
+ aws_account_id = data.aws_caller_identity.current.account_id
20
+ aws_region = data.aws_region.current.name
21
+ }
@@ -0,0 +1,33 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import { FileCheckType } from 'declapract';
3
+ import { FileContentsFunction } from 'declapract/dist/domain';
4
+
5
+ import { readFile } from '../../../utils/readFile';
6
+
7
+ /**
8
+ * declare the expected contents
9
+ */
10
+ export const contents: FileContentsFunction = async (context) => {
11
+ // grab the superset of best practices content
12
+ const contentsSuperset = await readFile(`${__dirname}/jest.unit.env.ts`);
13
+
14
+ // remove things that are irrelevant, based on other practices in use in project
15
+ let contents = contentsSuperset;
16
+ if (!context.projectPractices.includes('config'))
17
+ contents = contents.replace(
18
+ `
19
+ jest.mock('./src/utils/config/getConfig', () => ({
20
+ getConfig: jest.fn().mockImplementation(() => require('./config/test.json')), // mock that getConfig just returns plaintext test env config in unit tests
21
+ }));
22
+ `,
23
+ '',
24
+ );
25
+
26
+ // return the narrowed contents
27
+ return contents;
28
+ };
29
+
30
+ /**
31
+ * check that they're contained in the file
32
+ */
33
+ export const check: FileCheckType = FileCheckType.CONTAINS;
package/dist/useCases.yml CHANGED
@@ -2,7 +2,7 @@
2
2
  use-cases:
3
3
  typescript-project:
4
4
  practices:
5
- - cicd-integrate
5
+ - cicd-common
6
6
  - conventional-commits
7
7
  - directory-structure-src
8
8
  - domain
@@ -22,14 +22,14 @@ use-cases:
22
22
  extends:
23
23
  - typescript-project
24
24
  practices:
25
- - cicd-deploy-package
25
+ - cicd-package
26
26
  - node-package
27
27
  lambda-service:
28
28
  extends:
29
29
  - typescript-project
30
30
  practices:
31
31
  - artifact
32
- - cicd-deploy-service
32
+ - cicd-service
33
33
  - config
34
34
  - dates-and-times
35
35
  - environments-aws
@@ -0,0 +1,5 @@
1
+ import fs from 'fs';
2
+ import util from 'util';
3
+
4
+ export const readFile = async (filePath: string) =>
5
+ util.promisify(fs.readFile)(filePath, 'utf-8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "declapract-typescript-ehmpathy",
3
- "version": "0.22.8",
3
+ "version": "0.23.2",
4
4
  "description": "declapract best practices declarations for typescript",
5
5
  "main": "src/index.js",
6
6
  "repository": "ehmpathy/declapract-typescript-ehmpathy",
@@ -40,7 +40,7 @@
40
40
  "uuid": "3.4.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "declapract": "~0.10.10"
43
+ "declapract": "~0.11.2"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@commitlint/cli": "13.1.0",
@@ -1,21 +0,0 @@
1
- name: publish
2
-
3
- on:
4
- push:
5
- tags:
6
- - v*
7
-
8
- jobs:
9
- test:
10
- uses: ./.github/workflows/.test.yml
11
- with:
12
- aws-region: us-east-1
13
- aws-account-id: '@declapract{variable.awsAccountId.dev}'
14
- secrets:
15
- aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
16
- aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
17
-
18
- publish:
19
- uses: ./.github/workflows/.publish-npm.yml
20
- secrets:
21
- npm-auth-token: ${{ secrets.NPM_TOKEN }}
@@ -1,6 +0,0 @@
1
- {
2
- "scripts": {
3
- "fix:format": "npm run fix:format:prettier && npm run fix:format:terraform",
4
- "test:format": "npm run test:format:prettier && npm run test:format:terraform"
5
- }
6
- }