Skip to content

Commit

Permalink
fix: render cmd and flag sum/desc ejs template (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 authored May 16, 2023
1 parent 9faf2b1 commit 293c4f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@salesforce/dev-scripts": "^2.0.4",
"@salesforce/plugin-login": "^1.1.15",
"@salesforce/prettier-config": "^0.0.2",
"@types/ejs": "^3.1.2",
"@types/fs-extra": "^9.0.13",
"@types/lodash.uniqby": "^4.7.6",
"@typescript-eslint/eslint-plugin": "^4.2.0",
Expand Down Expand Up @@ -104,4 +105,4 @@
"access": "public"
},
"main": "lib/index.js"
}
}
24 changes: 22 additions & 2 deletions src/ditamap/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ensureString,
JsonMap,
} from '@salesforce/ts-types';
import * as ejs from 'ejs';
import { CommandClass, punctuate } from '../utils';
import { Ditamap } from './ditamap';

Expand Down Expand Up @@ -53,11 +54,30 @@ export class Command extends Ditamap {

super(filename, {});

for (const flag of Object.keys(command.flags)) {
if (command.flags[flag].summary) {
command.flags[flag].summary = ejs.render(command.flags[flag].summary, {
command,
config: { bin: commandMeta.binary },
});
}
if (command.flags[flag].description) {
command.flags[flag].description = ejs.render(command.flags[flag].description, {
command,
config: { bin: commandMeta.binary },
});
}
}

this.flags = ensureObject(command.flags);

const summary = punctuate(asString(command.summary));
const summary = punctuate(
asString(ejs.render(command.summary || '', { command, config: { bin: commandMeta.binary } }))
);

const description = asString(command.description);
const description = asString(
ejs.render(command.description || '', { command, config: { bin: commandMeta.binary } })
);

// Help are all the lines after the first line in the description. Before oclif, there was a 'help' property so continue to
// support that.
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,11 @@
dependencies:
"@types/node" "*"

"@types/ejs@^3.1.2":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@types/ejs/-/ejs-3.1.2.tgz#75d277b030bc11b3be38c807e10071f45ebc78d9"
integrity sha512-ZmiaE3wglXVWBM9fyVC17aGPkLo/UgaOjEiI2FXQfyczrCefORPxIe+2dVmnmk3zkVIbizjrlQzmPGhSYGXG5g==

"@types/expect@^1.20.4":
version "1.20.4"
resolved "https://registry.yarnpkg.com/@types/expect/-/expect-1.20.4.tgz#8288e51737bf7e3ab5d7c77bfa695883745264e5"
Expand Down

0 comments on commit 293c4f2

Please sign in to comment.