or run

tessl search
Log in

Version

Files

tile.json

tessl/npm-nestjs--schematics

Angular-style schematics for the NestJS framework, enabling generation of application components through a command-line interface.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@nestjs/schematics@11.0.x

To install, run

tessl install tessl/npm-nestjs--schematics@11.0.0

index.mddocs/

NestJS Schematics

NestJS Schematics provides Angular-style code generators for the NestJS framework, enabling developers to quickly scaffold application components, modules, and entire project structures through a command-line interface. Built on Angular DevKit schematics, it offers 20+ generators with TypeScript support, dependency injection setup, and standardized project patterns.

Package Information

  • Package Name: @nestjs/schematics
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install -g @nestjs/cli (includes schematics) or npm install @nestjs/schematics

Core Imports

For programmatic use:

import { 
  MetadataManager, 
  ModuleDeclarator, 
  NameParser,
  DEFAULT_LANGUAGE,
  PROJECT_TYPE 
} from '@nestjs/schematics';

Most users interact via the Nest CLI:

nest generate <schematic> <name> [options]
# or
ng generate @nestjs/schematics:<schematic> <name> [options]

Basic Usage

CLI Usage (Most Common)

# Generate a new Nest application
nest new my-app

# Generate components
nest generate service users
nest generate controller auth --no-spec
nest generate module products
nest generate guard roles

# Generate resources with CRUD operations
nest generate resource posts --type=rest --crud

# Generate library in monorepo
nest generate library shared

Programmatic Usage

import { NameParser, ModuleDeclarator } from '@nestjs/schematics';

// Parse component names and paths
const parser = new NameParser();
const location = parser.parse({ name: 'user-service', path: 'src/users' });

// Declare module imports
const declarator = new ModuleDeclarator();
const updatedContent = declarator.declare(moduleContent, {
  metadata: 'providers',
  symbol: 'UserService',
  type: 'class'
});

Architecture

NestJS Schematics is built around several key components:

  • Schematic Collection: 20+ code generators for different NestJS components and patterns
  • Utility Library: Comprehensive set of classes and functions for AST manipulation, module management, and file operations
  • Template System: File templates with variable substitution for consistent code generation
  • Angular DevKit Integration: Built on Angular's schematic framework for robust file operations and tree transformations
  • TypeScript AST Support: Advanced code analysis and modification capabilities

Capabilities

Schematic Collection

Complete set of code generators for NestJS applications including controllers, services, modules, guards, pipes, filters, and more. Supports both standalone components and full applications with monorepo structures.

// Core application schematics
function application(options: ApplicationOptions): Rule;
function module(options: ModuleOptions): Rule;
function controller(options: ControllerOptions): Rule;
function service(options: ServiceOptions): Rule;

// Common schematic options pattern
interface BaseSchematicOptions {
  name: string;
  path?: string | Path;
  module?: Path;
  skipImport?: boolean;
  metadata?: string;
  language?: string;
  sourceRoot?: string;
  spec?: boolean;
  specFileSuffix?: string;
  flat?: boolean;
}

Schematics Collection

Utility Library

Comprehensive toolkit for TypeScript/JavaScript code manipulation, module management, and project structure operations. Includes AST parsers, file system helpers, and NestJS-specific utilities.

class MetadataManager {
  insert(metadata: string, symbol: string, staticOptions?: DeclarationOptions['staticOptions']): string | undefined;
}

class ModuleDeclarator {
  declare(content: string, options: DeclarationOptions): string;
}

class NameParser {
  parse(options: ParseOptions): Location;
}

interface DeclarationOptions {
  metadata: string;
  symbol: string;
  type?: string;
  staticOptions?: {
    name: string;
    value: string;
  };
}

Utility Library

Default Constants

Pre-configured default values and project type constants for consistent application generation.

const DEFAULT_LANGUAGE: string;
const DEFAULT_VERSION: string;
const DEFAULT_PATH_NAME: string;
const PROJECT_TYPE: {
  LIBRARY: 'library';
  APPLICATION: 'application';
};

Types

Core Interfaces

interface Location {
  name: string;
  path: Path;
}

interface ParseOptions {
  name: string;
  path?: string;
}

interface FindOptions {
  name: string;
  path: Path;
}

enum NodeDependencyType {
  Default = 'dependencies',
  Dev = 'devDependencies',
  Peer = 'peerDependencies',
  Optional = 'optionalDependencies'
}

interface NodeDependency {
  type: NodeDependencyType;
  name: string;
  version: string;
  overwrite?: boolean;
}