Skip to content

Commit

Permalink
feat: support sfdx plugins with release notes or changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Dec 17, 2021
1 parent 3e04ccc commit 0d49214
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions messages/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
flags: {
version: 'CLI version or tag for which to display release notes.',
hook: 'This hidden parameter is used in post install or update hooks.',
plugin: 'Plugin name for which to display release notes.',
},
examples: [
`Display release notes for the currently installed CLI version:
Expand Down
21 changes: 17 additions & 4 deletions src/commands/info/releasenotes/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export default class Display extends SfdxCommand {

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

public static args = [
{
name: 'plugin',
description: messages.getMessage('flags.plugin'),
},
];

protected static flagsConfig = {
version: flags.string({
char: 'v',
Expand Down Expand Up @@ -66,9 +73,15 @@ export default class Display extends SfdxCommand {
}

try {
const installedVersion = this.config.pjson.version;
const plugin = (this.args.plugin as string)
? this.config.plugins.filter((p) => p.name === (this.args.plugin as string))[0]
: this.config;

if (!plugin) throw new Error(`No plugin '${this.args.plugin as string}' found`);

const installedVersion = plugin.pjson.version;

const infoConfig = await getInfoConfig(this.config.root);
const infoConfig = await getInfoConfig(plugin.root);

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

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

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

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

if (isHook) {
if (env.getBoolean(HIDE_FOOTER)) {
await Lifecycle.getInstance().emitTelemetry({ eventName: 'FOOTER_HIDDEN' });
} else {
const footer = messages.getMessage('footer', [this.config.bin, releaseNotesPath, HIDE_NOTES, HIDE_FOOTER]);
const footer = messages.getMessage('footer', [plugin.name, releaseNotesPath, HIDE_NOTES, HIDE_FOOTER]);
this.ux.log(marked.parse(footer));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/parseReleaseNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const parseReleaseNotes = (notes: string, version: string, baseUrl: string): mar

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

Expand Down
4 changes: 2 additions & 2 deletions test/commands/info/releasenotes/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('info:releasenotes:display', () => {
}

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

const cmd = new TestDisplay(params, oclifConfigStub);

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

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

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

0 comments on commit 0d49214

Please sign in to comment.