mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { IContext, IRollupContext, VerbosityLevel } from "./context";
|
|
import * as _ from "lodash";
|
|
|
|
export class RollupContext implements IContext
|
|
{
|
|
private hasContext: boolean = true;
|
|
|
|
constructor(private verbosity: VerbosityLevel, private bail: boolean, private context: IRollupContext, private prefix: string = "")
|
|
{
|
|
this.hasContext = _.isFunction(this.context.warn) && _.isFunction(this.context.error);
|
|
}
|
|
|
|
public warn(message: string): void
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Warning)
|
|
return;
|
|
|
|
if (this.hasContext)
|
|
this.context.warn(`${message}`);
|
|
else
|
|
console.log(`${this.prefix}${message}`);
|
|
}
|
|
|
|
public error(message: string): void
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Error)
|
|
return;
|
|
|
|
if (this.hasContext)
|
|
{
|
|
if (this.bail)
|
|
this.context.error(`${message}`);
|
|
else
|
|
this.context.warn(`${message}`);
|
|
}
|
|
else
|
|
console.log(`${this.prefix}${message}`);
|
|
}
|
|
|
|
public info(message: string): void
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Info)
|
|
return;
|
|
console.log(`${this.prefix}${message}`);
|
|
}
|
|
|
|
public debug(message: string): void
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Debug)
|
|
return;
|
|
console.log(`${this.prefix}${message}`);
|
|
}
|
|
}
|