mirror of
https://github.com/Wessel/pikmin.git
synced 2026-07-27 18:51:15 +02:00
Still gotta fix typings, temporary fix
This commit is contained in:
67
index.d.ts
vendored
67
index.d.ts
vendored
@@ -1,66 +1,39 @@
|
|||||||
import { WriteStream } from "fs";
|
import { WriteStream } from "fs";
|
||||||
|
|
||||||
declare namespace Pikmin
|
declare namespace Pikmin {
|
||||||
{
|
export const loggers: Pikmin.Collection<Pikmin.instance>;
|
||||||
export const loggers: Pikmin.Collection<Pikmin.instance>;
|
export const version: string;
|
||||||
export const version: string;
|
export const colors: Pikmin.Colors;
|
||||||
export const colors: Pikmin.Colors;
|
|
||||||
|
|
||||||
export function bind(i: Pikmin.instance, a?: Console, b?: any): void;
|
export function bind(i: Pikmin.instance, a?: Console, b?: any): void;
|
||||||
export function unbind(i: Pikmin.instance): void;
|
export function unbind(i: Pikmin.instance): void;
|
||||||
|
|
||||||
export class instance {
|
export class instance {
|
||||||
constructor(options?: Pikmin.InstanceOptions);
|
constructor(options?: Pikmin.InstanceOptions);
|
||||||
|
|
||||||
public log: {
|
|
||||||
[x: string]: any;
|
|
||||||
|
|
||||||
__bound__: Console;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The name of the instance */
|
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
/** The base format */
|
|
||||||
public baseFormat: string;
|
public baseFormat: string;
|
||||||
|
|
||||||
/** An array of transports */
|
|
||||||
public transports: Pikmin.Transport[];
|
public transports: Pikmin.Transport[];
|
||||||
|
|
||||||
/**
|
public [x: string]: function(msg, ...args): void;
|
||||||
* Adds a transport
|
|
||||||
* @param transport The transport to add
|
|
||||||
* @param options Any options to bind
|
|
||||||
*/
|
|
||||||
public addTransport(transport: Pikmin.Transport, options?: { autogen: boolean }): void;
|
public addTransport(transport: Pikmin.Transport, options?: { autogen: boolean }): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Collection<T> extends Map<string | number, T>
|
export class Collection<T> extends Map<string | number, T> {
|
||||||
{
|
public filter(i: (a: T) => boolean): T[];
|
||||||
public filter(i: (a: T) => boolean): T[];
|
public map(i: (a: T) => any): T[];
|
||||||
public map(i: (a: T) => any): T[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class ConsoleTransport implements Transport {
|
||||||
* The console transport that logs anything to the terminal
|
|
||||||
*/
|
|
||||||
export class ConsoleTransport implements Transport
|
|
||||||
{
|
|
||||||
constructor(options: Pikmin.InstanceOptions & { process: NodeJS.Process });
|
constructor(options: Pikmin.InstanceOptions & { process: NodeJS.Process });
|
||||||
|
|
||||||
/** The type of the transport, implemented by the Transport interface */
|
|
||||||
public type: 'CONSOLE' | 'WEBHOOK' | 'FILE';
|
public type: 'CONSOLE' | 'WEBHOOK' | 'FILE';
|
||||||
|
|
||||||
/** The name of the transport, implemented by the Transport interface */
|
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
/** The parent of the transport, implemented by the Transport interface; resolves by `undefined` */
|
|
||||||
public parent: any | undefined;
|
public parent: any | undefined;
|
||||||
|
|
||||||
/** The defaults of the transport, implemented by the Transport interface */
|
public defaults: {
|
||||||
public defaults: { inspect: boolean }
|
inspect: boolean
|
||||||
|
}
|
||||||
|
|
||||||
/** The NodeJS.Process tty, only to use Stdout#write */
|
|
||||||
public process: NodeJS.Process;
|
public process: NodeJS.Process;
|
||||||
append(options: { inspect: boolean }, data: string): void;
|
append(options: { inspect: boolean }, data: string): void;
|
||||||
destroy(): this;
|
destroy(): this;
|
||||||
@@ -70,19 +43,11 @@ declare namespace Pikmin
|
|||||||
{
|
{
|
||||||
constructor(options: { file: string, flags?: '-a', format: string });
|
constructor(options: { file: string, flags?: '-a', format: string });
|
||||||
|
|
||||||
/** The type of the transport, implemented by the Transport interface */
|
|
||||||
public type: 'CONSOLE' | 'WEBHOOK' | 'FILE';
|
public type: 'CONSOLE' | 'WEBHOOK' | 'FILE';
|
||||||
|
|
||||||
/** The name of the transport, implemented by the Transport interface */
|
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
/** The parent of the transport, implemented by the Transport interface; resolves by `undefined` */
|
|
||||||
public parent: any | undefined;
|
public parent: any | undefined;
|
||||||
|
|
||||||
/** The defaults of the transport, implemented by the Transport interface */
|
|
||||||
public defaults: { inspect: boolean }
|
public defaults: { inspect: boolean }
|
||||||
|
|
||||||
/** The write stream */
|
|
||||||
public stream: WriteStream;
|
public stream: WriteStream;
|
||||||
append(options: { inspect: boolean }, data: string): void;
|
append(options: { inspect: boolean }, data: string): void;
|
||||||
destroy(): this;
|
destroy(): this;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const PikminError = require('./PikminError');
|
|||||||
module.exports = class PikminInstance {
|
module.exports = class PikminInstance {
|
||||||
/**
|
/**
|
||||||
* Create a pikmin instance
|
* Create a pikmin instance
|
||||||
*
|
*
|
||||||
* @param {object} options The options for the instance
|
* @param {object} options The options for the instance
|
||||||
* @param {string} [options.name='main'] The logger's name
|
* @param {string} [options.name='main'] The logger's name
|
||||||
* @param {string} [options.format='[%h:%m:%s] %l ->'] The logger's format
|
* @param {string} [options.format='[%h:%m:%s] %l ->'] The logger's format
|
||||||
@@ -42,7 +42,7 @@ module.exports = class PikminInstance {
|
|||||||
if (transport.name) {
|
if (transport.name) {
|
||||||
this[transport.name] = (msg, options) => this._print(msg, Object.assign(transport.defaults, options), transport.name, transport.format || this.baseFormat);
|
this[transport.name] = (msg, options) => this._print(msg, Object.assign(transport.defaults, options), transport.name, transport.format || this.baseFormat);
|
||||||
this.__log__[transport.name] = (msg, options) => this._print(msg, Object.assign(transport.defaults, options), transport.name, transport.format || this.baseFormat);
|
this.__log__[transport.name] = (msg, options) => this._print(msg, Object.assign(transport.defaults, options), transport.name, transport.format || this.baseFormat);
|
||||||
} else transport.permanent = true;
|
} else transport.permanent = true;
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
throw new PikminError(`Failed to write to transporter:\r\n${ex}`);
|
throw new PikminError(`Failed to write to transporter:\r\n${ex}`);
|
||||||
}
|
}
|
||||||
@@ -59,19 +59,19 @@ module.exports = class PikminInstance {
|
|||||||
|
|
||||||
if (type(transport) !== 2) throw new TypeError(`"transports" must be type of object but received type ${typeof transport}`);
|
if (type(transport) !== 2) throw new TypeError(`"transports" must be type of object but received type ${typeof transport}`);
|
||||||
if (transport.name && this[transport.name]) throw new PikminError(`A transporter\'s name inflicted with an already existing declaration`);
|
if (transport.name && this[transport.name]) throw new PikminError(`A transporter\'s name inflicted with an already existing declaration`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (transport.type === 'FILE' && options.autogen) transport.append(`<PIKMIN_AUTOGEN_LINE<${now.days}/${now.months}/${now.years} ${now.hours}:${now.minutes}:${now.seconds}>>\r\n`);
|
if (transport.type === 'FILE' && options.autogen) transport.append(`<PIKMIN_AUTOGEN_LINE<${now.days}/${now.months}/${now.years} ${now.hours}:${now.minutes}:${now.seconds}>>\r\n`);
|
||||||
|
|
||||||
this.transports.push(transport);
|
this.transports.push(transport);
|
||||||
if (transport.name) {
|
if (transport.name) {
|
||||||
this[transport.name] = (msg, opt) => this._print(msg, Object.assign(transport.defaults, opt), transport.name, transport.format || this.baseFormat,);
|
this[transport.name] = (msg, opt) => this._print(msg, Object.assign(transport.defaults, opt), transport.name, transport.format || this.baseFormat,);
|
||||||
this.__log__[transport.name] = (msg, opt) => this._print(msg, Object.assign(transport.defaults, opt), transport.name, transport.format || this.baseFormat);
|
this.__log__[transport.name] = (msg, opt) => this._print(msg, Object.assign(transport.defaults, opt), transport.name, transport.format || this.baseFormat);
|
||||||
} else transport.permanent = true;
|
} else transport.permanent = true;
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
throw new PikminError(`Failed to write to transporter:\r\n${ex}`);
|
throw new PikminError(`Failed to write to transporter:\r\n${ex}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pikmin.loggers.set(this.name, this.__log__);
|
Pikmin.loggers.set(this.name, this.__log__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user