Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated types for logs #24

Merged
merged 10 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@

## [1.1.0](https://github.com/ubiquity/ubiquibot-logger/compare/v1.0.0...v1.1.0) (2024-07-02)


### Features

* export pretty-logs ([bb9e691](https://github.com/ubiquity/ubiquibot-logger/commit/bb9e691f85b7b52cd339d82e4f98fe409a801a7b))
* logging NPM module initial port from ubiquibot refactor/general ([1ffe3d0](https://github.com/ubiquity/ubiquibot-logger/commit/1ffe3d00060e77b9eee3a0258d8baba2e5991e77))


### Bug Fixes

* updated target branch for release-please.yml ([dcbdcea](https://github.com/ubiquity/ubiquibot-logger/commit/dcbdcea5a4e71de7072023c2caef432c7b984115))

## 1.0.0 (2024-07-02)


### Features

* export pretty-logs ([bb9e691](https://github.com/ubiquity/ubiquibot-logger/commit/bb9e691f85b7b52cd339d82e4f98fe409a801a7b))
Expand Down
43 changes: 7 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,18 @@
"description": "Ubiquity logging module with Supabase support.",
"author": "Ubiquity DAO",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"tsup": {
"entry": [
"src/logs.ts",
"src/pretty-logs.ts"
],
"splitting": false,
"sourcemap": true,
"clean": true,
"dts": true,
"format": [
"cjs",
"esm"
]
},
"files": [
"dist/*"
],
"main": "./dist/logs.js",
"typesVersions": {
"*": {
".": [
"./dist/logs.d.ts"
],
"pretty-logs": [
"./dist/pretty-logs.d.ts"
]
}
},
"exports": {
".": {
"types": "./dist/logs.d.ts",
"require": "./dist/logs.cjs",
"import": "./dist/logs.js"
},
"./pretty-logs": {
"types": "./dist/pretty-logs.d.ts",
"require": "./dist/pretty-logs.cjs",
"import": "./dist/pretty-logs.js"
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"files": [
"dist/*"
],
"scripts": {
"build": "tsup",
"prepare": "husky install",
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Logs } from "./logs";
import { PrettyLogs } from "./pretty-logs";
import { LogReturn, Metadata, LogLevel, LogLevelWithOk, Colors } from "./types/log-types";
import { cleanLogString, cleanSpyLogs } from "./utils";
import { LOG_LEVEL, COLORS } from "./constants";

export type { LogReturn, Metadata, LogLevel, LogLevelWithOk, Colors };
export { Logs, PrettyLogs, cleanLogString, cleanSpyLogs, LOG_LEVEL, COLORS };
10 changes: 5 additions & 5 deletions src/pretty-logs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LOG_LEVEL, COLORS } from "./constants";
import { Metadata, PrettyLogsWithOk, Colors } from "./types/log-types";
import { Metadata, LogLevelWithOk, Colors } from "./types/log-types";

export class PrettyLogs {
constructor() {
Expand Down Expand Up @@ -34,7 +34,7 @@ export class PrettyLogs {
this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata);
}

private _logWithStack(type: PrettyLogsWithOk, message: string, metaData?: Metadata | string | unknown) {
private _logWithStack(type: LogLevelWithOk, message: string, metaData?: Metadata | string | unknown) {
this._log(type, message);
if (typeof metaData === "string") {
this._log(type, metaData);
Expand Down Expand Up @@ -95,8 +95,8 @@ export class PrettyLogs {
return !Reflect.ownKeys(obj).some((key) => typeof obj[String(key)] !== "function");
}

private _log(type: PrettyLogsWithOk, message: string | Record<string, unknown>) {
const defaultSymbols: Record<PrettyLogsWithOk, string> = {
private _log(type: LogLevelWithOk, message: string | Record<string, unknown>) {
const defaultSymbols: Record<LogLevelWithOk, string> = {
fatal: "×",
ok: "✓",
error: "⚠",
Expand All @@ -121,7 +121,7 @@ export class PrettyLogs {

const fullLogString = logString;

const colorMap: Record<PrettyLogsWithOk, [keyof typeof console, Colors]> = {
const colorMap: Record<LogLevelWithOk, [keyof typeof console, Colors]> = {
fatal: ["error", COLORS.fgRed],
ok: ["log", COLORS.fgGreen],
error: ["warn", COLORS.fgYellow],
Expand Down
6 changes: 3 additions & 3 deletions src/types/log-types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { COLORS, LOG_LEVEL } from "../constants";

type LogMessage = { raw: string; diff: string; level: LogLevel; type: PrettyLogsWithOk };
type LogMessage = { raw: string; diff: string; level: LogLevel; type: LogLevelWithOk };
type LogFunction = (message: string, metadata?: Metadata) => void;

export type Colors = (typeof COLORS)[keyof typeof COLORS];
export type LogLevel = (typeof LOG_LEVEL)[keyof typeof LOG_LEVEL];
export type PrettyLogsWithOk = "ok" | LogLevel;
export type LogLevelWithOk = "ok" | LogLevel;

export type LogParams = {
consoleLog: LogFunction;
logMessage: string;
level: LogLevel;
type: PrettyLogsWithOk;
type: LogLevelWithOk;
metadata?: Metadata;
};

Expand Down
12 changes: 12 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/index.ts"],
splitting: false,
sourcemap: false,
clean: true,
dts: true,
target: "esnext",
outDir: "dist",
format: ["cjs", "esm"],
});
Loading