From e51d6aa6879c085ae9efac990d6d406a79615088 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 27 Aug 2021 15:36:53 -0600 Subject: [PATCH] feat: rename to sf-plugins-core --- CHANGELOG.md | 30 ++++++++++--------------- README.md | 4 ++-- package.json | 9 ++++---- src/deployer.ts | 54 ++++++++++++++++++++++----------------------- src/exported.ts | 3 ++- src/hooks.ts | 43 ++++++++++++++++++++++++++++++++++++ src/types/index.ts | 50 +++++++++++++++++++++++++++++++++++++++++ yarn.lock | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 194 insertions(+), 54 deletions(-) create mode 100644 src/hooks.ts create mode 100644 src/types/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d74d37e6e..56133ea5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,62 +2,54 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -### [0.0.10](https://github.com/salesforcecli/plugin-deploy-retrieve-utils/compare/v0.0.9...v0.0.10) (2021-08-10) - +### [0.0.10](https://github.com/salesforcecli/sf-plugins-core/compare/v0.0.9...v0.0.10) (2021-08-10) ### Bug Fixes -* correct header to data column alignment ([a6d1baf](https://github.com/salesforcecli/plugin-deploy-retrieve-utils/commit/a6d1bafd098443dcb4381f03fd7283594d263c8d)) - -### [0.0.9](https://github.com/salesforcecli/plugin-deploy-retrieve-utils/compare/v0.0.8...v0.0.9) (2021-07-15) +- correct header to data column alignment ([a6d1baf](https://github.com/salesforcecli/sf-plugins-core/commit/a6d1bafd098443dcb4381f03fd7283594d263c8d)) +### [0.0.9](https://github.com/salesforcecli/sf-plugins-core/compare/v0.0.8...v0.0.9) (2021-07-15) ### Bug Fixes -* rename ProjectDeployOptions to DeployOptions ([eafefcf](https://github.com/salesforcecli/plugin-deploy-retrieve-utils/commit/eafefcfb55f73e96e2b0b08bb3129b6aa0fb6571)) +- rename ProjectDeployOptions to DeployOptions ([eafefcf](https://github.com/salesforcecli/sf-plugins-core/commit/eafefcfb55f73e96e2b0b08bb3129b6aa0fb6571)) -### [0.0.8](https://github.com/salesforcecli/plugin-deploy-retrieve-utils/compare/v0.0.7...v0.0.8) (2021-07-15) +### [0.0.8](https://github.com/salesforcecli/sf-plugins-core/compare/v0.0.7...v0.0.8) (2021-07-15) ### [0.0.7](https://github.com/salesforcecli/plugin-project-utils/compare/v0.0.6...v0.0.7) (2021-07-01) - ### Features -* support deploy file ([99b4a81](https://github.com/salesforcecli/plugin-project-utils/commit/99b4a81b1a844714233a30679ae267c6866ba4a2)) +- support deploy file ([99b4a81](https://github.com/salesforcecli/plugin-project-utils/commit/99b4a81b1a844714233a30679ae267c6866ba4a2)) ### [0.0.6](https://github.com/salesforcecli/plugin-project-utils/compare/v0.0.5...v0.0.6) (2021-06-28) - ### Bug Fixes -* allow empty log message ([1272215](https://github.com/salesforcecli/plugin-project-utils/commit/1272215b62a35e89072df2f02c1bab6c2999e056)) +- allow empty log message ([1272215](https://github.com/salesforcecli/plugin-project-utils/commit/1272215b62a35e89072df2f02c1bab6c2999e056)) ### [0.0.5](https://github.com/salesforcecli/plugin-project-utils/compare/v0.0.4...v0.0.5) (2021-06-28) - ### Features -* add Prompter class ([7f7861f](https://github.com/salesforcecli/plugin-project-utils/commit/7f7861f68dc74d815a1bf2d668edd719496524ff)) +- add Prompter class ([7f7861f](https://github.com/salesforcecli/plugin-project-utils/commit/7f7861f68dc74d815a1bf2d668edd719496524ff)) ### [0.0.4](https://github.com/salesforcecli/plugin-project-utils/compare/v0.0.3...v0.0.4) (2021-06-28) - ### Bug Fixes -* update Options type ([f24a800](https://github.com/salesforcecli/plugin-project-utils/commit/f24a800409e026605f08717cd572e89afcdf35d0)) +- update Options type ([f24a800](https://github.com/salesforcecli/plugin-project-utils/commit/f24a800409e026605f08717cd572e89afcdf35d0)) ### [0.0.3](https://github.com/salesforcecli/plugin-project-utils/compare/v0.0.2...v0.0.3) (2021-06-28) - ### Features -* add Deployables class ([0405a6b](https://github.com/salesforcecli/plugin-project-utils/commit/0405a6bdc78cf44237e1bd51efb2199c275678ca)) +- add Deployables class ([0405a6b](https://github.com/salesforcecli/plugin-project-utils/commit/0405a6bdc78cf44237e1bd51efb2199c275678ca)) ### [0.0.2](https://github.com/salesforcecli/plugin-project-utils/compare/v0.0.1...v0.0.2) (2021-06-24) ### 0.0.1 (2021-06-24) - ### Features -* deployer interface ([fbfee1e](https://github.com/salesforcecli/plugin-project-utils/commit/fbfee1eb223c67ead31dfd6da65ed6d55c83015d)) +- deployer interface ([fbfee1e](https://github.com/salesforcecli/plugin-project-utils/commit/fbfee1eb223c67ead31dfd6da65ed6d55c83015d)) diff --git a/README.md b/README.md index f57f866d7..2e4e61256 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![NPM](https://img.shields.io/npm/v/@salesforce/plugin-deploy-retrieve-utils.svg)](https://www.npmjs.com/package/@salesforce/plugin-deploy-retrieve-utils) +[![NPM](https://img.shields.io/npm/v/@salesforce/sf-plugins-core.svg)](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. diff --git a/package.json b/package.json index 7e1ef231e..1c84eea3e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@salesforce/plugin-deploy-retrieve-utils", + "name": "@salesforce/sf-plugins-core", "version": "0.0.10", "description": "Utils for writing deploy and retrieve plugins", "main": "lib/exported", @@ -22,12 +22,12 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/salesforcecli/plugin-deploy-retrieve-utils.git" + "url": "git+https://github.com/salesforcecli/sf-plugins-core.git" }, "bugs": { - "url": "https://github.com/salesforcecli/plugin-deploy-retrieve-utils/issues" + "url": "https://github.com/salesforcecli/sf-plugins-core/issues" }, - "homepage": "https://github.com/salesforcecli/plugin-deploy-retrieve-utils#readme", + "homepage": "https://github.com/salesforcecli/sf-plugins-core#readme", "files": [ "lib", "!lib/**/*.map" @@ -40,6 +40,7 @@ } }, "dependencies": { + "@oclif/core": "^0.5.33", "@salesforce/kit": "^1.5.8", "@salesforce/ts-types": "^1.5.13", "cli-ux": "^5.6.2", diff --git a/src/deployer.ts b/src/deployer.ts index 2b925eedd..8926f749b 100644 --- a/src/deployer.ts +++ b/src/deployer.ts @@ -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: 'user@salesforce.com' }, - * } - */ -export interface DeployOptions { - [key: string]: T; -} - export abstract class Deployable { - abstract getAppName(): string; - abstract getAppType(): string; - abstract getAppPath(): string; - abstract getEnvType(): Nullable; + 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; + public abstract setup(flags: Deployer.Flags, options: Deployer.Options): Promise; /** * Deploy the app. */ public abstract deploy(): Promise; } + +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: 'user@salesforce.com' }, + * } + */ + export type Options = JsonMap & { + [key: string]: T; + }; +} diff --git a/src/exported.ts b/src/exported.ts index 243d19aef..1a58e5578 100644 --- a/src/exported.ts +++ b/src/exported.ts @@ -6,5 +6,6 @@ */ export { generateTableChoices } from './util'; -export { Deployable, Deployer, DeployOptions, DeployerOptions, Preferences } from './deployer'; +export { Deployable, Deployer } from './deployer'; export { Prompter } from './prompter'; +export { runHook, SfHook } from './hooks'; diff --git a/src/hooks.ts b/src/hooks.ts new file mode 100644 index 000000000..b98f10325 --- /dev/null +++ b/src/hooks.ts @@ -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 extends Hooks { + 'sf:env:list': EnvList.HookMeta; + 'sf:env:display': EnvDisplay.HookMeta; + 'sf:deploy': Deploy.HookMeta; + 'sf:login': Login.HookMeta; +} + +type GenericHook = Hook>; + +export namespace SfHook { + export type EnvList = GenericHook<'sf:env:list', T>; + export type EnvDisplay = GenericHook<'sf:env:display', T>; + export type Deploy = GenericHook<'sf:deploy', T>; + export type Login = Hook<'sf:login', SfHooks>; +} + +export async function runHook( + config: Config, + hookName: T, + options: SfHooks[T]['options'] = {} +): Promise> { + const timeout = Duration.milliseconds(env.getNumber('SF_HOOK_TIMEOUT_MS') || 5000); + const results = await config.runHook(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; +} diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 000000000..8286a3c0b --- /dev/null +++ b/src/types/index.ts @@ -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 = { + options: {}; + return: T; + }; +} + +export namespace EnvList { + type Table = { + data: T[]; + columns: Array; + title: string; + }; + + type Options = { + all: boolean; + }; + + export type HookMeta = { + options: Options; + return: Array>; + }; +} + +export namespace Deploy { + export type HookMeta = { + options: {}; + return: T[]; + }; +} + +export namespace Login { + export type HookMeta = { + options: {}; + return: void; + }; +} diff --git a/yarn.lock b/yarn.lock index d71ef520f..d4535e98d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -430,6 +430,29 @@ is-wsl "^2.1.1" tslib "^2.0.0" +"@oclif/core@^0.5.33": + version "0.5.33" + resolved "https://registry.npmjs.org/@oclif/core/-/core-0.5.33.tgz#3d304436163653044dd37c173e2fc504cdf40040" + integrity sha512-4zaDkhDM319U4TsIlYx7GlGTfVRCUuOx3GXh/FpAGY7dPwrtRv5xKKiR87LWZIt1En1Q58E1cSGKeR1lQ3WNnQ== + dependencies: + "@oclif/linewrap" "^1.0.0" + chalk "^4.1.0" + clean-stack "^3.0.0" + cli-ux "^5.1.0" + debug "^4.1.1" + fs-extra "^9.0.1" + get-package-type "^0.1.0" + globby "^11.0.1" + indent-string "^4.0.0" + is-wsl "^2.1.1" + lodash.template "^4.4.0" + semver "^7.3.2" + string-width "^4.2.0" + strip-ansi "^6.0.0" + tslib "^2.0.0" + widest-line "^3.1.0" + wrap-ansi "^7.0.0" + "@oclif/dev-cli@^1": version "1.26.0" resolved "https://registry.npmjs.org/@oclif/dev-cli/-/dev-cli-1.26.0.tgz#e3ec294b362c010ffc8948003d3770955c7951fd" @@ -1250,6 +1273,38 @@ cli-spinners@^2.5.0: resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.6.0.tgz#36c7dc98fb6a9a76bd6238ec3f77e2425627e939" integrity sha512-t+4/y50K/+4xcCRosKkA7W4gTr1MySvLV0q+PxmG7FJ5g+66ChKurYjxBCjHggHH3HA5Hh9cy+lcUGWDqVH+4Q== +cli-ux@^5.1.0: + version "5.6.3" + resolved "https://registry.npmjs.org/cli-ux/-/cli-ux-5.6.3.tgz#eecdb2e0261171f2b28f2be6b18c490291c3a287" + integrity sha512-/oDU4v8BiDjX2OKcSunGH0iGDiEtj2rZaGyqNuv9IT4CgcSMyVWAMfn0+rEHaOc4n9ka78B0wo1+N1QX89f7mw== + dependencies: + "@oclif/command" "^1.6.0" + "@oclif/errors" "^1.2.1" + "@oclif/linewrap" "^1.0.0" + "@oclif/screen" "^1.0.3" + ansi-escapes "^4.3.0" + ansi-styles "^4.2.0" + cardinal "^2.1.1" + chalk "^4.1.0" + clean-stack "^3.0.0" + cli-progress "^3.4.0" + extract-stack "^2.0.0" + fs-extra "^8.1" + hyperlinker "^1.0.0" + indent-string "^4.0.0" + is-wsl "^2.2.0" + js-yaml "^3.13.1" + lodash "^4.17.11" + natural-orderby "^2.0.1" + object-treeify "^1.1.4" + password-prompt "^1.1.2" + semver "^7.3.2" + string-width "^4.2.0" + strip-ansi "^6.0.0" + supports-color "^8.1.0" + supports-hyperlinks "^2.1.0" + tslib "^2.0.0" + cli-ux@^5.2.1, cli-ux@^5.6.2: version "5.6.2" resolved "https://registry.npmjs.org/cli-ux/-/cli-ux-5.6.2.tgz#c78b953b14cdf95b4bb6aae8db0ab6745333405c"