Skip to content

Commit

Permalink
fix: update exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Aug 30, 2021
1 parent 6a56b58 commit 548ab46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/exported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
export { generateTableChoices } from './util';
export { Deployable, Deployer } from './deployer';
export { Prompter } from './prompter';
export { runHook, SfHook } from './hooks';
export { JsonObject, TableObject } from './types';
export { SfHook } from './hooks';
export * from './types';
30 changes: 16 additions & 14 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ interface SfHooks<T = unknown> extends Hooks {

type GenericHook<T extends keyof SfHooks, P> = Hook<T, SfHooks<P>>;

export class SfHook {
public static async run<T extends keyof SfHooks>(
config: Config,
hookName: T,
options: SfHooks[T]['options'] = {}
): Promise<Hook.Result<SfHooks[T]['return']>> {
const timeout = Duration.milliseconds(env.getNumber('SF_HOOK_TIMEOUT_MS') || 5000);
const results = await config.runHook<T>(hookName, options, timeout.milliseconds);
results.failures.forEach((failure) => {
cli.debug(`Failed to run ${hookName} hook for ${failure.plugin.name}`);
cli.debug(failure.error.toString());
});
return results;
}
}

export namespace SfHook {
export type EnvList<T> = GenericHook<'sf:env:list', T>;
export type EnvDisplay<T> = GenericHook<'sf:env:display', T>;
export type Deploy<T> = GenericHook<'sf:deploy', T>;
export type Login = Hook<'sf:login', SfHooks>;
}

export async function runHook<T extends keyof SfHooks>(
config: Config,
hookName: T,
options: SfHooks[T]['options'] = {}
): Promise<Hook.Result<SfHooks[T]['return']>> {
const timeout = Duration.milliseconds(env.getNumber('SF_HOOK_TIMEOUT_MS') || 5000);
const results = await config.runHook<T>(hookName, options, timeout.milliseconds);
results.failures.forEach((failure) => {
cli.debug(`Failed to run ${hookName} hook for ${failure.plugin.name}`);
cli.debug(failure.error.toString());
});
return results;
}

0 comments on commit 548ab46

Please sign in to comment.