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

refactor: add project names to project option in nxc plugin #1961

Merged
merged 1 commit into from
Jan 2, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@ class NxGenerateService(val project: Project) {
options: List<NxGeneratorOption>? = null
) {
val generatorOptions =
if (options != null) options
else {
val nxProjectNames =
project.service<NxlsService>().workspace()?.workspace?.projects?.keys?.toList()
?: emptyList()
project
options
?: project
.service<NxlsService>()
.generatorOptions(
NxGeneratorOptionsRequestOptions(
Expand All @@ -127,17 +123,6 @@ class NxGenerateService(val project: Project) {
generator.path
)
)
.map {
if (
it.name == "project" ||
it.name == "projectName" ||
it.dropdown == "projects"
) {
it.items = nxProjectNames
}
it
}
}

val generatorWithOptions = NxGenerator(generator, generatorOptions)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { GeneratorSchema } from '@nx-console/shared/generate-ui-types';
import { SchemaProcessor } from '../nx-console-plugin-types';
import { NxWorkspace } from '@nx-console/shared/types';
import { isProjectOption } from '@nx-console/shared/schema';

export const addProjectItemsToOptionProcessor: SchemaProcessor = (
schema: GeneratorSchema,
workspace: NxWorkspace
) => {
return {
...schema,
options: (schema.options ?? []).map((option) => {
if (isProjectOption(option)) {
const projects = Object.keys(workspace.workspace.projects);
option.items = projects.sort();
}
return option;
}),
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NxConsolePluginsDefinition } from '../nx-console-plugin-types';
import { addProjectItemsToOptionProcessor } from './add-project-items-to-option-processor';
import { filterInternalAndDeprecatedProcessor } from './filter-internal-and-deprecated-processor';
import { gitCleanMessageFactory } from './git-clean-message-factory';
import {
Expand All @@ -17,6 +18,7 @@ export const internalPlugins: NxConsolePluginsDefinition = {
filterInternalAndDeprecatedProcessor,
prefillProjectAndDirProcessor,
nameAndDirectoryProcessor,
addProjectItemsToOptionProcessor,
],
validators: [],
startupMessageFactories: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,8 @@ export async function openGenerateUi(
};
}

generateUIWebview.openGenerateUi(
await augmentGeneratorSchema({
...generator,
context: generatorContext,
})
);
}

async function augmentGeneratorSchema(
generatorSchema: GeneratorSchema
): Promise<GeneratorSchema> {
for (const option of generatorSchema.options) {
if (isProjectOption(option)) {
const projects = Object.entries(await getNxWorkspaceProjects());
option.items = projects.map((entry) => entry[0]).sort();
}
}

return generatorSchema;
generateUIWebview.openGenerateUi({
...generator,
context: generatorContext,
});
}