Skip to content

Commit

Permalink
Merge pull request #588 from amtrack/refactor/sf-plugin-style
Browse files Browse the repository at this point in the history
  • Loading branch information
amtrack committed Oct 27, 2023
2 parents b255d55 + 3425175 commit 5861381
Show file tree
Hide file tree
Showing 69 changed files with 2,537 additions and 2,722 deletions.
4 changes: 0 additions & 4 deletions .prettierrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Create a scratch org and try it yourself:

```console
sf org create scratch -f config/project-scratch-def.json -a browserforce-dev -d
BROWSER_DEBUG=true ./bin/run browserforce:apply -f src/plugins/admins-can-log-in-as-any-user/enable.json -u browserforce-dev
BROWSER_DEBUG=true ./bin/run browserforce:apply -f src/plugins/admins-can-log-in-as-any-user/disable.json -u browserforce-dev
BROWSER_DEBUG=true ./bin/run browserforce apply -f src/plugins/admins-can-log-in-as-any-user/enable.json -u browserforce-dev
BROWSER_DEBUG=true ./bin/run browserforce apply -f src/plugins/admins-can-log-in-as-any-user/disable.json -u browserforce-dev
```

Now it's your turn!
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Actions Status](https://github.com/amtrack/sfdx-browserforce-plugin/workflows/Test%20and%20Release/badge.svg)](https://github.com/amtrack/sfdx-browserforce-plugin/actions)

Unlike the [Scratch Org Definition Configuration](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_def_file.htm) which can only be used **on the creation of a scratch org** (`sfdx force:org:create -f config/scratch-def.json`),
the _Browserforce Configuration_ allows to "shape" **any org**, (e.g. scratch org, sandbox or production org) with **similar preferences and unofficial preferences** that are not (yet) available in the _Scratch Org Definition Configuration_ or as _Metadata_ (`sf browserforce:apply -f config/setup-admin-login-as-any.json -u [email protected]`).
the _Browserforce Configuration_ allows to "shape" **any org**, (e.g. scratch org, sandbox or production org) with **similar preferences and unofficial preferences** that are not (yet) available in the _Scratch Org Definition Configuration_ or as _Metadata_ (`sf browserforce apply -f config/setup-admin-login-as-any.json -u [email protected]`).

Further benefits:

Expand Down Expand Up @@ -49,14 +49,14 @@ $ sfdx-browserforce browserforce -h
browser automation

USAGE
$ sfdx-browserforce-plugin browserforce:COMMAND
$ sfdx-browserforce-plugin browserforce COMMAND

COMMANDS
browserforce:apply apply a plan from a definition file
browserforce:plan retrieve state and generate plan file
browserforce apply apply a plan from a definition file
browserforce plan retrieve state and generate plan file
```

Both the `browserforce:apply` and `browserforce:plan` commands expect a config file and a target username or alias for the org.
Both the `browserforce apply` and `browserforce plan` commands expect a config file and a target username or alias for the org.

# Example

Expand All @@ -80,7 +80,7 @@ Tip: If you use _Visual Studio Code_, you can leverage tab completion to build t
Next apply the config:

```console
$ sf browserforce:apply -f ./config/setup-admin-login-as-any.json --targetusername [email protected]
$ sf browserforce apply -f ./config/setup-admin-login-as-any.json --target-org [email protected]
logging in... done
Applying definition file ./config/setup-admin-login-as-any.json to org [email protected]
[Security] retrieving state... done
Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
},
"dependencies": {
"@mdapi-issues/listmetadata-standardvalueset": "2.0.3",
"@salesforce/command": "5.2.16",
"json-merge-patch": "1.0.2",
"@salesforce/sf-plugins-core": "4.0.0",
"p-retry": "4.6.2",
"puppeteer": "19.2.0",
"tslib": "2.4.0"
"puppeteer": "19.2.0"
},
"devDependencies": {
"@types/mocha": "10.0.3",
"@types/node": "18.18.7",
"@salesforce/dev-config": "4.1.0",
"@salesforce/prettier-config": "0.0.3",
"@types/mocha": "10.0.2",
"@types/node": "18.18.5",
"mocha": "10.2.0",
"nyc": "15.1.0",
"oclif": "4.0.3",
"oclif": "4.0.2",
"prettier": "3.0.3",
"ts-node": "10.9.1",
"typescript": "5.2.2"
},
Expand All @@ -39,7 +40,8 @@
],
"license": "MIT",
"oclif": {
"bin": "sfdx-browserforce-plugin",
"bin": "sf",
"topicSeparator": " ",
"commands": "./lib/commands",
"topics": {
"browserforce": {
Expand All @@ -58,7 +60,7 @@
"generate:plugin": "npx hygen plugin new",
"prepack": "yarn build",
"prepare": "yarn build",
"test": "nyc --reporter=lcov --reporter=text mocha --require ts-node/register \"test/**/*.test.ts\" \"src/**/*.test.ts\"",
"test:e2e": "mocha --require ts-node/register --slow 30s --timeout 2m --file test/e2e-setup.ts \"test/**/*.e2e-spec.ts\" \"src/**/*.e2e-spec.ts\""
"test": "tsc -p test && nyc --reporter=lcov --reporter=text mocha --require ts-node/register \"test/**/*.test.ts\" \"src/**/*.test.ts\"",
"test:e2e": "tsc -p test && mocha --require ts-node/register --slow 30s --timeout 2m --file test/e2e-setup.ts \"test/**/*.e2e-spec.ts\" \"src/**/*.e2e-spec.ts\""
}
}
6 changes: 6 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const salesforcePrettierConfig = require('@salesforce/prettier-config');

module.exports = {
...salesforcePrettierConfig,
trailingComma: 'none'
};
53 changes: 26 additions & 27 deletions src/browserforce-command.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { Flags, SfCommand, Ux, requiredOrgFlagWithDeprecations } from '@salesforce/sf-plugins-core';
import { promises } from 'fs';
import * as path from 'path';
import { Browserforce } from './browserforce';
import { ConfigParser } from './config-parser';
import * as DRIVERS from './plugins';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages(
'sfdx-browserforce-plugin',
'browserforce'
);
const messages = Messages.loadMessages('sfdx-browserforce-plugin', 'browserforce');

export class BrowserforceCommand extends SfdxCommand {
protected static requiresUsername = true;

protected static flagsConfig = {
definitionfile: flags.string({
export class BrowserforceCommand extends SfCommand<unknown> {
public static readonly flags = {
'target-org': requiredOrgFlagWithDeprecations,
definitionfile: Flags.string({
char: 'f',
summary: messages.getMessage('definitionFileDescription'),
description: messages.getMessage('definitionFileDescription')
}),
planfile: flags.string({
planfile: Flags.string({
char: 'p',
name: 'plan',
summary: messages.getMessage('planFileDescription'),
description: messages.getMessage('planFileDescription')
}),
statefile: flags.string({
statefile: Flags.string({
char: 's',
name: 'state',
summary: messages.getMessage('stateFileDescription'),
description: messages.getMessage('stateFileDescription')
})
};
Expand All @@ -36,35 +35,35 @@ export class BrowserforceCommand extends SfdxCommand {
protected settings: any[];

public async init(): Promise<void> {
const { flags } = await this.parse(BrowserforceCommand);
await super.init();
const definitionFileData = await promises.readFile(
path.resolve(this.flags.definitionfile),
'utf8'
);
let definition;
try {
definition = JSON.parse(definitionFileData);
} catch (err) {
throw new Error('Failed parsing definitionfile');
if (flags.definitionfile) {
const definitionFileData = await promises.readFile(path.resolve(flags.definitionfile), 'utf8');
try {
definition = JSON.parse(definitionFileData);
} catch (err) {
throw new Error('Failed parsing definitionfile');
}
}
// TODO: use require.resolve to dynamically load plugins from npm packages
this.settings = ConfigParser.parse(DRIVERS, definition);
this.bf = new Browserforce(this.org, this.ux);
this.ux.startSpinner('logging in');
this.bf = new Browserforce(flags['target-org'], new Ux({ jsonEnabled: this.jsonEnabled() }));
this.spinner.start('logging in');
await this.bf.login();
this.ux.stopSpinner();
this.spinner.stop();
}

public async run(): Promise<unknown> {
throw new Error('BrowserforceCommand should not be run directly');
}

public async finally(err: Error): Promise<void> {
this.ux.stopSpinner();
public async finally(err?: Error): Promise<void> {
this.spinner.stop(err?.message);
if (this.bf) {
this.ux.startSpinner('logging out');
this.spinner.start('logging out');
await this.bf.logout();
this.ux.stopSpinner();
this.spinner.stop();
}
}
}
Loading

0 comments on commit 5861381

Please sign in to comment.