Scaffold TypeScript project and add core logger

This commit is contained in:
2026-08-12 20:50:40 +02:00
parent abfbc1e2da
commit a9a8fa7c3f
9 changed files with 3116 additions and 0 deletions

9
.eslintrc.cjs Normal file
View File

@@ -0,0 +1,9 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
env: { node: true, es2022: true },
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
ignorePatterns: ['dist', 'node_modules'],
};

4
.gitignore vendored
View File

@@ -37,3 +37,7 @@ _testmain.go
.zed
deploy.config
node_modules/
dist/
coverage/

6
.prettierrc.json Normal file
View File

@@ -0,0 +1,6 @@
{
"singleQuote": true,
"semi": true,
"printWidth": 100,
"trailingComma": "es5"
}

36
package.json Normal file
View File

@@ -0,0 +1,36 @@
{
"name": "sugarr",
"version": "0.1.0",
"private": true,
"main": "dist/app/index.js",
"scripts": {
"dev": "tsx watch src/app/index.ts",
"build": "tsc -p tsconfig.json",
"start": "node dist/app/index.js",
"test": "vitest run",
"test:watch": "vitest",
"lint": "eslint src test --ext .ts",
"format": "prettier --write ."
},
"dependencies": {
"dotenv": "^16.4.5",
"fastify": "^5.0.0",
"langfuse": "^3.30.0",
"node-cron": "^3.0.3",
"openai": "^4.60.0",
"pino": "^9.4.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^22.7.4",
"@types/node-cron": "^3.0.11",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"eslint": "^8.57.0",
"pino-pretty": "^11.2.2",
"prettier": "^3.3.3",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
}
}

3013
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
import pino from 'pino';
export type Logger = pino.Logger;
export function createLogger(name: string): Logger {
const isProduction = process.env.NODE_ENV === 'production';
return pino({
name,
level: process.env.LOG_LEVEL ?? 'info',
transport: isProduction ? undefined : { target: 'pino-pretty' },
});
}

View File

@@ -0,0 +1,11 @@
import { describe, expect, it } from 'vitest';
import { createLogger } from '../../../src/core/logging/logger';
describe('createLogger', () => {
it('creates a pino logger with the given name bound', () => {
const logger = createLogger('test-logger');
expect(logger.bindings().name).toBe('test-logger');
expect(typeof logger.info).toBe('function');
expect(typeof logger.error).toBe('function');
});
});

17
tsconfig.json Normal file
View File

@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "Node",
"lib": ["ES2022"],
"outDir": "dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": false,
"sourceMap": true
},
"include": ["src"]
}

8
vitest.config.ts Normal file
View File

@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
include: ['test/**/*.test.ts'],
},
});