This document describes the internal API architecture of Multi Grep Replacer, including IPC communication between main and renderer processes, configuration file formats, and public APIs for extensions.
The communication between main and renderer processes uses Electron's IPC (Inter-Process Communication) system with contextBridge for security.
Displays a native folder selection dialog.
Request:
await window.electronAPI.selectFolder()Response:
{
success: true,
path: "/path/to/selected/folder",
canceled: false
}Searches for files in the specified directory with optional filters.
Request:
await window.electronAPI.searchFiles({
directory: "/path/to/search",
extensions: [".html", ".css", ".js"],
recursive: true,
excludePatterns: ["node_modules", ".git"]
})Response:
{
success: true,
files: [
{
path: "/path/to/file1.html",
name: "file1.html",
size: 1024,
modified: "2025-08-18T10:00:00.000Z"
}
],
totalCount: 1,
totalSize: 1024
}Executes the replacement operation with specified rules.
Request:
await window.electronAPI.executeReplacement({
targetDirectory: "/path/to/files",
rules: [
{
id: "rule_1",
from: "old-text",
to: "new-text",
enabled: true,
caseSensitive: true
}
],
options: {
fileExtensions: [".html", ".css"],
dryRun: false,
maxConcurrentFiles: 10
}
})Response:
{
success: true,
summary: {
totalFiles: 5,
modifiedFiles: 3,
totalReplacements: 15,
executionTime: 1247
},
details: [
{
path: "/path/to/file1.html",
changes: 3,
replacements: [
{
rule: "rule_1",
from: "old-text",
to: "new-text",
count: 3,
positions: [
{ line: 1, column: 5 },
{ line: 3, column: 12 },
{ line: 7, column: 8 }
]
}
]
}
]
}Loads a configuration file.
Request:
await window.electronAPI.loadConfig({
filePath: "/path/to/config.json"
})Response:
{
success: true,
config: {
// Configuration object structure
}
}Saves the current configuration to a file.
Request:
await window.electronAPI.saveConfig({
filePath: "/path/to/config.json",
config: {
// Configuration object
}
})Response:
{
success: true,
filePath: "/path/to/config.json"
}Retrieves application information.
Request:
await window.electronAPI.getAppInfo()Response:
{
name: "Multi Grep Replacer",
version: "1.0.0",
electron: "25.0.0",
node: "18.15.0",
platform: "darwin",
arch: "arm64"
}Retrieves current performance statistics.
Request:
await window.electronAPI.getPerformanceStats()Response:
{
memory: {
heapUsed: 45678912,
heapTotal: 67108864,
external: 1234567,
rss: 89012345
},
cpu: {
usage: 12.5,
loadAverage: [1.2, 1.1, 0.9]
},
files: {
cached: 156,
processed: 1247
}
}Recursively finds files in a directory.
Parameters:
directory(string): Target directory pathoptions(object):extensions(string[]): File extensions to includeexcludePatterns(string[]): Patterns to excluderecursive(boolean): Include subdirectoriesmaxFiles(number): Maximum number of files to find
Returns: Promise<FileInfo[]>
Reads file contents with encoding detection.
Parameters:
filePath(string): Path to file
Returns: Promise<string>
Writes content to file with UTF-8 encoding.
Parameters:
filePath(string): Path to filecontent(string): Content to write
Returns: Promise<void>
Checks read/write permissions for a file.
Parameters:
filePath(string): Path to file
Returns: Promise<PermissionInfo>
{
readable: true,
writable: true,
exists: true,
isDirectory: false
}Processes multiple files with replacement rules.
Parameters:
filePaths(string[]): Array of file pathsrules(ReplacementRule[]): Array of replacement rulesoptions(ProcessingOptions): Processing options
Returns: Promise<ReplacementResult>
Processes a single file with replacement rules.
Parameters:
filePath(string): Path to filerules(ReplacementRule[]): Array of replacement rules
Returns: Promise<FileReplacementResult>
Loads configuration from JSON file.
Parameters:
filePath(string): Path to configuration file
Returns: Promise<Configuration>
Saves configuration to JSON file.
Parameters:
config(Configuration): Configuration objectfilePath(string): Path to save file
Returns: Promise<void>
Validates configuration object structure.
Parameters:
config(object): Configuration to validate
Returns: ValidationResult
Adds a new replacement rule to the UI.
Parameters:
rule(ReplacementRule): Rule to add
Returns: string (rule ID)
Removes a replacement rule from the UI.
Parameters:
ruleId(string): ID of rule to remove
Returns: boolean
Updates an existing replacement rule.
Parameters:
ruleId(string): ID of rule to updateupdates(Partial<ReplacementRule>): Updates to apply
Returns: boolean
Shows the progress display.
Parameters:
totalFiles(number): Total number of files to process
Returns: void
Updates progress information.
Parameters:
current(number): Current file indextotal(number): Total number of filescurrentFile(string): Name of current file being processed
Returns: void
Hides the progress display.
Returns: void
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"app_info": {
"name": "string",
"version": "string",
"created_at": "ISO8601 datetime",
"description": "string",
"author": "string",
"tags": ["string"]
},
"replacements": [ReplacementRule],
"target_settings": TargetSettings,
"replacement_settings": ReplacementSettings,
"ui_settings": UISettings,
"advanced_settings": AdvancedSettings
}{
"id": "string",
"from": "string",
"to": "string",
"enabled": "boolean",
"description": "string?",
"case_sensitive": "boolean",
"whole_word": "boolean",
"use_regex": "boolean"
}{
"file_extensions": ["string"],
"exclude_patterns": ["string"],
"include_subdirectories": "boolean",
"max_file_size": "number",
"encoding": "string"
}{
"case_sensitive": "boolean",
"use_regex": "boolean",
"backup_enabled": "boolean",
"preserve_file_permissions": "boolean",
"dry_run": "boolean"
}{
"theme": "light|dark|auto",
"window": {
"width": "number",
"height": "number",
"resizable": "boolean",
"center": "boolean"
},
"remember_last_folder": "boolean",
"auto_save_config": "boolean",
"show_file_count_preview": "boolean",
"confirm_before_execution": "boolean"
}{
"max_concurrent_files": "number",
"progress_update_interval": "number",
"log_level": "debug|info|warn|error",
"enable_crash_reporting": "boolean",
"memory_limit": "number",
"timeout": "number"
}Emitted during file processing to report progress.
Data:
{
current: 5,
total: 100,
currentFile: "/path/to/file.html",
replacements: 12,
elapsedTime: 5432
}Emitted when replacement operation completes.
Data:
{
success: true,
summary: ReplacementSummary,
details: FileReplacementResult[]
}Emitted when an error occurs.
Data:
{
code: "ERROR_CODE",
message: "Error description",
details: {},
stack: "Error stack trace"
}Emitted when a replacement rule is added.
Data:
{
ruleId: "rule_123",
rule: ReplacementRule
}Emitted when a replacement rule is removed.
Data:
{
ruleId: "rule_123"
}Emitted when a configuration is loaded.
Data:
{
filePath: "/path/to/config.json",
config: Configuration
}FILE_NOT_FOUND: Specified file does not existFILE_ACCESS_DENIED: Permission denied accessing fileFILE_TOO_LARGE: File exceeds maximum size limitFILE_ENCODING_ERROR: File encoding not supportedDIRECTORY_NOT_FOUND: Target directory does not existDIRECTORY_ACCESS_DENIED: Permission denied accessing directory
INVALID_RULE: Replacement rule is invalidREPLACEMENT_FAILED: Replacement operation failedNO_FILES_FOUND: No files found matching criteriaEXECUTION_TIMEOUT: Operation timed outMEMORY_LIMIT_EXCEEDED: Memory usage exceeded limit
CONFIG_FILE_NOT_FOUND: Configuration file not foundCONFIG_INVALID_FORMAT: Configuration file format invalidCONFIG_VALIDATION_FAILED: Configuration validation failedCONFIG_SAVE_FAILED: Failed to save configuration
INSUFFICIENT_MEMORY: System memory insufficientDISK_SPACE_LOW: Disk space insufficientPROCESS_CRASHED: Process crashed unexpectedlyIPC_COMMUNICATION_FAILED: IPC communication failed
interface FileInfo {
path: string;
name: string;
size: number;
modified: string;
}
interface ReplacementRule {
id: string;
from: string;
to: string;
enabled: boolean;
description?: string;
caseSensitive: boolean;
wholeWord: boolean;
useRegex: boolean;
}
interface ReplacementResult {
success: boolean;
summary: {
totalFiles: number;
modifiedFiles: number;
totalReplacements: number;
executionTime: number;
};
details: FileReplacementResult[];
}
interface FileReplacementResult {
path: string;
changes: number;
replacements: {
rule: string;
from: string;
to: string;
count: number;
positions: { line: number; column: number }[];
}[];
error?: string;
}
interface ProcessingOptions {
fileExtensions?: string[];
dryRun?: boolean;
maxConcurrentFiles?: number;
timeout?: number;
}
interface PermissionInfo {
readable: boolean;
writable: boolean;
exists: boolean;
isDirectory: boolean;
}
interface ValidationResult {
isValid: boolean;
errors: string[];
warnings: string[];
}Note: Extension API is planned for version 2.0
interface Plugin {
name: string;
version: string;
activate(context: PluginContext): void;
deactivate(): void;
}
interface PluginContext {
subscriptions: Disposable[];
registerCommand(command: string, callback: Function): Disposable;
registerReplacementProvider(provider: ReplacementProvider): Disposable;
}Last updated: 2025-12-24 | Version 1.0.0