Skip to content

Commit 7206f75

Browse files
authored
Save deploy options to project-deploy-options.json (#73)
* feat: allow users to save project-deploy-settings.json * chore: bump plugin-project-utils * chore: rename variable
1 parent cf55c64 commit 7206f75

File tree

3 files changed

+76
-20
lines changed

3 files changed

+76
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@oclif/core": "^0.5.19",
99
"@salesforce/core": "^3.1.1-v3.1",
10-
"@salesforce/plugin-project-utils": "^0.0.5",
10+
"@salesforce/plugin-project-utils": "^0.0.7",
1111
"tslib": "^2"
1212
},
1313
"devDependencies": {
@@ -18,7 +18,7 @@
1818
"@salesforce/dev-scripts": "^0.9.14",
1919
"@salesforce/plugin-command-reference": "^1.3.0",
2020
"@salesforce/plugin-functions": "^0.2.13",
21-
"@salesforce/plugin-project-org": "^0.0.1",
21+
"@salesforce/plugin-project-org": "^0.0.2",
2222
"@salesforce/prettier-config": "^0.0.2",
2323
"@salesforce/ts-sinon": "1.3.18",
2424
"@typescript-eslint/eslint-plugin": "^4.2.0",

src/commands/project/deploy.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
import { Command, Flags } from '@oclif/core';
99
import { fs, Messages } from '@salesforce/core';
1010
import { Env } from '@salesforce/kit';
11-
import { Deployable, Deployer, generateTableChoices, Prompter } from '@salesforce/plugin-project-utils';
11+
import {
12+
Deployable,
13+
Deployer,
14+
generateTableChoices,
15+
ProjectDeployOptions,
16+
Prompter,
17+
} from '@salesforce/plugin-project-utils';
1218

1319
Messages.importMessagesDirectory(__dirname);
1420

1521
const messages = Messages.loadMessages('@salesforce/plugin-project', 'project.deploy');
1622

23+
export const DEPLOY_OPTIONS_FILE = 'project-deploy-options.json';
24+
1725
export default class ProjectDeploy extends Command {
1826
public static summary = messages.getMessage('summary');
1927
public static description = messages.getMessage('description');
@@ -31,23 +39,41 @@ export default class ProjectDeploy extends Command {
3139
const { flags } = await this.parse(ProjectDeploy);
3240

3341
flags.interactive = await this.isInteractive(flags.interactive);
42+
const options = await this.readOptions();
3443

3544
this.log('Analyzing project');
3645

37-
let deployers = (await this.config.runHook('project:findDeployers', {})) as Deployer[];
46+
if (!flags.interactive) {
47+
this.log(`Using options found in ${DEPLOY_OPTIONS_FILE}`);
48+
}
49+
50+
let deployers = (await this.config.runHook('project:findDeployers', options)) as Deployer[];
3851
deployers = deployers.reduce((x, y) => x.concat(y), [] as Deployer[]);
3952

4053
if (deployers.length === 0) {
4154
this.log('Found nothing in the project to deploy');
4255
} else {
43-
deployers = await this.selectDeployers(deployers);
56+
if (flags.interactive) {
57+
deployers = await this.selectDeployers(deployers);
58+
}
4459

4560
if (deployers.length === 0) {
4661
this.log('Nothing was selected to deploy.');
4762
}
4863

64+
const deployOptions: ProjectDeployOptions = {};
65+
for (const deployer of deployers) {
66+
const opts = options[deployer.getName()] ?? {};
67+
deployOptions[deployer.getName()] = await deployer.setup(flags, opts);
68+
}
69+
70+
if (flags.interactive && (await this.askToSave())) {
71+
await fs.writeJson(DEPLOY_OPTIONS_FILE, deployOptions, { space: 2 });
72+
this.log();
73+
this.log(`Your deploy options have been saved to ${DEPLOY_OPTIONS_FILE}`);
74+
}
75+
4976
for (const deployer of deployers) {
50-
await deployer.setup(flags);
5177
await deployer.deploy();
5278
}
5379
}
@@ -59,10 +85,28 @@ export default class ProjectDeploy extends Command {
5985
*/
6086
public async isInteractive(interactive: boolean): Promise<boolean> {
6187
if (interactive) return true;
62-
const deployFileExists = await fs.fileExists('project-deploy-options.json');
88+
const deployFileExists = await fs.fileExists(DEPLOY_OPTIONS_FILE);
6389
return deployFileExists ? false : true;
6490
}
6591

92+
public async readOptions(): Promise<ProjectDeployOptions> {
93+
if (await fs.fileExists(DEPLOY_OPTIONS_FILE)) {
94+
return (await fs.readJson(DEPLOY_OPTIONS_FILE)) as ProjectDeployOptions;
95+
} else {
96+
return {};
97+
}
98+
}
99+
100+
public async askToSave(): Promise<boolean> {
101+
const prompter = new Prompter();
102+
const { save } = await prompter.prompt<{ save: boolean }>({
103+
name: 'save',
104+
message: 'Would you like to save these deploy options for future runs?',
105+
type: 'confirm',
106+
});
107+
return save;
108+
}
109+
66110
public async selectDeployers(deployers: Deployer[]): Promise<Deployer[]> {
67111
const deployables: Deployable[] = deployers.reduce((x, y) => x.concat(y.deployables), [] as Deployable[]);
68112
const columns = { name: 'APP OR PACKAGE', type: 'TYPE', path: 'PATH' };

yarn.lock

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,10 @@
633633
is-wsl "^2.1.1"
634634
tslib "^2.0.0"
635635

636-
"@oclif/core@^0.5.19":
637-
version "0.5.19"
638-
resolved "https://registry.npmjs.org/@oclif/core/-/core-0.5.19.tgz#5d4fdaa85f4b40be5ef2ddb5ff8fa85a49bb656d"
639-
integrity sha512-JX/VB7zyEMnIm8dWilc7hcxLDmZg0gKDeI3pB0zJUsWKW7rGVHnhFSd5NP0hY3TIilSnC64e6h0xKMM2HDDuVQ==
636+
"@oclif/core@^0.5.18":
637+
version "0.5.20"
638+
resolved "https://registry.npmjs.org/@oclif/core/-/core-0.5.20.tgz#d5bdeb212389547130cadd2067ba447c0c8202c1"
639+
integrity sha512-J90/MgqivtkcvB1pSSP8ohHnTjspRoc0fKDlMLjSpMHZ0WxoH1lY2B4tOMnOYJ7ibJY1SKhoSPpIDdXGZcPm1g==
640640
dependencies:
641641
"@oclif/linewrap" "^1.0.0"
642642
chalk "^4.1.0"
@@ -656,10 +656,10 @@
656656
widest-line "^3.1.0"
657657
wrap-ansi "^7.0.0"
658658

659-
"@oclif/core@^0.5.7":
660-
version "0.5.14"
661-
resolved "https://registry.npmjs.org/@oclif/core/-/core-0.5.14.tgz#eadb9de79cd3cd5f7d1970e3fa37a75d22ec4e58"
662-
integrity sha512-UvKAxCX3sV2kAq2rar0+G/7SGlPYG78R99nHjSCarMVk+KAVle+8ZV8OXIs8OHfnHWRKZMuc1Q5sdG2JIRiIZQ==
659+
"@oclif/core@^0.5.19":
660+
version "0.5.19"
661+
resolved "https://registry.npmjs.org/@oclif/core/-/core-0.5.19.tgz#5d4fdaa85f4b40be5ef2ddb5ff8fa85a49bb656d"
662+
integrity sha512-JX/VB7zyEMnIm8dWilc7hcxLDmZg0gKDeI3pB0zJUsWKW7rGVHnhFSd5NP0hY3TIilSnC64e6h0xKMM2HDDuVQ==
663663
dependencies:
664664
"@oclif/linewrap" "^1.0.0"
665665
chalk "^4.1.0"
@@ -1090,14 +1090,16 @@
10901090
open "8.2.0"
10911091
tslib "^2"
10921092

1093-
"@salesforce/plugin-project-org@^0.0.1":
1094-
version "0.0.1"
1095-
resolved "https://registry.npmjs.org/@salesforce/plugin-project-org/-/plugin-project-org-0.0.1.tgz#6a2fe2968ae5f87e3f165b359072fb63efc306c4"
1096-
integrity sha512-B6hvwjLQEM3Fvm3XYb4e2YQs6iJSTB3rKCeBWFEsw1c1BgISw5CnxYkvqeCaimHDrkFhMiKGy8/VgXKOlO4t1A==
1093+
"@salesforce/plugin-project-org@^0.0.2":
1094+
version "0.0.2"
1095+
resolved "https://registry.npmjs.org/@salesforce/plugin-project-org/-/plugin-project-org-0.0.2.tgz#369b4a65153a58d8f791b72a68187b7006816445"
1096+
integrity sha512-hDYMBXIT+HIk/GeE25Q+7m790ku6AT1YT+KsPrRwsvzrSJWZI75xqX/KCYfTZagAjiAxmuhq1UT0201rcKbzaQ==
10971097
dependencies:
1098-
"@oclif/core" "^0.5.7"
1098+
"@oclif/core" "^0.5.18"
10991099
"@salesforce/core" "3.1.0-v3.0"
1100+
"@salesforce/plugin-project-utils" "^0.0.5"
11001101
"@salesforce/source-deploy-retrieve" "^2.1.3"
1102+
chalk "^4.1.1"
11011103
cli-ux "^5.5.1"
11021104
tslib "^2"
11031105

@@ -1111,6 +1113,16 @@
11111113
cli-ux "^5.6.2"
11121114
inquirer "^8.1.1"
11131115

1116+
"@salesforce/plugin-project-utils@^0.0.7":
1117+
version "0.0.7"
1118+
resolved "https://registry.npmjs.org/@salesforce/plugin-project-utils/-/plugin-project-utils-0.0.7.tgz#e7b1427b7579255d54bdbf0e8795292e5e6e1e6e"
1119+
integrity sha512-sMEFpOELbZ2RP+zaYlasGgdVV/lorx8eh3j6lgJVVzXoxJntSEA188Ejnx2o8F0qTwIpwzgltkoeXlWiFbJqkQ==
1120+
dependencies:
1121+
"@salesforce/kit" "^1.5.8"
1122+
"@salesforce/ts-types" "^1.5.13"
1123+
cli-ux "^5.6.2"
1124+
inquirer "^8.1.1"
1125+
11141126
"@salesforce/prettier-config@^0.0.2":
11151127
version "0.0.2"
11161128
resolved "https://registry.yarnpkg.com/@salesforce/prettier-config/-/prettier-config-0.0.2.tgz#ded39bf7cb75238edc9db6dd093649111350f8bc"

0 commit comments

Comments
 (0)