Skip to content

Commit 0f36826

Browse files
author
Ovidiu Barabula
committed
feat(core): add logger to task manager and set test api exports
1 parent 3cc3102 commit 0f36826

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/task-manager/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert, expect } from 'chai';
22
import * as gulp from 'gulp';
33
import 'mocha';
4-
import TaskManager, { ERRORS, TaskSubscriber } from './index';
4+
import TaskManager, { TaskSubscriber } from './index';
55

66

77
// Helper: create custom hook task
@@ -28,7 +28,7 @@ describe('TaskManager', () => {
2828
const taskManager = TaskManager();
2929
expect(taskManager)
3030
.to.be.an('object')
31-
.to.have.all.keys('getSubscribers', 'run', 'hasTasks', 'getHooks', 'getTasks');
31+
.to.have.all.keys('getSubscribers', 'run', 'hasTasks', 'getHooks', 'getTasks', 'subscribe');
3232
});
3333

3434

src/task-manager/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import * as gulp from 'gulp';
99
import { QuestionnaireSubscriber } from '../config-wizard';
10+
import Logger, { ILogger } from '../util/logger';
1011
import { hasNested, limitFn } from '../util/utility-functions';
1112

1213

@@ -21,9 +22,12 @@ export interface TaskSubscriber {
2122
export interface TaskManager {
2223
run(hook: string): Promise<boolean>;
2324
getSubscribers(): TaskSubscriber;
25+
/* test:start */
26+
subscribe?(task: string, hook: string): boolean;
2427
hasTasks?(hook: string): boolean;
2528
getTasks?(): Tasks;
2629
getHooks?(): string[];
30+
/* test:end */
2731
}
2832

2933
export interface TaskManagerOptions {
@@ -38,6 +42,7 @@ export interface TaskManagerOptions {
3842
function TaskManager(options?: TaskManagerOptions): TaskManager {
3943
let hooks: string[] = [];
4044
const tasks: Tasks = {};
45+
const logger: ILogger = Logger('frontvue')('TaskManager');
4146

4247
if (options && hasNested(options, 'hooks')) {
4348
hooks = [...hooks, ...options.hooks];
@@ -57,8 +62,7 @@ function TaskManager(options?: TaskManagerOptions): TaskManager {
5762
return resolve(true);
5863
}
5964

60-
// TODO: Log out error message using custom logger
61-
console.log(`>>> hook ${hook} doesn't exist or doesn't have any tasks`);
65+
logger.warn(`<${hook}> hook doesn't exist or has no tasks`);
6266
return resolve(false);
6367
});
6468
}
@@ -94,6 +98,11 @@ function TaskManager(options?: TaskManagerOptions): TaskManager {
9498
}
9599

96100

101+
/**
102+
* Subscribe a task to a hook
103+
* @param task Task name
104+
* @param hook Hook name
105+
*/
97106
function subscribe(task: string, hook: string): boolean {
98107
// Create new array for hook, if not available
99108
if (!hasNested(tasks, hook)) {
@@ -149,6 +158,7 @@ function TaskManager(options?: TaskManagerOptions): TaskManager {
149158
getHooks,
150159
getTasks,
151160
hasTasks,
161+
subscribe,
152162
};
153163
/* test:end */
154164

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy