-
-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11b3bff
commit df7c224
Showing
4 changed files
with
100 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import chalk from "chalk"; | ||
|
||
const log = (message: string) => process.stdout.write(message); | ||
const logError = (message: string) => process.stderr.write(message); | ||
|
||
export class Logger { | ||
public name: string; | ||
|
||
constructor(input: { name?: string, start?: boolean} | string) { | ||
if (input) { | ||
if (typeof input === "string") { | ||
this.name = input; | ||
} else { | ||
if (!input.name || input.name === "") { | ||
throw new Error("Name of the task was not passed"); | ||
} | ||
this.name = input.name; | ||
if (input.start) { | ||
this.start(); | ||
} | ||
} | ||
} else { | ||
throw new Error("Name of the task was not passed"); | ||
} | ||
} | ||
|
||
public log(message: string) { | ||
message = this.build(message); | ||
message = ` ${chalk.bold("•")} ${message}`; | ||
log(message); | ||
} | ||
|
||
public success(message: string) { | ||
message = this.build(message); | ||
message = chalk.green(` ${chalk.bold("\u2713")} ${message}`); | ||
log(message); | ||
} | ||
|
||
public error(message: string) { | ||
message = this.build(message); | ||
message = chalk.red(` ${chalk.bold("\u2717")} ${message}`); | ||
logError(message); | ||
} | ||
|
||
public warn(message: string) { | ||
message = this.build(message); | ||
message = chalk.yellowBright(` ${chalk.bold("⚠")} ${message}`); | ||
log(message); | ||
} | ||
|
||
public info(message: string) { | ||
message = this.build(message); | ||
message = chalk.cyan(` ${chalk.bold("i")} ${message}`); | ||
log(message); | ||
} | ||
|
||
public clrscr() { | ||
log("\x1Bc"); | ||
this.start(); | ||
} | ||
|
||
public custom(symbol: string, message: string) { | ||
if (symbol.length !== 1) { | ||
throw new Error("Only single character can be passed to custom"); | ||
} else { | ||
message = this.build(message); | ||
message = ` ${chalk.bold(symbol)} ${message}`; | ||
log(message); | ||
} | ||
} | ||
|
||
private build(message: string): string { | ||
const lines = message.split("\n"); | ||
if (lines.length === 1) { | ||
return lines[0]; | ||
} | ||
message = lines[0] + "\n"; | ||
|
||
for (let i = 1; i < lines.length; i++) { | ||
message += ` ${lines[i]}\n`; | ||
} | ||
return message; | ||
} | ||
|
||
private start() { | ||
const message: string = `${ chalk.bold(this.name) } - ${chalk.cyan("webpack-cli")}` + "\n"; | ||
log(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@webpack-cli/log", | ||
"version": "0.0.1", | ||
"description": "custom task based logger", | ||
"main": "index.js", | ||
"author": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.packages.json" | ||
} |