Skip to content

Commit a8da2e7

Browse files
committed
feat: add --dry-run flag to apply command
The probably unused plan command and related flags on the apply command like --planfile and --statefile have been removed in favor of a --dry-run flag on the apply command. BREAKING CHANGE: The plan command has been removed. Use "apply --dry-run" instead.
1 parent c10f700 commit a8da2e7

6 files changed

Lines changed: 25 additions & 90 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Apply the config:
4444
```console
4545
$ sf browserforce apply -f ./config/currency.json --target-org myOrg@example.com
4646
logging in... done
47-
Applying definition file ./config/currency.json to org myOrg@example.com
47+
Applying config file ./config/currency.json to org myOrg@example.com
4848
[CompanyInformation] retrieving state... done
4949
[CompanyInformation] changing 'defaultCurrencyIsoCode' to '"English (South Africa) - ZAR"'... done
5050
logging out... done

src/browserforce-command.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@ export abstract class BrowserforceCommand<T> extends SfCommand<T> {
1212
'target-org': Flags.requiredOrg(),
1313
definitionfile: Flags.string({
1414
char: 'f',
15-
description: 'path to a browserforce state file',
15+
description: 'path to a browserforce config file',
1616
}),
17-
planfile: Flags.string({
18-
char: 'p',
19-
name: 'plan',
20-
description: 'path to a browserforce plan file',
21-
}),
22-
statefile: Flags.string({
23-
char: 's',
24-
name: 'state',
25-
description:
26-
'path to a browserforce definition file\nThe schema is similar to the scratch org definition file.\nSee https://github.com/amtrack/sfdx-browserforce-plugin#supported-org-preferences for supported values.',
17+
'dry-run': Flags.boolean({
18+
char: 'd',
19+
description: 'dry run',
20+
env: 'BROWSERFORCE_DRY_RUN',
2721
}),
2822
};
2923
protected bf: Browserforce;
@@ -40,7 +34,7 @@ export abstract class BrowserforceCommand<T> extends SfCommand<T> {
4034
try {
4135
definition = JSON.parse(definitionFileData);
4236
} catch (err) {
43-
throw new Error('Failed parsing definitionfile');
37+
throw new Error('Failed parsing config file');
4438
}
4539
}
4640
handleDeprecations(definition);

src/commands/browserforce/apply.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ type BrowserforceApplyResponse = {
55
};
66

77
export class BrowserforceApply extends BrowserforceCommand<BrowserforceApplyResponse> {
8-
public static description = 'apply a plan from a definition file';
8+
public static description = 'apply a plan from a config file';
99
public static examples = [
1010
`$ <%= config.bin %> <%= command.id %> -f ./config/currency.json --target-org myOrg@example.com
1111
logging in... done
12-
Applying definition file ./config/currency.json to org myOrg@example.com
12+
Applying config file ./config/currency.json to org myOrg@example.com
1313
[CompanyInformation] retrieving state... done
1414
[CompanyInformation] changing 'defaultCurrencyIsoCode' to '"English (South Africa) - ZAR"'... done
1515
logging out... done
@@ -18,7 +18,7 @@ export class BrowserforceApply extends BrowserforceCommand<BrowserforceApplyResp
1818

1919
public async run(): Promise<BrowserforceApplyResponse> {
2020
const { flags } = await this.parse(BrowserforceApply);
21-
this.log(`Applying definition file ${flags.definitionfile} to org ${flags['target-org'].getUsername()}`);
21+
this.log(`Applying config file ${flags.definitionfile} to org ${flags['target-org'].getUsername()}`);
2222
for (const setting of this.settings) {
2323
const driver = setting.Driver;
2424
const instance = new driver(this.bf);
@@ -32,21 +32,24 @@ export class BrowserforceApply extends BrowserforceCommand<BrowserforceApplyResp
3232
}
3333
this.spinner.stop();
3434
const diff = instance.diff(state, setting.value);
35+
const action = flags['dry-run'] ? 'would change' : 'changing';
3536
if (diff !== undefined) {
3637
this.spinner.start(
3738
`[${driver.name}] ${Object.keys(diff)
3839
.map((key) => {
39-
return `changing '${key}' to '${JSON.stringify(diff[key])}'`;
40+
return `${action} '${key}' to '${JSON.stringify(diff[key])}'`;
4041
})
4142
.join('\n')}`,
4243
);
43-
try {
44-
await instance.apply(diff);
45-
} catch (err) {
46-
this.spinner.stop('failed');
47-
throw err;
44+
if (!flags['dry-run']) {
45+
try {
46+
await instance.apply(diff);
47+
} catch (err) {
48+
this.spinner.stop('failed');
49+
throw err;
50+
}
51+
this.spinner.stop();
4852
}
49-
this.spinner.stop();
5053
} else {
5154
this.log(`[${driver.name}] no action necessary`);
5255
}

src/commands/browserforce/plan.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/plugins/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"$id": "https://github.com/amtrack/sfdx-browserforce-plugin/src/plugins/schema.json",
4-
"title": "Browserforce Definition Configuration",
5-
"description": "The browserforce definition file contains the configuration values that defines browser automation tasks for Salesforce orgs.",
4+
"title": "Browserforce Configuration",
5+
"description": "The browserforce config file contains the configuration values that defines browser automation tasks for Salesforce orgs.",
66
"type": "object",
77
"properties": {
88
"settings": {

test/config-parser.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as DRIVERS from '../src/plugins/index.js';
44

55
describe('ConfigParser', () => {
66
describe('parse()', () => {
7-
it('should parse a valid definition file', () => {
7+
it('should parse a valid config file', () => {
88
const definition = {
99
settings: {
1010
security: {},
@@ -13,7 +13,7 @@ describe('ConfigParser', () => {
1313
const result = ConfigParser.parse(DRIVERS, definition);
1414
assert.deepStrictEqual(result[0].Driver.name, 'Security');
1515
});
16-
it('should fail parsing an invalid definition file', () => {
16+
it('should fail parsing an invalid config file', () => {
1717
const definition = {
1818
foo: {
1919
bar: {
@@ -27,7 +27,7 @@ describe('ConfigParser', () => {
2727
ConfigParser.parse(DRIVERS, anonymousDefinition);
2828
}, /Missing 'settings' attribute in definition:/);
2929
});
30-
it('should fail parsing a definition file with an invalid plugin', () => {
30+
it('should fail parsing a config file with an invalid plugin', () => {
3131
const definition = {
3232
settings: {
3333
foo: {

0 commit comments

Comments
 (0)