Skip to content

Commit

Permalink
feat: rename to sf-plugins-core
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Aug 30, 2021
1 parent bba761d commit e51d6aa
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 54 deletions.
30 changes: 11 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand All @@ -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",
Expand Down
54 changes: 26 additions & 28 deletions src/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
}

Expand Down Expand Up @@ -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: 'user@salesforce.com' },
* }
*/
export type Options<T = AnyJson> = JsonMap & {
[key: string]: T;
};
}
3 changes: 2 additions & 1 deletion src/exported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
43 changes: 43 additions & 0 deletions src/hooks.ts
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;
}
50 changes: 50 additions & 0 deletions src/types/index.ts
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;
};
}
55 changes: 55 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e51d6aa

Please sign in to comment.