Skip to content

Commit

Permalink
feat: ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
amtrack committed Oct 26, 2024
1 parent 3d516ff commit 6159c65
Show file tree
Hide file tree
Showing 84 changed files with 248 additions and 229 deletions.
2 changes: 1 addition & 1 deletion _templates/plugin/new/index.e2e-spec.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
to: src/plugins/<%= h.changeCase.paramCase(name) %>/index.e2e-spec.ts
---
import assert from 'assert';
import { type Config, <%= h.changeCase.pascalCase(name) %> } from '.';
import { type Config, <%= h.changeCase.pascalCase(name) %> } from './index.js';

describe(<%= h.changeCase.pascalCase(name) %>.name, function() {
let plugin: <%= h.changeCase.pascalCase(name) %>;
Expand Down
2 changes: 1 addition & 1 deletion _templates/plugin/new/index.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
to: src/plugins/<%= h.changeCase.paramCase(name) %>/index.ts
sh: "npx prettier --write 'src/plugins/<%= h.changeCase.paramCase(name) %>/*' 'src/plugins/index.ts'"
---
import { BrowserforcePlugin } from '../../plugin';
import { BrowserforcePlugin } from '../../plugin.js';

const PATHS = {
BASE: 'partnerbt/loginAccessPolicies.apexp'
Expand Down
2 changes: 1 addition & 1 deletion _templates/plugin/new/plugins-index.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ to: src/plugins/index.ts
inject: true
before: export {
---
import { <%= name %> as <%= h.changeCase.camelCase(name) %> } from './<%= h.changeCase.paramCase(name) %>';
import { <%= name %> as <%= h.changeCase.camelCase(name) %> } from './<%= h.changeCase.paramCase(name) %>/index.js';
11 changes: 6 additions & 5 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node

const oclif = require("@oclif/core");
// eslint-disable-next-line node/shebang
async function main() {
const { execute } = await import('@oclif/core');
await execute({ dir: import.meta.url });
}

oclif
.run()
.then(require("@oclif/core/flush"))
.catch(require("@oclif/core/handle"));
await main();
7 changes: 0 additions & 7 deletions messages/browserforce.json

This file was deleted.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0-development",
"description": "sfdx plugin for browser automation",
"author": "Matthias Rolke <[email protected]>",
"type": "module",
"bin": {
"sfdx-browserforce-plugin": "bin/run"
},
Expand All @@ -24,13 +25,9 @@
"ts-node": "10.9.1",
"typescript": "5.2.2"
},
"engines": {
"node": ">=14.0.0"
},
"files": [
"/bin",
"/lib",
"/messages",
"/oclif.manifest.json"
],
"keywords": [
Expand All @@ -52,6 +49,10 @@
"-h"
]
},
"mocha": {
"loader": "ts-node/esm",
"no-warnings": "ExperimentalWarning"
},
"repository": "amtrack/sfdx-browserforce-plugin",
"scripts": {
"build": "rm -rf lib && tsc -p . && oclif manifest",
Expand All @@ -60,7 +61,7 @@
"generate:plugin": "npx hygen plugin new",
"prepack": "yarn build",
"prepare": "yarn build",
"test": "tsc --resolveJsonModule -p test && nyc --reporter=lcov --reporter=text mocha --require ts-node/register \"test/**/*.test.ts\" \"src/**/*.test.ts\"",
"test:e2e": "tsc --resolveJsonModule -p test && 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 \"test/**/*.test.ts\" \"src/**/*.test.ts\"",
"test:e2e": "tsc -p test && mocha --slow 30s --timeout 2m --file test/e2e-setup.ts \"test/**/*.e2e-spec.ts\" \"src/**/*.e2e-spec.ts\""
}
}
6 changes: 3 additions & 3 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const salesforcePrettierConfig = require('@salesforce/prettier-config');
import salesforcePrettierConfig from '@salesforce/prettier-config';

module.exports = {
export default {
...salesforcePrettierConfig,
trailingComma: 'none'
singleQuote: false
};
57 changes: 25 additions & 32 deletions src/browserforce-command.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
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';
import { Browserforce } from './browserforce.js';
import { ConfigParser } from './config-parser.js';
import * as DRIVERS from './plugin.js';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('sfdx-browserforce-plugin', 'browserforce');
const baseFlags = {
'target-org': requiredOrgFlagWithDeprecations,
definitionfile: Flags.string({
char: 'f',
description: 'path to a browserforce state file'
}),
planfile: Flags.string({
char: 'p',
name: 'plan',
description: 'path to a browserforce plan file'
}),
statefile: Flags.string({
char: 's',
name: 'state',
description: '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.'
})
};

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({
char: 'p',
name: 'plan',
summary: messages.getMessage('planFileDescription'),
description: messages.getMessage('planFileDescription')
}),
statefile: Flags.string({
char: 's',
name: 'state',
summary: messages.getMessage('stateFileDescription'),
description: messages.getMessage('stateFileDescription')
})
};
export abstract class BrowserforceCommand<T> extends SfCommand<T> {

protected bf: Browserforce;
protected settings: any[];

public async init(): Promise<void> {
const { flags } = await this.parse(BrowserforceCommand);
await super.init();
const { flags } = await this.parse({
flags: this.ctor.flags,
baseFlags
});
let definition;
if (flags.definitionfile) {
const definitionFileData = await promises.readFile(path.resolve(flags.definitionfile), 'utf8');
Expand All @@ -54,10 +51,6 @@ export class BrowserforceCommand extends SfCommand<unknown> {
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.spinner.stop(err?.message);
if (this.bf) {
Expand Down
2 changes: 1 addition & 1 deletion src/browserforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Org } from '@salesforce/core';
import { type Ux } from '@salesforce/sf-plugins-core';
import pRetry from 'p-retry';
import { Browser, Frame, launch, Page, WaitForOptions } from 'puppeteer';
import { LoginPage } from './pages/login';
import { LoginPage } from './pages/login.js';

const ERROR_DIV_SELECTOR = '#errorTitle';
const ERROR_DIVS_SELECTOR = 'div.errorMsg';
Expand Down
19 changes: 10 additions & 9 deletions src/commands/browserforce/apply.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Messages } from '@salesforce/core';
import { BrowserforceCommand } from '../../browserforce-command';
import { BrowserforceCommand } from '../../browserforce-command.js';

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

export class BrowserforceApply extends BrowserforceCommand {
public static description = messages.getMessage('applyCommandDescription');
type BrowserforceApplyResponse = {
success: boolean;
}

export class BrowserforceApply extends BrowserforceCommand<BrowserforceApplyResponse> {
public static description = 'apply a plan from a definition file';
public static examples = [
`$ <%= config.bin %> <%= command.id %> -f ./config/setup-admin-login-as-any.json --target-org [email protected]
logging in... done
Expand All @@ -17,7 +16,7 @@ export class BrowserforceApply extends BrowserforceCommand {
`
];

public async run(): Promise<unknown> {
public async run(): Promise<BrowserforceApplyResponse> {
const { flags } = await this.parse(BrowserforceApply);
this.log(`Applying definition file ${flags.definitionfile} to org ${flags['target-org'].getUsername()}`);
for (const setting of this.settings) {
Expand Down Expand Up @@ -52,6 +51,8 @@ export class BrowserforceApply extends BrowserforceCommand {
this.log(`[${driver.name}] no action necessary`);
}
}
return { success: true };
return {
success: true
};
}
}
17 changes: 8 additions & 9 deletions src/commands/browserforce/plan.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { writeFile } from 'fs/promises';
import { Messages } from '@salesforce/core';
import * as path from 'path';
import { BrowserforceCommand } from '../../browserforce-command';
import { BrowserforceCommand } from '../../browserforce-command.js';

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

export class BrowserforcePlanCommand extends BrowserforceCommand {
public static description = messages.getMessage('planCommandDescription');
type BrowserforceApplyResponse = {
success: boolean;
}

export class BrowserforcePlanCommand extends BrowserforceCommand<BrowserforceApplyResponse> {
public static description = 'retrieve state and generate plan file';
public static examples = [
`$ <%= config.bin %> <%= command.id %> -f ./config/setup-admin-login-as-any.json --target-org [email protected]
logging in... done
Expand All @@ -19,7 +18,7 @@ export class BrowserforcePlanCommand extends BrowserforceCommand {
`
];

public async run(): Promise<unknown> {
public async run(): Promise<BrowserforceApplyResponse> {
const { flags } = await this.parse(BrowserforcePlanCommand);
this.log(
`Generating plan with definition file ${flags.definitionfile} from org ${flags['target-org'].getUsername()}`
Expand Down Expand Up @@ -58,6 +57,6 @@ export class BrowserforcePlanCommand extends BrowserforceCommand {
await writeFile(path.resolve(flags.planfile), JSON.stringify(plan, null, 2));
this.spinner.stop();
}
return { success: true, plan };
return { success: true };
}
}
2 changes: 1 addition & 1 deletion src/config-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserforcePlugin } from './plugin';
import { BrowserforcePlugin } from './plugin.js';

type Drivers = {
[key: string]: typeof BrowserforcePlugin;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Org } from '@salesforce/core';
import { Browserforce } from './browserforce';
import { deepDiff } from './plugins/utils';
import { Browserforce } from './browserforce.js';
import { deepDiff } from './plugins/utils.js';

export abstract class BrowserforcePlugin {
protected browserforce: Browserforce;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/activity-settings/index.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { ActivitySettings } from '.';
import { ActivitySettings } from './index.js';

describe(ActivitySettings.name, function () {
let plugin: ActivitySettings;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/activity-settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserforcePlugin } from '../../plugin';
import { BrowserforcePlugin } from '../../plugin.js';

const PATHS = {
BASE: 'setup/activitiesSetupPage.apexp'
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/communities/index.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { Communities } from '.';
import { Communities } from './index.js';

describe.skip(Communities.name, function () {
let plugin: Communities;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/communities/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserforcePlugin } from '../../plugin';
import { BrowserforcePlugin } from '../../plugin.js';

const PATHS = {
BASE: '_ui/networks/setup/NetworkSettingsPage'
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/company-information/index.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { CompanyInformation, Config } from '.';
import { CompanyInformation, Config } from './index.js';

describe(CompanyInformation.name, function () {
let plugin: CompanyInformation;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/company-information/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserforcePlugin } from '../../plugin';
import { BrowserforcePlugin } from '../../plugin.js';

const PATHS = (orgId: string) => ({
BASE: `/${orgId}/e`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { type Config, CustomerPortalAvailableCustomObjects } from '.';
import { type Config, CustomerPortalAvailableCustomObjects } from './index.js';

type T = {
description: string;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/customer-portal/available-custom-objects/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Record } from 'jsforce';
import { BrowserforcePlugin } from '../../../plugin';
import { semanticallyCleanObject } from '../../utils';
import { BrowserforcePlugin } from '../../../plugin.js';
import { semanticallyCleanObject } from '../../utils.js';

const SELECTORS = {
SAVE_BUTTON: 'input[name="save"]',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/customer-portal/enabled/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { CustomerPortalEnable as CustomerPortalEnabled } from '.';
import { CustomerPortalEnable as CustomerPortalEnabled } from './index.js';

type T = {
description: string;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/customer-portal/enabled/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserforcePlugin } from '../../../plugin';
import { BrowserforcePlugin } from '../../../plugin.js';

const PATHS = {
EDIT_VIEW: '_ui/core/portal/CustomerSuccessPortalSetup/e'
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/customer-portal/index.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import assert from 'assert';
import * as child from 'child_process';
import { fileURLToPath } from 'node:url';
import * as path from 'path';
import { CustomerPortalAvailableCustomObjects } from './available-custom-objects';
import { CustomerPortalEnable } from './enabled';
import { CustomerPortalSetup } from './portals';
import { CustomerPortalAvailableCustomObjects } from './available-custom-objects/index.js';
import { CustomerPortalEnable } from './enabled/index.js';
import { CustomerPortalSetup } from './portals/index.js';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

describe('CustomerPortal', () => {
describe(CustomerPortalEnable.name, function () {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/customer-portal/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { CustomerPortal } from '.';
import { CustomerPortal } from './index.js';

const tests = [
{
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/customer-portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BrowserforcePlugin } from '../../plugin';
import { BrowserforcePlugin } from '../../plugin.js';
import {
CustomerPortalAvailableCustomObjects,
Config as CustomerPortalAvailableCustomObjectsConfig
} from './available-custom-objects';
import { CustomerPortalEnable, Config as CustomerPortalEnableConfig } from './enabled';
import { CustomerPortalSetup, Config as CustomerPortalSetupConfig } from './portals';
} from './available-custom-objects/index.js';
import { CustomerPortalEnable, Config as CustomerPortalEnableConfig } from './enabled/index.js';
import { CustomerPortalSetup, Config as CustomerPortalSetupConfig } from './portals/index.js';

type Config = {
enabled?: CustomerPortalEnableConfig;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/customer-portal/portals/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { CustomerPortalSetup } from '.';
import { CustomerPortalSetup } from './index.js';

const tests = [
{
Expand Down
Loading

0 comments on commit 6159c65

Please sign in to comment.