Skip to content

Commit 293c4f2

Browse files
authored
fix: render cmd and flag sum/desc ejs template (#350)
1 parent 9faf2b1 commit 293c4f2

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@salesforce/dev-scripts": "^2.0.4",
2424
"@salesforce/plugin-login": "^1.1.15",
2525
"@salesforce/prettier-config": "^0.0.2",
26+
"@types/ejs": "^3.1.2",
2627
"@types/fs-extra": "^9.0.13",
2728
"@types/lodash.uniqby": "^4.7.6",
2829
"@typescript-eslint/eslint-plugin": "^4.2.0",
@@ -104,4 +105,4 @@
104105
"access": "public"
105106
},
106107
"main": "lib/index.js"
107-
}
108+
}

src/ditamap/command.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
ensureString,
1616
JsonMap,
1717
} from '@salesforce/ts-types';
18+
import * as ejs from 'ejs';
1819
import { CommandClass, punctuate } from '../utils';
1920
import { Ditamap } from './ditamap';
2021

@@ -53,11 +54,30 @@ export class Command extends Ditamap {
5354

5455
super(filename, {});
5556

57+
for (const flag of Object.keys(command.flags)) {
58+
if (command.flags[flag].summary) {
59+
command.flags[flag].summary = ejs.render(command.flags[flag].summary, {
60+
command,
61+
config: { bin: commandMeta.binary },
62+
});
63+
}
64+
if (command.flags[flag].description) {
65+
command.flags[flag].description = ejs.render(command.flags[flag].description, {
66+
command,
67+
config: { bin: commandMeta.binary },
68+
});
69+
}
70+
}
71+
5672
this.flags = ensureObject(command.flags);
5773

58-
const summary = punctuate(asString(command.summary));
74+
const summary = punctuate(
75+
asString(ejs.render(command.summary || '', { command, config: { bin: commandMeta.binary } }))
76+
);
5977

60-
const description = asString(command.description);
78+
const description = asString(
79+
ejs.render(command.description || '', { command, config: { bin: commandMeta.binary } })
80+
);
6181

6282
// Help are all the lines after the first line in the description. Before oclif, there was a 'help' property so continue to
6383
// support that.

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,11 @@
12271227
dependencies:
12281228
"@types/node" "*"
12291229

1230+
"@types/ejs@^3.1.2":
1231+
version "3.1.2"
1232+
resolved "https://registry.yarnpkg.com/@types/ejs/-/ejs-3.1.2.tgz#75d277b030bc11b3be38c807e10071f45ebc78d9"
1233+
integrity sha512-ZmiaE3wglXVWBM9fyVC17aGPkLo/UgaOjEiI2FXQfyczrCefORPxIe+2dVmnmk3zkVIbizjrlQzmPGhSYGXG5g==
1234+
12301235
"@types/expect@^1.20.4":
12311236
version "1.20.4"
12321237
resolved "https://registry.yarnpkg.com/@types/expect/-/expect-1.20.4.tgz#8288e51737bf7e3ab5d7c77bfa695883745264e5"

0 commit comments

Comments
 (0)