diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..83b6947 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +CHANGELOG.md \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 31d99d3..87dc265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/package.json b/package.json index 56ee81a..4775657 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..4a3b845 --- /dev/null +++ b/src/index.ts @@ -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 }; diff --git a/src/pretty-logs.ts b/src/pretty-logs.ts index 2f0bcd5..fd89618 100644 --- a/src/pretty-logs.ts +++ b/src/pretty-logs.ts @@ -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() { @@ -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); @@ -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) { - const defaultSymbols: Record = { + private _log(type: LogLevelWithOk, message: string | Record) { + const defaultSymbols: Record = { fatal: "×", ok: "✓", error: "⚠", @@ -121,7 +121,7 @@ export class PrettyLogs { const fullLogString = logString; - const colorMap: Record = { + const colorMap: Record = { fatal: ["error", COLORS.fgRed], ok: ["log", COLORS.fgGreen], error: ["warn", COLORS.fgYellow], diff --git a/src/types/log-types.ts b/src/types/log-types.ts index 50ca812..6f25618 100644 --- a/src/types/log-types.ts +++ b/src/types/log-types.ts @@ -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; }; diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 0000000..a942512 --- /dev/null +++ b/tsup.config.ts @@ -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"], +});