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: make the path option always visible when using generate #1192

Merged
merged 1 commit into from
Dec 11, 2021
Merged
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
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;
}