From edb5139265ad0ec1476b23cb04752fca5a7d999a Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 12:38:43 +0100 Subject: [PATCH 01/41] PLA-256 Update tsconfig options --- src/backend-test/index.ts | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/backend-test/index.ts diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts new file mode 100644 index 00000000..3e337a1a --- /dev/null +++ b/src/backend-test/index.ts @@ -0,0 +1,58 @@ +import {NodePackageManager} from 'projen/lib/javascript' +import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' +import {IWithTelemetryReportUrl} from '../common' + +export interface OttofellerBackendTestProjectOptions extends TypeScriptProjectOptions {} + +export class OttofellerBackendTestProject extends TypeScriptProject implements IWithTelemetryReportUrl { + readonly reportTargetUrl?: string + readonly reportTargetAuthHeaderName?: string + + constructor(options: OttofellerBackendTestProjectOptions) { + super({ + ...options, + bundlerOptions: {}, + jest: true, + eslint: false, + projenrcTs: true, + projenrcJs: false, + name: 'backend-test', + packageManager: options.packageManager ?? NodePackageManager.NPM, + srcdir: options.srcdir ?? '.', + + tsconfig: { + compilerOptions: { + target: 'esnext', + module: 'esnext', + noEmit: true, + isolatedModules: false, + strict: true, + noImplicitAny: true, + strictNullChecks: true, + strictPropertyInitialization: true, + noImplicitThis: true, + alwaysStrict: true, + noUnusedParameters: true, + noImplicitReturns: true, + noFallthroughCasesInSwitch: true, + noUncheckedIndexedAccess: true, + baseUrl: './', + paths: { + '*': ['./*'], + }, + esModuleInterop: true, + skipLibCheck: true, + forceConsistentCasingInFileNames: true, + resolveJsonModule: true, + }, + }, + + // In case Github is enabled remove all default stuff. + githubOptions: {mergify: false, pullRequestLint: false}, + buildWorkflow: false, + release: false, + depsUpgrade: false, + pullRequestTemplate: false, + }) + } +} From e1b19ba1bc822ab7d3dd5e8d43f2555cb70ec74f Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 12:49:21 +0100 Subject: [PATCH 02/41] PLA-256 Add assets dir and sampleCode func --- src/backend-test/assets/.env.development | 3 +++ src/backend-test/index.ts | 5 +++++ src/backend-test/sample-code.ts | 11 +++++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/backend-test/assets/.env.development create mode 100644 src/backend-test/sample-code.ts diff --git a/src/backend-test/assets/.env.development b/src/backend-test/assets/.env.development new file mode 100644 index 00000000..6f616da6 --- /dev/null +++ b/src/backend-test/assets/.env.development @@ -0,0 +1,3 @@ +HASURA_GRAPHQL_URL=http://localhost:8080/v1/graphql +HASURA_GRAPHQL_ADMIN_SECRET=111 +UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar \ No newline at end of file diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 3e337a1a..07ca2d35 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,6 +1,8 @@ import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' import {IWithTelemetryReportUrl} from '../common' +import * as path from 'path' +import { sampleCode } from './sample-code' export interface OttofellerBackendTestProjectOptions extends TypeScriptProjectOptions {} @@ -54,5 +56,8 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I depsUpgrade: false, pullRequestTemplate: false, }) + + const assetsDir = path.join(__dirname, '..', '..', 'src/backend-test/assets') + sampleCode(this, options, assetsDir) } } diff --git a/src/backend-test/sample-code.ts b/src/backend-test/sample-code.ts new file mode 100644 index 00000000..998a6798 --- /dev/null +++ b/src/backend-test/sample-code.ts @@ -0,0 +1,11 @@ +import { SampleFile } from "projen"; +import { OttofellerBackendTestProject, OttofellerBackendTestProjectOptions } from "."; +import * as path from 'path' + +export function sampleCode(project: OttofellerBackendTestProject, options: OttofellerBackendTestProjectOptions, assetsDir: string){ + if (options.sampleCode === false){ + return + } + + new SampleFile(project, '.env.development', {sourcePath: path.join(assetsDir, '.env.development')}) +} \ No newline at end of file From 4d18803a8b126627a3b9aa28e2d26e2643ff3e6b Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 13:43:20 +0100 Subject: [PATCH 03/41] PLA-256 Add script to template --- src/backend-test/index.ts | 10 ++++++++++ src/index.ts | 1 + 2 files changed, 11 insertions(+) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 07ca2d35..73fdbe8d 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -6,6 +6,12 @@ import { sampleCode } from './sample-code' export interface OttofellerBackendTestProjectOptions extends TypeScriptProjectOptions {} +/** + * Backend-test template with TypeScript support. + * + * @pjid ottofeller-backend-test + */ + export class OttofellerBackendTestProject extends TypeScriptProject implements IWithTelemetryReportUrl { readonly reportTargetUrl?: string readonly reportTargetAuthHeaderName?: string @@ -59,5 +65,9 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I const assetsDir = path.join(__dirname, '..', '..', 'src/backend-test/assets') sampleCode(this, options, assetsDir) + + this.addScripts({ + 'test': 'jest --detectOpenHandles', + }) } } diff --git a/src/index.ts b/src/index.ts index 1021a10c..cc5a1067 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,3 +4,4 @@ export * from './common' export * from './nextjs' export * from './playwright' export * from './sst' +export * from './backend-test' From a700f5e08123eb6547a8da3352676e94e76fce91 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 14:00:03 +0100 Subject: [PATCH 04/41] PLA-256 Add postSynthesize --- src/backend-test/index.ts | 16 ++++++++++++---- src/backend-test/sample-code.ts | 20 ++++++++++++-------- src/index.ts | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 73fdbe8d..9d69d67c 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,8 +1,9 @@ +import {execSync} from 'child_process' +import * as path from 'path' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' -import {IWithTelemetryReportUrl} from '../common' -import * as path from 'path' -import { sampleCode } from './sample-code' +import {IWithTelemetryReportUrl, collectTelemetry} from '../common' +import {sampleCode} from './sample-code' export interface OttofellerBackendTestProjectOptions extends TypeScriptProjectOptions {} @@ -67,7 +68,14 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I sampleCode(this, options, assetsDir) this.addScripts({ - 'test': 'jest --detectOpenHandles', + test: 'jest --detectOpenHandles', }) } + + postSynthesize(): void { + execSync('prettier --write .projenrc.ts') + execSync('eslint --fix .projenrc.ts') + + collectTelemetry(this) + } } diff --git a/src/backend-test/sample-code.ts b/src/backend-test/sample-code.ts index 998a6798..76df5ee7 100644 --- a/src/backend-test/sample-code.ts +++ b/src/backend-test/sample-code.ts @@ -1,11 +1,15 @@ -import { SampleFile } from "projen"; -import { OttofellerBackendTestProject, OttofellerBackendTestProjectOptions } from "."; import * as path from 'path' +import {SampleFile} from 'projen' +import {OttofellerBackendTestProject, OttofellerBackendTestProjectOptions} from '.' -export function sampleCode(project: OttofellerBackendTestProject, options: OttofellerBackendTestProjectOptions, assetsDir: string){ - if (options.sampleCode === false){ - return - } +export function sampleCode( + project: OttofellerBackendTestProject, + options: OttofellerBackendTestProjectOptions, + assetsDir: string, +) { + if (options.sampleCode === false) { + return + } - new SampleFile(project, '.env.development', {sourcePath: path.join(assetsDir, '.env.development')}) -} \ No newline at end of file + new SampleFile(project, '.env.development', {sourcePath: path.join(assetsDir, '.env.development')}) +} diff --git a/src/index.ts b/src/index.ts index cc5a1067..ec085a0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ export * from './apollo-server' +export * from './backend-test' export * from './cdk' export * from './common' export * from './nextjs' export * from './playwright' export * from './sst' -export * from './backend-test' From 1e564fc6d409b1acbca61ec5f7538db81f3e9b39 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 14:05:28 +0100 Subject: [PATCH 05/41] PLA-256 Update tsconfig --- src/backend-test/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 9d69d67c..757c14a1 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -52,7 +52,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I esModuleInterop: true, skipLibCheck: true, forceConsistentCasingInFileNames: true, - resolveJsonModule: true, }, }, From c6ccdf3dec2e252580606d642d7dffe0d084d0e6 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 14:08:45 +0100 Subject: [PATCH 06/41] PLA-256 Update interface --- src/backend-test/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 757c14a1..611a8266 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -2,10 +2,22 @@ import {execSync} from 'child_process' import * as path from 'path' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' -import {IWithTelemetryReportUrl, collectTelemetry} from '../common' +import { + IWithTelemetryReportUrl, + WithCustomLintPaths, + WithDefaultWorkflow, + WithGitHooks, + WithTelemetry, + collectTelemetry, +} from '../common' import {sampleCode} from './sample-code' -export interface OttofellerBackendTestProjectOptions extends TypeScriptProjectOptions {} +export interface OttofellerBackendTestProjectOptions + extends TypeScriptProjectOptions, + WithTelemetry, + WithGitHooks, + WithCustomLintPaths, + WithDefaultWorkflow {} /** * Backend-test template with TypeScript support. From dd117c4ce9245638ece327e62fa8998accf9f3e6 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 14:19:07 +0100 Subject: [PATCH 07/41] PLA-256 Add tasks for remove --- src/backend-test/index.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 611a8266..da4ff23c 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,4 +1,3 @@ -import {execSync} from 'child_process' import * as path from 'path' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' @@ -75,17 +74,46 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I pullRequestTemplate: false, }) + // ANCHOR Source code const assetsDir = path.join(__dirname, '..', '..', 'src/backend-test/assets') sampleCode(this, options, assetsDir) + // // ANCHOR playwright config + // new SampleFile(this, 'playwright.config.ts', {sourcePath: path.join(assetsDir, 'playwright.config.ts.sample')}) + this.addScripts({ test: 'jest --detectOpenHandles', }) + + /* + * Clean off the projen tasks and if needed replace them with regular npm scripts. + * This way we ensure smooth ejection experience with all the commands visible in package.json + * and no need to keep the projen task runner within an ejected project. + */ + const tasksToRemove = [ + 'build', + 'bump', + 'clobber', + 'compile', + 'package', + 'post-compile', + 'post-upgrade', + 'pre-compile', + 'release', + 'test', + // eslint-disable-next-line @cspell/spellchecker -- the word is used once, so no need to add it to the dictionary + 'unbump', + 'upgrade', + 'watch', + 'projen', + ] + + tasksToRemove.forEach(this.removeTask.bind(this)) } postSynthesize(): void { - execSync('prettier --write .projenrc.ts') - execSync('eslint --fix .projenrc.ts') + // execSync('prettier --write .projenrc.ts') + // execSync('eslint --fix .projenrc.ts') collectTelemetry(this) } From 31ea970b72e68787ab776922ddd494317d4cce6f Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 17:21:59 +0100 Subject: [PATCH 08/41] PLA-256 Add tests and eslint-qa --- src/backend-test/__tests__/index.ts | 24 ++++++ src/backend-test/eslint-config-qa.ts | 113 +++++++++++++++++++++++++++ src/backend-test/index.ts | 27 ++++--- 3 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 src/backend-test/__tests__/index.ts create mode 100644 src/backend-test/eslint-config-qa.ts diff --git a/src/backend-test/__tests__/index.ts b/src/backend-test/__tests__/index.ts new file mode 100644 index 00000000..73081005 --- /dev/null +++ b/src/backend-test/__tests__/index.ts @@ -0,0 +1,24 @@ +import {synthSnapshot} from 'projen/lib/util/synth' +import { OttofellerBackendTestProject, OttofellerBackendTestProjectOptions } from '..' + +jest.mock('child_process') + +describe('Backend-test template', () => { + + test('has prettier and eslint configs', () => { + const project = new TestNextJsTypeScriptProject() + const snapshot = synthSnapshot(project) + expect(snapshot['.prettierrc.json']).toBeDefined() + expect(snapshot['.eslintrc.json']).toBeDefined() + }) +}) + +class TestNextJsTypeScriptProject extends OttofellerBackendTestProject { + constructor(options: Partial = {}) { + super({ + ...options, + name: 'test-nextjs-project', + defaultReleaseBranch: 'main', + }) + } +} diff --git a/src/backend-test/eslint-config-qa.ts b/src/backend-test/eslint-config-qa.ts new file mode 100644 index 00000000..86d14f75 --- /dev/null +++ b/src/backend-test/eslint-config-qa.ts @@ -0,0 +1,113 @@ +import {Linter} from 'eslint' + +export const eslintConfigQa: Linter.Config = { + root: true, + env: { + jest: true, + node: true, + }, + ignorePatterns: ['generated/index.ts', '**/*.generated.ts'], + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + ecmaVersion: 'latest', + sourceType: 'module', + }, + rules: { + 'padding-line-between-statements': [ + 'error', + { + blankLine: 'any', + prev: '*', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-block-like', + }, + { + blankLine: 'always', + prev: 'multiline-block-like', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-const', + }, + { + blankLine: 'always', + prev: 'multiline-const', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-expression', + }, + { + blankLine: 'always', + prev: 'multiline-expression', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-let', + }, + { + blankLine: 'always', + prev: 'multiline-let', + next: '*', + }, + { + blankLine: 'never', + prev: ['singleline-const', 'singleline-let'], + next: ['singleline-const', 'singleline-let'], + }, + ], + '@typescript-eslint/ban-ts-comment': ['off'], + '@typescript-eslint/consistent-type-assertions': ['off'], + '@typescript-eslint/consistent-type-definitions': ['error', 'type'], + '@typescript-eslint/no-shadow': ['error'], + '@typescript-eslint/no-unused-expressions': ['error'], + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + }, + ], + curly: ['error'], + 'import/no-relative-parent-imports': ['error'], + 'no-negated-condition': ['error'], + 'no-nested-ternary': ['error'], + 'eslint-comments/disable-enable-pair': [ + 'error', + { + allowWholeFile: true, + }, + ], + 'eslint-comments/no-aggregating-enable': ['error'], + 'eslint-comments/no-duplicate-disable': ['error'], + 'eslint-comments/no-unlimited-disable': ['error'], + 'eslint-comments/no-unused-disable': ['error'], + 'eslint-comments/no-unused-enable': ['error'], + 'eslint-comments/no-use': [ + 'error', + { + allow: ['eslint-disable', 'eslint-disable-next-line', 'eslint-enable'], + }, + ], + 'eslint-comments/require-description': [ + 'error', + { + ignore: ['eslint-enable'], + }, + ], + }, + extends: ['plugin:import/typescript', 'plugin:prettier/recommended'], + plugins: ['@typescript-eslint', 'eslint-comments', 'import', '@ottofeller/ottofeller'], +} diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index da4ff23c..01604668 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,15 +1,12 @@ +import {execSync} from 'child_process' import * as path from 'path' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' -import { - IWithTelemetryReportUrl, - WithCustomLintPaths, - WithDefaultWorkflow, - WithGitHooks, - WithTelemetry, - collectTelemetry, -} from '../common' +import {IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' +import {WithCustomLintPaths, addLinters} from '../common/lint' +// import {eslintConfigQa} from './eslint-config-qa' import {sampleCode} from './sample-code' +import { eslintConfigQa } from './eslint-config-qa' export interface OttofellerBackendTestProjectOptions extends TypeScriptProjectOptions, @@ -109,11 +106,21 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I ] tasksToRemove.forEach(this.removeTask.bind(this)) + + // ANCHOR ESLint and prettier setup + const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] + const extraEslintConfigs = [eslintConfigQa] + addLinters({project: this.parent.li, lintPaths, extraEslintConfigs}) + + // this.eslint?. + + this.package.file.addDeletionOverride('main') + this.package.file.addDeletionOverride('types') } postSynthesize(): void { - // execSync('prettier --write .projenrc.ts') - // execSync('eslint --fix .projenrc.ts') + execSync('prettier --write .projenrc.ts') + execSync('eslint --fix .projenrc.ts') collectTelemetry(this) } From ac41389ffae9765f3a11059d48d96c278e568e66 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 18:29:07 +0100 Subject: [PATCH 09/41] PLA-256 Add Graphql as option --- src/backend-test/__tests__/index.ts | 24 --------------- src/backend-test/assets/codegen.ts | 34 +++++++++++++++++++++ src/backend-test/index.ts | 46 ++++++++++++++++++++++++++--- 3 files changed, 76 insertions(+), 28 deletions(-) delete mode 100644 src/backend-test/__tests__/index.ts create mode 100644 src/backend-test/assets/codegen.ts diff --git a/src/backend-test/__tests__/index.ts b/src/backend-test/__tests__/index.ts deleted file mode 100644 index 73081005..00000000 --- a/src/backend-test/__tests__/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {synthSnapshot} from 'projen/lib/util/synth' -import { OttofellerBackendTestProject, OttofellerBackendTestProjectOptions } from '..' - -jest.mock('child_process') - -describe('Backend-test template', () => { - - test('has prettier and eslint configs', () => { - const project = new TestNextJsTypeScriptProject() - const snapshot = synthSnapshot(project) - expect(snapshot['.prettierrc.json']).toBeDefined() - expect(snapshot['.eslintrc.json']).toBeDefined() - }) -}) - -class TestNextJsTypeScriptProject extends OttofellerBackendTestProject { - constructor(options: Partial = {}) { - super({ - ...options, - name: 'test-nextjs-project', - defaultReleaseBranch: 'main', - }) - } -} diff --git a/src/backend-test/assets/codegen.ts b/src/backend-test/assets/codegen.ts new file mode 100644 index 00000000..6ff8007b --- /dev/null +++ b/src/backend-test/assets/codegen.ts @@ -0,0 +1,34 @@ +import type {CodegenConfig} from '@graphql-codegen/cli' + + +//FIXME - Change to Codegen from app-backend-user +const codegenConfig: CodegenConfig = { + overwrite: true, + schema: './schema.json', + + // The following paths and corresponding output settings are defaults for the nextjs project. + generates: { + 'generated/types.ts': { + documents: ['pages/**/graphql/*.{ts,tsx}'], + plugins: ['typescript', 'typescript-operations'], + }, + + 'generated/frontend.ts': { + documents: ['pages/**/graphql/*.tsx'], + preset: 'import-types', + presetConfig: {typesPath: './types'}, + plugins: ['typescript-react-apollo'], + }, + + 'generated/api.ts': { + documents: ['pages/**/graphql/*.ts'], + preset: 'import-types', + presetConfig: {typesPath: './types'}, + plugins: ['typescript-operations', 'typescript-graphql-request'], + }, + + './schema.json': {plugins: ['introspection']}, + }, +} + +export default codegenConfig diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 01604668..7a05013d 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -5,15 +5,22 @@ import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript import {IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' import {WithCustomLintPaths, addLinters} from '../common/lint' // import {eslintConfigQa} from './eslint-config-qa' +import {AssetFile} from '../common/files/AssetFile' import {sampleCode} from './sample-code' -import { eslintConfigQa } from './eslint-config-qa' export interface OttofellerBackendTestProjectOptions extends TypeScriptProjectOptions, WithTelemetry, WithGitHooks, WithCustomLintPaths, - WithDefaultWorkflow {} + WithDefaultWorkflow { + /** + * Set up GraphQL dependencies and supplementary script. + * + * @default true + */ + readonly isGraphqlEnabled?: boolean +} /** * Backend-test template with TypeScript support. @@ -109,11 +116,42 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I // ANCHOR ESLint and prettier setup const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] - const extraEslintConfigs = [eslintConfigQa] - addLinters({project: this.parent.li, lintPaths, extraEslintConfigs}) + // const extraEslintConfigs = [eslintConfigQa] + addLinters({project: this, lintPaths}) // this.eslint?. + // ANCHOR Set up GraphQL + const isGraphqlEnabled = options.isGraphqlEnabled ?? true + + if (isGraphqlEnabled) { + this.addDevDeps( + '@graphql-codegen/add', + '@graphql-codegen/cli', + '@graphql-codegen/import-types-preset', + '@graphql-codegen/introspection', + '@graphql-codegen/named-operations-object', + '@graphql-codegen/typescript', + '@graphql-codegen/typescript-graphql-request', + '@graphql-codegen/typescript-operations', + '@graphql-codegen/typescript-react-apollo', + ) + + this.addDeps('@apollo/client', 'graphql') + + // ANCHOR Codegen + new AssetFile(this, 'codegen.ts', { + sourcePath: path.join(assetsDir, 'codegen.ts'), + readonly: false, + marker: false, + }) + + this.addScripts({ + 'generate-graphql-schema': 'npx apollo schema:download', + 'gql-to-ts': 'graphql-codegen -r dotenv/config --config codegen.ts', + }) + } + this.package.file.addDeletionOverride('main') this.package.file.addDeletionOverride('types') } From 60e2209f0eee62419235aa3528163850a075bfd3 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 13 Dec 2023 21:47:04 +0100 Subject: [PATCH 10/41] PLA-256 Fix tsconfig and codegen files --- src/backend-test/assets/codegen.ts | 34 ------- src/backend-test/assets/codegen.ts.sample | 114 ++++++++++++++++++++++ src/backend-test/eslint-config-qa.ts | 2 +- src/backend-test/index.ts | 37 ++----- 4 files changed, 125 insertions(+), 62 deletions(-) delete mode 100644 src/backend-test/assets/codegen.ts create mode 100644 src/backend-test/assets/codegen.ts.sample diff --git a/src/backend-test/assets/codegen.ts b/src/backend-test/assets/codegen.ts deleted file mode 100644 index 6ff8007b..00000000 --- a/src/backend-test/assets/codegen.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type {CodegenConfig} from '@graphql-codegen/cli' - - -//FIXME - Change to Codegen from app-backend-user -const codegenConfig: CodegenConfig = { - overwrite: true, - schema: './schema.json', - - // The following paths and corresponding output settings are defaults for the nextjs project. - generates: { - 'generated/types.ts': { - documents: ['pages/**/graphql/*.{ts,tsx}'], - plugins: ['typescript', 'typescript-operations'], - }, - - 'generated/frontend.ts': { - documents: ['pages/**/graphql/*.tsx'], - preset: 'import-types', - presetConfig: {typesPath: './types'}, - plugins: ['typescript-react-apollo'], - }, - - 'generated/api.ts': { - documents: ['pages/**/graphql/*.ts'], - preset: 'import-types', - presetConfig: {typesPath: './types'}, - plugins: ['typescript-operations', 'typescript-graphql-request'], - }, - - './schema.json': {plugins: ['introspection']}, - }, -} - -export default codegenConfig diff --git a/src/backend-test/assets/codegen.ts.sample b/src/backend-test/assets/codegen.ts.sample new file mode 100644 index 00000000..15a56b39 --- /dev/null +++ b/src/backend-test/assets/codegen.ts.sample @@ -0,0 +1,114 @@ +import {CodegenConfig} from '@graphql-codegen/cli' +import dotenv from 'dotenv' + +dotenv.config({path: '.env.local'}) +dotenv.config({path: '.env.development'}) + +if (!process.env.HASURA_GRAPHQL_URL || !process.env.HASURA_GRAPHQL_ADMIN_SECRET) { + process.exit(1) +} + +const config: CodegenConfig = { + overwrite: true, + + config: { + defaultScalarType: 'unknown', + scalars: { + uuid: 'string', + _uuid: 'Array', + timestamp: 'string', + timestamptz: 'string', + numeric: 'string', + jsonb: 'any', + json: 'any', + bigint: 'string', + AWSDate: 'string', + AWSTime: 'string', + AWSDateTime: 'string', + AWSTimestamp: 'string', + AWSEmail: 'string', + AWSJSON: 'string', + AWSURL: 'string', + AWSPhone: 'string', + AWSIPAddress: 'string', + interval: 'string', + date: 'string', + float8: 'string', + }, + }, + + generates: { + // Generate common types + 'generated/index.ts': { + schema: [ + { + [process.env.HASURA_GRAPHQL_URL]: { + headers: { + 'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET, + 'x-hasura-user-id': 'service', + 'x-hasura-user-role': 'service', + }, + }, + }, + ], + plugins: [ + 'typescript', + { + add: { + placement: 'prepend', + content: '/* eslint-disable -- Generated */ // @ts-nocheck', + }, + }, + ], + config: { + strictScalars: true, + skipDocumentsValidation: { + OverlappingFieldsCanBeMergedRule: true, + }, + }, + }, + + // Generate types for graphql requests + src: { + schema: [ + { + [process.env.HASURA_GRAPHQL_URL]: { + headers: { + 'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET, + 'x-hasura-user-id': 'service', + 'x-hasura-user-role': 'service', + }, + }, + }, + ], + documents: ['common/graphql/**/*.ts', '!common/graphql/**/*.generated.ts'], + preset: 'near-operation-file', + presetConfig: { + extension: '.generated.ts', + baseTypesPath: '~generated', + }, + plugins: ['typescript-operations', 'typescript-graphql-request'], + config: { + skipTypename: true, + useTypeImports: true, + directiveArgumentAndInputFieldMappings: 'Model', + }, + }, + + // Generate schema file for e2e + 'schema.graphql': { + schema: [ + { + [process.env.HASURA_GRAPHQL_URL]: { + headers: { + 'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET, + }, + }, + }, + ], + plugins: ['schema-ast'], + }, + }, +} + +export default config \ No newline at end of file diff --git a/src/backend-test/eslint-config-qa.ts b/src/backend-test/eslint-config-qa.ts index 86d14f75..74f482d8 100644 --- a/src/backend-test/eslint-config-qa.ts +++ b/src/backend-test/eslint-config-qa.ts @@ -108,6 +108,6 @@ export const eslintConfigQa: Linter.Config = { }, ], }, - extends: ['plugin:import/typescript', 'plugin:prettier/recommended'], + extends: ['plugin:prettier/recommended'], plugins: ['@typescript-eslint', 'eslint-comments', 'import', '@ottofeller/ottofeller'], } diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 7a05013d..14f4cc18 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,11 +1,11 @@ import {execSync} from 'child_process' import * as path from 'path' +import {SampleFile} from 'projen' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' import {IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' import {WithCustomLintPaths, addLinters} from '../common/lint' -// import {eslintConfigQa} from './eslint-config-qa' -import {AssetFile} from '../common/files/AssetFile' +import {eslintConfigQa} from './eslint-config-qa' import {sampleCode} from './sample-code' export interface OttofellerBackendTestProjectOptions @@ -46,27 +46,12 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I tsconfig: { compilerOptions: { - target: 'esnext', - module: 'esnext', - noEmit: true, - isolatedModules: false, - strict: true, - noImplicitAny: true, - strictNullChecks: true, - strictPropertyInitialization: true, - noImplicitThis: true, - alwaysStrict: true, - noUnusedParameters: true, - noImplicitReturns: true, - noFallthroughCasesInSwitch: true, - noUncheckedIndexedAccess: true, baseUrl: './', + target: 'es6', + skipLibCheck: true, paths: { '*': ['./*'], }, - esModuleInterop: true, - skipLibCheck: true, - forceConsistentCasingInFileNames: true, }, }, @@ -114,12 +99,12 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I tasksToRemove.forEach(this.removeTask.bind(this)) + this.addDeps('dotenv') + // ANCHOR ESLint and prettier setup const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] - // const extraEslintConfigs = [eslintConfigQa] - addLinters({project: this, lintPaths}) - - // this.eslint?. + const extraEslintConfigs = [eslintConfigQa] + addLinters({project: this, lintPaths, extraEslintConfigs}) // ANCHOR Set up GraphQL const isGraphqlEnabled = options.isGraphqlEnabled ?? true @@ -140,10 +125,8 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.addDeps('@apollo/client', 'graphql') // ANCHOR Codegen - new AssetFile(this, 'codegen.ts', { - sourcePath: path.join(assetsDir, 'codegen.ts'), - readonly: false, - marker: false, + new SampleFile(this, 'codegen.ts', { + sourcePath: path.join(assetsDir, 'codegen.ts.sample'), }) this.addScripts({ From 95ed8d66b2e1fc4c70b9895a7ddc8dc4c76d6fb0 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 14 Dec 2023 11:23:08 +0100 Subject: [PATCH 11/41] PLA-256 Add dynamdb set up --- src/backend-test/assets/eslintrc.json.sample | 111 +++++++++++++++++++ src/backend-test/index.ts | 36 ++++-- 2 files changed, 138 insertions(+), 9 deletions(-) create mode 100644 src/backend-test/assets/eslintrc.json.sample diff --git a/src/backend-test/assets/eslintrc.json.sample b/src/backend-test/assets/eslintrc.json.sample new file mode 100644 index 00000000..d73d16c0 --- /dev/null +++ b/src/backend-test/assets/eslintrc.json.sample @@ -0,0 +1,111 @@ +{ + "root": true, + "env": { + "jest": true, + "node": true + }, + "ignorePatterns": ["generated/index.ts", "**/*.generated.ts"], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": "latest", + "sourceType": "module" + }, + "rules": { + "padding-line-between-statements": [ + "error", + { + "blankLine": "any", + "prev": "*", + "next": "*" + }, + { + "blankLine": "always", + "prev": "*", + "next": "multiline-block-like" + }, + { + "blankLine": "always", + "prev": "multiline-block-like", + "next": "*" + }, + { + "blankLine": "always", + "prev": "*", + "next": "multiline-const" + }, + { + "blankLine": "always", + "prev": "multiline-const", + "next": "*" + }, + { + "blankLine": "always", + "prev": "*", + "next": "multiline-expression" + }, + { + "blankLine": "always", + "prev": "multiline-expression", + "next": "*" + }, + { + "blankLine": "always", + "prev": "*", + "next": "multiline-let" + }, + { + "blankLine": "always", + "prev": "multiline-let", + "next": "*" + }, + { + "blankLine": "never", + "prev": ["singleline-const", "singleline-let"], + "next": ["singleline-const", "singleline-let"] + } + ], + "@typescript-eslint/ban-ts-comment": ["off"], + "@typescript-eslint/consistent-type-assertions": ["off"], + "@typescript-eslint/consistent-type-definitions": ["error", "type"], + "@typescript-eslint/no-shadow": ["error"], + "@typescript-eslint/no-unused-expressions": ["error"], + "@typescript-eslint/no-unused-vars": [ + "error", + { + "argsIgnorePattern": "^_" + } + ], + "curly": ["error"], + "import/no-relative-parent-imports": ["error"], + "no-negated-condition": ["error"], + "no-nested-ternary": ["error"], + "eslint-comments/disable-enable-pair": [ + "error", + { + "allowWholeFile": true + } + ], + "eslint-comments/no-aggregating-enable": ["error"], + "eslint-comments/no-duplicate-disable": ["error"], + "eslint-comments/no-unlimited-disable": ["error"], + "eslint-comments/no-unused-disable": ["error"], + "eslint-comments/no-unused-enable": ["error"], + "eslint-comments/no-use": [ + "error", + { + "allow": ["eslint-disable", "eslint-disable-next-line", "eslint-enable"] + } + ], + "eslint-comments/require-description": [ + "error", + { + "ignore": ["eslint-enable"] + } + ] + }, + "extends": ["plugin:import/typescript", "plugin:prettier/recommended"], + "plugins": ["@typescript-eslint", "eslint-comments", "import", "@ottofeller/ottofeller"] +} diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 14f4cc18..a92589e6 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -4,8 +4,7 @@ import {SampleFile} from 'projen' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' import {IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' -import {WithCustomLintPaths, addLinters} from '../common/lint' -import {eslintConfigQa} from './eslint-config-qa' +import {WithCustomLintPaths} from '../common/lint' import {sampleCode} from './sample-code' export interface OttofellerBackendTestProjectOptions @@ -20,6 +19,12 @@ export interface OttofellerBackendTestProjectOptions * @default true */ readonly isGraphqlEnabled?: boolean + /** + * Set up AWS DynamoDb dependencies and supplementary script. + * + * @default true + */ + readonly isAWSDynamoDBlEnabled?: boolean } /** @@ -67,9 +72,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I const assetsDir = path.join(__dirname, '..', '..', 'src/backend-test/assets') sampleCode(this, options, assetsDir) - // // ANCHOR playwright config - // new SampleFile(this, 'playwright.config.ts', {sourcePath: path.join(assetsDir, 'playwright.config.ts.sample')}) - this.addScripts({ test: 'jest --detectOpenHandles', }) @@ -101,10 +103,26 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.addDeps('dotenv') - // ANCHOR ESLint and prettier setup - const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] - const extraEslintConfigs = [eslintConfigQa] - addLinters({project: this, lintPaths, extraEslintConfigs}) + // // ANCHOR ESLint and prettier setup + // const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] + // const extraEslintConfigs = [eslintConfigQa] + // addLinters({project: this, lintPaths, extraEslintConfigs}) + + + + new SampleFile(this, 'eslintrc.json', { + sourcePath: path.join(assetsDir, 'eslintrc.json.sample'), + }) + + //ANCHOR - Set up AWS DynamoDb Client + const isAWSDynamoDBlEnabled = options.isAWSDynamoDBlEnabled ?? true + + if(isAWSDynamoDBlEnabled) { + this.addDevDeps( + '@aws-sdk/client-dynamodb', + '@aws-sdk/lib-dynamodb' + ) + } // ANCHOR Set up GraphQL const isGraphqlEnabled = options.isGraphqlEnabled ?? true From 156da916c079e7f48fd19bf36b56d9e62e28978a Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 14 Dec 2023 11:26:32 +0100 Subject: [PATCH 12/41] PLA-256 Update gql script --- src/backend-test/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index a92589e6..42a359d2 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -148,8 +148,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I }) this.addScripts({ - 'generate-graphql-schema': 'npx apollo schema:download', - 'gql-to-ts': 'graphql-codegen -r dotenv/config --config codegen.ts', + 'gql-to-ts': 'graphql-codegen', }) } From 31deb56d6e0bb703554ea707c21b534f1b4072fb Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 14 Dec 2023 11:36:19 +0100 Subject: [PATCH 13/41] PLA-256 Pass codegen.ts as asset insted sample --- src/backend-test/assets/{codegen.ts.sample => codegen.ts} | 2 +- src/backend-test/index.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) rename src/backend-test/assets/{codegen.ts.sample => codegen.ts} (98%) diff --git a/src/backend-test/assets/codegen.ts.sample b/src/backend-test/assets/codegen.ts similarity index 98% rename from src/backend-test/assets/codegen.ts.sample rename to src/backend-test/assets/codegen.ts index 15a56b39..aaedd1af 100644 --- a/src/backend-test/assets/codegen.ts.sample +++ b/src/backend-test/assets/codegen.ts @@ -1,5 +1,5 @@ import {CodegenConfig} from '@graphql-codegen/cli' -import dotenv from 'dotenv' +import * as dotenv from 'dotenv' dotenv.config({path: '.env.local'}) dotenv.config({path: '.env.development'}) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 42a359d2..4ed77dbd 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -3,7 +3,7 @@ import * as path from 'path' import {SampleFile} from 'projen' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' -import {IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' +import {AssetFile, IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' import {WithCustomLintPaths} from '../common/lint' import {sampleCode} from './sample-code' @@ -143,8 +143,10 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.addDeps('@apollo/client', 'graphql') // ANCHOR Codegen - new SampleFile(this, 'codegen.ts', { - sourcePath: path.join(assetsDir, 'codegen.ts.sample'), + new AssetFile(this, 'codegen.ts', { + sourcePath: path.join(assetsDir, 'codegen.ts'), + readonly: false, + marker: false, }) this.addScripts({ From 84654cbaf167d7c6b6e9a0d31716dfd8742ce827 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 14 Dec 2023 13:06:40 +0100 Subject: [PATCH 14/41] PLA-256 Pass eslint as asset instead sample --- .../assets/{eslintrc.json.sample => eslintrc.json} | 0 src/backend-test/index.ts | 13 ++++--------- 2 files changed, 4 insertions(+), 9 deletions(-) rename src/backend-test/assets/{eslintrc.json.sample => eslintrc.json} (100%) diff --git a/src/backend-test/assets/eslintrc.json.sample b/src/backend-test/assets/eslintrc.json similarity index 100% rename from src/backend-test/assets/eslintrc.json.sample rename to src/backend-test/assets/eslintrc.json diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 4ed77dbd..9fcdbb2e 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,6 +1,5 @@ import {execSync} from 'child_process' import * as path from 'path' -import {SampleFile} from 'projen' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' import {AssetFile, IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' @@ -104,14 +103,10 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.addDeps('dotenv') // // ANCHOR ESLint and prettier setup - // const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] - // const extraEslintConfigs = [eslintConfigQa] - // addLinters({project: this, lintPaths, extraEslintConfigs}) - - - - new SampleFile(this, 'eslintrc.json', { - sourcePath: path.join(assetsDir, 'eslintrc.json.sample'), + new AssetFile(this, '.eslintrc.json', { + sourcePath: path.join(assetsDir, 'eslintrc.json'), + readonly: false, + marker: false, }) //ANCHOR - Set up AWS DynamoDb Client From 23815bc6306f413e29583667fe0f5618e38cff86 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 14 Dec 2023 14:53:20 +0100 Subject: [PATCH 15/41] PLA-256 Add axios --- src/backend-test/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 9fcdbb2e..320c6f6d 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -101,6 +101,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I tasksToRemove.forEach(this.removeTask.bind(this)) this.addDeps('dotenv') + this.addDeps('axios') // // ANCHOR ESLint and prettier setup new AssetFile(this, '.eslintrc.json', { From 43ba515c66198b9aaa3c2432aa9341c312004246 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 14 Dec 2023 15:59:29 +0100 Subject: [PATCH 16/41] PLA-256 Add test samples --- .../assets/api/auth/index.ts.sample | 2 + .../assets/api/auth/request.ts.sample | 4 ++ .../assets/api/auth/response.ts.sample | 4 ++ .../assets/common/client.ts.sample | 7 +++ .../assets/common/index.ts.sample | 1 + .../assets/tests/auth.spec.ts.sample | 43 +++++++++++++++++++ src/backend-test/sample-code.ts | 9 ++++ 7 files changed, 70 insertions(+) create mode 100644 src/backend-test/assets/api/auth/index.ts.sample create mode 100644 src/backend-test/assets/api/auth/request.ts.sample create mode 100644 src/backend-test/assets/api/auth/response.ts.sample create mode 100644 src/backend-test/assets/common/client.ts.sample create mode 100644 src/backend-test/assets/common/index.ts.sample create mode 100644 src/backend-test/assets/tests/auth.spec.ts.sample diff --git a/src/backend-test/assets/api/auth/index.ts.sample b/src/backend-test/assets/api/auth/index.ts.sample new file mode 100644 index 00000000..85e4093a --- /dev/null +++ b/src/backend-test/assets/api/auth/index.ts.sample @@ -0,0 +1,2 @@ +export * from './request' +export * from './response' \ No newline at end of file diff --git a/src/backend-test/assets/api/auth/request.ts.sample b/src/backend-test/assets/api/auth/request.ts.sample new file mode 100644 index 00000000..f5fc0d7e --- /dev/null +++ b/src/backend-test/assets/api/auth/request.ts.sample @@ -0,0 +1,4 @@ +export type AuthRequestBody = { + login: string | undefined + password: string | undefined + } \ No newline at end of file diff --git a/src/backend-test/assets/api/auth/response.ts.sample b/src/backend-test/assets/api/auth/response.ts.sample new file mode 100644 index 00000000..6ddedf8c --- /dev/null +++ b/src/backend-test/assets/api/auth/response.ts.sample @@ -0,0 +1,4 @@ +export type AuthResponseBody = { + token?: string + message?: string + } \ No newline at end of file diff --git a/src/backend-test/assets/common/client.ts.sample b/src/backend-test/assets/common/client.ts.sample new file mode 100644 index 00000000..a34fa0f2 --- /dev/null +++ b/src/backend-test/assets/common/client.ts.sample @@ -0,0 +1,7 @@ +import axios from 'axios' + +export const client = axios.create({ + baseURL: process.env.BASE_URL, + timeout: 15000, + validateStatus: () => true, +}) \ No newline at end of file diff --git a/src/backend-test/assets/common/index.ts.sample b/src/backend-test/assets/common/index.ts.sample new file mode 100644 index 00000000..7eec814f --- /dev/null +++ b/src/backend-test/assets/common/index.ts.sample @@ -0,0 +1 @@ +export * from './client' \ No newline at end of file diff --git a/src/backend-test/assets/tests/auth.spec.ts.sample b/src/backend-test/assets/tests/auth.spec.ts.sample new file mode 100644 index 00000000..d301f94b --- /dev/null +++ b/src/backend-test/assets/tests/auth.spec.ts.sample @@ -0,0 +1,43 @@ +import {AuthRequestBody, AuthResponseBody} from 'api/auth' +import {AxiosRequestConfig, AxiosResponse} from 'axios' +import {client} from 'common/client' + +describe('Authorization & Authentication', () => { + test('Sign in with existing credentials', async () => { + const payload: AxiosRequestConfig = { + method: 'post', + url: '/auth', + data: { + login: process.env.USERNAME, + password: process.env.PASSWORD, + }, + } + + const response: AxiosResponse = await client.request(payload) + + expect(response.status).toEqual(200) + + expect(response.data).toEqual({ + token: expect.any(String), + }) + }) + + test('Sign in with not existing credentials', async () => { + const payload: AxiosRequestConfig = { + method: 'post', + url: '/auth', + data: { + login: 'invalid', + password: 'invalid', + }, + } + + const response: AxiosResponse = await client.request(payload) + + expect(response.status).toEqual(404) + + expect(response.data).toEqual({ + message: expect.any(String), + }) + }) +}) \ No newline at end of file diff --git a/src/backend-test/sample-code.ts b/src/backend-test/sample-code.ts index 76df5ee7..5abb286b 100644 --- a/src/backend-test/sample-code.ts +++ b/src/backend-test/sample-code.ts @@ -12,4 +12,13 @@ export function sampleCode( } new SampleFile(project, '.env.development', {sourcePath: path.join(assetsDir, '.env.development')}) + + new SampleFile(project, 'api/auth/index.ts', {sourcePath: path.join(assetsDir, 'api/auth/index.ts.sample')}) + new SampleFile(project, 'api/auth/request.ts', {sourcePath: path.join(assetsDir, 'api/auth/request.ts.sample')}) + new SampleFile(project, 'api/auth/response.ts', {sourcePath: path.join(assetsDir, 'api/auth/response.ts.sample')}) + + new SampleFile(project, 'common/client.ts', {sourcePath: path.join(assetsDir, 'common/client.ts.sample')}) + new SampleFile(project, 'common/index.ts', {sourcePath: path.join(assetsDir, 'common/index.ts.sample')}) + + new SampleFile(project, 'tests/auth.spec.ts', {sourcePath: path.join(assetsDir, 'tests/auth.spec.ts.sample')}) } From e01b8f6ada4c848c8e3c5359af2118ec26c563b9 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 14 Dec 2023 16:55:54 +0100 Subject: [PATCH 17/41] PLA-256 Fix format --- src/backend-test/assets/codegen.ts | 2 +- src/backend-test/index.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/backend-test/assets/codegen.ts b/src/backend-test/assets/codegen.ts index aaedd1af..f1e6df19 100644 --- a/src/backend-test/assets/codegen.ts +++ b/src/backend-test/assets/codegen.ts @@ -111,4 +111,4 @@ const config: CodegenConfig = { }, } -export default config \ No newline at end of file +export default config diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 320c6f6d..42748c2e 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -2,7 +2,14 @@ import {execSync} from 'child_process' import * as path from 'path' import {NodePackageManager} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' -import {AssetFile, IWithTelemetryReportUrl, WithDefaultWorkflow, WithGitHooks, WithTelemetry, collectTelemetry} from '../common' +import { + AssetFile, + IWithTelemetryReportUrl, + WithDefaultWorkflow, + WithGitHooks, + WithTelemetry, + collectTelemetry, +} from '../common' import {WithCustomLintPaths} from '../common/lint' import {sampleCode} from './sample-code' @@ -113,11 +120,8 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I //ANCHOR - Set up AWS DynamoDb Client const isAWSDynamoDBlEnabled = options.isAWSDynamoDBlEnabled ?? true - if(isAWSDynamoDBlEnabled) { - this.addDevDeps( - '@aws-sdk/client-dynamodb', - '@aws-sdk/lib-dynamodb' - ) + if (isAWSDynamoDBlEnabled) { + this.addDevDeps('@aws-sdk/client-dynamodb', '@aws-sdk/lib-dynamodb') } // ANCHOR Set up GraphQL From 9d2108f0c46434508e10ff8908611a25c1fe4ebe Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 15 Dec 2023 12:51:44 +0100 Subject: [PATCH 18/41] PLA-256 Remove defaut jest from template --- .../__tests__/__snapshots__/index.ts.snap | 891 ++++++++++++++++++ src/backend-test/__tests__/index.ts | 20 + src/backend-test/index.ts | 2 +- 3 files changed, 912 insertions(+), 1 deletion(-) create mode 100644 src/backend-test/__tests__/__snapshots__/index.ts.snap create mode 100644 src/backend-test/__tests__/index.ts diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap new file mode 100644 index 00000000..669fdca0 --- /dev/null +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -0,0 +1,891 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Backend-test template sets defaults 1`] = ` +{ + ".env.development": "HASURA_GRAPHQL_URL=http://localhost:8080/v1/graphql +HASURA_GRAPHQL_ADMIN_SECRET=111 +UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar", + ".eslintrc.json": { + "env": { + "jest": true, + "node": true, + }, + "extends": [ + "plugin:import/typescript", + "plugin:prettier/recommended", + ], + "ignorePatterns": [ + "generated/index.ts", + "**/*.generated.ts", + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true, + }, + "ecmaVersion": "latest", + "sourceType": "module", + }, + "plugins": [ + "@typescript-eslint", + "eslint-comments", + "import", + "@ottofeller/ottofeller", + ], + "root": true, + "rules": { + "@typescript-eslint/ban-ts-comment": [ + "off", + ], + "@typescript-eslint/consistent-type-assertions": [ + "off", + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "type", + ], + "@typescript-eslint/no-shadow": [ + "error", + ], + "@typescript-eslint/no-unused-expressions": [ + "error", + ], + "@typescript-eslint/no-unused-vars": [ + "error", + { + "argsIgnorePattern": "^_", + }, + ], + "curly": [ + "error", + ], + "eslint-comments/disable-enable-pair": [ + "error", + { + "allowWholeFile": true, + }, + ], + "eslint-comments/no-aggregating-enable": [ + "error", + ], + "eslint-comments/no-duplicate-disable": [ + "error", + ], + "eslint-comments/no-unlimited-disable": [ + "error", + ], + "eslint-comments/no-unused-disable": [ + "error", + ], + "eslint-comments/no-unused-enable": [ + "error", + ], + "eslint-comments/no-use": [ + "error", + { + "allow": [ + "eslint-disable", + "eslint-disable-next-line", + "eslint-enable", + ], + }, + ], + "eslint-comments/require-description": [ + "error", + { + "ignore": [ + "eslint-enable", + ], + }, + ], + "import/no-relative-parent-imports": [ + "error", + ], + "no-negated-condition": [ + "error", + ], + "no-nested-ternary": [ + "error", + ], + "padding-line-between-statements": [ + "error", + { + "blankLine": "any", + "next": "*", + "prev": "*", + }, + { + "blankLine": "always", + "next": "multiline-block-like", + "prev": "*", + }, + { + "blankLine": "always", + "next": "*", + "prev": "multiline-block-like", + }, + { + "blankLine": "always", + "next": "multiline-const", + "prev": "*", + }, + { + "blankLine": "always", + "next": "*", + "prev": "multiline-const", + }, + { + "blankLine": "always", + "next": "multiline-expression", + "prev": "*", + }, + { + "blankLine": "always", + "next": "*", + "prev": "multiline-expression", + }, + { + "blankLine": "always", + "next": "multiline-let", + "prev": "*", + }, + { + "blankLine": "always", + "next": "*", + "prev": "multiline-let", + }, + { + "blankLine": "never", + "next": [ + "singleline-const", + "singleline-let", + ], + "prev": [ + "singleline-const", + "singleline-let", + ], + }, + ], + }, + }, + ".gitattributes": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". + +/.eslintrc.json linguist-generated +/.gitattributes linguist-generated +/.gitignore linguist-generated +/.npmignore linguist-generated +/.npmrc linguist-generated +/.projen/** linguist-generated +/.projen/deps.json linguist-generated +/.projen/files.json linguist-generated +/.projen/tasks.json linguist-generated +/codegen.ts linguist-generated +/LICENSE linguist-generated +/package-lock.json linguist-generated +/package.json linguist-generated +/tsconfig.dev.json linguist-generated +/tsconfig.json linguist-generated", + ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". +!/.gitattributes +!/.projen/tasks.json +!/.projen/deps.json +!/.projen/files.json +!/package.json +!/LICENSE +!/.npmignore +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json +pids +*.pid +*.seed +*.pid.lock +lib-cov +coverage +*.lcov +.nyc_output +build/Release +node_modules/ +jspm_packages/ +*.tsbuildinfo +.eslintcache +*.tgz +.yarn-integrity +.cache +!/.projenrc.js +!/.npmrc +!/test/ +!/tsconfig.json +!/tsconfig.dev.json +!/./ +/lib +/dist/ +!/.eslintrc.json +!/codegen.ts +", + ".npmignore": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". +/.projen/ +/test/ +/tsconfig.dev.json +/./ +!/lib/ +!/lib/**/*.js +!/lib/**/*.d.ts +dist +/tsconfig.json +/.github/ +/.vscode/ +/.idea/ +/.projenrc.js +tsconfig.tsbuildinfo +", + ".projen/deps.json": { + "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", + "dependencies": [ + { + "name": "@aws-sdk/client-dynamodb", + "type": "build", + }, + { + "name": "@aws-sdk/lib-dynamodb", + "type": "build", + }, + { + "name": "@graphql-codegen/add", + "type": "build", + }, + { + "name": "@graphql-codegen/cli", + "type": "build", + }, + { + "name": "@graphql-codegen/import-types-preset", + "type": "build", + }, + { + "name": "@graphql-codegen/introspection", + "type": "build", + }, + { + "name": "@graphql-codegen/named-operations-object", + "type": "build", + }, + { + "name": "@graphql-codegen/typescript", + "type": "build", + }, + { + "name": "@graphql-codegen/typescript-graphql-request", + "type": "build", + }, + { + "name": "@graphql-codegen/typescript-operations", + "type": "build", + }, + { + "name": "@graphql-codegen/typescript-react-apollo", + "type": "build", + }, + { + "name": "@types/node", + "type": "build", + "version": "^16", + }, + { + "name": "projen", + "type": "build", + }, + { + "name": "ts-node", + "type": "build", + }, + { + "name": "typescript", + "type": "build", + }, + { + "name": "@apollo/client", + "type": "runtime", + }, + { + "name": "axios", + "type": "runtime", + }, + { + "name": "dotenv", + "type": "runtime", + }, + { + "name": "graphql", + "type": "runtime", + }, + ], + }, + ".projen/files.json": { + "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", + "files": [ + ".gitattributes", + ".gitignore", + ".npmignore", + ".npmrc", + ".projen/deps.json", + ".projen/files.json", + ".projen/tasks.json", + "LICENSE", + "tsconfig.dev.json", + "tsconfig.json", + ], + }, + ".projen/tasks.json": { + "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", + "env": { + "PATH": "$(npx -c "node --print process.env.PATH")", + }, + "tasks": { + "default": { + "description": "Synthesize project files", + "name": "default", + "steps": [ + { + "exec": "ts-node --project tsconfig.dev.json .projenrc.ts", + }, + ], + }, + "eject": { + "description": "Remove projen from the project", + "env": { + "PROJEN_EJECTING": "true", + }, + "name": "eject", + "steps": [ + { + "spawn": "default", + }, + ], + }, + "install": { + "description": "Install project dependencies and update lockfile (non-frozen)", + "name": "install", + "steps": [ + { + "exec": "npm install", + }, + ], + }, + "install:ci": { + "description": "Install project dependencies using frozen lockfile", + "name": "install:ci", + "steps": [ + { + "exec": "npm ci", + }, + ], + }, + }, + }, + "LICENSE": " + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +", + "README.md": "# replace this", + "api/auth/index.ts": "export * from './request' +export * from './response'", + "api/auth/request.ts": "export type AuthRequestBody = { + login: string | undefined + password: string | undefined + }", + "api/auth/response.ts": "export type AuthResponseBody = { + token?: string + message?: string + }", + "codegen.ts": "import {CodegenConfig} from '@graphql-codegen/cli' +import * as dotenv from 'dotenv' + +dotenv.config({path: '.env.local'}) +dotenv.config({path: '.env.development'}) + +if (!process.env.HASURA_GRAPHQL_URL || !process.env.HASURA_GRAPHQL_ADMIN_SECRET) { + process.exit(1) +} + +const config: CodegenConfig = { + overwrite: true, + + config: { + defaultScalarType: 'unknown', + scalars: { + uuid: 'string', + _uuid: 'Array', + timestamp: 'string', + timestamptz: 'string', + numeric: 'string', + jsonb: 'any', + json: 'any', + bigint: 'string', + AWSDate: 'string', + AWSTime: 'string', + AWSDateTime: 'string', + AWSTimestamp: 'string', + AWSEmail: 'string', + AWSJSON: 'string', + AWSURL: 'string', + AWSPhone: 'string', + AWSIPAddress: 'string', + interval: 'string', + date: 'string', + float8: 'string', + }, + }, + + generates: { + // Generate common types + 'generated/index.ts': { + schema: [ + { + [process.env.HASURA_GRAPHQL_URL]: { + headers: { + 'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET, + 'x-hasura-user-id': 'service', + 'x-hasura-user-role': 'service', + }, + }, + }, + ], + plugins: [ + 'typescript', + { + add: { + placement: 'prepend', + content: '/* eslint-disable -- Generated */ // @ts-nocheck', + }, + }, + ], + config: { + strictScalars: true, + skipDocumentsValidation: { + OverlappingFieldsCanBeMergedRule: true, + }, + }, + }, + + // Generate types for graphql requests + src: { + schema: [ + { + [process.env.HASURA_GRAPHQL_URL]: { + headers: { + 'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET, + 'x-hasura-user-id': 'service', + 'x-hasura-user-role': 'service', + }, + }, + }, + ], + documents: ['common/graphql/**/*.ts', '!common/graphql/**/*.generated.ts'], + preset: 'near-operation-file', + presetConfig: { + extension: '.generated.ts', + baseTypesPath: '~generated', + }, + plugins: ['typescript-operations', 'typescript-graphql-request'], + config: { + skipTypename: true, + useTypeImports: true, + directiveArgumentAndInputFieldMappings: 'Model', + }, + }, + + // Generate schema file for e2e + 'schema.graphql': { + schema: [ + { + [process.env.HASURA_GRAPHQL_URL]: { + headers: { + 'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET, + }, + }, + }, + ], + plugins: ['schema-ast'], + }, + }, +} + +export default config +", + "common/client.ts": "import axios from 'axios' + +export const client = axios.create({ + baseURL: process.env.BASE_URL, + timeout: 15000, + validateStatus: () => true, +})", + "common/index.ts": "export * from './client'", + "package.json": { + "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", + "dependencies": { + "@apollo/client": "*", + "axios": "*", + "dotenv": "*", + "graphql": "*", + }, + "devDependencies": { + "@aws-sdk/client-dynamodb": "*", + "@aws-sdk/lib-dynamodb": "*", + "@graphql-codegen/add": "*", + "@graphql-codegen/cli": "*", + "@graphql-codegen/import-types-preset": "*", + "@graphql-codegen/introspection": "*", + "@graphql-codegen/named-operations-object": "*", + "@graphql-codegen/typescript": "*", + "@graphql-codegen/typescript-graphql-request": "*", + "@graphql-codegen/typescript-operations": "*", + "@graphql-codegen/typescript-react-apollo": "*", + "@types/node": "^16", + "projen": "*", + "ts-node": "*", + "typescript": "*", + }, + "license": "Apache-2.0", + "name": "backend-test", + "scripts": { + "default": "npx projen default", + "eject": "npx projen eject", + "gql-to-ts": "graphql-codegen", + "projen": "npx projen", + "test": "jest --detectOpenHandles", + }, + "version": "0.0.0", + }, + "tests/auth.spec.ts": "import {AuthRequestBody, AuthResponseBody} from 'api/auth' +import {AxiosRequestConfig, AxiosResponse} from 'axios' +import {client} from 'common/client' + +describe('Authorization & Authentication', () => { + test('Sign in with existing credentials', async () => { + const payload: AxiosRequestConfig = { + method: 'post', + url: '/auth', + data: { + login: process.env.USERNAME, + password: process.env.PASSWORD, + }, + } + + const response: AxiosResponse = await client.request(payload) + + expect(response.status).toEqual(200) + + expect(response.data).toEqual({ + token: expect.any(String), + }) + }) + + test('Sign in with not existing credentials', async () => { + const payload: AxiosRequestConfig = { + method: 'post', + url: '/auth', + data: { + login: 'invalid', + password: 'invalid', + }, + } + + const response: AxiosResponse = await client.request(payload) + + expect(response.status).toEqual(404) + + expect(response.data).toEqual({ + message: expect.any(String), + }) + }) +})", + "tsconfig.dev.json": { + "compilerOptions": { + "alwaysStrict": true, + "baseUrl": "./", + "declaration": true, + "esModuleInterop": true, + "experimentalDecorators": true, + "inlineSourceMap": true, + "inlineSources": true, + "lib": [ + "es2019", + ], + "module": "CommonJS", + "noEmitOnError": false, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "paths": { + "*": [ + "./*", + ], + }, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "stripInternal": true, + "target": "es6", + }, + "exclude": [ + "node_modules", + ], + "include": [ + ".projenrc.js", + "./**/*.ts", + "test/**/*.ts", + ".projenrc.ts", + "projenrc/**/*.ts", + ], + }, + "tsconfig.json": { + "compilerOptions": { + "alwaysStrict": true, + "baseUrl": "./", + "declaration": true, + "esModuleInterop": true, + "experimentalDecorators": true, + "inlineSourceMap": true, + "inlineSources": true, + "lib": [ + "es2019", + ], + "module": "CommonJS", + "noEmitOnError": false, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "outDir": "lib", + "paths": { + "*": [ + "./*", + ], + }, + "resolveJsonModule": true, + "rootDir": ".", + "skipLibCheck": true, + "strict": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "stripInternal": true, + "target": "es6", + }, + "exclude": [], + "include": [ + "./**/*.ts", + ], + }, +} +`; diff --git a/src/backend-test/__tests__/index.ts b/src/backend-test/__tests__/index.ts new file mode 100644 index 00000000..33642bd8 --- /dev/null +++ b/src/backend-test/__tests__/index.ts @@ -0,0 +1,20 @@ +import {synthSnapshot} from 'projen/lib/util/synth' +import {OttofellerBackendTestProject, OttofellerBackendTestProjectOptions} from '..' + +describe('Backend-test template', () => { + test('sets defaults', () => { + const project = new TestBackendTestProject({hasGitHooks: true}) + const snapshot = synthSnapshot(project) + expect(snapshot).toMatchSnapshot() + }) +}) + +class TestBackendTestProject extends OttofellerBackendTestProject { + constructor(options: Partial = {}) { + super({ + ...options, + name: 'test-backend-test-project', + defaultReleaseBranch: 'main', + }) + } +} \ No newline at end of file diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 42748c2e..aae7c117 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -47,7 +47,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I super({ ...options, bundlerOptions: {}, - jest: true, + jest: false, eslint: false, projenrcTs: true, projenrcJs: false, From 6eba19de770be001ce7110e2bfbdb4c017045c9c Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 15 Dec 2023 13:25:21 +0100 Subject: [PATCH 19/41] PLA-256 Add jest config --- .../__tests__/__snapshots__/index.ts.snap | 32 +++++++++++++++++++ src/backend-test/assets/.env.development | 5 ++- src/backend-test/assets/jest.config.ts | 14 ++++++++ src/backend-test/index.ts | 13 +++++++- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/backend-test/assets/jest.config.ts diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 669fdca0..018e4e87 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -180,6 +180,7 @@ UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar", /.projen/files.json linguist-generated /.projen/tasks.json linguist-generated /codegen.ts linguist-generated +/jest.config.ts linguist-generated /LICENSE linguist-generated /package-lock.json linguist-generated /package.json linguist-generated @@ -224,6 +225,7 @@ jspm_packages/ !/./ /lib /dist/ +!/jest.config.ts !/.eslintrc.json !/codegen.ts ", @@ -323,6 +325,18 @@ tsconfig.tsbuildinfo "name": "graphql", "type": "runtime", }, + { + "name": "jest", + "type": "runtime", + }, + { + "name": "jest-extended", + "type": "runtime", + }, + { + "name": "ts-jest", + "type": "runtime", + }, ], }, ".projen/files.json": { @@ -724,6 +738,21 @@ export const client = axios.create({ validateStatus: () => true, })", "common/index.ts": "export * from './client'", + "jest.config.ts": "import type {Config} from 'jest' +import * as dotenv from 'dotenv' + +dotenv.config({path: './.env.local'}) +dotenv.config({path: './.env.development'}) + +const config: Config = { + testTimeout: 60000, + preset: 'ts-jest', + moduleDirectories: ['node_modules', ''], + setupFilesAfterEnv: ['jest-extended/all'], +} + +export default config +", "package.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", "dependencies": { @@ -731,6 +760,9 @@ export const client = axios.create({ "axios": "*", "dotenv": "*", "graphql": "*", + "jest": "*", + "jest-extended": "*", + "ts-jest": "*", }, "devDependencies": { "@aws-sdk/client-dynamodb": "*", diff --git a/src/backend-test/assets/.env.development b/src/backend-test/assets/.env.development index 6f616da6..dbd20e22 100644 --- a/src/backend-test/assets/.env.development +++ b/src/backend-test/assets/.env.development @@ -1,3 +1,6 @@ HASURA_GRAPHQL_URL=http://localhost:8080/v1/graphql HASURA_GRAPHQL_ADMIN_SECRET=111 -UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar \ No newline at end of file +UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar +BASE_URL=https://paysis.cyclic.app/ +USERNAME=adminius +PASSWORD=supers3cret \ No newline at end of file diff --git a/src/backend-test/assets/jest.config.ts b/src/backend-test/assets/jest.config.ts new file mode 100644 index 00000000..bfbf1828 --- /dev/null +++ b/src/backend-test/assets/jest.config.ts @@ -0,0 +1,14 @@ +import type {Config} from 'jest' +import * as dotenv from 'dotenv' + +dotenv.config({path: './.env.local'}) +dotenv.config({path: './.env.development'}) + +const config: Config = { + testTimeout: 60000, + preset: 'ts-jest', + moduleDirectories: ['node_modules', ''], + setupFilesAfterEnv: ['jest-extended/all'], +} + +export default config diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index aae7c117..7bd4577c 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -109,8 +109,19 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.addDeps('dotenv') this.addDeps('axios') + this.addDeps('jest') + this.addDeps('ts-jest') + this.addDeps('jest-extended') - // // ANCHOR ESLint and prettier setup + // ANCHOR Jest setup + new AssetFile(this, 'jest.config.ts', { + sourcePath: path.join(assetsDir, 'jest.config.ts'), + readonly: false, + marker: false, + }) + + + // ANCHOR ESLint and prettier setup new AssetFile(this, '.eslintrc.json', { sourcePath: path.join(assetsDir, 'eslintrc.json'), readonly: false, From 67896d99bd4b25dfc761768f6571ed359a72b941 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 15 Dec 2023 13:41:52 +0100 Subject: [PATCH 20/41] PLA-256 Add format and lint scripts --- .../__tests__/__snapshots__/index.ts.snap | 11 ++++++++--- src/backend-test/__tests__/index.ts | 2 +- src/backend-test/assets/jest.config.ts | 2 +- src/backend-test/index.ts | 6 +++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 018e4e87..1e83a13c 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -4,7 +4,10 @@ exports[`Backend-test template sets defaults 1`] = ` { ".env.development": "HASURA_GRAPHQL_URL=http://localhost:8080/v1/graphql HASURA_GRAPHQL_ADMIN_SECRET=111 -UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar", +UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar +BASE_URL=https://paysis.cyclic.app/ +USERNAME=adminius +PASSWORD=supers3cret", ".eslintrc.json": { "env": { "jest": true, @@ -738,8 +741,8 @@ export const client = axios.create({ validateStatus: () => true, })", "common/index.ts": "export * from './client'", - "jest.config.ts": "import type {Config} from 'jest' -import * as dotenv from 'dotenv' + "jest.config.ts": "import * as dotenv from 'dotenv' +import type {Config} from 'jest' dotenv.config({path: './.env.local'}) dotenv.config({path: './.env.development'}) @@ -786,7 +789,9 @@ export default config "scripts": { "default": "npx projen default", "eject": "npx projen eject", + "format": "prettier --write ./ && eslint --ext .ts ./ --fix", "gql-to-ts": "graphql-codegen", + "lint": "prettier --check ./ && eslint --ext .ts ./", "projen": "npx projen", "test": "jest --detectOpenHandles", }, diff --git a/src/backend-test/__tests__/index.ts b/src/backend-test/__tests__/index.ts index 33642bd8..67d3e26c 100644 --- a/src/backend-test/__tests__/index.ts +++ b/src/backend-test/__tests__/index.ts @@ -17,4 +17,4 @@ class TestBackendTestProject extends OttofellerBackendTestProject { defaultReleaseBranch: 'main', }) } -} \ No newline at end of file +} diff --git a/src/backend-test/assets/jest.config.ts b/src/backend-test/assets/jest.config.ts index bfbf1828..475509c3 100644 --- a/src/backend-test/assets/jest.config.ts +++ b/src/backend-test/assets/jest.config.ts @@ -1,5 +1,5 @@ -import type {Config} from 'jest' import * as dotenv from 'dotenv' +import type {Config} from 'jest' dotenv.config({path: './.env.local'}) dotenv.config({path: './.env.development'}) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 7bd4577c..e10a9560 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -120,7 +120,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I marker: false, }) - // ANCHOR ESLint and prettier setup new AssetFile(this, '.eslintrc.json', { sourcePath: path.join(assetsDir, 'eslintrc.json'), @@ -128,6 +127,11 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I marker: false, }) + this.addScripts({ + format: 'prettier --write ./ && eslint --ext .ts ./ --fix', + lint: 'prettier --check ./ && eslint --ext .ts ./', + }) + //ANCHOR - Set up AWS DynamoDb Client const isAWSDynamoDBlEnabled = options.isAWSDynamoDBlEnabled ?? true From 03fd7a4f417923af418373a6522004fb089e5acc Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 15 Dec 2023 14:07:48 +0100 Subject: [PATCH 21/41] PLA-256 Add format and lint as task to projen --- .../__tests__/__snapshots__/index.ts.snap | 71 +++++++------------ src/backend-test/index.ts | 25 ++++++- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 1e83a13c..fb0f2d28 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -353,7 +353,6 @@ tsconfig.tsbuildinfo ".projen/files.json", ".projen/tasks.json", "LICENSE", - "tsconfig.dev.json", "tsconfig.json", ], }, @@ -384,6 +383,17 @@ tsconfig.tsbuildinfo }, ], }, + "format": { + "name": "format", + "steps": [ + { + "exec": "prettier --write ./", + }, + { + "exec": "eslint --ext .ts ./ --fix", + }, + ], + }, "install": { "description": "Install project dependencies and update lockfile (non-frozen)", "name": "install", @@ -402,6 +412,17 @@ tsconfig.tsbuildinfo }, ], }, + "lint": { + "name": "lint", + "steps": [ + { + "exec": "prettier --check ./", + }, + { + "exec": "eslint --ext .ts ./", + }, + ], + }, }, }, "LICENSE": " @@ -789,9 +810,9 @@ export default config "scripts": { "default": "npx projen default", "eject": "npx projen eject", - "format": "prettier --write ./ && eslint --ext .ts ./ --fix", + "format": "npx projen format", "gql-to-ts": "graphql-codegen", - "lint": "prettier --check ./ && eslint --ext .ts ./", + "lint": "npx projen lint", "projen": "npx projen", "test": "jest --detectOpenHandles", }, @@ -840,50 +861,6 @@ describe('Authorization & Authentication', () => { }) }) })", - "tsconfig.dev.json": { - "compilerOptions": { - "alwaysStrict": true, - "baseUrl": "./", - "declaration": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "inlineSourceMap": true, - "inlineSources": true, - "lib": [ - "es2019", - ], - "module": "CommonJS", - "noEmitOnError": false, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "paths": { - "*": [ - "./*", - ], - }, - "resolveJsonModule": true, - "skipLibCheck": true, - "strict": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "stripInternal": true, - "target": "es6", - }, - "exclude": [ - "node_modules", - ], - "include": [ - ".projenrc.js", - "./**/*.ts", - "test/**/*.ts", - ".projenrc.ts", - "projenrc/**/*.ts", - ], - }, "tsconfig.json": { "compilerOptions": { "alwaysStrict": true, diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index e10a9560..9b357f7f 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -107,6 +107,8 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I tasksToRemove.forEach(this.removeTask.bind(this)) + this.tryRemoveFile('tsconfig.dev.json') + this.addDeps('dotenv') this.addDeps('axios') this.addDeps('jest') @@ -127,9 +129,26 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I marker: false, }) - this.addScripts({ - format: 'prettier --write ./ && eslint --ext .ts ./ --fix', - lint: 'prettier --check ./ && eslint --ext .ts ./', + this.tasks.addTask('format', { + steps: [ + { + exec: 'prettier --write ./', + }, + { + exec: 'eslint --ext .ts ./ --fix', + }, + ], + }) + + this.tasks.addTask('lint', { + steps: [ + { + exec: 'prettier --check ./', + }, + { + exec: 'eslint --ext .ts ./', + }, + ], }) //ANCHOR - Set up AWS DynamoDb Client From 827d11b68610c2ca0fb7dc4ca6d25d79b3ada210 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 15 Dec 2023 14:09:11 +0100 Subject: [PATCH 22/41] PLA-256 Add typecheck script --- src/backend-test/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 9b357f7f..7617ca4e 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -151,6 +151,15 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I ], }) + this.tasks.addTask('typecheck', { + steps: [ + { + exec: 'tsc', + }, + ], + }) + + //ANCHOR - Set up AWS DynamoDb Client const isAWSDynamoDBlEnabled = options.isAWSDynamoDBlEnabled ?? true From 2fc7321a94e97a38a8f3555a2d0898f0dd1aff4f Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Mon, 18 Dec 2023 14:13:46 +0100 Subject: [PATCH 23/41] PLA-256 Add properties to tsconfig --- .../__tests__/__snapshots__/index.ts.snap | 33 +++++++++++-------- src/backend-test/index.ts | 20 ++++++++++- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index fb0f2d28..e413b349 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -336,6 +336,10 @@ tsconfig.tsbuildinfo "name": "jest-extended", "type": "runtime", }, + { + "name": "prettier", + "type": "runtime", + }, { "name": "ts-jest", "type": "runtime", @@ -423,6 +427,14 @@ tsconfig.tsbuildinfo }, ], }, + "typecheck": { + "name": "typecheck", + "steps": [ + { + "exec": "tsc", + }, + ], + }, }, }, "LICENSE": " @@ -786,6 +798,7 @@ export default config "graphql": "*", "jest": "*", "jest-extended": "*", + "prettier": "*", "ts-jest": "*", }, "devDependencies": { @@ -815,6 +828,7 @@ export default config "lint": "npx projen lint", "projen": "npx projen", "test": "jest --detectOpenHandles", + "typecheck": "npx projen typecheck", }, "version": "0.0.0", }, @@ -865,35 +879,28 @@ describe('Authorization & Authentication', () => { "compilerOptions": { "alwaysStrict": true, "baseUrl": "./", - "declaration": true, "esModuleInterop": true, - "experimentalDecorators": true, - "inlineSourceMap": true, - "inlineSources": true, - "lib": [ - "es2019", - ], - "module": "CommonJS", - "noEmitOnError": false, + "forceConsistentCasingInFileNames": true, + "isolatedModules": false, + "module": "esnext", + "moduleResolution": "node", + "noEmit": true, "noFallthroughCasesInSwitch": true, "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, - "noUnusedLocals": true, + "noUncheckedIndexedAccess": true, "noUnusedParameters": true, - "outDir": "lib", "paths": { "*": [ "./*", ], }, "resolveJsonModule": true, - "rootDir": ".", "skipLibCheck": true, "strict": true, "strictNullChecks": true, "strictPropertyInitialization": true, - "stripInternal": true, "target": "es6", }, "exclude": [], diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 7617ca4e..ce1f45d9 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,6 +1,6 @@ import {execSync} from 'child_process' import * as path from 'path' -import {NodePackageManager} from 'projen/lib/javascript' +import {NodePackageManager, TypeScriptModuleResolution} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' import { AssetFile, @@ -57,6 +57,22 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I tsconfig: { compilerOptions: { + declaration: undefined, + experimentalDecorators: undefined, + inlineSourceMap: undefined, + inlineSources: undefined, + noEmitOnError: undefined, + noUnusedLocals: undefined, + lib: undefined, + outDir: undefined, + rootDir: undefined, + stripInternal: undefined, + forceConsistentCasingInFileNames: true, + isolatedModules: false, + module: 'esnext', + moduleResolution: TypeScriptModuleResolution.NODE, + noEmit: true, + noUncheckedIndexedAccess: true, baseUrl: './', target: 'es6', skipLibCheck: true, @@ -64,6 +80,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I '*': ['./*'], }, }, + }, // In case Github is enabled remove all default stuff. @@ -114,6 +131,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.addDeps('jest') this.addDeps('ts-jest') this.addDeps('jest-extended') + this.addDeps('prettier') // ANCHOR Jest setup new AssetFile(this, 'jest.config.ts', { From b845bfec33972f251ee1da91a728129f8ab38bfd Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Mon, 18 Dec 2023 14:20:44 +0100 Subject: [PATCH 24/41] PLA-256 Mov deps to array --- src/backend-test/index.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index ce1f45d9..67612343 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -89,16 +89,13 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I release: false, depsUpgrade: false, pullRequestTemplate: false, + deps: ['dotenv', 'axios', 'jest', 'ts-jest', 'jest-extended', 'prettier'] }) // ANCHOR Source code const assetsDir = path.join(__dirname, '..', '..', 'src/backend-test/assets') sampleCode(this, options, assetsDir) - this.addScripts({ - test: 'jest --detectOpenHandles', - }) - /* * Clean off the projen tasks and if needed replace them with regular npm scripts. * This way we ensure smooth ejection experience with all the commands visible in package.json @@ -126,14 +123,11 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.tryRemoveFile('tsconfig.dev.json') - this.addDeps('dotenv') - this.addDeps('axios') - this.addDeps('jest') - this.addDeps('ts-jest') - this.addDeps('jest-extended') - this.addDeps('prettier') - // ANCHOR Jest setup + this.addScripts({ + test: 'jest --detectOpenHandles', + }) + new AssetFile(this, 'jest.config.ts', { sourcePath: path.join(assetsDir, 'jest.config.ts'), readonly: false, From 651d383f78c0023b75d184262a45453a0309f48f Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Mon, 18 Dec 2023 14:28:30 +0100 Subject: [PATCH 25/41] PLA-256 Add prettier ignore --- .../__tests__/__snapshots__/index.ts.snap | 11 ++ src/backend-test/assets/.prettierignore | 3 + src/backend-test/eslint-config-qa.ts | 113 ------------------ src/backend-test/index.ts | 8 +- 4 files changed, 21 insertions(+), 114 deletions(-) create mode 100644 src/backend-test/assets/.prettierignore delete mode 100644 src/backend-test/eslint-config-qa.ts diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index e413b349..16be31a4 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -178,6 +178,7 @@ PASSWORD=supers3cret", /.gitignore linguist-generated /.npmignore linguist-generated /.npmrc linguist-generated +/.prettierignore linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated /.projen/files.json linguist-generated @@ -230,6 +231,7 @@ jspm_packages/ /dist/ !/jest.config.ts !/.eslintrc.json +!/.prettierignore !/codegen.ts ", ".npmignore": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". @@ -247,6 +249,10 @@ dist /.idea/ /.projenrc.js tsconfig.tsbuildinfo +", + ".prettierignore": "generated/index.ts +*.generated.ts +tsconfig.json ", ".projen/deps.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", @@ -324,6 +330,10 @@ tsconfig.tsbuildinfo "name": "dotenv", "type": "runtime", }, + { + "name": "eslint-plugin-prettier", + "type": "runtime", + }, { "name": "graphql", "type": "runtime", @@ -795,6 +805,7 @@ export default config "@apollo/client": "*", "axios": "*", "dotenv": "*", + "eslint-plugin-prettier": "*", "graphql": "*", "jest": "*", "jest-extended": "*", diff --git a/src/backend-test/assets/.prettierignore b/src/backend-test/assets/.prettierignore new file mode 100644 index 00000000..2e111650 --- /dev/null +++ b/src/backend-test/assets/.prettierignore @@ -0,0 +1,3 @@ +generated/index.ts +*.generated.ts +tsconfig.json diff --git a/src/backend-test/eslint-config-qa.ts b/src/backend-test/eslint-config-qa.ts deleted file mode 100644 index 74f482d8..00000000 --- a/src/backend-test/eslint-config-qa.ts +++ /dev/null @@ -1,113 +0,0 @@ -import {Linter} from 'eslint' - -export const eslintConfigQa: Linter.Config = { - root: true, - env: { - jest: true, - node: true, - }, - ignorePatterns: ['generated/index.ts', '**/*.generated.ts'], - parser: '@typescript-eslint/parser', - parserOptions: { - ecmaFeatures: { - jsx: true, - }, - ecmaVersion: 'latest', - sourceType: 'module', - }, - rules: { - 'padding-line-between-statements': [ - 'error', - { - blankLine: 'any', - prev: '*', - next: '*', - }, - { - blankLine: 'always', - prev: '*', - next: 'multiline-block-like', - }, - { - blankLine: 'always', - prev: 'multiline-block-like', - next: '*', - }, - { - blankLine: 'always', - prev: '*', - next: 'multiline-const', - }, - { - blankLine: 'always', - prev: 'multiline-const', - next: '*', - }, - { - blankLine: 'always', - prev: '*', - next: 'multiline-expression', - }, - { - blankLine: 'always', - prev: 'multiline-expression', - next: '*', - }, - { - blankLine: 'always', - prev: '*', - next: 'multiline-let', - }, - { - blankLine: 'always', - prev: 'multiline-let', - next: '*', - }, - { - blankLine: 'never', - prev: ['singleline-const', 'singleline-let'], - next: ['singleline-const', 'singleline-let'], - }, - ], - '@typescript-eslint/ban-ts-comment': ['off'], - '@typescript-eslint/consistent-type-assertions': ['off'], - '@typescript-eslint/consistent-type-definitions': ['error', 'type'], - '@typescript-eslint/no-shadow': ['error'], - '@typescript-eslint/no-unused-expressions': ['error'], - '@typescript-eslint/no-unused-vars': [ - 'error', - { - argsIgnorePattern: '^_', - }, - ], - curly: ['error'], - 'import/no-relative-parent-imports': ['error'], - 'no-negated-condition': ['error'], - 'no-nested-ternary': ['error'], - 'eslint-comments/disable-enable-pair': [ - 'error', - { - allowWholeFile: true, - }, - ], - 'eslint-comments/no-aggregating-enable': ['error'], - 'eslint-comments/no-duplicate-disable': ['error'], - 'eslint-comments/no-unlimited-disable': ['error'], - 'eslint-comments/no-unused-disable': ['error'], - 'eslint-comments/no-unused-enable': ['error'], - 'eslint-comments/no-use': [ - 'error', - { - allow: ['eslint-disable', 'eslint-disable-next-line', 'eslint-enable'], - }, - ], - 'eslint-comments/require-description': [ - 'error', - { - ignore: ['eslint-enable'], - }, - ], - }, - extends: ['plugin:prettier/recommended'], - plugins: ['@typescript-eslint', 'eslint-comments', 'import', '@ottofeller/ottofeller'], -} diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 67612343..95e2a600 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -89,7 +89,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I release: false, depsUpgrade: false, pullRequestTemplate: false, - deps: ['dotenv', 'axios', 'jest', 'ts-jest', 'jest-extended', 'prettier'] + deps: ['dotenv', 'axios', 'jest', 'ts-jest', 'jest-extended', 'prettier', 'eslint-plugin-prettier'] }) // ANCHOR Source code @@ -141,6 +141,12 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I marker: false, }) + new AssetFile(this, '.prettierignore', { + sourcePath: path.join(assetsDir, '.prettierignore'), + readonly: false, + marker: false, + }) + this.tasks.addTask('format', { steps: [ { From c9b4a2c257161fb2a3ca3c96f953624bf2da51cb Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Mon, 18 Dec 2023 15:12:55 +0100 Subject: [PATCH 26/41] PLA-256 Pass json files as ts using JsonFile class --- .../__tests__/__snapshots__/index.ts.snap | 33 ++++- src/backend-test/assets/.prettierignore | 1 + src/backend-test/assets/eslint-config.ts | 113 ++++++++++++++++++ src/backend-test/assets/eslintrc.json | 111 ----------------- src/backend-test/index.ts | 24 ++-- 5 files changed, 162 insertions(+), 120 deletions(-) create mode 100644 src/backend-test/assets/eslint-config.ts delete mode 100644 src/backend-test/assets/eslintrc.json diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 16be31a4..48a72461 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -14,7 +14,6 @@ PASSWORD=supers3cret", "node": true, }, "extends": [ - "plugin:import/typescript", "plugin:prettier/recommended", ], "ignorePatterns": [ @@ -179,6 +178,7 @@ PASSWORD=supers3cret", /.npmignore linguist-generated /.npmrc linguist-generated /.prettierignore linguist-generated +/.prettierrc.json linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated /.projen/files.json linguist-generated @@ -231,6 +231,7 @@ jspm_packages/ /dist/ !/jest.config.ts !/.eslintrc.json +!/.prettierrc.json !/.prettierignore !/codegen.ts ", @@ -253,7 +254,30 @@ tsconfig.tsbuildinfo ".prettierignore": "generated/index.ts *.generated.ts tsconfig.json +.eslintrc.json ", + ".prettierrc.json": { + "arrowParens": "always", + "bracketSameLine": false, + "bracketSpacing": false, + "embeddedLanguageFormatting": "auto", + "endOfLine": "lf", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "jsxSingleQuote": false, + "printWidth": 120, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "rangeStart": 0, + "requirePragma": false, + "semi": false, + "singleAttributePerLine": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false, + "vueIndentScriptAndStyle": false, + }, ".projen/deps.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", "dependencies": [ @@ -330,6 +354,10 @@ tsconfig.json "name": "dotenv", "type": "runtime", }, + { + "name": "eslint-config-prettier", + "type": "runtime", + }, { "name": "eslint-plugin-prettier", "type": "runtime", @@ -359,10 +387,12 @@ tsconfig.json ".projen/files.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", "files": [ + ".eslintrc.json", ".gitattributes", ".gitignore", ".npmignore", ".npmrc", + ".prettierrc.json", ".projen/deps.json", ".projen/files.json", ".projen/tasks.json", @@ -805,6 +835,7 @@ export default config "@apollo/client": "*", "axios": "*", "dotenv": "*", + "eslint-config-prettier": "*", "eslint-plugin-prettier": "*", "graphql": "*", "jest": "*", diff --git a/src/backend-test/assets/.prettierignore b/src/backend-test/assets/.prettierignore index 2e111650..cbf514bf 100644 --- a/src/backend-test/assets/.prettierignore +++ b/src/backend-test/assets/.prettierignore @@ -1,3 +1,4 @@ generated/index.ts *.generated.ts tsconfig.json +.eslintrc.json diff --git a/src/backend-test/assets/eslint-config.ts b/src/backend-test/assets/eslint-config.ts new file mode 100644 index 00000000..dfab3fd8 --- /dev/null +++ b/src/backend-test/assets/eslint-config.ts @@ -0,0 +1,113 @@ +import {Linter} from 'eslint' + +export const eslintConfig: Linter.Config = { + root: true, + env: { + jest: true, + node: true, + }, + ignorePatterns: ['generated/index.ts', '**/*.generated.ts'], + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + ecmaVersion: 'latest', + sourceType: 'module', + }, + rules: { + 'padding-line-between-statements': [ + 'error', + { + blankLine: 'any', + prev: '*', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-block-like', + }, + { + blankLine: 'always', + prev: 'multiline-block-like', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-const', + }, + { + blankLine: 'always', + prev: 'multiline-const', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-expression', + }, + { + blankLine: 'always', + prev: 'multiline-expression', + next: '*', + }, + { + blankLine: 'always', + prev: '*', + next: 'multiline-let', + }, + { + blankLine: 'always', + prev: 'multiline-let', + next: '*', + }, + { + blankLine: 'never', + prev: ['singleline-const', 'singleline-let'], + next: ['singleline-const', 'singleline-let'], + }, + ], + '@typescript-eslint/ban-ts-comment': ['off'], + '@typescript-eslint/consistent-type-assertions': ['off'], + '@typescript-eslint/consistent-type-definitions': ['error', 'type'], + '@typescript-eslint/no-shadow': ['error'], + '@typescript-eslint/no-unused-expressions': ['error'], + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + }, + ], + curly: ['error'], + 'import/no-relative-parent-imports': ['error'], + 'no-negated-condition': ['error'], + 'no-nested-ternary': ['error'], + 'eslint-comments/disable-enable-pair': [ + 'error', + { + allowWholeFile: true, + }, + ], + 'eslint-comments/no-aggregating-enable': ['error'], + 'eslint-comments/no-duplicate-disable': ['error'], + 'eslint-comments/no-unlimited-disable': ['error'], + 'eslint-comments/no-unused-disable': ['error'], + 'eslint-comments/no-unused-enable': ['error'], + 'eslint-comments/no-use': [ + 'error', + { + allow: ['eslint-disable', 'eslint-disable-next-line', 'eslint-enable'], + }, + ], + 'eslint-comments/require-description': [ + 'error', + { + ignore: ['eslint-enable'], + }, + ], + }, + extends: ['plugin:prettier/recommended'], + plugins: ['@typescript-eslint', 'eslint-comments', 'import', '@ottofeller/ottofeller'], +} diff --git a/src/backend-test/assets/eslintrc.json b/src/backend-test/assets/eslintrc.json deleted file mode 100644 index d73d16c0..00000000 --- a/src/backend-test/assets/eslintrc.json +++ /dev/null @@ -1,111 +0,0 @@ -{ - "root": true, - "env": { - "jest": true, - "node": true - }, - "ignorePatterns": ["generated/index.ts", "**/*.generated.ts"], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": "latest", - "sourceType": "module" - }, - "rules": { - "padding-line-between-statements": [ - "error", - { - "blankLine": "any", - "prev": "*", - "next": "*" - }, - { - "blankLine": "always", - "prev": "*", - "next": "multiline-block-like" - }, - { - "blankLine": "always", - "prev": "multiline-block-like", - "next": "*" - }, - { - "blankLine": "always", - "prev": "*", - "next": "multiline-const" - }, - { - "blankLine": "always", - "prev": "multiline-const", - "next": "*" - }, - { - "blankLine": "always", - "prev": "*", - "next": "multiline-expression" - }, - { - "blankLine": "always", - "prev": "multiline-expression", - "next": "*" - }, - { - "blankLine": "always", - "prev": "*", - "next": "multiline-let" - }, - { - "blankLine": "always", - "prev": "multiline-let", - "next": "*" - }, - { - "blankLine": "never", - "prev": ["singleline-const", "singleline-let"], - "next": ["singleline-const", "singleline-let"] - } - ], - "@typescript-eslint/ban-ts-comment": ["off"], - "@typescript-eslint/consistent-type-assertions": ["off"], - "@typescript-eslint/consistent-type-definitions": ["error", "type"], - "@typescript-eslint/no-shadow": ["error"], - "@typescript-eslint/no-unused-expressions": ["error"], - "@typescript-eslint/no-unused-vars": [ - "error", - { - "argsIgnorePattern": "^_" - } - ], - "curly": ["error"], - "import/no-relative-parent-imports": ["error"], - "no-negated-condition": ["error"], - "no-nested-ternary": ["error"], - "eslint-comments/disable-enable-pair": [ - "error", - { - "allowWholeFile": true - } - ], - "eslint-comments/no-aggregating-enable": ["error"], - "eslint-comments/no-duplicate-disable": ["error"], - "eslint-comments/no-unlimited-disable": ["error"], - "eslint-comments/no-unused-disable": ["error"], - "eslint-comments/no-unused-enable": ["error"], - "eslint-comments/no-use": [ - "error", - { - "allow": ["eslint-disable", "eslint-disable-next-line", "eslint-enable"] - } - ], - "eslint-comments/require-description": [ - "error", - { - "ignore": ["eslint-enable"] - } - ] - }, - "extends": ["plugin:import/typescript", "plugin:prettier/recommended"], - "plugins": ["@typescript-eslint", "eslint-comments", "import", "@ottofeller/ottofeller"] -} diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 95e2a600..724a3eea 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,5 +1,6 @@ import {execSync} from 'child_process' import * as path from 'path' +import {JsonFile} from 'projen' import {NodePackageManager, TypeScriptModuleResolution} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' import { @@ -11,6 +12,8 @@ import { collectTelemetry, } from '../common' import {WithCustomLintPaths} from '../common/lint' +import {prettierConfig} from '../common/lint/configs/prettier' +import {eslintConfig} from './assets/eslint-config' import {sampleCode} from './sample-code' export interface OttofellerBackendTestProjectOptions @@ -80,7 +83,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I '*': ['./*'], }, }, - }, // In case Github is enabled remove all default stuff. @@ -89,7 +91,16 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I release: false, depsUpgrade: false, pullRequestTemplate: false, - deps: ['dotenv', 'axios', 'jest', 'ts-jest', 'jest-extended', 'prettier', 'eslint-plugin-prettier'] + deps: [ + 'dotenv', + 'axios', + 'jest', + 'ts-jest', + 'jest-extended', + 'prettier', + 'eslint-plugin-prettier', + 'eslint-config-prettier', + ], }) // ANCHOR Source code @@ -135,11 +146,9 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I }) // ANCHOR ESLint and prettier setup - new AssetFile(this, '.eslintrc.json', { - sourcePath: path.join(assetsDir, 'eslintrc.json'), - readonly: false, - marker: false, - }) + new JsonFile(this, '.eslintrc.json', {obj: eslintConfig, marker: false}) + + new JsonFile(this, '.prettierrc.json', {obj: prettierConfig, marker: false}) new AssetFile(this, '.prettierignore', { sourcePath: path.join(assetsDir, '.prettierignore'), @@ -176,7 +185,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I }, ], }) - //ANCHOR - Set up AWS DynamoDb Client const isAWSDynamoDBlEnabled = options.isAWSDynamoDBlEnabled ?? true From e4f1043a932a1051571b44697d9cce39b9f3969f Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Mon, 18 Dec 2023 15:19:35 +0100 Subject: [PATCH 27/41] PLA-256 Add cath error to codegen file --- src/backend-test/__tests__/__snapshots__/index.ts.snap | 2 +- src/backend-test/assets/codegen.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 48a72461..0eee80e0 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -698,7 +698,7 @@ dotenv.config({path: '.env.local'}) dotenv.config({path: '.env.development'}) if (!process.env.HASURA_GRAPHQL_URL || !process.env.HASURA_GRAPHQL_ADMIN_SECRET) { - process.exit(1) + throw new Error('HASURA_GRAPHQL_URL or HASURA_GRAPHQL_ADMIN_SECRET is not exist. Check your .env files') } const config: CodegenConfig = { diff --git a/src/backend-test/assets/codegen.ts b/src/backend-test/assets/codegen.ts index f1e6df19..8f1e298b 100644 --- a/src/backend-test/assets/codegen.ts +++ b/src/backend-test/assets/codegen.ts @@ -5,7 +5,7 @@ dotenv.config({path: '.env.local'}) dotenv.config({path: '.env.development'}) if (!process.env.HASURA_GRAPHQL_URL || !process.env.HASURA_GRAPHQL_ADMIN_SECRET) { - process.exit(1) + throw new Error('HASURA_GRAPHQL_URL or HASURA_GRAPHQL_ADMIN_SECRET is not exist. Check your .env files') } const config: CodegenConfig = { From ff4ebcfc275bb80c5413fdaa7d3d2a061bec9bc3 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 21 Dec 2023 12:50:54 +0100 Subject: [PATCH 28/41] PLA-256 Fix typo --- src/backend-test/assets/codegen.ts | 2 +- src/backend-test/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend-test/assets/codegen.ts b/src/backend-test/assets/codegen.ts index 8f1e298b..c895cfaf 100644 --- a/src/backend-test/assets/codegen.ts +++ b/src/backend-test/assets/codegen.ts @@ -5,7 +5,7 @@ dotenv.config({path: '.env.local'}) dotenv.config({path: '.env.development'}) if (!process.env.HASURA_GRAPHQL_URL || !process.env.HASURA_GRAPHQL_ADMIN_SECRET) { - throw new Error('HASURA_GRAPHQL_URL or HASURA_GRAPHQL_ADMIN_SECRET is not exist. Check your .env files') + throw new Error('HASURA_GRAPHQL_URL or HASURA_GRAPHQL_ADMIN_SECRET does not exist. Check your .env files') } const config: CodegenConfig = { diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 724a3eea..a6c3ab7d 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -33,7 +33,7 @@ export interface OttofellerBackendTestProjectOptions * * @default true */ - readonly isAWSDynamoDBlEnabled?: boolean + readonly isAWSDynamoDBEnabled?: boolean } /** @@ -187,7 +187,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I }) //ANCHOR - Set up AWS DynamoDb Client - const isAWSDynamoDBlEnabled = options.isAWSDynamoDBlEnabled ?? true + const isAWSDynamoDBlEnabled = options.isAWSDynamoDBEnabled ?? true if (isAWSDynamoDBlEnabled) { this.addDevDeps('@aws-sdk/client-dynamodb', '@aws-sdk/lib-dynamodb') From bebe7be5c7100ac8c245ff840a79ffbaa1119dad Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 21 Dec 2023 12:56:25 +0100 Subject: [PATCH 29/41] PLA-256 Remove unnecessary devDeps --- src/backend-test/index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index a6c3ab7d..7a43555c 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -132,8 +132,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I tasksToRemove.forEach(this.removeTask.bind(this)) - this.tryRemoveFile('tsconfig.dev.json') - // ANCHOR Jest setup this.addScripts({ test: 'jest --detectOpenHandles', @@ -200,13 +198,12 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.addDevDeps( '@graphql-codegen/add', '@graphql-codegen/cli', - '@graphql-codegen/import-types-preset', '@graphql-codegen/introspection', '@graphql-codegen/named-operations-object', + "@graphql-codegen/near-operation-file-preset", '@graphql-codegen/typescript', '@graphql-codegen/typescript-graphql-request', '@graphql-codegen/typescript-operations', - '@graphql-codegen/typescript-react-apollo', ) this.addDeps('@apollo/client', 'graphql') From 72b22e8379103811477c9c0a94a6c4501708f08c Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 21 Dec 2023 15:54:54 +0100 Subject: [PATCH 30/41] PLA-256 Use addLinters func --- .../__tests__/__snapshots__/index.ts.snap | 192 +++++++++++++++++- src/backend-test/assets/.prettierignore | 1 + src/backend-test/assets/eslint-config.ts | 2 +- src/backend-test/index.ts | 24 ++- 4 files changed, 202 insertions(+), 17 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 0eee80e0..532127e6 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -10,16 +10,35 @@ USERNAME=adminius PASSWORD=supers3cret", ".eslintrc.json": { "env": { + "browser": true, "jest": true, "node": true, }, "extends": [ + "plugin:import/typescript", + "plugin:@cspell/recommended", + "plugin:import/typescript", "plugin:prettier/recommended", ], + "globals": { + "document": "readonly", + "navigator": "readonly", + "window": "readonly", + }, "ignorePatterns": [ "generated/index.ts", "**/*.generated.ts", ], + "overrides": [ + { + "files": [ + "**/__tests__/*", + ], + "rules": { + "import/no-relative-parent-imports": "off", + }, + }, + ], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaFeatures": { @@ -33,6 +52,11 @@ PASSWORD=supers3cret", "eslint-comments", "import", "@ottofeller/ottofeller", + "@cspell", + "@typescript-eslint", + "eslint-comments", + "import", + "@ottofeller/ottofeller", ], "root": true, "rules": { @@ -169,6 +193,12 @@ PASSWORD=supers3cret", }, ], }, + "settings": { + "react": { + "pragma": "React", + "version": "17", + }, + }, }, ".gitattributes": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". @@ -230,8 +260,8 @@ jspm_packages/ /lib /dist/ !/jest.config.ts -!/.eslintrc.json !/.prettierrc.json +!/.eslintrc.json !/.prettierignore !/codegen.ts ", @@ -255,6 +285,7 @@ tsconfig.tsbuildinfo *.generated.ts tsconfig.json .eslintrc.json +tsconfig.dev.json ", ".prettierrc.json": { "arrowParens": "always", @@ -290,15 +321,15 @@ tsconfig.json "type": "build", }, { - "name": "@graphql-codegen/add", + "name": "@cspell/eslint-plugin", "type": "build", }, { - "name": "@graphql-codegen/cli", + "name": "@graphql-codegen/add", "type": "build", }, { - "name": "@graphql-codegen/import-types-preset", + "name": "@graphql-codegen/cli", "type": "build", }, { @@ -309,6 +340,10 @@ tsconfig.json "name": "@graphql-codegen/named-operations-object", "type": "build", }, + { + "name": "@graphql-codegen/near-operation-file-preset", + "type": "build", + }, { "name": "@graphql-codegen/typescript", "type": "build", @@ -322,7 +357,7 @@ tsconfig.json "type": "build", }, { - "name": "@graphql-codegen/typescript-react-apollo", + "name": "@ottofeller/eslint-plugin-ottofeller", "type": "build", }, { @@ -330,6 +365,42 @@ tsconfig.json "type": "build", "version": "^16", }, + { + "name": "@typescript-eslint/eslint-plugin", + "type": "build", + "version": "6", + }, + { + "name": "@typescript-eslint/parser", + "type": "build", + "version": "6", + }, + { + "name": "@typescript-eslint/typescript-estree", + "type": "build", + "version": "6", + }, + { + "name": "eslint-plugin-eslint-comments", + "type": "build", + }, + { + "name": "eslint-plugin-import", + "type": "build", + }, + { + "name": "eslint", + "type": "build", + "version": "8", + }, + { + "name": "prettier", + "type": "build", + }, + { + "name": "prettier-plugin-organize-imports", + "type": "build", + }, { "name": "projen", "type": "build", @@ -397,6 +468,7 @@ tsconfig.json ".projen/files.json", ".projen/tasks.json", "LICENSE", + "tsconfig.dev.json", "tsconfig.json", ], }, @@ -698,7 +770,7 @@ dotenv.config({path: '.env.local'}) dotenv.config({path: '.env.development'}) if (!process.env.HASURA_GRAPHQL_URL || !process.env.HASURA_GRAPHQL_ADMIN_SECRET) { - throw new Error('HASURA_GRAPHQL_URL or HASURA_GRAPHQL_ADMIN_SECRET is not exist. Check your .env files') + throw new Error('HASURA_GRAPHQL_URL or HASURA_GRAPHQL_ADMIN_SECRET does not exist. Check your .env files') } const config: CodegenConfig = { @@ -814,6 +886,62 @@ export const client = axios.create({ validateStatus: () => true, })", "common/index.ts": "export * from './client'", + "cspell.json": { + "allowCompoundWords": true, + "dictionaries": [ + "typescript", + "node", + "npm", + "html", + "css", + ], + "enabled": true, + "enabledLanguageIds": [ + "typescript", + "typescriptreact", + "javascript", + "markdown", + "yaml", + "json", + ], + "ignorePaths": [ + ".gitignore", + "__tests__", + "CoreFeatures", + "Dockerfile", + "generated", + "hasura", + "node_modules", + "*.webp", + "*.tsbuildinfo", + "*.json", + "*.config.js", + "*.yaml", + "*.py", + "*.cfg", + "*.graphql", + "*.sum", + "**/parameters/**/*", + ], + "language": "en", + "version": "0.2", + "words": [ + "cicd", + "dangerules", + "devs", + "hasura", + "ilike", + "nextjs", + "ofmt", + "pkey", + "projen", + "projenrc", + "Println", + "testid", + "timestamptz", + "webm", + ], + }, "jest.config.ts": "import * as dotenv from 'dotenv' import type {Config} from 'jest' @@ -846,16 +974,25 @@ export default config "devDependencies": { "@aws-sdk/client-dynamodb": "*", "@aws-sdk/lib-dynamodb": "*", + "@cspell/eslint-plugin": "*", "@graphql-codegen/add": "*", "@graphql-codegen/cli": "*", - "@graphql-codegen/import-types-preset": "*", "@graphql-codegen/introspection": "*", "@graphql-codegen/named-operations-object": "*", + "@graphql-codegen/near-operation-file-preset": "*", "@graphql-codegen/typescript": "*", "@graphql-codegen/typescript-graphql-request": "*", "@graphql-codegen/typescript-operations": "*", - "@graphql-codegen/typescript-react-apollo": "*", + "@ottofeller/eslint-plugin-ottofeller": "*", "@types/node": "^16", + "@typescript-eslint/eslint-plugin": "6", + "@typescript-eslint/parser": "6", + "@typescript-eslint/typescript-estree": "6", + "eslint": "8", + "eslint-plugin-eslint-comments": "*", + "eslint-plugin-import": "*", + "prettier": "*", + "prettier-plugin-organize-imports": "*", "projen": "*", "ts-node": "*", "typescript": "*", @@ -917,6 +1054,45 @@ describe('Authorization & Authentication', () => { }) }) })", + "tsconfig.dev.json": { + "compilerOptions": { + "alwaysStrict": true, + "baseUrl": "./", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": false, + "module": "esnext", + "moduleResolution": "node", + "noEmit": true, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUncheckedIndexedAccess": true, + "noUnusedParameters": true, + "paths": { + "*": [ + "./*", + ], + }, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "target": "es6", + }, + "exclude": [ + "node_modules", + ], + "include": [ + ".projenrc.js", + "./**/*.ts", + "test/**/*.ts", + ".projenrc.ts", + "projenrc/**/*.ts", + ], + }, "tsconfig.json": { "compilerOptions": { "alwaysStrict": true, diff --git a/src/backend-test/assets/.prettierignore b/src/backend-test/assets/.prettierignore index cbf514bf..e35f8856 100644 --- a/src/backend-test/assets/.prettierignore +++ b/src/backend-test/assets/.prettierignore @@ -2,3 +2,4 @@ generated/index.ts *.generated.ts tsconfig.json .eslintrc.json +tsconfig.dev.json diff --git a/src/backend-test/assets/eslint-config.ts b/src/backend-test/assets/eslint-config.ts index dfab3fd8..cf3ea181 100644 --- a/src/backend-test/assets/eslint-config.ts +++ b/src/backend-test/assets/eslint-config.ts @@ -108,6 +108,6 @@ export const eslintConfig: Linter.Config = { }, ], }, - extends: ['plugin:prettier/recommended'], + extends: ['plugin:import/typescript', 'plugin:prettier/recommended'], plugins: ['@typescript-eslint', 'eslint-comments', 'import', '@ottofeller/ottofeller'], } diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 7a43555c..88c1439e 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -1,6 +1,5 @@ import {execSync} from 'child_process' import * as path from 'path' -import {JsonFile} from 'projen' import {NodePackageManager, TypeScriptModuleResolution} from 'projen/lib/javascript' import {TypeScriptProject, TypeScriptProjectOptions} from 'projen/lib/typescript' import { @@ -10,9 +9,9 @@ import { WithGitHooks, WithTelemetry, collectTelemetry, + setupTelemetry, } from '../common' -import {WithCustomLintPaths} from '../common/lint' -import {prettierConfig} from '../common/lint/configs/prettier' +import {WithCustomLintPaths, addLinters} from '../common/lint' import {eslintConfig} from './assets/eslint-config' import {sampleCode} from './sample-code' @@ -144,9 +143,9 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I }) // ANCHOR ESLint and prettier setup - new JsonFile(this, '.eslintrc.json', {obj: eslintConfig, marker: false}) - new JsonFile(this, '.prettierrc.json', {obj: prettierConfig, marker: false}) + const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] + addLinters({project: this, lintPaths, extraEslintConfigs: [eslintConfig]}) new AssetFile(this, '.prettierignore', { sourcePath: path.join(assetsDir, '.prettierignore'), @@ -154,6 +153,8 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I marker: false, }) + this.removeTask('format') + this.tasks.addTask('format', { steps: [ { @@ -165,6 +166,8 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I ], }) + this.removeTask('lint') + this.tasks.addTask('lint', { steps: [ { @@ -176,6 +179,8 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I ], }) + this.removeTask('typecheck') + this.tasks.addTask('typecheck', { steps: [ { @@ -185,9 +190,9 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I }) //ANCHOR - Set up AWS DynamoDb Client - const isAWSDynamoDBlEnabled = options.isAWSDynamoDBEnabled ?? true + const isAWSDynamoDBEnabled = options.isAWSDynamoDBEnabled ?? true - if (isAWSDynamoDBlEnabled) { + if (isAWSDynamoDBEnabled) { this.addDevDeps('@aws-sdk/client-dynamodb', '@aws-sdk/lib-dynamodb') } @@ -200,7 +205,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I '@graphql-codegen/cli', '@graphql-codegen/introspection', '@graphql-codegen/named-operations-object', - "@graphql-codegen/near-operation-file-preset", + '@graphql-codegen/near-operation-file-preset', '@graphql-codegen/typescript', '@graphql-codegen/typescript-graphql-request', '@graphql-codegen/typescript-operations', @@ -222,6 +227,9 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I this.package.file.addDeletionOverride('main') this.package.file.addDeletionOverride('types') + + // ANCHOR Telemetry + setupTelemetry(this, options) } postSynthesize(): void { From da96598a57de004748fb068abd251a93531c7508 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 21 Dec 2023 16:45:08 +0100 Subject: [PATCH 31/41] PLA-256 Add unit test for gql --- src/backend-test/__tests__/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/backend-test/__tests__/index.ts b/src/backend-test/__tests__/index.ts index 67d3e26c..b5148af5 100644 --- a/src/backend-test/__tests__/index.ts +++ b/src/backend-test/__tests__/index.ts @@ -7,6 +7,27 @@ describe('Backend-test template', () => { const snapshot = synthSnapshot(project) expect(snapshot).toMatchSnapshot() }) + + describe('has GraphQL', () => { + test('enabled by default', () => { + const project = new TestBackendTestProject() + const snapshot = synthSnapshot(project) + expect(snapshot['package.json'].dependencies).toHaveProperty('@apollo/client') + expect(snapshot['package.json'].dependencies).toHaveProperty('graphql') + expect(snapshot['package.json'].scripts).toHaveProperty('gql-to-ts') + expect(snapshot['codegen.ts']).toBeDefined() + }) + + test('disabled with an option', () => { + const project = new TestBackendTestProject({isGraphqlEnabled: false}) + const snapshot = synthSnapshot(project) + expect(snapshot['package.json'].dependencies).not.toHaveProperty('@apollo/client') + expect(snapshot['package.json'].dependencies).not.toHaveProperty('graphql') + expect(snapshot['package.json'].scripts).not.toHaveProperty('generate-graphql-schema') + expect(snapshot['package.json'].scripts).not.toHaveProperty('gql-to-ts') + expect(snapshot['codegen.ts']).not.toBeDefined() + }) + }) }) class TestBackendTestProject extends OttofellerBackendTestProject { From 5c5f06986c1bcd3cfbeae31bd9233b30b6e1f603 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Thu, 21 Dec 2023 17:05:26 +0100 Subject: [PATCH 32/41] PLA-256 Add AwsDynamoDb unit tests --- src/backend-test/__tests__/index.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/backend-test/__tests__/index.ts b/src/backend-test/__tests__/index.ts index b5148af5..dcc1854c 100644 --- a/src/backend-test/__tests__/index.ts +++ b/src/backend-test/__tests__/index.ts @@ -23,11 +23,26 @@ describe('Backend-test template', () => { const snapshot = synthSnapshot(project) expect(snapshot['package.json'].dependencies).not.toHaveProperty('@apollo/client') expect(snapshot['package.json'].dependencies).not.toHaveProperty('graphql') - expect(snapshot['package.json'].scripts).not.toHaveProperty('generate-graphql-schema') expect(snapshot['package.json'].scripts).not.toHaveProperty('gql-to-ts') expect(snapshot['codegen.ts']).not.toBeDefined() }) }) + + describe('has AwsDynamoDb', () => { + test('enabled by default', () => { + const project = new TestBackendTestProject() + const snapshot = synthSnapshot(project) + expect(snapshot['package.json'].devDependencies).toHaveProperty('@aws-sdk/client-dynamodb') + expect(snapshot['package.json'].devDependencies).toHaveProperty('@aws-sdk/lib-dynamodb') + }) + + test('disabled with an option', () => { + const project = new TestBackendTestProject({isAWSDynamoDBEnabled: false}) + const snapshot = synthSnapshot(project) + expect(snapshot['package.json'].devDependencies).not.toHaveProperty('@aws-sdk/client-dynamodb') + expect(snapshot['package.json'].devDependencies).not.toHaveProperty('@aws-sdk/lib-dynamodb') + }) + }) }) class TestBackendTestProject extends OttofellerBackendTestProject { From 35597250375bafadb97fd49e1e00381b190917d5 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 22 Dec 2023 12:48:52 +0100 Subject: [PATCH 33/41] PLA-256 Fix format issues in the sample files --- src/backend-test/assets/api/auth/index.ts.sample | 2 +- src/backend-test/assets/api/auth/request.ts.sample | 8 ++++---- src/backend-test/assets/api/auth/response.ts.sample | 8 ++++---- src/backend-test/assets/common/client.ts.sample | 2 +- src/backend-test/assets/common/index.ts.sample | 2 +- src/backend-test/assets/tests/auth.spec.ts.sample | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/backend-test/assets/api/auth/index.ts.sample b/src/backend-test/assets/api/auth/index.ts.sample index 85e4093a..b1f8aede 100644 --- a/src/backend-test/assets/api/auth/index.ts.sample +++ b/src/backend-test/assets/api/auth/index.ts.sample @@ -1,2 +1,2 @@ export * from './request' -export * from './response' \ No newline at end of file +export * from './response' diff --git a/src/backend-test/assets/api/auth/request.ts.sample b/src/backend-test/assets/api/auth/request.ts.sample index f5fc0d7e..3031301e 100644 --- a/src/backend-test/assets/api/auth/request.ts.sample +++ b/src/backend-test/assets/api/auth/request.ts.sample @@ -1,4 +1,4 @@ -export type AuthRequestBody = { - login: string | undefined - password: string | undefined - } \ No newline at end of file +export type AuthRequestBody { + login: string | undefined + password: string | undefined +} diff --git a/src/backend-test/assets/api/auth/response.ts.sample b/src/backend-test/assets/api/auth/response.ts.sample index 6ddedf8c..cad94de5 100644 --- a/src/backend-test/assets/api/auth/response.ts.sample +++ b/src/backend-test/assets/api/auth/response.ts.sample @@ -1,4 +1,4 @@ -export type AuthResponseBody = { - token?: string - message?: string - } \ No newline at end of file +export type AuthResponseBody { + token?: string + message?: string +} diff --git a/src/backend-test/assets/common/client.ts.sample b/src/backend-test/assets/common/client.ts.sample index a34fa0f2..089a2947 100644 --- a/src/backend-test/assets/common/client.ts.sample +++ b/src/backend-test/assets/common/client.ts.sample @@ -4,4 +4,4 @@ export const client = axios.create({ baseURL: process.env.BASE_URL, timeout: 15000, validateStatus: () => true, -}) \ No newline at end of file +}) diff --git a/src/backend-test/assets/common/index.ts.sample b/src/backend-test/assets/common/index.ts.sample index 7eec814f..83dae763 100644 --- a/src/backend-test/assets/common/index.ts.sample +++ b/src/backend-test/assets/common/index.ts.sample @@ -1 +1 @@ -export * from './client' \ No newline at end of file +export * from './client' diff --git a/src/backend-test/assets/tests/auth.spec.ts.sample b/src/backend-test/assets/tests/auth.spec.ts.sample index d301f94b..669779b6 100644 --- a/src/backend-test/assets/tests/auth.spec.ts.sample +++ b/src/backend-test/assets/tests/auth.spec.ts.sample @@ -40,4 +40,4 @@ describe('Authorization & Authentication', () => { message: expect.any(String), }) }) -}) \ No newline at end of file +}) From a99e70ee7b8d4f6346f686caa35c64002ffd831e Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 22 Dec 2023 13:03:39 +0100 Subject: [PATCH 34/41] PLA-256 Remove apollo and fix types issue --- src/backend-test/assets/.env.development | 2 +- src/backend-test/assets/api/auth/request.ts.sample | 2 +- src/backend-test/assets/api/auth/response.ts.sample | 2 +- src/backend-test/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend-test/assets/.env.development b/src/backend-test/assets/.env.development index dbd20e22..8dea85f0 100644 --- a/src/backend-test/assets/.env.development +++ b/src/backend-test/assets/.env.development @@ -3,4 +3,4 @@ HASURA_GRAPHQL_ADMIN_SECRET=111 UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar BASE_URL=https://paysis.cyclic.app/ USERNAME=adminius -PASSWORD=supers3cret \ No newline at end of file +PASSWORD=supers3cret diff --git a/src/backend-test/assets/api/auth/request.ts.sample b/src/backend-test/assets/api/auth/request.ts.sample index 3031301e..c0b044a0 100644 --- a/src/backend-test/assets/api/auth/request.ts.sample +++ b/src/backend-test/assets/api/auth/request.ts.sample @@ -1,4 +1,4 @@ -export type AuthRequestBody { +export type AuthRequestBody = { login: string | undefined password: string | undefined } diff --git a/src/backend-test/assets/api/auth/response.ts.sample b/src/backend-test/assets/api/auth/response.ts.sample index cad94de5..ca8f6d86 100644 --- a/src/backend-test/assets/api/auth/response.ts.sample +++ b/src/backend-test/assets/api/auth/response.ts.sample @@ -1,4 +1,4 @@ -export type AuthResponseBody { +export type AuthResponseBody = { token?: string message?: string } diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 88c1439e..de3a3b7d 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -211,7 +211,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I '@graphql-codegen/typescript-operations', ) - this.addDeps('@apollo/client', 'graphql') + this.addDeps('graphql') // ANCHOR Codegen new AssetFile(this, 'codegen.ts', { From 797a99fdd3ffe671dfbc5fccf1e79a2459953f13 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Fri, 22 Dec 2023 13:09:10 +0100 Subject: [PATCH 35/41] PLA-256 fix unit test --- .../__tests__/__snapshots__/index.ts.snap | 34 ++++++++++--------- src/backend-test/__tests__/index.ts | 2 -- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 532127e6..4835273a 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -7,7 +7,8 @@ HASURA_GRAPHQL_ADMIN_SECRET=111 UPLOAD_AVATAR_URL=https://api.worldcoin-distributors.com/user/upload-avatar BASE_URL=https://paysis.cyclic.app/ USERNAME=adminius -PASSWORD=supers3cret", +PASSWORD=supers3cret +", ".eslintrc.json": { "env": { "browser": true, @@ -413,10 +414,6 @@ tsconfig.dev.json "name": "typescript", "type": "build", }, - { - "name": "@apollo/client", - "type": "runtime", - }, { "name": "axios", "type": "runtime", @@ -754,15 +751,18 @@ tsconfig.dev.json ", "README.md": "# replace this", "api/auth/index.ts": "export * from './request' -export * from './response'", +export * from './response' +", "api/auth/request.ts": "export type AuthRequestBody = { - login: string | undefined - password: string | undefined - }", + login: string | undefined + password: string | undefined +} +", "api/auth/response.ts": "export type AuthResponseBody = { - token?: string - message?: string - }", + token?: string + message?: string +} +", "codegen.ts": "import {CodegenConfig} from '@graphql-codegen/cli' import * as dotenv from 'dotenv' @@ -884,8 +884,10 @@ export const client = axios.create({ baseURL: process.env.BASE_URL, timeout: 15000, validateStatus: () => true, -})", - "common/index.ts": "export * from './client'", +}) +", + "common/index.ts": "export * from './client' +", "cspell.json": { "allowCompoundWords": true, "dictionaries": [ @@ -960,7 +962,6 @@ export default config "package.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", "dependencies": { - "@apollo/client": "*", "axios": "*", "dotenv": "*", "eslint-config-prettier": "*", @@ -1053,7 +1054,8 @@ describe('Authorization & Authentication', () => { message: expect.any(String), }) }) -})", +}) +", "tsconfig.dev.json": { "compilerOptions": { "alwaysStrict": true, diff --git a/src/backend-test/__tests__/index.ts b/src/backend-test/__tests__/index.ts index dcc1854c..045eaea0 100644 --- a/src/backend-test/__tests__/index.ts +++ b/src/backend-test/__tests__/index.ts @@ -12,7 +12,6 @@ describe('Backend-test template', () => { test('enabled by default', () => { const project = new TestBackendTestProject() const snapshot = synthSnapshot(project) - expect(snapshot['package.json'].dependencies).toHaveProperty('@apollo/client') expect(snapshot['package.json'].dependencies).toHaveProperty('graphql') expect(snapshot['package.json'].scripts).toHaveProperty('gql-to-ts') expect(snapshot['codegen.ts']).toBeDefined() @@ -21,7 +20,6 @@ describe('Backend-test template', () => { test('disabled with an option', () => { const project = new TestBackendTestProject({isGraphqlEnabled: false}) const snapshot = synthSnapshot(project) - expect(snapshot['package.json'].dependencies).not.toHaveProperty('@apollo/client') expect(snapshot['package.json'].dependencies).not.toHaveProperty('graphql') expect(snapshot['package.json'].scripts).not.toHaveProperty('gql-to-ts') expect(snapshot['codegen.ts']).not.toBeDefined() From 9c5754ab4d00a06a5b6c279bf773a3563c636a42 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Tue, 2 Jan 2024 13:24:52 +0100 Subject: [PATCH 36/41] PLA-256 Update eslintPath --- src/backend-test/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index de3a3b7d..79155314 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -144,7 +144,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I // ANCHOR ESLint and prettier setup - const lintPaths = options.lintPaths ?? ['.projenrc.ts', 'src'] + const lintPaths = options.lintPaths ?? ['.projenrc.ts', '.'] addLinters({project: this, lintPaths, extraEslintConfigs: [eslintConfig]}) new AssetFile(this, '.prettierignore', { From 4264a41ac2dbddea4ab8e484d9925a858752ca02 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 17 Jan 2024 14:29:20 +0100 Subject: [PATCH 37/41] PLA-256 Remove tasks --- .../__tests__/__snapshots__/index.ts.snap | 18 ++++++--- src/backend-test/index.ts | 37 +------------------ 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index 4835273a..d73bbf1e 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -414,6 +414,10 @@ tsconfig.dev.json "name": "typescript", "type": "build", }, + { + "name": "@types/jest", + "type": "runtime", + }, { "name": "axios", "type": "runtime", @@ -497,13 +501,14 @@ tsconfig.dev.json ], }, "format": { + "description": "Perform code formatting and fixes of code-quality rules", "name": "format", "steps": [ { - "exec": "prettier --write ./", + "exec": "prettier --write .projenrc.ts .", }, { - "exec": "eslint --ext .ts ./ --fix", + "exec": "eslint --ext .js,.jsx,.ts,.tsx --ignore-pattern "!.projenrc.ts" .projenrc.ts . --fix", }, ], }, @@ -526,21 +531,23 @@ tsconfig.dev.json ], }, "lint": { + "description": "Check code formatting and code-quality rules", "name": "lint", "steps": [ { - "exec": "prettier --check ./", + "exec": "prettier --check .projenrc.ts .", }, { - "exec": "eslint --ext .ts ./", + "exec": "eslint --ext .js,.jsx,.ts,.tsx --ignore-pattern "!.projenrc.ts" .projenrc.ts .", }, ], }, "typecheck": { + "description": "Perform type checking on the source code", "name": "typecheck", "steps": [ { - "exec": "tsc", + "exec": "tsc --noEmit --project tsconfig.dev.json", }, ], }, @@ -962,6 +969,7 @@ export default config "package.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".", "dependencies": { + "@types/jest": "*", "axios": "*", "dotenv": "*", "eslint-config-prettier": "*", diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 79155314..6696da63 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -99,6 +99,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I 'prettier', 'eslint-plugin-prettier', 'eslint-config-prettier', + '@types/jest' ], }) @@ -153,42 +154,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I marker: false, }) - this.removeTask('format') - - this.tasks.addTask('format', { - steps: [ - { - exec: 'prettier --write ./', - }, - { - exec: 'eslint --ext .ts ./ --fix', - }, - ], - }) - - this.removeTask('lint') - - this.tasks.addTask('lint', { - steps: [ - { - exec: 'prettier --check ./', - }, - { - exec: 'eslint --ext .ts ./', - }, - ], - }) - - this.removeTask('typecheck') - - this.tasks.addTask('typecheck', { - steps: [ - { - exec: 'tsc', - }, - ], - }) - //ANCHOR - Set up AWS DynamoDb Client const isAWSDynamoDBEnabled = options.isAWSDynamoDBEnabled ?? true From 7c530ef8a79ddc063c96fd0da57da47485c5c83e Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 17 Jan 2024 14:32:55 +0100 Subject: [PATCH 38/41] PLA-256 Fix format issues --- src/backend-test/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 6696da63..62664afc 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -99,7 +99,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I 'prettier', 'eslint-plugin-prettier', 'eslint-config-prettier', - '@types/jest' + '@types/jest', ], }) From ca4de53658fed4fe1c37cfcaa30f66d97e172ac7 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Wed, 17 Jan 2024 14:50:18 +0100 Subject: [PATCH 39/41] PLA-256 Remove projenrc --- src/backend-test/__tests__/__snapshots__/index.ts.snap | 8 ++++---- src/backend-test/index.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend-test/__tests__/__snapshots__/index.ts.snap b/src/backend-test/__tests__/__snapshots__/index.ts.snap index d73bbf1e..b8b53043 100644 --- a/src/backend-test/__tests__/__snapshots__/index.ts.snap +++ b/src/backend-test/__tests__/__snapshots__/index.ts.snap @@ -505,10 +505,10 @@ tsconfig.dev.json "name": "format", "steps": [ { - "exec": "prettier --write .projenrc.ts .", + "exec": "prettier --write . .projenrc.ts", }, { - "exec": "eslint --ext .js,.jsx,.ts,.tsx --ignore-pattern "!.projenrc.ts" .projenrc.ts . --fix", + "exec": "eslint --ext .js,.jsx,.ts,.tsx --ignore-pattern "!.projenrc.ts" . .projenrc.ts --fix", }, ], }, @@ -535,10 +535,10 @@ tsconfig.dev.json "name": "lint", "steps": [ { - "exec": "prettier --check .projenrc.ts .", + "exec": "prettier --check . .projenrc.ts", }, { - "exec": "eslint --ext .js,.jsx,.ts,.tsx --ignore-pattern "!.projenrc.ts" .projenrc.ts .", + "exec": "eslint --ext .js,.jsx,.ts,.tsx --ignore-pattern "!.projenrc.ts" . .projenrc.ts", }, ], }, diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 62664afc..62e6597c 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -145,7 +145,7 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I // ANCHOR ESLint and prettier setup - const lintPaths = options.lintPaths ?? ['.projenrc.ts', '.'] + const lintPaths = options.lintPaths ?? ['.'] addLinters({project: this, lintPaths, extraEslintConfigs: [eslintConfig]}) new AssetFile(this, '.prettierignore', { From abb1f8cfdf24856d0cc2924240c13198740acc77 Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Mon, 29 Jan 2024 12:26:50 +0100 Subject: [PATCH 40/41] PLA-256 Remove empty line --- src/backend-test/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 62e6597c..7632067c 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -144,7 +144,6 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I }) // ANCHOR ESLint and prettier setup - const lintPaths = options.lintPaths ?? ['.'] addLinters({project: this, lintPaths, extraEslintConfigs: [eslintConfig]}) From 837a42b9ea701b7c4e4f4c384188660f3522f11d Mon Sep 17 00:00:00 2001 From: mishayouknowme Date: Mon, 29 Jan 2024 12:29:35 +0100 Subject: [PATCH 41/41] PLA-256 Add eslinignore file --- src/backend-test/assets/.eslintignore | 5 +++++ src/backend-test/index.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 src/backend-test/assets/.eslintignore diff --git a/src/backend-test/assets/.eslintignore b/src/backend-test/assets/.eslintignore new file mode 100644 index 00000000..d1a58144 --- /dev/null +++ b/src/backend-test/assets/.eslintignore @@ -0,0 +1,5 @@ +test-results/**/* +generated/index.ts +schema.graphql +*.generated.ts +*.generated.tsx diff --git a/src/backend-test/index.ts b/src/backend-test/index.ts index 7632067c..a2fa83ef 100644 --- a/src/backend-test/index.ts +++ b/src/backend-test/index.ts @@ -153,6 +153,12 @@ export class OttofellerBackendTestProject extends TypeScriptProject implements I marker: false, }) + new AssetFile(this, '.eslintignore', { + sourcePath: path.join(assetsDir, '.eslintignore'), + readonly: false, + marker: false, + }) + //ANCHOR - Set up AWS DynamoDb Client const isAWSDynamoDBEnabled = options.isAWSDynamoDBEnabled ?? true