@buildplease/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,99 @@
1
+ import { Bindings, Level, Logger } from "pino";
2
+ import { PrettyOptions } from "pino-pretty";
3
+ //#region src-node/console/console-options.d.ts
4
+ interface ConsoleOptions {
5
+ readonly enabled?: boolean;
6
+ }
7
+ //#endregion
8
+ //#region src-node/console/console.d.ts
9
+ interface ConsolePanelRow {
10
+ readonly label: string;
11
+ readonly value: string | number;
12
+ }
13
+ declare class Console {
14
+ private readonly instance;
15
+ constructor(options?: ConsoleOptions);
16
+ title(product: string, command: string, rows?: readonly ConsolePanelRow[]): void;
17
+ panel(title: string, rows: readonly ConsolePanelRow[], badge?: string | number): void;
18
+ step(label: string, message: string): string;
19
+ duration(ms: number): string;
20
+ emptyLine(): void;
21
+ log(message?: unknown, ...args: unknown[]): void;
22
+ info(message?: unknown, ...args: unknown[]): void;
23
+ start(message?: unknown, ...args: unknown[]): void;
24
+ success(message?: unknown, ...args: unknown[]): void;
25
+ warn(message?: unknown, ...args: unknown[]): void;
26
+ error(message?: unknown, ...args: unknown[]): void;
27
+ debug(message?: unknown, ...args: unknown[]): void;
28
+ private printPanel;
29
+ private formatPanel;
30
+ private formatPanelTop;
31
+ private formatPanelBottom;
32
+ private formatPanelRow;
33
+ private getPanelWidth;
34
+ private getTitleWidth;
35
+ private getRowsWidth;
36
+ private getRowWidth;
37
+ private visibleLength;
38
+ }
39
+ //#endregion
40
+ //#region src-node-test/console.d.ts
41
+ declare function makeConsoleFixture(): Console;
42
+ //#endregion
43
+ //#region src-node/logger/log-flag.d.ts
44
+ declare enum LogFlag {
45
+ Critical = "CRITICAL",
46
+ Serious = "SERIOUS",
47
+ Important = "IMPORTANT",
48
+ Notice = "NOTICE",
49
+ Routine = "ROUTINE"
50
+ }
51
+ //#endregion
52
+ //#region src-node/logger/log-options.d.ts
53
+ interface LogOptions {
54
+ readonly flag?: LogFlag;
55
+ readonly details?: unknown;
56
+ readonly error?: unknown;
57
+ readonly metadata?: unknown;
58
+ }
59
+ //#endregion
60
+ //#region src-node/logger/logger-options.d.ts
61
+ interface BaseLoggerTransportOptions {
62
+ readonly level?: Level;
63
+ }
64
+ interface LoggerConsoleTransportOptions extends BaseLoggerTransportOptions {
65
+ readonly type: 'console';
66
+ readonly target: 'pino-pretty';
67
+ readonly pretty?: PrettyOptions;
68
+ }
69
+ interface LoggerFileTransportOptions extends BaseLoggerTransportOptions {
70
+ readonly type: 'file';
71
+ readonly path: string;
72
+ }
73
+ type LoggerTransportOptions = LoggerConsoleTransportOptions | LoggerFileTransportOptions;
74
+ type LoggerOptions = {
75
+ readonly enabled: false;
76
+ readonly debug?: boolean;
77
+ readonly transports?: never;
78
+ } | {
79
+ readonly enabled: true;
80
+ readonly debug?: boolean;
81
+ readonly transports: readonly [LoggerTransportOptions, ...LoggerTransportOptions[]];
82
+ };
83
+ //#endregion
84
+ //#region src-node/logger/logger.d.ts
85
+ interface Logger$1 {
86
+ readonly instance: Logger;
87
+ info(title: string, options?: LogOptions): void;
88
+ debug(title: string, options?: LogOptions): void;
89
+ trace(title: string, options?: LogOptions): void;
90
+ warn(title: string, options?: LogOptions): void;
91
+ error(title: string, options?: LogOptions): void;
92
+ fatal(title: string, options?: LogOptions): void;
93
+ child(bindings: Bindings): Logger;
94
+ }
95
+ //#endregion
96
+ //#region src-node-test/logger.d.ts
97
+ declare function makeLoggerFixture(options?: LoggerOptions): Logger$1;
98
+ //#endregion
99
+ export { makeConsoleFixture, makeLoggerFixture };
@@ -0,0 +1,2 @@
1
+ import{createConsola as e}from"consola";import{colors as t}from"consola/utils";import n from"node:path";import r from"node:fs";import{fileURLToPath as i}from"node:url";import a from"pino";const o=/\u001B\[[0-9;]*m/g;var s=class{instance;constructor(t={}){this.instance=e({level:t.enabled===!1?-999:999,formatOptions:{colors:!0,date:!1}})}title(e,n,r=[]){this.printPanel({title:`${e} ${n}`.trim(),renderedTitle:`${t.cyan(t.bold(e))}${n?` ${t.dim(n)}`:``}`,rows:r,formatValue:t.green})}panel(e,n,r){this.printPanel({title:r===void 0?e:`${e} ${r}`,renderedTitle:`${t.cyan(t.bold(e))}${r===void 0?``:` ${t.green(String(r))}`}`,rows:n,formatValue:t.dim})}step(e,n){return`${t.cyan(e.padEnd(10,` `))}${n}`}duration(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(2)}s`}emptyLine(){this.instance.log(``)}log(e,...t){this.instance.log(e,...t)}info(e,...t){this.instance.info(e,...t)}start(e,...t){this.instance.start(e,...t)}success(e,...t){this.instance.success(e,...t)}warn(e,...t){this.instance.warn(e,...t)}error(e,...t){this.instance.error(e,...t)}debug(e,...t){this.instance.debug(e,...t)}printPanel(e){this.instance.log(this.formatPanel(e))}formatPanel(e){let t=this.getPanelWidth(e);return[this.formatPanelTop(e.renderedTitle,t),...e.rows.map(n=>this.formatPanelRow(n,t,e.formatValue)),this.formatPanelBottom(t)].join(`
2
+ `)}formatPanelTop(e,n){let r=Math.max(1,n-this.visibleLength(e)-5);return`${t.dim(`╭─`)} ${e} ${t.dim(`─`.repeat(r))}${t.dim(`╮`)}`}formatPanelBottom(e){return`${t.dim(`╰`)}${t.dim(`─`.repeat(e-2))}${t.dim(`╯`)}`}formatPanelRow(e,n,r){let i=e.label.padEnd(14,` `),a=String(e.value),o=this.visibleLength(i)+this.visibleLength(a)+4,s=Math.max(0,n-o);return`${t.dim(`│`)} ${t.blue(i)}${r(a)}${` `.repeat(s)} ${t.dim(`│`)}`}getPanelWidth(e){return Math.max(48,this.getTitleWidth(e),this.getRowsWidth(e.rows))}getTitleWidth(e){return this.visibleLength(e.title)+6}getRowsWidth(e){return Math.max(0,...e.map(e=>this.getRowWidth(e)))}getRowWidth(e){return 14+this.visibleLength(String(e.value))+4}visibleLength(e){return e.replace(o,``).length}};function c(){return new s({enabled:!1})}function l(e,t){if(n.isAbsolute(t))return n.normalize(t);let r;try{let t=new URL(e);if(t.protocol!==`file:`)throw Error(`Unsupported URL protocol "${t.protocol}"`);r=n.dirname(i(t))}catch{r=e}return n.resolve(r,t)}function u(e){let t=l(process.cwd(),e),i=r.existsSync(t)&&r.statSync(t).isDirectory()?t:n.dirname(t);if(!r.existsSync(i))throw Error(`Directory "${i}" does not exist.`);return t}function d(e){return e instanceof Error}function f(e,t={}){if(e==null)return{};let{filterNull:n=!0,filterUndefined:r=!0,filterEmptyString:i=!1,filterEmptyObject:a=!1,filterEmptyArray:o=!1}=t;return Object.keys(e).reduce((s,c)=>{let l=e[c];return p(l)&&Object.getPrototypeOf(l)===null&&(l=void 0),h(l)&&(l=f(l,t)),n&&l===null||r&&l===void 0||i&&l===``||a&&m(l)||o&&Array.isArray(l)&&l.length===0||(s[c]=l),s},{})}function p(e){return typeof e==`object`&&!!e}function m(e){return p(e)&&Object.keys(e).length===0}function h(e){return p(e)&&Object.getPrototypeOf(e)===Object.prototype}function g(e){return e==null||[`string`,`number`,`boolean`,`bigint`,`symbol`].includes(typeof e)}Array.prototype.isEmpty=function(){return this==null||this.length===0},String.prototype.capitalized=function(){let e=this==null?``:this.toString();return e.trim()?e.charAt(0).toUpperCase()+e.slice(1):``};const _={filterNull:!0,filterUndefined:!0,filterEmptyString:!0,filterEmptyArray:!0,filterEmptyObject:!0};var v=class{options;instance;constructor(e){this.options=e,this.instance=this.makeInstance()}info(e,t){this.log(`info`,e,t)}debug(e,t){this.log(`debug`,e,t)}trace(e,t){this.log(`trace`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}fatal(e,t){this.log(`fatal`,e,t)}child(e){return this.instance.child(e)}log(e,t,n){this.instance[e]({msg:t,...this.formatLogOptions(n)})}formatLogOptions(e){return e?f({flag:e.flag,details:this.formatUnknown(e.details),error:this.formatUnknown(e.error),metadata:this.formatUnknown(e.metadata)},_):{}}formatUnknown(e){if(d(e)){let t={type:e.constructor.name,message:e.message};this.options.debug&&e.stack&&(t.stack=e.stack);for(let n of Object.keys(e))n in t||(t[n]=e[n]);let n=f(t,_);return m(n)?void 0:n}if(Buffer.isBuffer(e))return`[Buffer]`;if(e&&typeof e.pipe==`function`)return`[Stream]`;if(p(e))try{let t=JSON.stringify(e);if(t===void 0)return;let n=JSON.parse(t);if(Array.isArray(n))return n.length>0?n:void 0;if(p(n)){let e=f(n,_);return m(e)?void 0:e}return n}catch{return{type:`NonSerializableObject`}}return g(e)?e:String(e)}makeInstance(){if(!this.options.enabled)return a({enabled:!1,timestamp:!0});let e=this.options.transports,t={level:this.makeGlobalLogLevel(e),enabled:!0,timestamp:!0,transport:{targets:this.makeTransportTargets(e)}};return a(t)}makeTransportTargets(e){if(e.filter(e=>e.type===`console`).length>1)throw Error(`[Logger] Multiple console transports are not supported.`);return e.map(e=>{switch(e.type){case`console`:return this.makeConsoleTransportTarget(e);case`file`:return this.makeFileTransportTarget(e)}})}makeConsoleTransportTarget(e){return{target:`pino-pretty`,level:this.makeTransportLevel(e.level),options:e.pretty}}makeFileTransportTarget(e){let t=this.makeTransportLevel(e.level),r=n.isAbsolute(e.path)?n.normalize(e.path):l(process.cwd(),e.path);return u(n.dirname(r)),{target:`pino/file`,level:t,options:{destination:r}}}makeTransportLevel(e){return this.options.debug?`trace`:e??`info`}makeGlobalLogLevel(e){if(this.options.debug)return`trace`;let t=e.at(0);if(!t)return`info`;let n={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},r=this.makeTransportLevel(t.level);for(let t of e.slice(1)){let e=this.makeTransportLevel(t.level);n[e]<n[r]&&(r=e)}return r}};function y(e={enabled:!1}){return new v(e)}export{c as makeConsoleFixture,y as makeLoggerFixture};
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@buildplease/core",
3
+ "version": "1.0.0",
4
+ "keywords": [],
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/BuildPlease/buildplease.git",
8
+ "directory": "packages/core"
9
+ },
10
+ "license": "MIT",
11
+ "author": "Simon Rastislav Kovačič",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "import": {
16
+ "types": "./dist/src/index.d.ts",
17
+ "default": "./dist/src/index.js"
18
+ },
19
+ "require": {
20
+ "types": "./dist/src/index.d.cts",
21
+ "default": "./dist/src/index.cjs"
22
+ }
23
+ },
24
+ "./node": {
25
+ "import": {
26
+ "types": "./dist/src-node/index.d.mts",
27
+ "default": "./dist/src-node/index.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./dist/src-node/index.d.cts",
31
+ "default": "./dist/src-node/index.cjs"
32
+ }
33
+ },
34
+ "./node/test": {
35
+ "import": {
36
+ "types": "./dist/src-node-test/index.d.mts",
37
+ "default": "./dist/src-node-test/index.mjs"
38
+ },
39
+ "require": {
40
+ "types": "./dist/src-node-test/index.d.cts",
41
+ "default": "./dist/src-node-test/index.cjs"
42
+ }
43
+ }
44
+ },
45
+ "files": [
46
+ "dist",
47
+ "resources"
48
+ ],
49
+ "dependencies": {
50
+ "async-mutex": "0.5.0",
51
+ "bcryptjs": "3.0.3",
52
+ "consola": "3.4.2",
53
+ "date-fns": "4.4.0",
54
+ "date-fns-tz": "3.2.0",
55
+ "ms": "2.1.3",
56
+ "pino": "10.3.1",
57
+ "pino-pretty": "13.1.3"
58
+ },
59
+ "devDependencies": {
60
+ "@types/ms": "2.1.0",
61
+ "@buildplease/identity": "1.0.0"
62
+ },
63
+ "peerDependencies": {
64
+ "inversify": "8.2.3",
65
+ "reflect-metadata": "0.2.2",
66
+ "zod": "4.4.3"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public",
70
+ "registry": "https://registry.npmjs.org/"
71
+ },
72
+ "scripts": {
73
+ "build": "tsdown --config-loader unrun",
74
+ "test": "vitest run",
75
+ "typecheck": "tsc -p tsconfig.json --noEmit"
76
+ }
77
+ }
@@ -0,0 +1 @@
1
+ export const Resources = {} as const;