Skip to content

Commit

Permalink
chore: fix typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed May 9, 2024
1 parent 0c50f4c commit a5be4b7
Show file tree
Hide file tree
Showing 100 changed files with 2,254 additions and 85 deletions.
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
"console": "integratedTerminal",
"stopOnEntry": false,
"autoAttachChildProcesses": true,
//"internalConsoleOptions": "openOnSessionStart",

"runtimeVersion": "21.7.0",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "backend:start"],
"presentation": { "group": "1" }
//"runtimeArgs": ["--loader", "ts-node/esm", "--experimental-specifier-resolution=node"]
},
{
"name": "🖼️ Launch Frontend",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"shared:build": "npm run build --prefix packages/shared",
"backend:start": "npm run start --prefix packages/backend",
"backend:build": "npm run build --prefix packages/backend",
"backend:dev": "npm run dev --prefix packages/backend",
"frontend:dev": "npm run dev --prefix packages/frontend",
"frontend:start": "npm run start --prefix packages/frontend",
"frontend:build": "npm run build --prefix packages/frontend",
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts", "src/**/*.test.ts"],
"exec": "bash scripts/start.sh"
}
7 changes: 2 additions & 5 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
"version": "0.0.1",
"description": "",
"main": "dist/main.js",
"types": "dist/index.js",
"type": "module",
"scripts": {
"test:watch": "jest --watchAll",
"test": "vitest",
"build": "rm -rf dist && npm run compile:ts",
"build": "rm -rf dist && tsc && tsc-alias",
"start": "export PACKAGE_JSON_VERSION=$(grep -o '\"version\": *\"[^\"]*\"' package.json | awk -F'\"' '{print $4}') && node --no-warnings --loader ts-node/esm --experimental-specifier-resolution=node ./dist/main.js",
"compile:ts": "tsc && npm run tsc-alias",
"tsc-alias": "tsc-alias -p tsconfig.json"
"dev": "nodemon"
},
"keywords": [],
"author": "Bruno Tot",
Expand Down
20 changes: 20 additions & 0 deletions packages/backend/scripts/shared/colors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

CLR_PREFIX="\033["
CLR_SUFFIX="m"

CYAN="0;34"
GREEN="1;32"
GREY="1;30"
RED="1;31"

RESET="0"

color() {
if [ "$PROD_ENV" == "true" ]; then
echo ""
else
local colorCode="${1:-$RESET}"
echo "$CLR_PREFIX$colorCode$CLR_SUFFIX"
fi
}
44 changes: 44 additions & 0 deletions packages/backend/scripts/shared/spinner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

SPINNER_PID=
SPINNER_MSG_LEFT=
SPINNER_MSG_RIGHT=
INITIAL_SPINNER_STATE=""
EMPTY=""

LOADER_SEQUENCE_1=("" "" "" "")
LOADER_SEQUENCE_2=("" "" "" "" "" "" "" "")
LOADER_SEQUENCE_3=("𓃉𓃉𓃉" "𓃉𓃉∘" "𓃉∘°" "∘°∘" "°∘𓃉" "∘𓃉𓃉")
LOADER_SEQUENCE_4=("/" "-" "\\" "|")

LOADER_SEQUENCE=("${LOADER_SEQUENCE_2[@]}")

