From 17c7b3d670e57f7dda7b073c24f79b3e22ef1892 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Mon, 15 May 2023 18:07:04 -0300 Subject: [PATCH] fix: render cmd and flag sum/desc ejs template --- package.json | 3 ++- src/ditamap/command.ts | 24 ++++++++++++++++++++++-- yarn.lock | 5 +++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5bffe3a9..136b6bb4 100644 --- a/package.json +++ b/package.json @@ -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", @@ -104,4 +105,4 @@ "access": "public" }, "main": "lib/index.js" -} \ No newline at end of file +} diff --git a/src/ditamap/command.ts b/src/ditamap/command.ts index 606cc691..4a2fedbe 100644 --- a/src/ditamap/command.ts +++ b/src/ditamap/command.ts @@ -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'; @@ -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. diff --git a/yarn.lock b/yarn.lock index 38a0f23d..e9f324ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"