Skip to content

Commit df7c224

Browse files
rishabh3112evenstensberg
authored andcommitted
feat(log): make log package
1 parent 11b3bff commit df7c224

4 files changed

Lines changed: 100 additions & 107 deletions

File tree

‎bin/log.js‎

Lines changed: 0 additions & 107 deletions
This file was deleted.

‎packages/log/index.ts‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
importchalkfrom"chalk";
2+
3+
constlog=(message: string)=>process.stdout.write(message);
4+
constlogError=(message: string)=>process.stderr.write(message);
5+
6+
exportclassLogger{
7+
publicname: string;
8+
9+
constructor(input: {name?: string,start?: boolean}|string){
10+
if(input){
11+
if(typeofinput==="string"){
12+
this.name=input;
13+
}else{
14+
if(!input.name||input.name===""){
15+
thrownewError("Name of the task was not passed");
16+
}
17+
this.name=input.name;
18+
if(input.start){
19+
this.start();
20+
}
21+
}
22+
}else{
23+
thrownewError("Name of the task was not passed");
24+
}
25+
}
26+
27+
publiclog(message: string){
28+
message=this.build(message);
29+
message=` ${chalk.bold("•")}${message}`;
30+
log(message);
31+
}
32+
33+
publicsuccess(message: string){
34+
message=this.build(message);
35+
message=chalk.green(` ${chalk.bold("\u2713")}${message}`);
36+
log(message);
37+
}
38+
39+
publicerror(message: string){
40+
message=this.build(message);
41+
message=chalk.red(` ${chalk.bold("\u2717")}${message}`);
42+
logError(message);
43+
}
44+
45+
publicwarn(message: string){
46+
message=this.build(message);
47+
message=chalk.yellowBright(` ${chalk.bold("⚠")}${message}`);
48+
log(message);
49+
}
50+
51+
publicinfo(message: string){
52+
message=this.build(message);
53+
message=chalk.cyan(` ${chalk.bold("i")}${message}`);
54+
log(message);
55+
}
56+
57+
publicclrscr(){
58+
log("\x1Bc");
59+
this.start();
60+
}
61+
62+
publiccustom(symbol: string,message: string){
63+
if(symbol.length!==1){
64+
thrownewError("Only single character can be passed to custom");
65+
}else{
66+
message=this.build(message);
67+
message=` ${chalk.bold(symbol)}${message}`;
68+
log(message);
69+
}
70+
}
71+
72+
privatebuild(message: string): string{
73+
constlines=message.split("\n");
74+
if(lines.length===1){
75+
returnlines[0];
76+
}
77+
message=lines[0]+"\n";
78+
79+
for(leti=1;i<lines.length;i++){
80+
message+=` ${lines[i]}\n`;
81+
}
82+
returnmessage;
83+
}
84+
85+
privatestart(){
86+
constmessage: string=`${chalk.bold(this.name)} - ${chalk.cyan("webpack-cli")}`+"\n";
87+
log(message);
88+
}
89+
}

‎packages/log/package.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@webpack-cli/log",
3+
"version": "0.0.1",
4+
"description": "custom task based logger",
5+
"main": "index.js",
6+
"author": "",
7+
"license": "MIT"
8+
}

‎packages/log/tsconfig.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../tsconfig.packages.json"
3+
}

0 commit comments

Comments
 (0)