From 4a7c38ace5a6243fb6f9f6f4cf1ca429b2378031 Mon Sep 17 00:00:00 2001 From: Steven Nance Date: Thu, 12 Sep 2024 01:50:49 +0200 Subject: [PATCH] chore: remove unused generators and executors --- .../nx-workshop-e2e/tests/nx-workshop.spec.ts | 9 +-- libs/nx-react-workshop/executors.json | 10 --- libs/nx-react-workshop/generators.json | 5 -- libs/nx-react-workshop/package.json | 1 - .../src/executors/build/executor.spec.ts | 11 --- .../src/executors/build/executor.ts | 8 -- .../src/executors/build/schema.d.ts | 1 - .../src/executors/build/schema.json | 10 --- .../files/src/index.ts__template__ | 1 - .../generators/nx-workshop/generator.spec.ts | 20 ----- .../src/generators/nx-workshop/generator.ts | 73 ------------------- .../src/generators/nx-workshop/schema.d.ts | 5 -- .../src/generators/nx-workshop/schema.json | 29 -------- 13 files changed, 4 insertions(+), 179 deletions(-) delete mode 100644 libs/nx-react-workshop/executors.json delete mode 100644 libs/nx-react-workshop/src/executors/build/executor.spec.ts delete mode 100644 libs/nx-react-workshop/src/executors/build/executor.ts delete mode 100644 libs/nx-react-workshop/src/executors/build/schema.d.ts delete mode 100644 libs/nx-react-workshop/src/executors/build/schema.json delete mode 100644 libs/nx-react-workshop/src/generators/nx-workshop/files/src/index.ts__template__ delete mode 100644 libs/nx-react-workshop/src/generators/nx-workshop/generator.spec.ts delete mode 100644 libs/nx-react-workshop/src/generators/nx-workshop/generator.ts delete mode 100644 libs/nx-react-workshop/src/generators/nx-workshop/schema.d.ts delete mode 100644 libs/nx-react-workshop/src/generators/nx-workshop/schema.json diff --git a/apps/nx-workshop-e2e/tests/nx-workshop.spec.ts b/apps/nx-workshop-e2e/tests/nx-workshop.spec.ts index 331c133..e1538c1 100644 --- a/apps/nx-workshop-e2e/tests/nx-workshop.spec.ts +++ b/apps/nx-workshop-e2e/tests/nx-workshop.spec.ts @@ -31,11 +31,10 @@ describe('nx-react-workshop', () => { }); // A noop to verify generator works and setup project in an "initial state" - execSync(`nx generate @nrwl/nx-react-workshop:complete-labs --lab=0`, { - cwd: projectDirectory, - stdio: 'inherit', - env: process.env, - }); + runNxCommand( + `generate @nrwl/nx-react-workshop:complete-labs --lab=0`, + projectDirectory + ); // Make a copy of the initial project state so we can compare against it later emptyProjectDirectory = join(process.cwd(), 'tmp', 'empty-project'); diff --git a/libs/nx-react-workshop/executors.json b/libs/nx-react-workshop/executors.json deleted file mode 100644 index b92c873..0000000 --- a/libs/nx-react-workshop/executors.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "executors": { - "build": { - "implementation": "./src/executors/build/executor", - "schema": "./src/executors/build/schema.json", - "description": "build executor" - } - } -} diff --git a/libs/nx-react-workshop/generators.json b/libs/nx-react-workshop/generators.json index 6766495..9cc9782 100644 --- a/libs/nx-react-workshop/generators.json +++ b/libs/nx-react-workshop/generators.json @@ -3,11 +3,6 @@ "name": "nx-react-workshop", "version": "0.0.1", "generators": { - "nx-react-workshop": { - "factory": "./src/generators/nx-react-workshop/generator", - "schema": "./src/generators/nx-react-workshop/schema.json", - "description": "nx-react-workshop generator" - }, "complete-labs": { "factory": "./src/generators/complete-labs/generator", "schema": "./src/generators/complete-labs/schema.json", diff --git a/libs/nx-react-workshop/package.json b/libs/nx-react-workshop/package.json index ebecbe5..9273f03 100644 --- a/libs/nx-react-workshop/package.json +++ b/libs/nx-react-workshop/package.json @@ -3,7 +3,6 @@ "version": "0.0.0", "main": "src/index.js", "generators": "./generators.json", - "executors": "./executors.json", "nx-migrations": { "migrations": "./migrations.json" }, diff --git a/libs/nx-react-workshop/src/executors/build/executor.spec.ts b/libs/nx-react-workshop/src/executors/build/executor.spec.ts deleted file mode 100644 index 32de13c..0000000 --- a/libs/nx-react-workshop/src/executors/build/executor.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BuildExecutorSchema } from './schema'; -import executor from './executor'; - -const options: BuildExecutorSchema = {}; - -describe('Build Executor', () => { - it('can run', async () => { - const output = await executor(options); - expect(output.success).toBe(true); - }); -}); diff --git a/libs/nx-react-workshop/src/executors/build/executor.ts b/libs/nx-react-workshop/src/executors/build/executor.ts deleted file mode 100644 index 39569a7..0000000 --- a/libs/nx-react-workshop/src/executors/build/executor.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { BuildExecutorSchema } from './schema'; - -export default async function runExecutor(options: BuildExecutorSchema) { - console.log('Executor ran for Build', options); - return { - success: true, - }; -} diff --git a/libs/nx-react-workshop/src/executors/build/schema.d.ts b/libs/nx-react-workshop/src/executors/build/schema.d.ts deleted file mode 100644 index f8247ab..0000000 --- a/libs/nx-react-workshop/src/executors/build/schema.d.ts +++ /dev/null @@ -1 +0,0 @@ -export interface BuildExecutorSchema {} // eslint-disable-line diff --git a/libs/nx-react-workshop/src/executors/build/schema.json b/libs/nx-react-workshop/src/executors/build/schema.json deleted file mode 100644 index d8d2d46..0000000 --- a/libs/nx-react-workshop/src/executors/build/schema.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "version": 2, - "outputCapture": "direct-nodejs", - "$schema": "http://json-schema.org/schema", - "title": "Build executor", - "description": "", - "type": "object", - "properties": {}, - "required": [] -} diff --git a/libs/nx-react-workshop/src/generators/nx-workshop/files/src/index.ts__template__ b/libs/nx-react-workshop/src/generators/nx-workshop/files/src/index.ts__template__ deleted file mode 100644 index dde3cb6..0000000 --- a/libs/nx-react-workshop/src/generators/nx-workshop/files/src/index.ts__template__ +++ /dev/null @@ -1 +0,0 @@ -const variable = "<%= projectName %>"; \ No newline at end of file diff --git a/libs/nx-react-workshop/src/generators/nx-workshop/generator.spec.ts b/libs/nx-react-workshop/src/generators/nx-workshop/generator.spec.ts deleted file mode 100644 index d11a755..0000000 --- a/libs/nx-react-workshop/src/generators/nx-workshop/generator.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { Tree, readProjectConfiguration } from '@nx/devkit'; - -import generator from './generator'; -import { NxWorkshopGeneratorSchema } from './schema'; - -describe('nx-react-workshop generator', () => { - let appTree: Tree; - const options: NxWorkshopGeneratorSchema = { name: 'test' }; - - beforeEach(() => { - appTree = createTreeWithEmptyWorkspace(); - }); - - it('should run successfully', async () => { - await generator(appTree, options); - const config = readProjectConfiguration(appTree, 'test'); - expect(config).toBeDefined(); - }); -}); diff --git a/libs/nx-react-workshop/src/generators/nx-workshop/generator.ts b/libs/nx-react-workshop/src/generators/nx-workshop/generator.ts deleted file mode 100644 index a1a030c..0000000 --- a/libs/nx-react-workshop/src/generators/nx-workshop/generator.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { - addProjectConfiguration, - formatFiles, - generateFiles, - getWorkspaceLayout, - names, - offsetFromRoot, - Tree, -} from '@nx/devkit'; -import * as path from 'path'; -import { NxWorkshopGeneratorSchema } from './schema'; - -interface NormalizedSchema extends NxWorkshopGeneratorSchema { - projectName: string; - projectRoot: string; - projectDirectory: string; - parsedTags: string[]; -} - -function normalizeOptions( - host: Tree, - options: NxWorkshopGeneratorSchema -): NormalizedSchema { - const name = names(options.name).fileName; - const projectDirectory = options.directory - ? `${names(options.directory).fileName}/${name}` - : name; - const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-'); - const projectRoot = `${getWorkspaceLayout(host).libsDir}/${projectDirectory}`; - const parsedTags = options.tags - ? options.tags.split(',').map((s) => s.trim()) - : []; - - return { - ...options, - projectName, - projectRoot, - projectDirectory, - parsedTags, - }; -} - -function addFiles(host: Tree, options: NormalizedSchema) { - const templateOptions = { - ...options, - ...names(options.name), - offsetFromRoot: offsetFromRoot(options.projectRoot), - template: '', - }; - generateFiles( - host, - path.join(__dirname, 'files'), - options.projectRoot, - templateOptions - ); -} - -export default async function (host: Tree, options: NxWorkshopGeneratorSchema) { - const normalizedOptions = normalizeOptions(host, options); - addProjectConfiguration(host, normalizedOptions.projectName, { - root: normalizedOptions.projectRoot, - projectType: 'library', - sourceRoot: `${normalizedOptions.projectRoot}/src`, - targets: { - build: { - executor: '@nrwl/nx-react-workshop:build', - }, - }, - tags: normalizedOptions.parsedTags, - }); - addFiles(host, normalizedOptions); - await formatFiles(host); -} diff --git a/libs/nx-react-workshop/src/generators/nx-workshop/schema.d.ts b/libs/nx-react-workshop/src/generators/nx-workshop/schema.d.ts deleted file mode 100644 index 47ef63b..0000000 --- a/libs/nx-react-workshop/src/generators/nx-workshop/schema.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface NxWorkshopGeneratorSchema { - name: string; - tags?: string; - directory?: string; -} diff --git a/libs/nx-react-workshop/src/generators/nx-workshop/schema.json b/libs/nx-react-workshop/src/generators/nx-workshop/schema.json deleted file mode 100644 index 223195b..0000000 --- a/libs/nx-react-workshop/src/generators/nx-workshop/schema.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "id": "NxWorkshop", - "title": "", - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "", - "$default": { - "$source": "argv", - "index": 0 - }, - "x-prompt": "What name would you like to use?" - }, - "tags": { - "type": "string", - "description": "Add tags to the project (used for linting)", - "alias": "t" - }, - "directory": { - "type": "string", - "description": "A directory where the project is placed", - "alias": "d" - } - }, - "required": ["name"] -}