forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventHooks.ts
More file actions
64 lines (59 loc) · 1.54 KB
/
EventHooks.ts
File metadata and controls
64 lines (59 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { IEventHooksJson } from './RushConfiguration';
/**
* Events happen during Rush runs.
* @beta
*/
export enum Event {
/**
* Pre Rush install event
*/
preRushInstall = 1,
/**
* Post Rush install event
*/
postRushInstall = 2,
/**
* Pre Rush build event
*/
preRushBuild = 3,
/**
* Post Rush build event
*/
postRushBuild = 4
}
/**
* This class represents Rush event hooks configured for this repo.
* Hooks are customized script actions that Rush executes when specific events occur.
* The actions are expressed as a command-line that is executed using the operating system shell.
* @beta
*/
export class EventHooks {
private _hooks: Map<Event, string[]>;
/**
* @internal
*/
public constructor(eventHooksJson: IEventHooksJson) {
this._hooks = new Map<Event, string[]>();
Object.getOwnPropertyNames(eventHooksJson).forEach((name) => {
const eventName: Event = Event[name];
if (eventName) {
const foundHooks: string[] = [];
if (eventHooksJson[name]) {
eventHooksJson[name].forEach((hook) => {
foundHooks.push(hook);
});
}
this._hooks.set(eventName, foundHooks);
}
});
}
/**
* Return all the scripts associated with the specified event.
* @param event - Rush event
*/
public get(event: Event): string[] {
return this._hooks.get(event) || [];
}
}