The workflow system provides high-level orchestration for schematic execution with lifecycle management, error handling, and context propagation. It serves as the primary interface for coordinating complex schematic operations with multiple collections and schematics.
Core workflow interface for executing schematics with full lifecycle management.
/**
* Main workflow interface for orchestrating schematic execution
*/
interface Workflow {
readonly context: Readonly<WorkflowExecutionContext>;
/** Execute a schematic with the given context */
execute(
options: Partial<WorkflowExecutionContext> & RequiredWorkflowExecutionContext
): Observable<void>;
}
/**
* Required execution context for workflow operations
*/
interface RequiredWorkflowExecutionContext {
collection: string;
schematic: string;
options: object;
}
/**
* Complete execution context with optional fields
*/
interface WorkflowExecutionContext extends RequiredWorkflowExecutionContext {
debug: boolean;
logger: logging.Logger;
parentContext?: Readonly<WorkflowExecutionContext>;
allowPrivate?: boolean;
}Abstract base class for implementing custom workflows.
/**
* Configuration options for base workflow
*/
interface BaseWorkflowOptions {
host: virtualFs.Host;
engineHost: EngineHost<{}, {}>;
registry?: schema.CoreSchemaRegistry;
force?: boolean;
dryRun?: boolean;
}
/**
* Abstract base workflow with common functionality
*/
abstract class BaseWorkflow implements Workflow {
constructor(options: BaseWorkflowOptions);
readonly context: Readonly<WorkflowExecutionContext>;
readonly engine: Engine<{}, {}>;
readonly engineHost: EngineHost<{}, {}>;
readonly registry: schema.SchemaRegistry;
readonly reporter: Observable<DryRunEvent>;
readonly lifeCycle: Observable<LifeCycleEvent>;
execute(
options: Partial<WorkflowExecutionContext> & RequiredWorkflowExecutionContext
): Observable<void>;
}Events emitted during workflow execution for monitoring and debugging.
/**
* Lifecycle events emitted during workflow execution
*/
interface LifeCycleEvent {
kind: 'start' | 'end' | 'workflow-start' | 'workflow-end' | 'post-tasks-start' | 'post-tasks-end';
}Usage Examples:
import { BaseWorkflow, BaseWorkflowOptions } from "@angular-devkit/schematics";
import { virtualFs, logging } from "@angular-devkit/core";
// Create a custom workflow
class CustomWorkflow extends BaseWorkflow {
constructor(options: BaseWorkflowOptions) {
super(options);
// Subscribe to lifecycle events
this.lifeCycle.subscribe(event => {
console.log(`Workflow event: ${event.kind}`);
});
}
}
// Execute a schematic through workflow
const workflow = new CustomWorkflow({
host: new virtualFs.SimpleMemoryHost(),
engineHost: new FileSystemEngineHost()
});
workflow.execute({
collection: '@schematics/angular',
schematic: 'component',
options: { name: 'my-component' },
debug: false,
logger: new logging.NullLogger()
}).subscribe({
next: () => console.log('Schematic executed successfully'),
error: (err) => console.error('Execution failed:', err)
});/**
* Exception thrown when workflow execution fails
*/
class UnsuccessfulWorkflowExecution extends BaseException {
constructor(message?: string);
}type ExecutionOptions = {
scope?: string;
interactive?: boolean;
};