Skip to content

Commit

Permalink
fix: move command force to plugin-source (#451)
Browse files Browse the repository at this point in the history
* fix: move command force to plugin-source

@W-10847992@

* chore: add force.nuts.ts
  • Loading branch information
peternhale authored Mar 16, 2022
1 parent 3325350 commit 5da7884
Show file tree
Hide file tree
Showing 6 changed files with 612 additions and 14 deletions.
6 changes: 6 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
{
"command": "force",
"plugin": "@salesforce/plugin-source",
"flags": ["json", "loglevel"],
"alias": []
},
{
"command": "force:mdapi:beta:convert",
"plugin": "@salesforce/plugin-source",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/config": "^1.18.2",
"@oclif/plugin-help": "^3.3.1",
"@salesforce/command": "^4.2.2",
"@salesforce/core": "^2.35.0",
"@salesforce/source-deploy-retrieve": "^5.12.2",
"@salesforce/source-tracking": "^1.1.3",
"chalk": "^4.1.2",
"cli-ux": "^5.6.3",
"got": "^11.8.3",
"open": "^8.4.0",
"proxy-agent": "^5.0.0",
"proxy-from-env": "^1.1.0",
"tslib": "^2"
},
"devDependencies": {
Expand All @@ -31,6 +35,7 @@
"@types/archiver": "^5.1.1",
"@types/debug": "^4.1.7",
"@types/jsforce": "^1.9.39",
"@types/proxy-from-env": "^1.0.1",
"@types/shelljs": "^0.8.11",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
Expand Down
89 changes: 89 additions & 0 deletions src/commands/force.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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';
import { ConfigAggregator } from '@salesforce/core';

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 apiFromConfig = ConfigAggregator.getValue('apiVersion').value as string;
if (apiFromConfig) {
return apiFromConfig;
}
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);
}
}
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();
});
});
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"rootDir": "src",
"baseUrl": ".",
"paths": {
"@oclif/config": ["node_modules/@oclif/config"],
"@salesforce/kit": ["node_modules/@salesforce/kit"],
"@salesforce/source-deploy-retrieve": ["node_modules/@salesforce/source-deploy-retrieve"],
"@salesforce/core": ["node_modules/@salesforce/core"]
}
},
"skipLibCheck": true
},
"include": ["./src/**/*.ts"]
}
Loading

0 comments on commit 5da7884

Please sign in to comment.