declapract-typescript-ehmpathy 0.23.0 → 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.
@@ -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;
@@ -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;
@@ -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.23.0",
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,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
- }