-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bba761d
commit e51d6aa
Showing
8 changed files
with
194 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[](https://www.npmjs.com/package/@salesforce/plugin-deploy-retrieve-utils) | ||
[](https://www.npmjs.com/package/@salesforce/sf-plugins-core) | ||
|
||
# Description | ||
|
||
Utilities for writing plugins that deploy or retrieve metadata from Salesforce Orgs | ||
Utilities for writing [sf](https://github.com/salesforcecli/cli) plugins. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { Config } from '@oclif/core/lib/interfaces/config'; | ||
import { Hook, Hooks } from '@oclif/core/lib/interfaces/hooks'; | ||
import { cli } from 'cli-ux'; | ||
import { Duration, env } from '@salesforce/kit'; | ||
import { Deployer } from './deployer'; | ||
import { EnvList, EnvDisplay, DataObject, Deploy, Login } from './types'; | ||
|
||
interface SfHooks<T = unknown> extends Hooks { | ||
'sf:env:list': EnvList.HookMeta<T & DataObject>; | ||
'sf:env:display': EnvDisplay.HookMeta<T & DataObject>; | ||
'sf:deploy': Deploy.HookMeta<T & Deployer>; | ||
'sf:login': Login.HookMeta; | ||
} | ||
|
||
type GenericHook<T extends keyof SfHooks, P> = Hook<T, SfHooks<P>>; | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { Deployer } from '../deployer'; | ||
|
||
export type DataObject = { | ||
[key: string]: string | boolean; | ||
}; | ||
|
||
export namespace EnvDisplay { | ||
export type HookMeta<T extends DataObject> = { | ||
options: {}; | ||
return: T; | ||
}; | ||
} | ||
|
||
export namespace EnvList { | ||
type Table<T extends DataObject> = { | ||
data: T[]; | ||
columns: Array<keyof T>; | ||
title: string; | ||
}; | ||
|
||
type Options = { | ||
all: boolean; | ||
}; | ||
|
||
export type HookMeta<T extends DataObject> = { | ||
options: Options; | ||
return: Array<Table<T>>; | ||
}; | ||
} | ||
|
||
export namespace Deploy { | ||
export type HookMeta<T extends Deployer> = { | ||
options: {}; | ||
return: T[]; | ||
}; | ||
} | ||
|
||
export namespace Login { | ||
export type HookMeta = { | ||
options: {}; | ||
return: void; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters