EIPC
Documentation

API Reference

CLI and programmatic API for EIPC code generation.

CLI

The generate-ipc command generates IPC wiring from your schema files.

generate-ipc <schemaDir> <outputDir> [--watch]

Arguments

ArgumentDescription
schemaDirDirectory containing .eipc schema files
outputDirOutput directory for generated code
--watchWatch for changes and regenerate automatically

Example

# One-time generation
generate-ipc src/schema src/ipc

# Watch mode for development
generate-ipc src/schema src/ipc --watch

Package.json Integration

{
  "scripts": {
    "generate:ipc": "generate-ipc src/schema src/ipc",
    "generate:ipc:watch": "generate-ipc src/schema src/ipc --watch"
  }
}

Programmatic API

For advanced use cases, you can use the programmatic API directly.

generateWiring

One-time generation of IPC wiring:

import { generateWiring } from '@marshallofsound/ipc';

await generateWiring({
  schemaFolder: './src/schema',
  wiringFolder: './src/ipc',
});

watchWiring

Watch for schema changes and regenerate automatically. Returns a promise that resolves once the watcher is ready:

import { watchWiring } from '@marshallofsound/ipc';

const watcher = await watchWiring({
  schemaFolder: './src/schema',
  wiringFolder: './src/ipc',
});

console.log('Watching for changes...');

watcher.on('change-detected', (file) => {
  console.log(`File changed: ${file}`);
});

watcher.on('generation-complete', () => {
  console.log('Regeneration complete');
});

watcher.on('generation-error', (error) => {
  console.error('Generation failed:', error.message);
});

// Stop watching when done
watcher.close();

Watcher Events

EventArgumentsDescription
change-detectedfile: stringA schema file was modified
file-addedfile: stringA new schema file was created
file-removedfile: stringA schema file was deleted
generation-startGeneration is starting
generation-completeGeneration finished successfully
generation-errorerror: ErrorGeneration failed
errorerror: ErrorWatcher encountered an error

Options

interface WiringOptions {
  /**
   * Absolute path to a folder containing .eipc schema files
   */
  schemaFolder: string;

  /**
   * Absolute path to output folder for generated code
   */
  wiringFolder: string;
}

Generated Output

Both the CLI and programmatic API create the following directory structure:

src/ipc/
├── .eipc-generated   # Marker file (do not delete)
├── browser/          # Main process implementations
│   └── {module}.ts
├── preload/          # Preload script code
│   └── {module}.ts
├── renderer/         # Renderer process client
│   └── {module}.ts
├── renderer-hooks/   # React hooks for stores
│   └── {module}.ts
├── common/           # Shared types
│   └── {module}.ts
├── common-runtime/   # Runtime utilities
│   └── {module}.ts
└── _internal/        # Internal generated code
    └── ...

Safety Check

EIPC writes a .eipc-generated marker file to the output directory. Before regenerating, it checks for this marker to prevent accidentally overwriting non-EIPC directories.

If you see this error:

Refusing to overwrite "src/ipc" - it exists but was not created by EIPC.

Either delete the directory manually, or choose a different output path.

Error Handling

Both methods throw on schema parsing errors with line/column information:

try {
  await generateWiring(options);
} catch (error) {
  console.error('Schema error:', error.message);
}

CLI exits with code 1 on error:

$ generate-ipc src/schema src/ipc
Error generating IPC wiring: Expected 'interface' but found 'foo' at line 5, column 1