Skip to content

Commit 3692bc8

Browse files
author
Daniil Ryazanov
authored
Merge pull request #321 from projectlint/master
Various improvements and clean-ups
2 parents 54a7763 + d0b1f06 commit 3692bc8

File tree

8 files changed

+68
-42
lines changed

8 files changed

+68
-42
lines changed

.huskyrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hooks": {
3-
"pre-commit": "yarn util:pre-commit",
4-
"commit-msg": "yarn util:commit-msg"
3+
"pre-commit": "npm run util:pre-commit",
4+
"commit-msg": "npm run util:commit-msg"
55
}
66
}

package.json

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
"url": "https://github.com/keindev/tasktree/issues"
3232
},
3333
"scripts": {
34-
"prepare:clean": "rimraf lib coverage",
3534
"check:lint": "eslint src/**/*.ts --fix",
3635
"check:spell": "cspell -c .vscode/cspell.json --no-summary \"*.*\" \"**/*.ts\" \"**/*.js\"",
37-
"check:test": "jest",
38-
"build:ts": "tsc",
39-
"build:ghinfo": "ghinfo generate -d media -t utils",
36+
"check:test": "npm test",
4037
"build": "npm-run-all prepare:* check:* build:*",
38+
"build:ghinfo": "ghinfo generate -d media -t utils",
39+
"build:ts": "tsc",
40+
"prepare": "tsc",
41+
"prepare:clean": "rimraf lib coverage",
42+
"test": "jest --coverage --notify",
4143
"util:changelog": "changelog generate",
4244
"util:commit-msg": "changelog lint --message HUSKY_GIT_PARAMS --lowercase-only",
4345
"util:pre-commit": "npm-run-all check:*"
@@ -46,33 +48,33 @@
4648
"node": ">=10.0.0"
4749
},
4850
"dependencies": {
49-
"chalk": "^3.0.0",
51+
"chalk": "^4.0.0",
5052
"color-convert": "^2.0.1",
5153
"elegant-spinner": "^2.0.0",
52-
"figures": "^3.1.0",
54+
"figures": "^3.2.0",
5355
"stdout-update": "^1.4.1"
5456
},
5557
"devDependencies": {
5658
"@types/color-convert": "^1.9.0",
57-
"@types/jest": "^25.1.1",
58-
"@types/node": "^13.5.2",
59-
"@typescript-eslint/eslint-plugin": "^2.18.0",
60-
"@typescript-eslint/parser": "^2.18.0",
59+
"@types/jest": "^25.2.1",
60+
"@types/node": "^13.13.4",
61+
"@typescript-eslint/eslint-plugin": "^2.30.0",
62+
"@typescript-eslint/parser": "^2.30.0",
6163
"changelog-guru": "^1.0.0",
62-
"cspell": "^4.0.46",
64+
"cspell": "^4.0.57",
6365
"eslint": "^6.8.0",
64-
"eslint-config-airbnb-base": "^14.0.0",
65-
"eslint-config-prettier": "^6.10.0",
66-
"eslint-plugin-import": "^2.20.0",
67-
"eslint-plugin-jest": "^23.6.0",
66+
"eslint-config-airbnb-base": "^14.1.0",
67+
"eslint-config-prettier": "^6.11.0",
68+
"eslint-plugin-import": "^2.20.2",
69+
"eslint-plugin-jest": "^23.8.2",
6870
"ghinfo": "^1.0.6",
69-
"husky": "^4.2.1",
70-
"jest": "^25.1.0",
71+
"husky": "^4.2.5",
72+
"jest": "^25.5.4",
7173
"npm-run-all": "^4.1.5",
72-
"prettier": "^1.19.1",
73-
"rimraf": "^3.0.1",
74+
"prettier": "^2.0.5",
75+
"rimraf": "^3.0.2",
7476
"strip-ansi": "^6.0.0",
75-
"ts-jest": "^25.1.0",
76-
"typescript": "^3.7.5"
77+
"ts-jest": "^25.4.0",
78+
"typescript": "^3.8.3"
7779
}
7880
}

