From d91f8ea184b6c1560a647cac96d49f0f82669d84 Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Sat, 11 Dec 2021 11:43:19 -0500 Subject: [PATCH] fix: make the `path` option always visible when using generate --- libs/server/src/lib/utils/utils.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/libs/server/src/lib/utils/utils.ts b/libs/server/src/lib/utils/utils.ts index 77d44de915..858c3bc4a2 100644 --- a/libs/server/src/lib/utils/utils.ts +++ b/libs/server/src/lib/utils/utils.ts @@ -13,6 +13,7 @@ import { OptionItemLabelValue, XPrompt, CliOption, + OptionPropertyDescription, } from '@nx-console/schema'; import { readdirSync, statSync } from 'fs'; @@ -361,25 +362,42 @@ export function toWorkspaceFormat( function schemaToOptions(schema: Schema): CliOption[] { return Object.keys(schema.properties).reduce( (cliOptions, option) => { - const currentProperties = schema.properties[option]; - const $default = currentProperties.$default; + const currentProperty = schema.properties[option]; + const $default = currentProperty.$default; const $defaultIndex = $default?.['$source'] === 'argv' ? $default['index'] : undefined; const positional: number | undefined = typeof $defaultIndex === 'number' ? $defaultIndex : undefined; - const visible = currentProperties.visible ?? true; - if (!visible || (currentProperties as any).hidden) { + const visible = isPropertyVisible(option, currentProperty); + if (!visible) { return cliOptions; } cliOptions.push({ name: option, positional, - ...currentProperties, + ...currentProperty, }); return cliOptions; }, [] ); } + +function isPropertyVisible( + option: string, + property: OptionPropertyDescription +): boolean { + const ALWAYS_VISIBLE_OPTIONS = ['path']; + + if (ALWAYS_VISIBLE_OPTIONS.includes(option)) { + return true; + } + + if ('hidden' in property) { + return !(property as any)['hidden']; + } + + return property.visible ?? true; +}