Angular CLI schematics for generating NgRx state management code including actions, reducers, effects, selectors, and feature modules.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
NgRx Schematics core utilities that provide shared functionality for AST manipulation, project analysis, string transformations, and code generation support. These utilities are used internally by all schematics and can be imported for custom schematic development.
String manipulation functions following Angular and NgRx naming conventions.
/**
* String utility functions for name transformations
*/
interface StringUtils {
/** Convert string to dash-case (kebab-case) */
dasherize: (str: string) => string;
/** Convert string from camelCase to words */
decamelize: (str: string) => string;
/** Convert string to camelCase */
camelize: (str: string) => string;
/** Convert string to PascalCase (UpperCamelCase) */
classify: (str: string) => string;
/** Convert string to snake_case */
underscore: (str: string) => string;
/** Group strings with separators */
group: (str: string, groupName?: string) => string;
/** Capitalize first letter */
capitalize: (str: string) => string;
/** Generate feature path from name */
featurePath: (name: string) => string;
/** Convert string to plural form */
pluralize: (str: string) => string;
}
// Access to string utilities
import { stringUtils } from '@ngrx/schematics/schematics-core';Usage Examples:
import { stringUtils } from '@ngrx/schematics/schematics-core';
// String transformations
stringUtils.dasherize('UserProfile'); // 'user-profile'
stringUtils.camelize('user-profile'); // 'userProfile'
stringUtils.classify('user-profile'); // 'UserProfile'
stringUtils.underscore('userProfile'); // 'user_profile'
stringUtils.capitalize('user'); // 'User'
stringUtils.pluralize('user'); // 'users'
// Feature path generation
stringUtils.featurePath('user'); // 'user'
stringUtils.group('actions', 'user'); // 'user/actions'TypeScript Abstract Syntax Tree manipulation utilities for code generation and modification.
/**
* Find AST nodes matching specific criteria
* @param node - Source AST node to search
* @param kind - TypeScript syntax kind to find
* @param max - Maximum number of results
* @returns Array of matching nodes
*/
function findNodes(
node: ts.Node,
kind: ts.SyntaxKind,
max?: number
): ts.Node[];
/**
* Get all source nodes from a TypeScript source file
* @param sourceFile - TypeScript source file
* @returns Array of source nodes
*/
function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[];
/**
* Get decorator metadata from a class or property
* @param source - TypeScript source file
* @param identifier - Decorator name to find
* @returns Decorator metadata nodes
*/
function getDecoratorMetadata(
source: ts.SourceFile,
identifier: string
): ts.Node[];
/**
* Get content of a key literal in an object
* @param source - TypeScript source file
* @param literal - Key name to find
* @returns Content of the key literal
*/
function getContentOfKeyLiteral(
source: ts.SourceFile,
literal: string
): string | null;Functions for managing TypeScript imports and module dependencies.
/**
* Insert an import statement into a TypeScript file
* @param source - TypeScript source file
* @param fileToEdit - Path of file being edited
* @param symbolName - Symbol to import
* @param fileName - Module to import from
* @param isDefault - Whether this is a default import
* @returns Change object representing the import insertion
*/
function insertImport(
source: ts.SourceFile,
fileToEdit: string,
symbolName: string,
fileName: string,
isDefault?: boolean
): Change;
/**
* Replace an existing import with a new one
* @param source - TypeScript source file
* @param path - File path
* @param importFrom - Original import source
* @param importAsIs - New import source
* @returns Change object representing the import replacement
*/
function replaceImport(
source: ts.SourceFile,
path: string,
importFrom: string,
importAsIs: string
): Change;Usage Examples:
import { insertImport, replaceImport } from '@ngrx/schematics/schematics-core';
import * as ts from 'typescript';
// Insert new import
const change = insertImport(
sourceFile,
'src/app/user/user.component.ts',
'Store',
'@ngrx/store'
);
// Replace existing import
const replaceChange = replaceImport(
sourceFile,
'src/app/user/user.component.ts',
'./old-path',
'./new-path'
);Functions for modifying Angular modules with proper dependency injection and imports.
/**
* Add import to NgModule imports array
* @param source - TypeScript source file
* @param modulePath - Path to module file
* @param importText - Import text to add
* @param importPath - Path of import
* @returns Array of changes to apply
*/
function addImportToModule(
source: ts.SourceFile,
modulePath: string,
importText: string,
importPath: string
): Change[];
/**
* Add declaration to NgModule declarations array
* @param source - TypeScript source file
* @param modulePath - Path to module file
* @param classifiedName - Name of component/directive/pipe
* @param importPath - Path to import from
* @returns Array of changes to apply
*/
function addDeclarationToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[];
/**
* Add export to NgModule exports array
* @param source - TypeScript source file
* @param modulePath - Path to module file
* @param classifiedName - Name to export
* @param importPath - Path to import from
* @returns Array of changes to apply
*/
function addExportToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[];
/**
* Add provider to NgModule providers array
* @param source - TypeScript source file
* @param modulePath - Path to module file
* @param classifiedName - Provider name
* @param importPath - Path to import from
* @returns Array of changes to apply
*/
function addProviderToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[];Utilities for analyzing Angular workspace and project structure.
/**
* Get project path for file generation
* @param host - Schematic tree host
* @param options - Schematic options
* @returns Resolved project path
*/
function getProjectPath(host: Tree, options: any): string;
/**
* Get project configuration from angular.json
* @param host - Schematic tree host
* @param projectName - Name of project
* @returns Project configuration object
*/
function getProject(host: Tree, projectName: string): any;
/**
* Check if project is a library
* @param host - Schematic tree host
* @param options - Schematic options
* @returns True if project is library
*/
function isLib(host: Tree, options: any): boolean;
/**
* Find module file from schematic options
* @param host - Schematic tree host
* @param options - Schematic options with module path
* @returns Path to module file
*/
function findModuleFromOptions(host: Tree, options: any): string;
/**
* Find component file from schematic options
* @param host - Schematic tree host
* @param options - Schematic options
* @returns Path to component file
*/
function findComponentFromOptions(host: Tree, options: any): string;Classes and functions for managing code changes and transformations.
/**
* Base class for representing code changes
*/
abstract class Change {
abstract apply(host: Host): Promise<void> | void;
abstract readonly path: string | null;
abstract readonly order: number;
abstract readonly description: string;
}
/**
* Represents an insertion change
*/
class InsertChange extends Change {
constructor(public path: string, public pos: number, public toAdd: string);
apply(host: Host): void;
}
/**
* Represents a removal change
*/
class RemoveChange extends Change {
constructor(public path: string, public pos: number, public length: number);
apply(host: Host): void;
}
/**
* Represents a replacement change
*/
class ReplaceChange extends Change {
constructor(
public path: string,
public pos: number,
public oldText: string,
public newText: string
);
apply(host: Host): void;
}
/**
* Create a change recorder for batch operations
* @param host - Schematic tree host
* @param path - File path
* @returns Update recorder
*/
function createChangeRecorder(host: Tree, path: string): UpdateRecorder;
/**
* Commit multiple changes to files
* @param host - Schematic tree host
* @param changes - Array of changes to apply
*/
function commitChanges(host: Tree, changes: Change[]): void;Specialized utilities for NgRx pattern generation and state management.
/**
* Add reducer to state interface
* @param source - TypeScript source file
* @param reducerPath - Path to reducer file
* @param reducerName - Name of reducer
* @returns Change objects for state modification
*/
function addReducerToState(
source: ts.SourceFile,
reducerPath: string,
reducerName: string
): Change[];
/**
* Add reducer to ActionReducerMap
* @param source - TypeScript source file
* @param reducerPath - Path to reducer file
* @param reducerName - Name of reducer
* @param featureKey - Feature key for reducer
* @returns Change objects for reducer map modification
*/
function addReducerToActionReducerMap(
source: ts.SourceFile,
reducerPath: string,
reducerName: string,
featureKey: string
): Change[];
/**
* Get prefix for action types
* @param options - Schematic options
* @returns Formatted prefix string
*/
function getPrefix(options: any): string;
/**
* Omit properties from object (utility for immutable updates)
* @param obj - Source object
* @param keys - Keys to omit
* @returns New object without specified keys
*/
function omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;Functions for reading and modifying Angular workspace configuration.
/**
* Application configuration interface
*/
interface AppConfig {
project: string;
path: string;
sourceRoot: string;
prefix: string;
}
/**
* Get workspace configuration from angular.json
* @param host - Schematic tree host
* @returns Workspace configuration object
*/
function getWorkspace(host: Tree): any;
/**
* Get path to workspace configuration file
* @param host - Schematic tree host
* @returns Path to angular.json or workspace.json
*/
function getWorkspacePath(host: Tree): string;Utilities for parsing file names and paths with proper Angular conventions.
/**
* Parse name and path from schematic options
* @param path - Base path
* @param name - Item name
* @returns Parsed name and path information
*/
function parseName(path: string, name: string): {
name: string;
path: string;
};
/**
* Build relative path between two files
* @param from - Source file path
* @param to - Target file path
* @returns Relative path string
*/
function buildRelativePath(from: string, to: string): string;Functions for managing package.json dependencies and configuration.
/**
* Add package to package.json dependencies
* @param host - Schematic tree host
* @param packageName - Package to add
* @param version - Package version
* @param dev - Whether to add to devDependencies
* @returns Change objects for package.json modification
*/
function addPackageToPackageJson(
host: Tree,
packageName: string,
version: string,
dev?: boolean
): Change[];
/**
* Update package version in package.json
* @param host - Schematic tree host
* @param packageName - Package to update
* @param version - New version
* @returns Change objects for package.json modification
*/
function updatePackage(
host: Tree,
packageName: string,
version: string
): Change[];
/**
* Get current platform version
*/
const platformVersion: string;