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

feat: run-many prompts for projects #1064

Merged
merged 2 commits into from
Apr 23, 2021
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
41 changes: 34 additions & 7 deletions libs/vscode/tasks/src/lib/nx-task-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -266,14 +261,28 @@ async function promptForRunMany() {
return;
}

const flags = await selectFlags('run-many', RUN_MANY_OPTIONS, 'nx');
let options = RUN_MANY_OPTIONS;
const projects = validProjectsForTarget(target);
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', options, 'nx', { target });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding target to the userSetFlags parameter shows 'Execute: nx run-many --target=on the Command Palette instead of justnx: run-many` with the selected options. Seems to make more sense as that's how you'd use the run-many command.


if (flags !== undefined) {
const task = NxTask.create(
{
command: 'run-many',
flags,
positional: `--target=${target}`,
},
cliTaskProvider.getWorkspacePath()
);
Expand Down Expand Up @@ -324,3 +333,21 @@ 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<ProjectDef>(json.projects)
.filter(
([_, project]) => project.architect && project.architect[target]
)
.map(([project]) => project)
)
).sort();
}
3 changes: 2 additions & 1 deletion libs/vscode/tasks/src/lib/select-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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({
Expand Down