Skip to content

Commit

Permalink
feat: add an allowlist and a blocklist for generators (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Jul 20, 2022
1 parent ebcd217 commit 86d0c35
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
26 changes: 21 additions & 5 deletions apps/vscode/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,6 @@
"default": true,
"description": "Help make Nx Console better by sending anonymous usage data to the Nx Console team."
},
"nxConsole.useNVM": {
"type": "boolean",
"default": false,
"description": "Runs tasks using Node Version Manager"
},
"nxConsole.enableGenerateFromContextMenu": {
"type": "boolean",
"default": true,
Expand All @@ -695,6 +690,27 @@
"type": "boolean",
"default": true,
"description": "Configures a TypeScript language server plugin to include configured libraries in root files for TypeScript projects. This allows for importing libraries into other libraries even when the import was not there before."
},
"nxConsole.enableGeneratorFilters": {
"type": "boolean",
"default": true,
"description": "Enables the filter for listed generators with Nx Console."
},
"nxConsole.generatorAllowlist": {
"type": "array",
"default": [],
"items": {
"type": "string"
},
"description": "A list of generator names to show in the picker (can be combined with Generator Block List).\n\nThe name of the generator should be in this format: @package:generator.\n‎ ‎ ‎ ‎ ‎eamples: @nrwl/workspace:library, workspace-generator:my-generator"
},
"nxConsole.generatorBlocklist": {
"type": "array",
"default": [],
"items": {
"type": "string"
},
"description": "A list of generator names to hide in the picker (can be combined with Generator Allow List).\n\nThe name of the generator should be in this format: @package:generator.\n‎ ‎ ‎ ‎ ‎ examples: @nrwl/workspace:library, workspace-generator:my-generator"
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion libs/vscode/configuration/src/lib/configuration-keys.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const GLOBAL_CONFIG_KEYS = [
'enableTelemetry',
'useNVM',
'enableGenerateFromContextMenu',
'enableWorkspaceConfigCodeLens',
'enableLibraryImports',
'enableGeneratorFilters',
'generatorAllowlist',
'generatorBlocklist',
] as const;

/**
Expand Down
24 changes: 23 additions & 1 deletion libs/vscode/tasks/src/lib/select-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
normalizeSchema,
readAndCacheJsonFile,
} from '@nx-console/server';
import { GlobalConfigurationStore } from '@nx-console/vscode/configuration';
import { nxWorkspace } from '@nx-console/vscode/nx-workspace';
import { QuickPickItem, window } from 'vscode';

Expand Down Expand Up @@ -81,6 +82,7 @@ export async function selectGenerator(
interface GenerateQuickPickItem extends QuickPickItem {
collectionName: string;
generator: Generator;
generatorName: string;
collectionPath: string;
}
const { workspace } = await nxWorkspace();
Expand All @@ -93,12 +95,32 @@ export async function selectGenerator(
return {
description: generatorData.description,
label: `${generatorData.collection} - ${generatorData.name}`,
generatorName: `${generatorData.collection}:${generatorData.name}`,
collectionName: generatorData.collection,
collectionPath: collection.path,
generator: generatorData,
};
});

if (GlobalConfigurationStore.instance.get('enableGeneratorFilters') ?? true) {
const allowlist: string[] =
GlobalConfigurationStore.instance.get('generatorAllowlist') ?? [];
const blocklist: string[] =
GlobalConfigurationStore.instance.get('generatorBlocklist') ?? [];

if (allowlist.length > 0) {
generatorsQuickPicks = generatorsQuickPicks.filter((item) =>
allowlist.includes(item.generatorName)
);
}

if (blocklist.length > 0) {
generatorsQuickPicks = generatorsQuickPicks.filter(
(item) => !blocklist.includes(item.generatorName)
);
}
}

if (generatorType) {
generatorsQuickPicks = generatorsQuickPicks.filter((generator) => {
return generator.generator.type === generatorType;
Expand All @@ -123,7 +145,7 @@ export async function selectGenerator(
selection.collectionPath,
workspaceType
));
const positional = `${selection.collectionName}:${selection.generator.name}`;
const positional = selection.generatorName;
return {
...selection.generator,
options,
Expand Down

0 comments on commit 86d0c35

Please sign in to comment.