spinner() {
local delay=0.1
local idx=0

while true; do
echo -ne "\r$1${LOADER_SEQUENCE[$idx]}$2"
idx=$(( (idx + 1) % ${#LOADER_SEQUENCE[@]} ))
sleep $delay
done
}

start() {
SPINNER_MSG_LEFT="${1:-$EMPTY}"
SPINNER_MSG_RIGHT="${2:-$EMPTY}"
if [ "$PROD_ENV" == "true" ]; then
echo -e "$SPINNER_MSG_LEFT${LOADER_SEQUENCE[0]}$SPINNER_MSG_RIGHT"
else
echo ""
spinner "$SPINNER_MSG_LEFT" "$SPINNER_MSG_RIGHT" & SPINNER_PID=$!
fi
}

stop() {
if [ "$PROD_ENV" != "true" ]; then
FINISH_REPLACER="${1:-$INITIAL_SPINNER_STATE}"
kill $SPINNER_PID
echo -ne "\r$SPINNER_MSG_LEFT$FINISH_REPLACER$SPINNER_MSG_RIGHT"
fi
}
37 changes: 37 additions & 0 deletions packages/backend/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

PWD_THIS=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${PWD_THIS}/shared/spinner.sh"
source "${PWD_THIS}/shared/colors.sh"

PWD_BACKEND="$PWD_THIS/.."

APP="$1"
VERSION="$2"

export PACKAGE_JSON_VERSION=$(grep -o '\"version\": *\"[^\"]*\"' package.json | awk -F'\"' '{print $4}')

rm -rf dist

start "" " $(color $CYAN)1.$(color) Compiling shared package"
cd "${PWD_BACKEND}/../shared" && rm -rf dist && npx tsc
stop "$(color $GREEN)$(color)"

start "" " $(color $CYAN)2.$(color) Compiling backend package"
cd "${PWD_BACKEND}" && rm -rf dist && npx tsc
stop "$(color $GREEN)$(color)"

start "" " $(color $CYAN)3.$(color) Converting path aliases to relative paths"
npx tsc-alias -p "${PWD_BACKEND}/tsconfig.json"
stop "$(color $GREEN)$(color)"

echo -e "\n$(color $GREEN)$(color $CYAN)3.$(color) Starting...\n"
node --no-warnings --loader ts-node/esm --experimental-specifier-resolution=node "${PWD_BACKEND}/dist/main.js"

#
#
#
#export PACKAGE_JSON_VERSION=$(grep -o '\"version\": *\"[^\"]*\"' package.json | awk -F'\"' '{print $4}')
#node --no-warnings --loader ts-node/esm --experimental-specifier-resolution=node ./dist/main.js

echo -e "\n"
2 changes: 2 additions & 0 deletions packages/backend/src/__tests__/product.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//import supertest from "supertest";

describe("product", () => {
beforeAll(async () => {});

/*beforeAll(async () => {
const mongoServer = await MongoMemoryServer.create();
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/config/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ process.on("uncaughtException", err => {
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
process.exit(1);
});
});
2 changes: 2 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export * from "@org/backend/config";
export * from "@org/backend/decorators";
export * from "@org/backend/infrastructure";
export * from "@org/backend/types";

// HELLO
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export class UserController {
};
}

return {
status: 403,
body: new ErrorResponse(req.originalUrl, 403, "User not found").content,
};

return {
status: 200,
body: users[0],
Expand Down
22 changes: 22 additions & 0 deletions packages/backend/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//import { MongoMemoryServer } from "mongodb-memory-server";

// This will hold the instance of MongoMemoryServer
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let mongoServer: any = null;

export async function setup() {
//mongoServer = await MongoMemoryServer.create();
//const uri = mongoServer.getUri();
//await mongoose.connect(uri);
}

export async function teardown() {
//if (mongoose.connection.readyState !== 0) {
// await mongoose.disconnect();
//}
//if (mongoServer) {
// await mongoServer.stop();
//}
}

export default { setup, teardown };
29 changes: 16 additions & 13 deletions packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
{
"extends": "../../tsconfig.json",
"ts-node": {
"transpileOnly": true,
"files": true,
// Tell ts-node CLI to install the --loader automatically, explained below
"esm": true,
"compilerOptions": {
"module": "ESNext"
},
"require": ["tsconfig-paths/register"]
},
"compilerOptions": {
"skipLibCheck": true,
"outDir": "./dist",
"types": ["jest", "node", "@types/jest"],
"esModuleInterop": true,
"moduleResolution": "Node",

"baseUrl": ".",
"baseUrl": "./src",
"paths": {
"@org/backend/config": ["./src/config/index"],
"@org/backend/config/*": ["./src/config/*"],
"@org/backend/decorators": ["./src/decorators/index"],
"@org/backend/decorators/*": ["./src/decorators/*"],
"@org/backend/types": ["./src/types/index"],
"@org/backend/types/*": ["./src/types/*"],
"@org/backend/infrastructure": ["./src/infrastructure/index"],
"@org/backend/infrastructure/*": ["./src/infrastructure/*"]
"@org/backend/*": ["*"],
"@org/shared": ["../../shared/dist/index"],
"*": ["../node_modules/*"]
}
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
},
"include": ["src/**/*"],
"exclude": ["src/logs"]
}
2 changes: 2 additions & 0 deletions packages/backend/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export default defineConfig({
plugins: [tsconfigPaths()],
test: {
globals: true,
//globalSetup: "./test-setup.ts", // Path to your setup file
//globalTeardown: "./test-setup.ts", // Path to your teardown file
},
});
1 change: 0 additions & 1 deletion packages/frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
"name": "@org/shared",
"version": "0.0.1",
"description": "",
"main": "dist/index",
"types": "dist/index",
"main": "dist/index.js",
"type": "module",
"scripts": {
"build": "pnpm run clean && pnpm run compile",
"clean": "rimraf ./dist",
"compile": "tsc -p tsconfig.build.json",
"compile": "tsc",
"prepublishOnly": "pnpm run build",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/config/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {};
import "./setup";
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions packages/shared/src/config/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/shared/src/config/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/shared/src/config/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/shared/src/config/setup/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions packages/shared/src/config/setup/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/shared/src/config/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/shared/src/config/setup/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions packages/shared/src/models/domain/ErrorLog.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import z from "zod";
export declare const ErrorLog: z.ZodObject<
{
_id: z.ZodType<String, z.ZodTypeDef, String>;
details: z.ZodString;
status: z.ZodNumber;
message: z.ZodString;
path: z.ZodString;
timestamp: z.ZodString;
metadata: z.ZodRecord<z.ZodString, z.ZodAny>;
},
"strip",
z.ZodTypeAny,
{
path: string;
message: string;
status: number;
_id: String;
details: string;
timestamp: string;
metadata: Record<string, any>;
},
{
path: string;
message: string;
status: number;
_id: String;
details: string;
timestamp: string;
metadata: Record<string, any>;
}
>;
export type ErrorLog = z.infer<typeof ErrorLog>;
//# sourceMappingURL=ErrorLog.d.ts.map
1 change: 1 addition & 0 deletions packages/shared/src/models/domain/ErrorLog.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions packages/shared/src/models/domain/ErrorLog.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/shared/src/models/domain/ErrorLog.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a5be4b7

Please sign in to comment.