CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nx--workspace

The Workspace plugin contains executors and generators that are useful for any Nx workspace and serves as a foundation for other plugins.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

generators.mddocs/

Project Generators

Core generators for creating, moving, and managing projects within Nx workspaces. These generators handle project lifecycle management, from creation to removal, and provide essential workspace organization capabilities.

Capabilities

Move Generator

Moves applications or libraries to different folders within the workspace, updating all references and configurations.

/**
 * Move an application or library to another folder
 * @param tree - The file system tree
 * @param schema - Configuration for the move operation
 * @returns Promise resolving to generator callback
 */
function moveGenerator(tree: Tree, schema: MoveSchema): Promise<GeneratorCallback>;

interface MoveSchema {
  /** Name of the project to move */
  projectName: string;
  /** New destination path for the project */  
  destination: string;
  /** Import path for the project */
  importPath?: string;
  /** Update import paths in other projects */
  updateImportPath: boolean;
  /** Skip formatting after move */
  skipFormat?: boolean;
  /** New project name after move */
  newProjectName?: string;
}

Usage Example:

import { Tree } from "@nx/devkit";
import { moveGenerator } from "@nx/workspace";

// Move a library to a different folder
await moveGenerator(tree, {
  projectName: "shared-utils",
  destination: "libs/common/shared-utils",
  updateImportPath: true
});

Remove Generator

Removes applications or libraries from the workspace, cleaning up all references and configurations.

/**
 * Remove an application or library from the workspace
 * @param tree - The file system tree
 * @param schema - Configuration for the remove operation
 * @returns Promise resolving when removal is complete
 */
function removeGenerator(tree: Tree, schema: RemoveSchema): Promise<void>;

interface RemoveSchema {
  /** Name of the project to remove */
  projectName: string;
  /** Skip formatting after removal */
  skipFormat: boolean;
  /** Force removal even if project has dependents */
  forceRemove: boolean;
  /** Import path for the project */
  importPath?: string;
}

Usage Example:

import { Tree } from "@nx/devkit";
import { removeGenerator } from "@nx/workspace";

// Remove a project from the workspace
await removeGenerator(tree, {
  projectName: "old-feature-lib",
  skipFormat: false,
  forceRemove: false
});

Run Commands Generator

Generates targets to run shell commands in the terminal, useful for custom build scripts and automation.

/**
 * Generates a target to run any command in the terminal
 * @param tree - The file system tree
 * @param schema - Configuration for the run commands target
 * @returns Promise resolving when target is created
 */
function runCommandsGenerator(tree: Tree, schema: RunCommandsSchema): Promise<void>;

interface RunCommandsSchema {
  /** Name of the target */
  name: string;
  /** Command to execute */
  command: string;
  /** Name of the project to add the target to */
  project: string;
  /** Working directory for the command */
  cwd?: string;
  /** Output paths for caching */
  outputs?: string;
  /** Environment file to load */
  envFile?: string;
}

Usage Example:

import { Tree } from "@nx/devkit";
import { runCommandsGenerator } from "@nx/workspace";

// Add a custom build target
await runCommandsGenerator(tree, {
  project: "my-app",
  name: "docker-build",
  command: "docker build -t my-app .",
  cwd: "apps/my-app",
  outputs: "dist/apps/my-app"
});

Convert to Nx Project Generator

Converts existing projects to use Nx project configuration format, fixing configuration issues.

/**
 * Fixes projects configuration to use Nx format
 * @param tree - The file system tree
 * @param schema - Configuration for the conversion
 * @returns Promise resolving when conversion is complete
 */
function convertToNxProjectGenerator(tree: Tree, schema: ConvertSchema): Promise<void>;

interface ConvertSchema {
  /** Name of the project to convert */
  project?: string;
  /** Convert all projects */
  all?: boolean;
  /** Reformat configuration files */
  reformat?: boolean;
  /** Skip formatting after conversion */
  skipFormat?: boolean;
}

Usage Example:

import { Tree } from "@nx/devkit";
import { convertToNxProjectGenerator } from "@nx/workspace";

// Fix configuration for a specific project
await convertToNxProjectGenerator(tree, {
  project: "legacy-app",
  reformat: true
});

// Fix all projects in workspace
await convertToNxProjectGenerator(tree, {
  all: true,
  reformat: true
});

NPM Package Generator

Creates minimal NPM packages within the workspace for publishing libraries.

/**
 * Create a minimal NPM package
 * @param tree - The file system tree  
 * @param options - Configuration for the package
 * @returns Promise resolving to generator callback
 */
function npmPackageGenerator(tree: Tree, options: ProjectOptions): Promise<GeneratorCallback>;

interface ProjectOptions {
  /** Directory where the package should be created */
  directory: string;
  /** Name of the package (optional, derived from directory if not provided) */
  name?: string;
}

Usage Example:

import { Tree } from "@nx/devkit";
import { npmPackageGenerator } from "@nx/workspace";

// Create a new NPM package
const callback = await npmPackageGenerator(tree, {
  directory: "libs/my-package",
  name: "my-package"
});

// Execute any post-generation tasks
if (callback) {
  callback();
}

Generator Configuration

Available CLI Generators

All generators are available through the Nx CLI and can be configured via generators.json:

  • preset: Create application in empty workspace (hidden)
  • move: Move projects between folders (aliases: mv)
  • remove: Remove projects from workspace (aliases: rm)
  • convert-to-monorepo: Convert project to monorepo structure
  • new: Create new workspace (hidden)
  • run-commands: Create terminal command targets (aliases: run-command, target)
  • fix-configuration: Fix project configurations (aliases: convert-to-nx-project)
  • npm-package: Create minimal NPM packages
  • ci-workflow: Generate CI workflow configurations
  • infer-targets: Convert projects to use inferred targets

Schema Validation

Each generator includes JSON schema validation for its options, ensuring type safety and proper configuration validation at runtime.

Types

interface MoveSchema {
  projectName: string;
  destination: string;
  importPath?: string;
  updateImportPath: boolean;
  skipFormat?: boolean;
  newProjectName?: string;
}

interface RemoveSchema {
  projectName: string;
  skipFormat: boolean;
  forceRemove: boolean;
  importPath?: string;
}

interface RunCommandsSchema {
  name: string;
  command: string;
  project: string;
  cwd?: string;
  outputs?: string;
  envFile?: string;
}

interface ConvertSchema {
  project?: string;
  all?: boolean;
  reformat?: boolean;
  skipFormat?: boolean;
}

interface ProjectOptions {
  directory: string;
  name?: string;
}

Install with Tessl CLI

npx tessl i tessl/npm-nx--workspace

docs

cli-config.md

file-utilities.md

generators.md

index.md

linter.md

project-types.md

typescript-config.md

tile.json