Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 78594b9

Browse files
CzBuCHinchanged
authored andcommitted
fix(tslint): fixed all auto-fixable errors in Log.ts
1 parent c1ba79f commit 78594b9

File tree

1 file changed

+70
-69
lines changed

1 file changed

+70
-69
lines changed

src/Log.ts

Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ import * as log from "fliplog";
44
import * as prettysize from "prettysize";
55
import * as prettyTime from "pretty-time";
66
import * as zlib from "zlib";
7-
import { getDateTime } from './Utils';
7+
import { getDateTime } from "./Utils";
88

99
// @TODO: I've moved this into fliplog in v1, migrate to that
1010
export class Indenter {
11-
public store: Map<string, any> = new Map()
11+
public store: Map<string, any> = new Map();
1212
constructor() {
13-
this.set('indent', 0);
13+
this.set("indent", 0);
1414
}
1515

1616
// easy set/set
1717
public set(key: string, val: any): Indenter {
18-
this.store.set(key, val)
18+
this.store.set(key, val);
1919
return this;
2020
}
2121
public get(key: string) {
2222
return this.store.get(key);
2323
}
2424
// back to 0
2525
public reset(): Indenter {
26-
return this.set('indent', 0);
26+
return this.set("indent", 0);
2727
}
2828
// tap value
2929
public tap(key: string, cb: Function): Indenter {
@@ -32,22 +32,22 @@ export class Indenter {
3232
}
3333
// increment
3434
public indent(level: number): Indenter {
35-
return this.tap('indent', indent => indent + level);
35+
return this.tap("indent", indent => indent + level);
3636
}
3737
// specific number
3838
public level(level: number): Indenter {
39-
return this.set('indent', level);
39+
return this.set("indent", level);
4040
}
4141
// string repeat indent
4242
public toString(): string {
43-
return ' '.repeat(this.get('indent'))
43+
return " ".repeat(this.get("indent"));
4444
}
4545
public toNumber(): number {
46-
return this.get('indent');
46+
return this.get("indent");
4747
}
4848
public [Symbol.toPrimitive](hint: string) {
49-
if (hint === 'number') { return this.toNumber(); }
50-
return this.toString();;
49+
if (hint === "number") { return this.toNumber(); }
50+
return this.toString();
5151
}
5252
}
5353

@@ -58,46 +58,47 @@ export class Indenter {
5858
* - [ ] fix the →→→→→→→
5959
*/
6060
export class Log {
61+
public static defer(fn: Function) {
62+
Log.deferred.push(fn);
63+
}
64+
private static deferred: Function[] = [];
65+
6166
public timeStart = process.hrtime();
6267
public printLog: any = true;
6368
public debugMode: any = false;
6469
public spinner: any;
6570
public indent: Indenter = new Indenter();
6671
private totalSize = 0;
67-
private static deferred: Function[] = [];
68-
public static defer (fn: Function) {
69-
Log.deferred.push(fn)
70-
}
7172

7273
constructor(public context: WorkFlowContext) {
7374
this.printLog = context.doLog;
7475
this.debugMode = context.debugMode;
7576

76-
log.filter((arg) => {
77+
log.filter(arg => {
7778
// conditions for filtering specific tags
78-
const debug = this.debugMode
79-
const level = this.printLog
79+
const debug = this.debugMode;
80+
const level = this.printLog;
8081
const hasTag = tag =>
81-
arg.tags.includes(tag)
82+
arg.tags.includes(tag);
8283
const levelHas = tag =>
83-
debug || (level && level.includes && level.includes(tag) && !level.includes('!' + tag));
84+
debug || (level && level.includes && level.includes(tag) && !level.includes("!" + tag));
8485

8586

8687
// when off, silent
87-
if (level === false) return false;
88+
if (level === false) { return false; }
8889

8990
// counting this as verbose for now
9091
if (level === true && debug === true) { return null; }
9192

92-
if (level == 'error') {
93-
if (!hasTag('error')) { return false; }
93+
if (level === "error") {
94+
if (!hasTag("error")) { return false; }
9495
}
9596
// could be verbose, reasoning, etc
96-
if (hasTag('magic')) {
97-
if (!levelHas('magic')) { return false; }
97+
if (hasTag("magic")) {
98+
if (!levelHas("magic")) { return false; }
9899
}
99-
if (hasTag('filelist')) {
100-
if (!levelHas('filelist')) { return false; }
100+
if (hasTag("filelist")) {
101+
if (!levelHas("filelist")) { return false; }
101102
}
102103

103104
// if not false and conditions pass, log it
@@ -106,10 +107,10 @@ export class Log {
106107

107108
setTimeout(() => {
108109
if (this.printLog) {
109-
Log.deferred.forEach(x => x(this))
110+
Log.deferred.forEach(x => x(this));
110111
}
111-
Log.deferred = []
112-
})
112+
Log.deferred = [];
113+
});
113114
}
114115
// --- config ---
115116

@@ -120,21 +121,21 @@ export class Log {
120121
return this;
121122
}
122123
public printOptions(title: string, obj: any) {
123-
let indent = this.indent.level(2) + '';;
124+
const indent = this.indent.level(2) + "";
124125

125-
let indent2 = this.indent.level(4) + '';;
126+
const indent2 = this.indent.level(4) + "";
126127

127128
// @TODO: moved this into fliplog v1, migrate
128-
log.addPreset('min', instance => {
129+
log.addPreset("min", instance => {
129130
instance.formatter(data => {
130-
return log.inspector()(data).split('\n')
131-
.map(data => indent2 + data)
132-
.map(data => data.replace(/[{},]/, ''))
133-
.join('\n');;
131+
return log.inspector()(data).split("\n")
132+
.map(data2 => indent2 + data2)
133+
.map(data2 => data2.replace(/[{},]/, ""))
134+
.join("\n");
134135
});
135136
});
136137

137-
log.bold().yellow(`${indent}${title}\n`).preset('min').data(obj).echo();
138+
log.bold().yellow(`${indent}${title}\n`).preset("min").data(obj).echo();
138139

139140
// for (let i in obj) {
140141
// indent = this.indent.level(6) + ''
@@ -160,7 +161,7 @@ export class Log {
160161
return this;
161162
}
162163
public bundleEnd(name: string, collection: ModuleCollection) {
163-
let took = process.hrtime(this.timeStart) as [number, number];
164+
const took = process.hrtime(this.timeStart) as [number, number];
164165

165166
log
166167
.ansi()
@@ -178,20 +179,20 @@ export class Log {
178179
const indentStr = this.indent.toString();
179180
const indent = +this.indent;
180181
const interval = 20;
181-
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].map(frame => indentStr + frame);
182+
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"].map(frame => indentStr + frame);
182183
const spinner = { frames, interval };
183184

184185
// @TODO @FIXME the spinner needs to be scoped inside of fliplog, has todo to update
185186
// instantiate
186-
this.spinner = log.requirePkg('ora')({ text, indent, spinner });
187+
this.spinner = log.requirePkg("ora")({ text, indent, spinner });
187188
this.spinner.start();
188189
this.spinner.indent = +this.indent;
189190
this.spinner.succeeded = false;
190191

191192
// safety for if errors happen so it does not keep spinning
192193
setTimeout(() => {
193194
if (this.spinner.succeeded === false && this.spinner.fail) {
194-
this.spinner.fail();;
195+
this.spinner.fail();
195196
}
196197
}, 1000);
197198

@@ -221,9 +222,9 @@ export class Log {
221222

222223
// @TODO: list vendor files as filter
223224
public echoDefaultCollection(collection: ModuleCollection, contents: string) {
224-
if (this.printLog === false) return this;
225-
let bytes = Buffer.byteLength(contents, "utf8");
226-
let size = prettysize(bytes);
225+
if (this.printLog === false) { return this; }
226+
const bytes = Buffer.byteLength(contents, "utf8");
227+
const size = prettysize(bytes);
227228
this.totalSize += bytes;
228229

229230
const indent = this.indent.reset().indent(+1).toString();
@@ -233,11 +234,11 @@ export class Log {
233234
const dependencies = new Map(Array.from(collection.dependencies).sort());
234235
dependencies.forEach(file => {
235236
if (file.info.isRemoteFile) { return; }
236-
const indent = this.indent.level(4).toString()
237+
const indentItem = this.indent.level(4).toString();
237238
log
238239
// .tags('filelist')
239-
.white(`${indent}${file.info.fuseBoxPath}`)
240-
.echo()
240+
.white(`${indentItem}${file.info.fuseBoxPath}`)
241+
.echo();
241242
});
242243

243244
log
@@ -256,8 +257,8 @@ export class Log {
256257
// └── lodash 14.2 kB (12 files)
257258
public echoCollection(collection: ModuleCollection, contents: string) {
258259
if (this.printLog === false) { return this; }
259-
let bytes = Buffer.byteLength(contents, "utf8");
260-
let size = prettysize(bytes);
260+
const bytes = Buffer.byteLength(contents, "utf8");
261+
const size = prettysize(bytes);
261262
this.totalSize += bytes;
262263
const indent = this.indent.toString(); // reset
263264

@@ -275,7 +276,7 @@ export class Log {
275276
}
276277

277278
public end(header?: string) {
278-
let took = process.hrtime(this.timeStart) as [number, number];
279+
const took = process.hrtime(this.timeStart) as [number, number];
279280
this.echoBundleStats(header || "Bundle", this.totalSize, took);
280281
return this;
281282
}
@@ -286,18 +287,18 @@ export class Log {
286287
*
287288
* string | number | Buffer
288289
*/
289-
public echoGzip(size: any, msg: string | any = '') {
290-
if (!size) return this;
290+
public echoGzip(size: any, msg: string | any = "") {
291+
if (!size) { return this; }
291292
const yellow = log.chalk().yellow;
292293
const gzipped = zlib.gzipSync(size, { level: 9 }).length;
293-
const gzippedSize = prettysize(gzipped) + ' (gzipped)';
294+
const gzippedSize = prettysize(gzipped) + " (gzipped)";
294295
const compressedSize = prettysize(size.length);
295296
const prettyGzip = yellow(`${compressedSize}, ${gzippedSize}`);
296297
log
297-
.title(this.indent + '')
298+
.title(this.indent + "")
298299
.when(msg,
299300
() => log.text(msg),
300-
() => log.bold('size: '))
301+
() => log.bold("size: "))
301302
.data(prettyGzip)
302303
.echo();
303304
return this;
@@ -328,19 +329,19 @@ export class Log {
328329
public echoSparkyTaskStart(taskName: string) {
329330
const gray = log.chalk().gray;
330331
const magenta = log.chalk().magenta;
331-
let str = ['[', gray(getDateTime()), ']', ' Starting']
332-
str.push(` '${magenta(taskName)}' `)
333-
console.log(str.join(''));
332+
const str = ["[", gray(getDateTime()), "]", " Starting"];
333+
str.push(` '${magenta(taskName)}' `);
334+
console.log(str.join(""));
334335
return this;
335336
}
336337

337-
public echoSparkyTaskEnd(taskName, took: [number, number]){
338+
public echoSparkyTaskEnd(taskName, took: [number, number]) {
338339
const gray = log.chalk().gray;
339340
const magenta = log.chalk().magenta;
340-
let str = ['[', gray(getDateTime()), ']', ' Resolved']
341-
str.push(` '${magenta(taskName)}' `, 'after ')
341+
const str = ["[", gray(getDateTime()), "]", " Resolved"];
342+
str.push(` '${magenta(taskName)}' `, "after ");
342343
str.push(`${gray(prettyTime(took, "ms"))}`);
343-
console.log(str.join(''));
344+
console.log(str.join(""));
344345
return this;
345346
}
346347

@@ -352,20 +353,20 @@ export class Log {
352353
public echoSparkyTaskHelp(taskName: string, taskHelp: string) {
353354
log
354355
.ansi()
355-
.write(' ')
356+
.write(" ")
356357
.cyan(taskName)
357358
.white(taskHelp)
358359
.echo();
359360
}
360361

361362
// --- generalized ---
362363
public groupHeader(str: string) {
363-
log.color('bold.underline').text(`${str}`).echo();
364+
log.color("bold.underline").text(`${str}`).echo();
364365
return this;
365366
}
366367
public echoInfo(str: string) {
367368
const indent = this.indent.level(2);
368-
log.preset('info').green(`${indent}${str}`).echo();
369+
log.preset("info").green(`${indent}${str}`).echo();
369370
return this;
370371
}
371372
public error(error: Error) {
@@ -374,7 +375,7 @@ export class Log {
374375
// log.factory().notify({title: error.message, message: error.stack}).echo()
375376
// }
376377

377-
log.tags('error').data(error).echo();
378+
log.tags("error").data(error).echo();
378379
return this;
379380
}
380381

@@ -383,7 +384,7 @@ export class Log {
383384
if (metadata) {
384385
log.data(metadata);
385386
}
386-
log.tags('magic').magenta(str).echo();
387+
log.tags("magic").magenta(str).echo();
387388
return this;
388389
}
389390

@@ -405,7 +406,7 @@ export class Log {
405406
return this;
406407
}
407408
public echoError(str: string) {
408-
log.red(` → ERROR ${str}`).echo()
409+
log.red(` → ERROR ${str}`).echo();
409410
}
410411
public echoRed(msg) {
411412
log.red(msg).echo();

0 commit comments

Comments
 (0)