Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render cmd and flag sum/desc ejs template #350

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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