initial commit

This commit is contained in:
Timofey Gelazoniya 2023-11-01 20:47:10 +03:00
commit a7e3f110a0
Signed by: zeldon
GPG Key ID: 047886915281DD2A
8 changed files with 1671 additions and 0 deletions

2
.env.example Normal file
View File

@ -0,0 +1,2 @@
NODE_ENV=development
LOG_LEVEL=trace

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
dist
.env

4
index.ts Normal file
View File

@ -0,0 +1,4 @@
import { logger } from "#root/logger.js";
logger.info("Hello!");
logger.debug("I am a teapot");

1584
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

25
package.json Normal file
View File

@ -0,0 +1,25 @@
{
"main": "dist/index.js",
"type": "module",
"imports": {
"#root/*": "./dist/src/*"
},
"scripts": {
"dev": "npm run clean && tsc-watch --onSuccess \"tsx index.ts\"",
"build": "npm run clean && tsc --noEmit false",
"clean": "rimraf dist"
},
"devDependencies": {
"@types/node": "^20.8.10",
"rimraf": "^5.0.5",
"tsc-watch": "^6.0.4",
"tsx": "^3.14.0",
"typescript": "^5.2.2"
},
"dependencies": {
"dotenv": "^16.3.1",
"envalid": "^7.3.1",
"pino": "^8.16.1",
"pino-pretty": "^10.2.3"
}
}

9
src/env.ts Normal file
View File

@ -0,0 +1,9 @@
import 'dotenv/config';
import { cleanEnv, str } from 'envalid';
export const env = cleanEnv(process.env, {
NODE_ENV: str({ choices: ["development", "production"] }),
LOG_LEVEL: str({
choices: ["trace", "debug", "info", "warn", "error", "fatal", "silent"],
}),
});

20
src/logger.ts Normal file
View File

@ -0,0 +1,20 @@
import { env } from "#root/env.js";
import { LoggerOptions, pino } from "pino";
import PinoPretty, { PrettyOptions } from "pino-pretty";
const options: LoggerOptions = {
level: env.LOG_LEVEL
};
const prettyOptions: PrettyOptions = {
ignore: 'pid,hostname',
colorize: env.isDev ? true : false,
translateTime: 'SYS:dd.mm.yyyy, HH:MM:ss'
};
export let logger = pino(options);
if (env.isDev) {
// @ts-ignore
logger = pino(options, PinoPretty(prettyOptions));
}

24
tsconfig.json Normal file
View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true,
"preserveWatchOutput": true,
"noEmit": true,
"module": "NodeNext",
"target": "ES2021",
"moduleResolution": "NodeNext",
"sourceMap": true,
"outDir": "dist",
"rootDir": ".",
"paths": {
"#root/*": [
"./src/*"
]
}
},
"include": [
"src/**/*",
"index.ts"
]
}