fix(core): add stub for conformance:check, add messaging (#28250)

This commit is contained in:
James Henry 2024-10-02 22:12:55 +04:00 committed by GitHub
parent 8821b70815
commit fe01c61635
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,7 @@ import {
yargsAffectedGraphCommand, yargsAffectedGraphCommand,
} from './deprecated/command-objects'; } from './deprecated/command-objects';
import { yargsSyncCheckCommand, yargsSyncCommand } from './sync/command-object'; import { yargsSyncCheckCommand, yargsSyncCommand } from './sync/command-object';
import { output } from '../utils/output';
// Ensure that the output takes up the available width of the terminal. // Ensure that the output takes up the available width of the terminal.
yargs.wrap(yargs.terminalWidth()); yargs.wrap(yargs.terminalWidth());
@ -101,6 +102,7 @@ export const commandsObject = yargs
.command(yargsLoginCommand) .command(yargsLoginCommand)
.command(yargsLogoutCommand) .command(yargsLogoutCommand)
.command(resolveConformanceCommandObject()) .command(resolveConformanceCommandObject())
.command(resolveConformanceCheckCommandObject())
.scriptName('nx') .scriptName('nx')
.help() .help()
// NOTE: we handle --version in nx.ts, this just tells yargs that the option exists // NOTE: we handle --version in nx.ts, this just tells yargs that the option exists
@ -108,19 +110,43 @@ export const commandsObject = yargs
// hit, as the implementation in nx.ts is hit first and calls process.exit(0). // hit, as the implementation in nx.ts is hit first and calls process.exit(0).
.version(); .version();
function createMissingConformanceCommand(
command: 'conformance' | 'conformance:check'
) {
return {
command,
// Hide from --help output in the common case of not having the plugin installed
describe: false,
handler: () => {
output.error({
title: `${command} is not available`,
bodyLines: [
`In order to use the \`nx ${command}\` command you must have an active Powerpack license and the \`@nx/powerpack-conformance\` plugin installed.`,
'',
'To learn more, visit https://nx.dev/features/powerpack/conformance',
],
});
process.exit(1);
},
};
}
function resolveConformanceCommandObject() { function resolveConformanceCommandObject() {
try { try {
const { yargsConformanceCommand } = require('@nx/powerpack-conformance'); const { yargsConformanceCommand } = require('@nx/powerpack-conformance');
return yargsConformanceCommand; return yargsConformanceCommand;
} catch (e) { } catch {
return { return createMissingConformanceCommand('conformance');
command: 'conformance', }
// Hide from --help output in the common case of not having the plugin installed }
describe: false,
handler: () => { function resolveConformanceCheckCommandObject() {
// TODO: Add messaging to help with learning more about powerpack and conformance try {
process.exit(1); const {
}, yargsConformanceCheckCommand,
}; } = require('@nx/powerpack-conformance');
return yargsConformanceCheckCommand;
} catch {
return createMissingConformanceCommand('conformance:check');
} }
} }