-
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,36 +6,15 @@ | |
*/ | ||
|
||
import { EventEmitter } from 'events'; | ||
import { JsonMap, Nullable } from '@salesforce/ts-types'; | ||
import { AnyJson, JsonMap } from '@salesforce/ts-types'; | ||
import cli from 'cli-ux'; | ||
import { QuestionCollection } from 'inquirer'; | ||
import { Prompter } from './prompter'; | ||
|
||
export interface Preferences { | ||
interactive: boolean; | ||
} | ||
|
||
export type DeployerOptions = JsonMap; | ||
|
||
/** | ||
* This interface represents the aggregation of all deployer options, e.g. | ||
* { | ||
* 'Salesforce Apps': { | ||
* testLevel: 'RunLocalTests', | ||
* apps: ['force-app'], | ||
* }, | ||
* 'Salesforce Functions': { username: '[email protected]' }, | ||
* } | ||
*/ | ||
export interface DeployOptions<T extends DeployerOptions = DeployerOptions> { | ||
[key: string]: T; | ||
} | ||
|
||
export abstract class Deployable { | ||
abstract getAppName(): string; | ||
abstract getAppType(): string; | ||
abstract getAppPath(): string; | ||
abstract getEnvType(): Nullable<string>; | ||
abstract getName(): string; | ||
abstract getType(): string; | ||
abstract getPath(): string; | ||
abstract getParent(): Deployer; | ||
} | ||
|
||
|
@@ -86,17 +65,36 @@ export abstract class Deployer extends EventEmitter { | |
|
||
/** | ||
* Perform any initialization or setup. This is the time to prompt the | ||
* user for any needed information. It should do so by respecting the user's | ||
* preferences when possible (i.e. interactive mode or wait times). | ||
* user for any needed information. | ||
* | ||
* If options are passed it, it should use those instead of prompting the for the passed in information | ||
* | ||
* Uses the returned dictionary as the information to store in the deploy-options.json file. | ||
*/ | ||
public abstract setup(preferences: Preferences, options: DeployerOptions): Promise<DeployerOptions>; | ||
public abstract setup(flags: Deployer.Flags, options: Deployer.Options): Promise<Deployer.Options>; | ||
|
||
/** | ||
* Deploy the app. | ||
*/ | ||
public abstract deploy(): Promise<void>; | ||
} | ||
|
||
export namespace Deployer { | ||
export type Flags = { | ||
interactive: boolean; | ||
}; | ||
|
||
/** | ||
* This interface represents the aggregation of all deployer options, e.g. | ||
* { | ||
* 'Salesforce Apps': { | ||
* testLevel: 'RunLocalTests', | ||
* apps: ['force-app'], | ||
* }, | ||
* 'Salesforce Functions': { username: '[email protected]' }, | ||
* } | ||
*/ | ||
export type Options<T = AnyJson> = JsonMap & { | ||
[key: string]: T; | ||
}; | ||
} |
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