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(misc): add configuration option to print-affected #13422

Merged
merged 1 commit into from Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/generated/cli/print-affected.md
Expand Up @@ -61,6 +61,12 @@ Type: `string`

Base of the current branch (usually main)

### configuration

Type: `string`

This is the configuration to use when performing tasks on projects

### exclude

Type: `array`
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/nx.json
Expand Up @@ -81,7 +81,7 @@
"name": "print-affected",
"id": "print-affected",
"file": "generated/cli/print-affected",
"content": "---\ntitle: 'print-affected - CLI command'\ndescription: 'Prints information about the projects and targets affected by changes'\n---\n\n# print-affected\n\nPrints information about the projects and targets affected by changes\n\n## Usage\n\n```terminal\nnx print-affected\n```\n\nInstall `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.\n\n### Examples\n\nPrint information about affected projects and the project graph:\n\n```terminal\n nx print-affected\n```\n\nPrint information about the projects affected by the changes between main and HEAD (e.g,. PR):\n\n```terminal\n nx print-affected --base=main --head=HEAD\n```\n\nPrints information about the affected projects and a list of tasks to test them:\n\n```terminal\n nx print-affected --target=test\n```\n\nPrints the projects property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=projects\n```\n\nPrints the tasks.target.project property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=tasks.target.project\n```\n\n## Options\n\n### all\n\nType: `boolean`\n\nAll projects\n\n### base\n\nType: `string`\n\nBase of the current branch (usually main)\n\n### exclude\n\nType: `array`\n\nDefault: `[]`\n\nExclude certain projects from being processed\n\n### files\n\nType: `array`\n\nChange the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas\n\n### head\n\nType: `string`\n\nLatest commit of the current branch (usually HEAD)\n\n### help\n\nType: `boolean`\n\nShow help\n\n### select\n\nType: `string`\n\nSelect the subset of the returned json document (e.g., --select=projects)\n\n### target\n\nType: `string`\n\nTask to run for affected projects\n\n### type\n\nType: `string`\n\nChoices: [app, lib]\n\nSelect the type of projects to be returned (e.g., --type=app)\n\n### uncommitted\n\nType: `boolean`\n\nUncommitted changes\n\n### untracked\n\nType: `boolean`\n\nUntracked changes\n\n### version\n\nType: `boolean`\n\nShow version number\n"
"content": "---\ntitle: 'print-affected - CLI command'\ndescription: 'Prints information about the projects and targets affected by changes'\n---\n\n# print-affected\n\nPrints information about the projects and targets affected by changes\n\n## Usage\n\n```terminal\nnx print-affected\n```\n\nInstall `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.\n\n### Examples\n\nPrint information about affected projects and the project graph:\n\n```terminal\n nx print-affected\n```\n\nPrint information about the projects affected by the changes between main and HEAD (e.g,. PR):\n\n```terminal\n nx print-affected --base=main --head=HEAD\n```\n\nPrints information about the affected projects and a list of tasks to test them:\n\n```terminal\n nx print-affected --target=test\n```\n\nPrints the projects property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=projects\n```\n\nPrints the tasks.target.project property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=tasks.target.project\n```\n\n## Options\n\n### all\n\nType: `boolean`\n\nAll projects\n\n### base\n\nType: `string`\n\nBase of the current branch (usually main)\n\n### configuration\n\nType: `string`\n\nThis is the configuration to use when performing tasks on projects\n\n### exclude\n\nType: `array`\n\nDefault: `[]`\n\nExclude certain projects from being processed\n\n### files\n\nType: `array`\n\nChange the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas\n\n### head\n\nType: `string`\n\nLatest commit of the current branch (usually HEAD)\n\n### help\n\nType: `boolean`\n\nShow help\n\n### select\n\nType: `string`\n\nSelect the subset of the returned json document (e.g., --select=projects)\n\n### target\n\nType: `string`\n\nTask to run for affected projects\n\n### type\n\nType: `string`\n\nChoices: [app, lib]\n\nSelect the type of projects to be returned (e.g., --type=app)\n\n### uncommitted\n\nType: `boolean`\n\nUncommitted changes\n\n### untracked\n\nType: `boolean`\n\nUntracked changes\n\n### version\n\nType: `boolean`\n\nShow version number\n"
},
{
"name": "format:check",
Expand Down
1 change: 1 addition & 0 deletions packages/nx/bin/init-local.ts
Expand Up @@ -68,6 +68,7 @@ function isKnownCommand() {
'affected:dep-graph',
'format',
'workspace-schematic',
'connect-to-nx-cloud',
'clear-cache',
'help',
];
Expand Down
47 changes: 29 additions & 18 deletions packages/nx/src/command-line/nx-commands.ts
Expand Up @@ -58,7 +58,9 @@ export const commandsObject = yargs
describe: 'Run target for multiple listed projects',
builder: (yargs) =>
linkToNxDevAndExamples(
withRunManyOptions(withOutputStyleOption(withTargetOption(yargs))),
withRunManyOptions(
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
),
'run-many'
),
handler: async (args) =>
Expand All @@ -70,7 +72,9 @@ export const commandsObject = yargs
builder: (yargs) =>
linkToNxDevAndExamples(
withAffectedOptions(
withRunOptions(withOutputStyleOption(withTargetOption(yargs)))
withRunOptions(
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
)
),
'affected'
),
Expand Down Expand Up @@ -190,7 +194,10 @@ export const commandsObject = yargs
builder: (yargs) =>
linkToNxDevAndExamples(
withAffectedOptions(
withTargetOption(withPrintAffectedOptions(yargs), false)
withTargetAndConfigurationOption(
withPrintAffectedOptions(yargs),
false
)
),
'print-affected'
),
Expand Down Expand Up @@ -443,12 +450,6 @@ function withRunOptions(yargs: yargs.Argv): yargs.Argv {
describe: 'This is the name of the tasks runner configured in nx.json',
type: 'string',
})
.options('configuration', {
describe:
'This is the configuration to use when performing tasks on projects',
type: 'string',
alias: 'c',
})
.option('prod', {
describe: 'Use the production configuration',
type: 'boolean',
Expand Down Expand Up @@ -626,14 +627,24 @@ function withOutputStyleOption(
});
}

function withTargetOption(yargs: yargs.Argv, demandOption = true): yargs.Argv {
return yargs.option('target', {
describe: 'Task to run for affected projects',
type: 'string',
requiresArg: true,
demandOption,
global: false,
});
function withTargetAndConfigurationOption(
yargs: yargs.Argv,
demandOption = true
): yargs.Argv {
return yargs
.option('target', {
describe: 'Task to run for affected projects',
type: 'string',
requiresArg: true,
demandOption,
global: false,
})
.options('configuration', {
describe:
'This is the configuration to use when performing tasks on projects',
type: 'string',
alias: 'c',
});
}

function withNewOptions(yargs: yargs.Argv) {
Expand Down Expand Up @@ -692,7 +703,7 @@ function withRunOneOptions(yargs: yargs.Argv) {
);

const res = withRunOptions(
withOutputStyleOption(withTargetOption(yargs, false), [
withOutputStyleOption(withTargetAndConfigurationOption(yargs, false), [
'dynamic',
'static',
'stream',
Expand Down