-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38bac8d
commit cf85208
Showing
2 changed files
with
82 additions
and
53 deletions.
There are no files selected for viewing
95 changes: 42 additions & 53 deletions
95
ThePhasesOfCraftship/2_best_practice_first/deployment/assignment/end/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,52 @@ | ||
{ | ||
"name": "dddforum", | ||
"name": "@dddforum/backend", | ||
"version": "1.0.0", | ||
"description": "", | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"engines": { | ||
"node": ">=16.16.0" | ||
}, | ||
"description": "The backend for dddforum", | ||
"main": "index.js", | ||
"scripts": { | ||
"test:e2e:frontend": "npm run test:e2e --workspace=@dddforum/frontend", | ||
"test:e2e:backend": "npm run test:e2e --workspace=@dddforum/backend", | ||
"test:infra:all": "npm run test:infra --workspaces --if-present", | ||
"test:infra:backend": "npm run test:infra --workspace=@dddforum/backend", | ||
"test:unit:backend": "npm run test:unit --workspace=@dddforum/backend", | ||
"test:unit": "npm run test:unit --workspaces --if-present", | ||
"test:staging": "npm run test:staging --workspace=@dddforum/backend", | ||
"clean": "npm run clean --workspaces --if-present", | ||
"build": "npm run build --workspaces --if-present", | ||
"build:ci:backend": "npm run build --workspace @dddforum/shared && npm run build --workspace @dddforum/backend", | ||
"build:ci:frontend": "npm run build --workspace @dddforum/shared && npm run build --workspace @dddforum/frontend", | ||
"start:dev:backend": "npm run start:dev --workspace=@dddforum/backend", | ||
"start:dev:frontend": "npm run start:dev --workspace=@dddforum/frontend", | ||
"start:ci:backend": "npm run generate:database && npm run migrate:deploy && npm run start:ci --workspace @dddforum/backend", | ||
"generate:database": "npm run generate --workspace=@dddforum/backend", | ||
"migrate:deploy": "npm run migrate:deploy --workspace=@dddforum/backend", | ||
"lint": "npm run lint --workspaces --if-present", | ||
"prettier-format": "run-script-os", | ||
"prettier-format:win32": "prettier --config .prettierrc \"./**/src/**/*.ts\" --write", | ||
"prettier-format:darwin:linux": "prettier --config .prettierrc './**/src/**/*.ts' --write", | ||
"prettier-format:default": "prettier --config .prettierrc './**/src/**/*.ts' --write", | ||
"prettier-watch": "run-script-os", | ||
"prettier-watch:win32": "onchange \"src/**/*.ts\" -- prettier --write {{changed}}", | ||
"prettier-watch:darwin:linux": "onchange 'src/**/*.ts' -- prettier --write {{changed}}", | ||
"prettier-watch:default": "onchange 'src/**/*.ts' -- prettier --write {{changed}}" | ||
"clean": "rimraf ./dist", | ||
"build": "npm run clean && tsc -b tsconfig.build.json && tsc-alias -p tsconfig.build.json -r ../../tsAliasReplacer.js", | ||
"generate": "ts-node prepareEnv.ts prisma generate --schema=./src/shared/database/prisma/schema.prisma", | ||
"migrate": "ts-node prepareEnv.ts prisma migrate dev --schema=./src/shared/database/prisma/schema.prisma", | ||
"db:reset": "ts-node prepareEnv.ts prisma migrate reset --preview-feature --schema src/shared/database/prisma/schema.prisma && npm run migrate && npm run generate", | ||
"start:dev": "ts-node -r tsconfig-paths/register prepareDevCli.ts .env.development && dotenv -e .env.development -- nodemon", | ||
"start:dev:no-watch": "npm run generate && npm run migrate && ts-node prepareEnv.ts ts-node src/index.ts", | ||
"start:ci": "node dist/index.js", | ||
"migrate:deploy": "npx prisma migrate deploy --schema src/shared/database/prisma/schema.prisma", | ||
"lint": "eslint . --ext .ts --fix", | ||
"test": "jest", | ||
"test:dev": "jest --watchAll", | ||
"test:e2e": "jest -c jest.config.e2e.ts", | ||
"test:e2e:dev": "jest -c jest.config.e2e.ts --watch", | ||
"test:infra": "jest -c jest.config.infra.ts", | ||
"test:infra:dev": "jest -c jest.config.infra.ts --watch", | ||
"test:unit": "jest -c jest.config.unit.ts", | ||
"test:unit:dev": "jest -c jest.config.unit.ts --watchAll", | ||
"test:staging": "npm run generate && npm run migrate && npm run test:e2e" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^18.16.19", | ||
"@typescript-eslint/eslint-plugin": "^6.13.0", | ||
"envalid": "^8.0.0", | ||
"eslint": "^8.53.0", | ||
"eslint-plugin-jest": "^27.6.0", | ||
"eslint-plugin-prettier": "^5.0.1", | ||
"jest": "^29.5.0", | ||
"jest-cucumber": "3.0.1", | ||
"jest-mock-extended": "^3.0.7", | ||
"rimraf": "^3.0.2", | ||
"run-script-os": "^1.1.6", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"tsc-alias": "^1.8.8", | ||
"typescript": "^5.3.2" | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run test && npm run prettier-format && npm run lint" | ||
} | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/cors": "^2.8.17", | ||
"@types/express": "^4.17.17", | ||
"@types/nodemailer": "^6.4.15", | ||
"@types/supertest": "^6.0.2", | ||
"dotenv": "^16.3.1", | ||
"dotenv-cli": "^7.3.0", | ||
"nodemon": "^2.0.19", | ||
"supertest": "^7.0.0" | ||
}, | ||
"dependencies": { | ||
"nodemailer": "^6.9.13", | ||
"tsconfig-paths": "^4.2.0" | ||
"@dddforum/shared": "file:../shared", | ||
"@prisma/client": "^4.16.0", | ||
"cors": "^2.8.5", | ||
"express": "^4.18.2", | ||
"prisma": "^4.16.0" | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
ThePhasesOfCraftship/2_best_practice_first/deployment/assignment/end/prepareEnv.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
/** | ||
* This script allows you to call any other following script with | ||
* `ts-node prepareEnv <whatever you want to call next>` and if your app | ||
* is running in development mode (not no NODE_ENV set at all, assumed), it | ||
* will load the env file before you call the script. This loads the environment | ||
* up properly. | ||
* | ||
* We currently need this for prisma commands to allow prisma to take the config from | ||
* .env.development in development mode, and from the secrets in the deployment tools in | ||
* production. | ||
*/ | ||
|
||
import { execSync } from 'child_process'; | ||
import * as path from 'path'; | ||
|
||
export const prepareEnv = (): void => { | ||
const env = process.env.NODE_ENV || 'development'; | ||
console.log(env) | ||
const packageRoot = path.resolve(__dirname); | ||
const execParams = { | ||
cwd: packageRoot, | ||
stdio: 'inherit', | ||
} as const; | ||
|
||
const script = process.argv.splice(2).join(' '); | ||
|
||
if (env === 'development') { | ||
const devEnvFile = '.env.development' | ||
console.log(`Preparing dev environment using ${devEnvFile}`); | ||
execSync(`dotenv -e ${devEnvFile} -- ${script}`, execParams); | ||
return; | ||
} | ||
|
||
console.log(`Running ${script} in ${process.env.NODE_ENV} mode without loading from env file.`); | ||
execSync(`${script}`, execParams); | ||
|
||
}; | ||
|
||
prepareEnv(); |