Skip to content

Commit

Permalink
Merge pull request #23 from ubq-testing/development
Browse files Browse the repository at this point in the history
feat: updated exports for the logger
  • Loading branch information
gentlementlegen authored Jul 9, 2024
2 parents 47188b8 + b09e049 commit d18f3c8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 44 deletions.
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 @@ -2,20 +2,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
40 changes: 7 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +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"],
});

0 comments on commit d18f3c8

Please sign in to comment.