|
| 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 | +} |
0 commit comments