Skip to content

Commit

Permalink
fix: make the path option always visible when using generate
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Dec 11, 2021
1 parent 6f25ba0 commit d91f8ea
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions libs/server/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
OptionItemLabelValue,
XPrompt,
CliOption,
OptionPropertyDescription,
} from '@nx-console/schema';

import { readdirSync, statSync } from 'fs';
Expand Down Expand Up @@ -361,25 +362,42 @@ export function toWorkspaceFormat(
function schemaToOptions(schema: Schema): CliOption[] {
return Object.keys(schema.properties).reduce<CliOption[]>(
(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;
}

0 comments on commit d91f8ea

Please sign in to comment.