From d9efbf8372320b7e7020fd4505c403a71ea79d35 Mon Sep 17 00:00:00 2001 From: Sandi Barr Date: Mon, 19 Apr 2021 13:18:07 -0500 Subject: [PATCH 1/2] feat: run-many prompts from projects --- libs/vscode/tasks/src/lib/nx-task-commands.ts | 25 +++++++++++++++++-- libs/vscode/tasks/src/lib/select-flags.ts | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libs/vscode/tasks/src/lib/nx-task-commands.ts b/libs/vscode/tasks/src/lib/nx-task-commands.ts index 3b8cecd90d..ecc4b0ec00 100644 --- a/libs/vscode/tasks/src/lib/nx-task-commands.ts +++ b/libs/vscode/tasks/src/lib/nx-task-commands.ts @@ -266,14 +266,19 @@ async function promptForRunMany() { return; } - const flags = await selectFlags('run-many', RUN_MANY_OPTIONS, 'nx'); + const projects = validProjectsForTarget(target); + const projectsOption = RUN_MANY_OPTIONS.find(opt => opt.name === 'projects'); + if (projectsOption && projects && projects.length) { + projectsOption.enum = projects; + } + + const flags = await selectFlags('run-many', RUN_MANY_OPTIONS, 'nx', {target}); if (flags !== undefined) { const task = NxTask.create( { command: 'run-many', flags, - positional: `--target=${target}`, }, cliTaskProvider.getWorkspacePath() ); @@ -324,3 +329,19 @@ async function promptForMigrate() { ); tasks.executeTask(task); } + +function validProjectsForTarget(target: string): string[] | undefined { + const { validWorkspaceJson, json } = verifyWorkspace(); + + if (!validWorkspaceJson || !json) { + return; + } + + return Array.from( + new Set( + Object.entries(json.projects) + .filter(([_, project]) => project.architect && project.architect[target]) + .map(([project]) => project) + ) + ).sort(); +} diff --git a/libs/vscode/tasks/src/lib/select-flags.ts b/libs/vscode/tasks/src/lib/select-flags.ts index 6362462058..26a0a5680f 100644 --- a/libs/vscode/tasks/src/lib/select-flags.ts +++ b/libs/vscode/tasks/src/lib/select-flags.ts @@ -23,7 +23,7 @@ export async function selectFlags( const flagValue = await promptForFlagValue(selection.flag); - if (flagValue) { + if (flagValue && flagValue.length > 0) { userSetFlags[selection.flag.flagName] = flagValue; } else { delete userSetFlags[selection.flag.flagName]; @@ -83,6 +83,7 @@ function promptForFlagValue(flagToSet: CliTaskFlagQuickPickItem) { } else if (flagToSet.option.enum && flagToSet.option.enum.length) { return window.showQuickPick([...flagToSet.option.enum.map(String)], { placeHolder, + canPickMany: flagToSet.option.type === 'array' }); } else { return window.showInputBox({ From 28a47e40b91ee525e19409b1f475ffcf70c34b70 Mon Sep 17 00:00:00 2001 From: Sandi Barr Date: Mon, 19 Apr 2021 14:52:47 -0500 Subject: [PATCH 2/2] projects option --- libs/vscode/tasks/src/lib/nx-task-commands.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/libs/vscode/tasks/src/lib/nx-task-commands.ts b/libs/vscode/tasks/src/lib/nx-task-commands.ts index ecc4b0ec00..104481c23a 100644 --- a/libs/vscode/tasks/src/lib/nx-task-commands.ts +++ b/libs/vscode/tasks/src/lib/nx-task-commands.ts @@ -142,11 +142,6 @@ const AFFECTED_OPTIONS: Option[] = [ ].map((v) => ({ ...v, aliases: [] })); const RUN_MANY_OPTIONS: Option[] = [ - { - name: 'projects', - type: OptionType.Array, - description: 'Projects to run', - }, { name: 'all', type: OptionType.Boolean, description: 'All projects' }, { name: 'parallel', @@ -266,13 +261,22 @@ async function promptForRunMany() { return; } + let options = RUN_MANY_OPTIONS; const projects = validProjectsForTarget(target); - const projectsOption = RUN_MANY_OPTIONS.find(opt => opt.name === 'projects'); - if (projectsOption && projects && projects.length) { - projectsOption.enum = projects; + if (projects && projects.length) { + options = [ + { + name: 'projects', + type: OptionType.Array, + description: 'Projects to run', + aliases: [], + enum: projects, + }, + ...RUN_MANY_OPTIONS, + ]; } - const flags = await selectFlags('run-many', RUN_MANY_OPTIONS, 'nx', {target}); + const flags = await selectFlags('run-many', options, 'nx', { target }); if (flags !== undefined) { const task = NxTask.create( @@ -340,7 +344,9 @@ function validProjectsForTarget(target: string): string[] | undefined { return Array.from( new Set( Object.entries(json.projects) - .filter(([_, project]) => project.architect && project.architect[target]) + .filter( + ([_, project]) => project.architect && project.architect[target] + ) .map(([project]) => project) ) ).sort();