src/ProgressBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class ProgressBar {
192192
result = result.replace(`:${key}`, value);
193193
});
194194

195-
return this.badges ? Theme.join(Wrapper.SPACE, result, theme.badge(type)) : result;
195+
return this.badges ? Theme.join(Wrapper.SPACE, result, theme.badge(theme.type2badge(type))) : result;
196196
}
197197

198198
private getBlocks(theme: Theme, type: IndicationType, length: number): string {

src/Task.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export enum TaskStatus {
1010
Completed = 1,
1111
Failed = 2,
1212
Skipped = 3,
13+
Warning = 4,
1314
}
1415

1516
export interface ITaskOptions {
@@ -20,6 +21,7 @@ export interface ITaskOptions {
2021
export class Task {
2122
private uid: number;
2223
private text: string;
24+
private badge = '';
2325
private status: TaskStatus;
2426
private autoClear: boolean;
2527
private bars: ProgressBar[] = [];
@@ -113,10 +115,10 @@ export class Task {
113115
this.bars = [];
114116
}
115117

116-
public complete(text?: string, clear = this.autoClear): Task {
118+
public complete(text?: string, clear = this.autoClear, status = TaskStatus.Completed): Task {
117119
if (this.havePendingSubtasks()) this.fail('Subtasks is not complete.');
118120

119-
this.setStatus(TaskStatus.Completed, text, clear);
121+
this.setStatus(status, text, clear);
120122
this.bars = this.bars.filter((bar): boolean => {
121123
bar.complete();
122124

@@ -179,6 +181,16 @@ export class Task {
179181
return rows.map((row): string => theme.paint(row, type));
180182
}
181183

184+
public setBadge(badge: string): Task {
185+
this.badge = badge;
186+
187+
return this;
188+
}
189+
190+
public getBadge(): string {
191+
return this.badge;
192+
}
193+
182194
private setStatus(status: TaskStatus, text?: string, clear?: boolean): void {
183195
if (this.isPending()) {
184196
if (text) this.text = text;

src/TaskTree.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ export class TaskTree {
2525
private started = false;
2626
private offset = 0;
2727

28-
private constructor(theme?: ThemeOptions) {
28+
private constructor(theme?: ThemeOptions, stdout?: NodeJS.WriteStream, stderr?: NodeJS.WriteStream) {
2929
this.tasks = [];
3030
this.theme = new Theme(theme);
31-
this.manager = UpdateManager.getInstance();
31+
this.manager = UpdateManager.getInstance(stdout, stderr);
3232
}
3333

34-
public static tree(theme?: ThemeOptions): TaskTree {
34+
public static tree(theme?: ThemeOptions, stdout?: NodeJS.WriteStream, stderr?: NodeJS.WriteStream): TaskTree {
3535
if (!TaskTree.instance) {
36-
TaskTree.instance = new TaskTree(theme);
36+
TaskTree.instance = new TaskTree(theme, stdout, stderr);
3737
}
3838

3939
return TaskTree.instance;

src/Theme.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export enum IndicationColor {
3939

4040
export enum IndicationBadge {
4141
Default = '',
42-
Error = '[fail]',
42+
Error = '[error]',
43+
Fail = '[fail]',
4344
Skip = '[skip]',
4445
}
4546

@@ -109,6 +110,9 @@ export class Theme {
109110
case TaskStatus.Skipped:
110111
type = IndicationType.Skip;
111112
break;
113+
case TaskStatus.Warning:
114+
type = IndicationType.Warning;
115+
break;
112116
case TaskStatus.Failed:
113117
type = IndicationType.Error;
114118
break;
@@ -204,28 +208,36 @@ export class Theme {
204208
return symbol ? this.paint(symbol, type) : symbol;
205209
}
206210

207-
public badge(type: IndicationType): string {
211+
public type2badge(type: IndicationType): string {
208212
const { badges } = this;
209213
const badge = Theme.getValueBy(badges, type, (): string => {
210214
if (type === IndicationType.Error) return IndicationBadge.Error;
215+
// if (type === IndicationType.Fail) return IndicationBadge.Fail;
211216
if (type === IndicationType.Skip) return IndicationBadge.Skip;
212217

213218
return badges.get(IndicationType.Default) || IndicationBadge.Default;
214219
});
215220

221+
return badge;
222+
}
223+
224+
public badge(badge: string): string {
216225
return badge ? this.paint(badge, IndicationType.Dim) : badge;
217226
}
218227

219228
public title(task: Task, level: number): string {
220229
const type = Theme.type(task.getStatus(), task.haveSubtasks());
221-
const badge = this.badge(type);
230+
const badge = this.badge(task.getBadge() || this.type2badge(type));
222231
const symbol = this.symbol(type);
223232
let prefix = Wrapper.EMPTY;
224233

225234
if (level)
226235
prefix = task.haveSubtasks() ? this.symbol(IndicationType.Subtask) : this.symbol(IndicationType.Default);
227236

228-
return Theme.indent(level, prefix, symbol, task.getText(), badge);
237+
const text = (type === IndicationType.Error || type === IndicationType.Warning)
238+
? this.paint(task.getText(), type) : task.getText()
239+
240+
return Theme.indent(level, prefix, symbol, text, badge);
229241
}
230242

231243
public errors(errors: string[], level: number): string[] {

src/__tests__/Theme.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ describe('Theme', (): void => {
1818
expect(stripAnsi(theme.symbol(IndicationType.Skip))).toBe(stripAnsi(Figures.arrowDown));
1919
expect(stripAnsi(theme.symbol(IndicationType.Error))).toBe(stripAnsi(Figures.cross));
2020

21-
expect(theme.badge(IndicationType.Default)).toBe(IndicationBadge.Default);
22-
expect(stripAnsi(theme.badge(IndicationType.Skip))).toBe(IndicationBadge.Skip);
23-
expect(stripAnsi(theme.badge(IndicationType.Error))).toBe(IndicationBadge.Error);
21+
expect(theme.badge(theme.type2badge(IndicationType.Default))).toBe(IndicationBadge.Default);
22+
expect(stripAnsi(theme.badge(theme.type2badge(IndicationType.Skip)))).toBe(IndicationBadge.Skip);
23+
expect(stripAnsi(theme.badge(theme.type2badge(IndicationType.Error)))).toBe(IndicationBadge.Error);
2424
});
2525

2626
it('Custom', (): void => {
@@ -43,9 +43,9 @@ describe('Theme', (): void => {
4343
expect(stripAnsi(theme.symbol(IndicationType.Skip))).toBe(symbol);
4444
expect(stripAnsi(theme.symbol(IndicationType.Error))).toBe(symbol);
4545

46-
expect(theme.badge(IndicationType.Default)).toBe(IndicationBadge.Default);
47-
expect(stripAnsi(theme.badge(IndicationType.Success))).toBe(badge);
48-
expect(stripAnsi(theme.badge(IndicationType.Skip))).toBe(badge);
49-
expect(stripAnsi(theme.badge(IndicationType.Error))).toBe(badge);
46+
expect(theme.badge(theme.type2badge(IndicationType.Default))).toBe(IndicationBadge.Default);
47+
expect(stripAnsi(theme.badge(theme.type2badge(IndicationType.Success)))).toBe(badge);
48+
expect(stripAnsi(theme.badge(theme.type2badge(IndicationType.Skip)))).toBe(badge);
49+
expect(stripAnsi(theme.badge(theme.type2badge(IndicationType.Error)))).toBe(badge);
5050
});
5151
});

src/__tests__/__snapshots__/ProgressBar.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ exports[`ProgressBar Default 1`] = `"******************** 100% 0.0s test"`;
44

55
exports[`ProgressBar Statuses Complete 1`] = `"******************** 100% 0.0s :custom"`;
66

7-
exports[`ProgressBar Statuses Fail 1`] = `"**********__________ 50% 0.0s :custom [fail]"`;
7+
exports[`ProgressBar Statuses Fail 1`] = `"**********__________ 50% 0.0s :custom [error]"`;
88

99
exports[`ProgressBar Statuses Skip 1`] = `"**********__________ 50% 0.0s :custom [skip]"`;

0 commit comments

Comments
 (0)