From c0ca8765619aaa9223b278e394ea296f89857135 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 10 Mar 2022 08:38:59 +0100 Subject: [PATCH] fix(@angular/cli): remove JSON serialized description from help output With this change we remove the JSON serialized description from the help output and also align the description properties between commands and subcommands. --- .../command-builder/utilities/json-help.ts | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/packages/angular/cli/src/command-builder/utilities/json-help.ts b/packages/angular/cli/src/command-builder/utilities/json-help.ts index 8e51e1153647..6c07dd2b8d4a 100644 --- a/packages/angular/cli/src/command-builder/utilities/json-help.ts +++ b/packages/angular/cli/src/command-builder/utilities/json-help.ts @@ -9,21 +9,6 @@ import yargs from 'yargs'; import { FullDescribe } from '../command-module'; -export interface JsonHelp { - name: string; - shortDescription?: string; - command: string; - longDescription?: string; - longDescriptionRelativePath?: string; - options: JsonHelpOption[]; - subcommands?: { - name: string; - description: string; - aliases: string[]; - deprecated: string | boolean; - }[]; -} - interface JsonHelpOption { name: string; type?: string; @@ -36,6 +21,25 @@ interface JsonHelpOption { description?: string; } +interface JsonHelpDescription { + shortDescription?: string; + longDescription?: string; + longDescriptionRelativePath?: string; +} + +interface JsonHelpSubcommand extends JsonHelpDescription { + name: string; + aliases: string[]; + deprecated: string | boolean; +} + +export interface JsonHelp extends JsonHelpDescription { + name: string; + command: string; + options: JsonHelpOption[]; + subcommands?: JsonHelpSubcommand[]; +} + export function jsonHelpUsage(): string { // eslint-disable-next-line @typescript-eslint/no-explicit-any const localYargs = yargs as any; @@ -102,35 +106,15 @@ export function jsonHelpUsage(): string { deprecated: string | boolean, ][] ) - .map(([name, description, _, aliases, deprecated]) => ({ + .map(([name, rawDescription, _, aliases, deprecated]) => ({ name: name.split(' ', 1)[0], command: name, - description, + ...parseDescription(rawDescription), aliases, deprecated, })) .sort((a, b) => a.name.localeCompare(b.name)); - const parseDescription = (rawDescription: string): Partial => { - try { - const { - longDescription, - describe: shortDescription, - longDescriptionRelativePath, - } = JSON.parse(rawDescription) as FullDescribe; - - return { - shortDescription, - longDescriptionRelativePath, - longDescription, - }; - } catch { - return { - shortDescription: rawDescription, - }; - } - }; - const [command, rawDescription] = usageInstance.getUsage()[0] ?? []; const output: JsonHelp = { @@ -143,3 +127,23 @@ export function jsonHelpUsage(): string { return JSON.stringify(output, undefined, 2); } + +function parseDescription(rawDescription: string): JsonHelpDescription { + try { + const { + longDescription, + describe: shortDescription, + longDescriptionRelativePath, + } = JSON.parse(rawDescription) as FullDescribe; + + return { + shortDescription, + longDescriptionRelativePath, + longDescription, + }; + } catch { + return { + shortDescription: rawDescription, + }; + } +}