Skip to content

Commit

Permalink
feat: migrate force command from toolbelt
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Feb 23, 2022
1 parent d1f15b6 commit 68ecc16
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/config": "^1",
"@oclif/plugin-help": "^3.3.1",
"@salesforce/command": "^4.1.5",
"@salesforce/core": "^2.29.0",
"@salesforce/kit": "^1.5.17",
Expand Down
84 changes: 84 additions & 0 deletions src/commands/force.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

// This is a doc command
/* istanbul ignore file */

import { SfdxCommand } from '@salesforce/command';
import got from 'got';
import { Help } from '@oclif/plugin-help';
import * as ProxyAgent from 'proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';

const getAsciiSignature = (apiVersion: string): string => `
DX DX DX
DX DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX
DX DX DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX
DX DX DX DX DX
DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX DX DX DX
DX DX DX DX DX DX DX DX DX
DX DX DX DX
DX DX DX DX DX DX
DX DX DX DX DX DX v${apiVersion}
DX DX DX
* Salesforce CLI Release Notes: https://github.com/forcedotcom/cli/tree/main/releasenotes
* Salesforce DX Setup Guide: https://sfdc.co/sfdx_setup_guide
* Salesforce DX Developer Guide: https://sfdc.co/sfdx_dev_guide
* Salesforce CLI Command Reference: https://sfdc.co/sfdx_cli_reference
* Salesforce Extensions for VS Code: https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode
`;

const getCurrentApiVersion = async (): Promise<string> => {
const url = 'https://mdcoverage.secure.force.com/services/apexrest/report';
return `${(
JSON.parse(
(
await got(url, {
agent: { https: ProxyAgent(getProxyForUrl(url)) },
})
).body
) as {
versions: { selected: number };
}
).versions.selected.toString()}.0`;
};

export class ForceCommand extends SfdxCommand {
public static readonly hidden = true;

public async run(): Promise<{ apiVersion: string }> {
const apiVersion = await getCurrentApiVersion();
this.ux.log(getAsciiSignature(apiVersion));
return { apiVersion };
}

// overrides the help so that it shows the help for the `force` topic and not "help" for this command
protected _help(): never {
const help = new Help(this.config);
// We need to include force in the args for topics to be shown
help.showHelp(process.argv.slice(2));
return this.exit(0);
}
}
6 changes: 0 additions & 6 deletions test/nuts/blank.nut.ts

This file was deleted.

36 changes: 36 additions & 0 deletions test/nuts/force.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { expect } from 'chai';

import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';

describe('force command', () => {
let session: TestSession;

before(async () => {
session = await TestSession.create({
project: {
name: 'forceNut',
},
});
});
it('returns an apiVersion in JSON', () => {
const result = execCmd<{ apiVersion: string }>('force --json', { ensureExitCode: 0 }).jsonOutput.result;
expect(result).to.be.an('object').that.has.all.keys('apiVersion');
expect(result.apiVersion).to.match(/^\d{2,}\.0$/);
expect(parseInt(result.apiVersion, 10)).to.be.greaterThan(53);
});
it('executes the cloud/links without JSON', () => {
const result = execCmd('force', { ensureExitCode: 0 }).shellOutput as string;
expect(result).to.include('Salesforce CLI Release Notes');
});

after(async () => {
await session.clean();
});
});
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"compilerOptions": {
"outDir": "lib",
"rootDir": "src",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@oclif/config": ["node_modules/@oclif/config"]
}
},
"include": ["./src/**/*.ts"]
}
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,23 @@
widest-line "^2.0.1"
wrap-ansi "^4.0.0"

"@oclif/plugin-help@^3.3.1":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-3.3.1.tgz#36adb4e0173f741df409bb4b69036d24a53bfb24"
integrity sha512-QuSiseNRJygaqAdABYFWn/H1CwIZCp9zp/PLid6yXvy6VcQV7OenEFF5XuYaCvSARe2Tg9r8Jqls5+fw1A9CbQ==
dependencies:
"@oclif/command" "^1.8.15"
"@oclif/config" "1.18.2"
"@oclif/errors" "1.3.5"
"@oclif/help" "^1.0.1"
chalk "^4.1.2"
indent-string "^4.0.0"
lodash "^4.17.21"
string-width "^4.2.0"
strip-ansi "^6.0.0"
widest-line "^3.1.0"
wrap-ansi "^6.2.0"

"@oclif/screen@^1.0.3", "@oclif/screen@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@oclif/screen/-/screen-1.0.4.tgz#b740f68609dfae8aa71c3a6cab15d816407ba493"
Expand Down

0 comments on commit 68ecc16

Please sign in to comment.