Skip to content

Commit c1a84ea

Browse files
committed
feat: support sfdx plugins with release notes or changelog
1 parent 3e04ccc commit c1a84ea

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

messages/display.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
flags: {
44
version: 'CLI version or tag for which to display release notes.',
55
hook: 'This hidden parameter is used in post install or update hooks.',
6+
plugin: 'Plugin name for which to display release notes.',
67
},
78
examples: [
89
`Display release notes for the currently installed CLI version:

src/commands/info/releasenotes/display.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export default class Display extends SfdxCommand {
3939

4040
public static examples = messages.getMessage('examples', [Display.helpers.join(', ')]).split(os.EOL);
4141

42+
public static args = [
43+
{
44+
name: 'plugin',
45+
description: messages.getMessage('flags.plugin'),
46+
},
47+
];
48+
4249
protected static flagsConfig = {
4350
version: flags.string({
4451
char: 'v',
@@ -66,9 +73,15 @@ export default class Display extends SfdxCommand {
6673
}
6774

6875
try {
69-
const installedVersion = this.config.pjson.version;
76+
const plugin = (this.args.plugin as string)
77+
? this.config.plugins.filter((p) => p.name === (this.args.plugin as string))[0]
78+
: this.config;
79+
80+
if (!plugin) throw new Error(`No plugin '${this.args.plugin as string}' found`);
81+
82+
const installedVersion = plugin.pjson.version;
7083

71-
const infoConfig = await getInfoConfig(this.config.root);
84+
const infoConfig = await getInfoConfig(plugin.root);
7285

7386
const { distTagUrl, releaseNotesPath, releaseNotesFilename } = infoConfig.releasenotes;
7487

@@ -86,15 +99,15 @@ export default class Display extends SfdxCommand {
8699
renderer: new TerminalRenderer({ emoji: false }),
87100
});
88101

89-
this.ux.log(marked.parse(`# Release notes for '${this.config.bin}':`));
102+
this.ux.log(marked.parse(`# Release notes for '${plugin.name}':`));
90103

91104
this.ux.log(marked.parser(tokens));
92105

93106
if (isHook) {
94107
if (env.getBoolean(HIDE_FOOTER)) {
95108
await Lifecycle.getInstance().emitTelemetry({ eventName: 'FOOTER_HIDDEN' });
96109
} else {
97-
const footer = messages.getMessage('footer', [this.config.bin, releaseNotesPath, HIDE_NOTES, HIDE_FOOTER]);
110+
const footer = messages.getMessage('footer', [plugin.name, releaseNotesPath, HIDE_NOTES, HIDE_FOOTER]);
98111
this.ux.log(marked.parse(footer));
99112
}
100113
}

src/shared/parseReleaseNotes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const parseReleaseNotes = (notes: string, version: string, baseUrl: string): mar
2121

2222
const tokens = parsed.filter((token) => {
2323
// TODO: Could make header depth (2) a setting in oclif.info.releasenotes
24-
if (token.type === 'heading' && token.depth === 2) {
24+
if (token.type === 'heading' && token.depth <= 2) {
2525
if (regexp.exec(token.text)) {
2626
found = true;
2727

test/commands/info/releasenotes/display.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('info:releasenotes:display', () => {
4646
}
4747

4848
const runDisplayCmd = async (params: string[]) => {
49-
oclifConfigStub.bin = 'sfdx';
49+
oclifConfigStub.name = 'sfdx-cli';
5050

5151
const cmd = new TestDisplay(params, oclifConfigStub);
5252

@@ -166,7 +166,7 @@ describe('info:releasenotes:display', () => {
166166
it('logs logs a header with cli bin', async () => {
167167
await runDisplayCmd([]);
168168

169-
expect(uxLogStub.args[0][0]).to.contain("# Release notes for 'sfdx':");
169+
expect(uxLogStub.args[0][0]).to.contain("# Release notes for 'sfdx-cli':");
170170
});
171171

172172
it('calls getReleaseNotes with passed version', async () => {

0 commit comments

Comments
 (0)