-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update project configuration and implement base service class f…
…or logging and configuration management
- Loading branch information
Showing
17 changed files
with
1,821 additions
and
103 deletions.
There are no files selected for viewing
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,4 +1,5 @@ | ||
node_modules/ | ||
node_modules | ||
logs/ | ||
dist/ | ||
config.toml | ||
|
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,3 +1,3 @@ | ||
nodejs 18.16.0 | ||
pnpm 6.24.4 | ||
pnpm 9.15.2 | ||
python 3.12.0 |
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,8 @@ | ||
import type { Logger } from 'winston'; | ||
import { config } from '@core/config'; | ||
import { logger } from '@core/logger'; | ||
|
||
export class ServiceBase { | ||
public log: Logger = logger; | ||
public config = config; | ||
} |
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
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,46 @@ | ||
import { z } from 'zod' | ||
|
||
if (!Bun.file('../config.toml').exists()) { | ||
throw new Error('Please create config.toml') | ||
} | ||
|
||
export const config = await z.object({ | ||
oauth: z.object({ | ||
consumerToken: z.string(), | ||
consumerSecret: z.string(), | ||
accessToken: z.string(), | ||
accessSecret: z.string(), | ||
}), | ||
bot: z.object({ | ||
apiUrl: z.string(), | ||
username: z.string(), | ||
contact: z.string(), | ||
timezone: z.string(), | ||
}), | ||
toolforge: z.object({ | ||
login: z.string(), | ||
tooluser: z.string(), | ||
deploykey: z.string(), | ||
}), | ||
replica: z.object({ | ||
username: z.string(), | ||
password: z.string(), | ||
dbname: z.string(), | ||
cluster: z.string(), | ||
port: z.number(), | ||
}), | ||
scripts: z.object({ | ||
archive: z.object({ | ||
key_salt: z.string().optional(), | ||
}), | ||
}), | ||
logger: z.object({ | ||
logPath: z.string(), | ||
level: z.string().default("info"), | ||
}), | ||
discord: z.object({ | ||
logger: z.object({ | ||
webhook: z.string().optional(), | ||
}), | ||
}), | ||
}).parseAsync(await import('../config.toml')) |
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,36 @@ | ||
import { createLogger, transports, format } from 'winston'; | ||
import { config } from '@core/config'; | ||
import chalk from 'chalk'; | ||
|
||
export const logger = createLogger({ | ||
level: config.logger.level, | ||
format: format.combine( | ||
format.timestamp(), | ||
format.errors({ | ||
stack: true, | ||
}), | ||
format.splat(), | ||
format.json(), | ||
), | ||
transports: [ | ||
new transports.File({ | ||
filename: `${config.logger.logPath}/output.log`, | ||
maxsize: 5242880, // 5MB | ||
}), | ||
new transports.File({ filename: 'error.log', level: 'error' }), | ||
new transports.Console({ | ||
format: format.combine( | ||
format.colorize(), | ||
format.printf(({ level, message, timestamp, durationMs }) => { | ||
return `${chalk.dim(`[${timestamp}]`)} ${level}: ${message}${durationMs ? ` ${chalk.dim(`(${durationMs}ms)`)}` : ''}`; | ||
}) | ||
) | ||
}), | ||
], | ||
exceptionHandlers: [ | ||
new transports.File({ filename: `${config.logger.logPath}/exceptions.log` }) | ||
], | ||
rejectionHandlers: [ | ||
new transports.File({ filename: 'rejections.log' }) | ||
] | ||
}); |
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
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
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 |
---|---|---|
|
@@ -15,24 +15,25 @@ | |
"dependencies": { | ||
"@commander-js/extra-typings": "^13.0.0", | ||
"@paralleldrive/cuid2": "^2.2.2", | ||
"bun": "^1.1.42", | ||
"chalk": "^5.4.1", | ||
"commander": "^13.0.0", | ||
"cors": "^2.8.5", | ||
"croner": "^9.0.0", | ||
"cronstrue": "^2.52.0", | ||
"moment": "^2.30.1", | ||
"mwn": "^2.0.4", | ||
"mysql2": "^3.12.0", | ||
"winston": "^3.17.0" | ||
"winston": "^3.17.0", | ||
"zod": "^3.24.1" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "^1.1.14", | ||
"@types/cors": "^2.8.17", | ||
"@types/cron": "^2.4.3", | ||
"@types/express": "^5.0.0", | ||
"@types/js-yaml": "^4.0.9", | ||
"@types/node": "^22.10.3", | ||
"@types/ssh2": "^1.15.1", | ||
"bun": "^1.1.42", | ||
"husky": "^9.1.7", | ||
"lint-staged": "^15.3.0", | ||
"prettier": "3.4.2", | ||
|
@@ -59,9 +60,10 @@ | |
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"format": "prettier --write . --ignore-unknown", | ||
"start": "bun core/web.ts", | ||
"build": "sh ./build.sh", | ||
"build": "bun i", | ||
"start": "bun ./core/web.ts", | ||
"prepare": "husky" | ||
}, | ||
"type": "module" | ||
"type": "module", | ||
"packageManager": "[email protected]" | ||
} |
Oops, something went wrong.