-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathSetEnvironmentVariablesPlugin.ts
More file actions
37 lines (33 loc) · 1.33 KB
/
SetEnvironmentVariablesPlugin.ts
File metadata and controls
37 lines (33 loc) · 1.33 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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import type { HeftConfiguration } from '../configuration/HeftConfiguration';
import type { IHeftTaskSession } from '../pluginFramework/HeftTaskSession';
import type { IHeftTaskPlugin } from '../pluginFramework/IHeftPlugin';
import type { SetEnvironmentVariablesHeftTaskEventOptions as ISetEnvironmentVariablesPluginOptions } from '../schemas/set-environment-variables-plugin.schema.json.d.ts';
export const PLUGIN_NAME: string = 'set-environment-variables-plugin';
/**
* @public
*/
export type { ISetEnvironmentVariablesPluginOptions };
export default class SetEnvironmentVariablesPlugin
implements IHeftTaskPlugin<ISetEnvironmentVariablesPluginOptions>
{
public apply(
taskSession: IHeftTaskSession,
heftConfiguration: HeftConfiguration,
{ environmentVariablesToSet }: ISetEnvironmentVariablesPluginOptions
): void {
taskSession.hooks.run.tap(
{
name: PLUGIN_NAME,
stage: Number.MIN_SAFE_INTEGER
},
() => {
for (const [key, value] of Object.entries(environmentVariablesToSet)) {
taskSession.logger.terminal.writeLine(`Setting environment variable ${key}=${value}`);
process.env[key] = value;
}
}
);
}
}