From 5efc4a28ed8c36a069f35286a7926fc5fbd0f644 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 30 Aug 2021 14:49:23 -0600 Subject: [PATCH 1/2] feat: use sf-plugins-core --- bin/dev | 11 ++++++----- package.json | 4 ++-- src/commands/deploy.ts | 29 ++++++++++++----------------- yarn.lock | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/bin/dev b/bin/dev index f90370a28..01fdab10b 100755 --- a/bin/dev +++ b/bin/dev @@ -2,13 +2,14 @@ process.env.NODE_ENV = 'development'; -const g = global.oclif = global.oclif || {}; +const g = (global.oclif = global.oclif || {}); + +const path = require('path'); +const project = path.join(__dirname, '..', 'tsconfig.json'); // In dev mode, always show stack traces global.oclif.debug = true; -require('ts-node').register() +require('ts-node').register({ project }); -require('@oclif/core').run() -.then(require('@oclif/core/flush')) -.catch(require('@oclif/core/handle')) +require('@oclif/core').run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle')); diff --git a/package.json b/package.json index 5dd4bb8bb..720b50b8b 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "author": "Salesforce", "bugs": "https://github.com/forcedotcom/cli/issues", "dependencies": { - "@oclif/core": "^0.5.31", + "@oclif/core": "^0.5.34", "@salesforce/core": "3.4.2", - "@salesforce/plugin-deploy-retrieve-utils": "^0.0.10", + "@salesforce/sf-plugins-core": "^0.0.13", "tslib": "^2" }, "devDependencies": { diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index d51b5df4c..6a0cd197c 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -8,13 +8,7 @@ import { Command, Flags } from '@oclif/core'; import { fs, Messages } from '@salesforce/core'; import { Env } from '@salesforce/kit'; -import { - Deployable, - Deployer, - generateTableChoices, - DeployOptions, - Prompter, -} from '@salesforce/plugin-deploy-retrieve-utils'; +import { Deployable, Deployer, generateTableChoices, Prompter, SfHook } from '@salesforce/sf-plugins-core'; Messages.importMessagesDirectory(__dirname); @@ -47,8 +41,9 @@ export default class Deploy extends Command { this.log(`Using options found in ${DEPLOY_OPTIONS_FILE}`); } - let deployers = (await this.config.runHook('project:findDeployers', options)) as Deployer[]; - deployers = deployers.reduce((x, y) => x.concat(y), [] as Deployer[]); + const hookResults = await SfHook.run(this.config, 'sf:deploy', options); + + let deployers = hookResults.successes.map((s) => s.result).reduce((x, y) => x.concat(y), [] as Deployer[]); if (deployers.length === 0) { this.log('Found nothing in the project to deploy'); @@ -61,10 +56,10 @@ export default class Deploy extends Command { this.log('Nothing was selected to deploy.'); } - const deployOptions: DeployOptions = {}; + const deployOptions: Deployer.Options = {}; for (const deployer of deployers) { const opts = options[deployer.getName()] ?? {}; - deployOptions[deployer.getName()] = await deployer.setup(flags, opts); + deployOptions[deployer.getName()] = await deployer.setup(flags, opts as Deployer.Options); } if (flags.interactive && (await this.askToSave())) { @@ -89,9 +84,9 @@ export default class Deploy extends Command { return deployFileExists ? false : true; } - public async readOptions(): Promise { + public async readOptions(): Promise { if (await fs.fileExists(DEPLOY_OPTIONS_FILE)) { - return (await fs.readJson(DEPLOY_OPTIONS_FILE)) as DeployOptions; + return (await fs.readJson(DEPLOY_OPTIONS_FILE)) as Deployer.Options; } else { return {}; } @@ -111,9 +106,9 @@ export default class Deploy extends Command { const deployables: Deployable[] = deployers.reduce((x, y) => x.concat(y.deployables), [] as Deployable[]); const columns = { name: 'APP OR PACKAGE', type: 'TYPE', path: 'PATH' }; const options = deployables.map((deployable) => ({ - name: deployable.getAppName(), - type: deployable.getAppType(), - path: deployable.getAppPath(), + name: deployable.getName(), + type: deployable.getType(), + path: deployable.getPath(), value: deployable, })); const prompter = new Prompter(); @@ -138,7 +133,7 @@ export default class Deploy extends Command { } const final: Deployer[] = []; - for (const [parent, children] of chosenDeployers.entries()) { + for (const [parent, children] of Array.from(chosenDeployers.entries())) { parent.selectDeployables(children); final.push(parent); } diff --git a/yarn.lock b/yarn.lock index 350c41b81..9a363e488 100644 --- a/yarn.lock +++ b/yarn.lock @@ -708,6 +708,29 @@ widest-line "^3.1.0" wrap-ansi "^7.0.0" +"@oclif/core@^0.5.33", "@oclif/core@^0.5.34": + version "0.5.34" + resolved "https://registry.npmjs.org/@oclif/core/-/core-0.5.34.tgz#d8cadcd609929560e6cc836c45d94bc99379e1f6" + integrity sha512-laLrm2tvIOr6uboDMVdAbBJMeAAgV0otkoF8imdyhYCsNcmXFyV3x0kwNGbEUYG945CQ0V00u7MS7tmlwdZlGw== + 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" @@ -1217,6 +1240,17 @@ resolved "https://registry.npmjs.org/@salesforce/schemas/-/schemas-1.0.1.tgz#d1db56759d2b22a7688e1821aec564e979237ad2" integrity sha512-78pP1GB/DbIS8nSWGL0GpQ27g02drrEo0vzYdRipGYAIXHMzlh1gqEsq0pOiIQlPm1MxWyEqbmf4GG5qSVsd0Q== +"@salesforce/sf-plugins-core@^0.0.13": + version "0.0.13" + resolved "https://registry.npmjs.org/@salesforce/sf-plugins-core/-/sf-plugins-core-0.0.13.tgz#c7f762d94f1cb9bb36b3f486eaa24f66eccaf488" + integrity sha512-hw7dlMNwGlAuJAPaXWotj0JjOEZxr8yyC9Y/NwW1vtM/NFragv77z6QxUDBsebA6t9C+vub8rH0JTP950dvBpg== + dependencies: + "@oclif/core" "^0.5.33" + "@salesforce/kit" "^1.5.8" + "@salesforce/ts-types" "^1.5.13" + cli-ux "^5.6.2" + inquirer "^8.1.1" + "@salesforce/source-deploy-retrieve@^4.1.0": version "4.1.0" resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-4.1.0.tgz#b28b8e1c9c810884315c564751e8854c4e1e16d3" From 0b772d8b751d760d7d3d76264cc899094c7ad5ac Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 30 Aug 2021 15:12:25 -0600 Subject: [PATCH 2/2] chore: code review --- src/commands/deploy.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index 6a0cd197c..be9101c1f 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -43,7 +43,7 @@ export default class Deploy extends Command { const hookResults = await SfHook.run(this.config, 'sf:deploy', options); - let deployers = hookResults.successes.map((s) => s.result).reduce((x, y) => x.concat(y), [] as Deployer[]); + let deployers = hookResults.successes.flatMap((s) => s.result); if (deployers.length === 0) { this.log('Found nothing in the project to deploy'); @@ -59,7 +59,7 @@ export default class Deploy extends Command { const deployOptions: Deployer.Options = {}; for (const deployer of deployers) { const opts = options[deployer.getName()] ?? {}; - deployOptions[deployer.getName()] = await deployer.setup(flags, opts as Deployer.Options); + deployOptions[deployer.getName()] = await deployer.setup(flags, opts); } if (flags.interactive && (await this.askToSave())) { @@ -84,9 +84,9 @@ export default class Deploy extends Command { return deployFileExists ? false : true; } - public async readOptions(): Promise { + public async readOptions(): Promise> { if (await fs.fileExists(DEPLOY_OPTIONS_FILE)) { - return (await fs.readJson(DEPLOY_OPTIONS_FILE)) as Deployer.Options; + return (await fs.readJson(DEPLOY_OPTIONS_FILE)) as Record; } else { return {}; }