Vendor Cordis framework packages as source
cordis 4.0.0-rc.6, plugin-loader, -include, -group, -timer, -hmr, -logger-console, cosmokit 1.8.1, schemastery 3.18.0 — copied from the cordis-workspace checkout, flattened under vendor/, original npm names, private: true. vendor/README.md is the manifest: upstream repos + commit SHAs, local-modification log, sync procedure. Local modification: hmr's locale YAML imports and .i18n() call removed (avoids a runtime YAML import hook we don't vendor).
This commit is contained in:
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-present Shigma
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
# @cordisjs/plugin-logger-console
|
||||
|
||||
Console exporter for the built-in Cordis logger service.
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { Context } from 'cordis'
|
||||
import ConsoleLogger from '@cordisjs/plugin-logger-console'
|
||||
|
||||
const root = new Context()
|
||||
await root.plugin(ConsoleLogger, {
|
||||
showDiff: true,
|
||||
levels: {
|
||||
default: 2,
|
||||
hmr: 3,
|
||||
},
|
||||
})
|
||||
|
||||
root.logger('app').info('started')
|
||||
```
|
||||
|
||||
## Config
|
||||
|
||||
| Field | Description |
|
||||
| --- | --- |
|
||||
| `colors` | Color support level, or `false` to disable colors. |
|
||||
| `maxLength` | Maximum rendered line length before truncation. |
|
||||
| `levels` | Per-logger minimum level map. |
|
||||
| `showDiff` | Show elapsed time since the previous message. |
|
||||
| `showTime` | Timestamp template. |
|
||||
| `label` | Label width, margin, and alignment options. |
|
||||
|
||||
The Node entry uses `node:util.inspect` for `%o` and `%O`; the browser entry
|
||||
passes log arguments through to `console`.
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@cordisjs/plugin-logger-console",
|
||||
"description": "Console logger exporter for cordis",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/shared.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/shared.d.ts",
|
||||
"node": "./lib/index.js",
|
||||
"default": "./lib/browser.js"
|
||||
},
|
||||
"./src/*": "./src/*",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"src"
|
||||
],
|
||||
"author": "Shigma <shigma10826@gmail.com>",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"cordis": "^4.0.0-rc.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"cosmokit": "^1.8.1",
|
||||
"schemastery": "^3.18.0",
|
||||
"supports-color": "^9.4.0"
|
||||
}
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import { Message } from 'cordis'
|
||||
import { ConsoleExporter as Base } from './shared.js'
|
||||
|
||||
/** Re-export shared console exporter config and base implementation. */
|
||||
export * from './shared.js'
|
||||
|
||||
/** Browser console exporter that dispatches to native console methods. */
|
||||
export class ConsoleExporter extends Base {
|
||||
export(message: Message) {
|
||||
const prefix = `[${message.type[0].toUpperCase()}] ${message.name}`
|
||||
const method = message.type === 'error' ? 'error' : message.type === 'warn' ? 'warn' : 'log'
|
||||
// eslint-disable-next-line no-console
|
||||
console[method](prefix, ...message.args)
|
||||
}
|
||||
}
|
||||
|
||||
export default ConsoleExporter
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
import { Formatter } from 'cordis'
|
||||
import { inspect } from 'node:util'
|
||||
import supportsColor from 'supports-color'
|
||||
import { ConsoleExporter as Base } from './shared.js'
|
||||
|
||||
/** Re-export shared console exporter config and base implementation. */
|
||||
export * from './shared.js'
|
||||
|
||||
const inspectFormatter: Formatter = (value, target) => {
|
||||
return inspect(value, { colors: !!target.colors, depth: Infinity, compact: true, breakLength: Infinity })
|
||||
}
|
||||
|
||||
/** Node console exporter with `util.inspect` object formatting. */
|
||||
export class ConsoleExporter extends Base {
|
||||
formatters: Record<string, Formatter> = {
|
||||
o: inspectFormatter,
|
||||
O: inspectFormatter,
|
||||
}
|
||||
|
||||
getDefaults() {
|
||||
return {
|
||||
...super.getDefaults(),
|
||||
colors: (supportsColor.stdout ? supportsColor.stdout.level : 0) as false | 0 | 1 | 2 | 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ConsoleExporter
|
||||
Vendored
+100
@@ -0,0 +1,100 @@
|
||||
import { Context, Exporter, Formatter, Logger, Message } from 'cordis'
|
||||
import { Time } from 'cosmokit'
|
||||
import z from 'schemastery'
|
||||
|
||||
/** Terminal color support level compatible with supports-color. */
|
||||
export type ColorSupportLevel = 0 | 1 | 2 | 3
|
||||
|
||||
/** Formatting options for the logger name label. */
|
||||
export interface LabelStyle {
|
||||
width?: number
|
||||
margin?: number
|
||||
align?: 'left' | 'right'
|
||||
}
|
||||
|
||||
/** Config namespace for console logger exporters. */
|
||||
export namespace ConsoleExporter {
|
||||
export interface Config {
|
||||
colors?: false | ColorSupportLevel
|
||||
maxLength?: number
|
||||
levels?: Record<string, number>
|
||||
showDiff?: boolean
|
||||
showTime?: string
|
||||
label?: LabelStyle
|
||||
}
|
||||
}
|
||||
|
||||
/** Shared console log exporter implementation used by Node and browser builds. */
|
||||
export class ConsoleExporter implements Exporter {
|
||||
static readonly name = 'logger-console'
|
||||
|
||||
static readonly Config: z<ConsoleExporter.Config> = z.object({
|
||||
colors: z.union([z.const(false), z.number()]),
|
||||
maxLength: z.number(),
|
||||
levels: z.dict(z.number()),
|
||||
showDiff: z.boolean().default(false),
|
||||
showTime: z.string().default('yyyy-MM-dd hh:mm:ss '),
|
||||
label: z.object({
|
||||
width: z.number(),
|
||||
margin: z.number(),
|
||||
align: z.union(['left', 'right']),
|
||||
}),
|
||||
}) as z<ConsoleExporter.Config>
|
||||
|
||||
colors!: false | ColorSupportLevel
|
||||
maxLength?: number
|
||||
levels?: Record<string, number>
|
||||
showDiff!: boolean
|
||||
showTime!: string
|
||||
label?: LabelStyle
|
||||
timestamp: number
|
||||
|
||||
formatters: Record<string, Formatter> = {}
|
||||
|
||||
constructor(public ctx: Context, config: ConsoleExporter.Config = {}) {
|
||||
Object.assign(this, this.getDefaults(), config)
|
||||
this.timestamp = Date.now()
|
||||
ctx.logger.exporter(this)
|
||||
}
|
||||
|
||||
getDefaults() {
|
||||
return {
|
||||
colors: false as false | ColorSupportLevel,
|
||||
showTime: 'yyyy-MM-dd hh:mm:ss ',
|
||||
showDiff: false,
|
||||
}
|
||||
}
|
||||
|
||||
export(message: Message) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(this.render(message))
|
||||
}
|
||||
|
||||
render(message: Message) {
|
||||
const prefix = `[${message.type[0].toUpperCase()}]`
|
||||
const space = ' '.repeat(this.label?.margin ?? 1)
|
||||
let indent = 3 + space.length, output = ''
|
||||
if (this.showTime) {
|
||||
indent += this.showTime.length
|
||||
output += Logger.color(this, 8, Time.template(this.showTime))
|
||||
}
|
||||
const code = Logger.code(message.name, this.colors)
|
||||
const label = Logger.color(this, code, message.name, ';1')
|
||||
const padLength = (this.label?.width ?? 0) + label.length - message.name.length
|
||||
if (this.label?.align === 'right') {
|
||||
output += label.padStart(padLength) + space + prefix + space
|
||||
indent += (this.label.width ?? 0) + space.length
|
||||
} else {
|
||||
output += prefix + space + label.padEnd(padLength) + space
|
||||
}
|
||||
output += Logger.format(this, message).replace(/\n/g, '\n' + ' '.repeat(indent))
|
||||
if (this.showDiff && this.timestamp) {
|
||||
const diff = message.ts - this.timestamp
|
||||
output += Logger.color(this, code, ' +' + Time.format(diff))
|
||||
}
|
||||
this.timestamp = message.ts
|
||||
return output
|
||||
}
|
||||
}
|
||||
|
||||
export default ConsoleExporter
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{ "path": "../cosmokit" },
|
||||
{ "path": "../cordis" },
|
||||
{ "path": "../schemastery" }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user