npm package: @listenrightmeeow/newk-core
Description: Core infrastructure for Newk optimization platform
Author: Mike Dyer
Latest version: 2.0.1
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# @listenrightmeeow/newk-core

[![npm version](https://img.shields.io/npm/v/@listenrightmeeow/newk-core)](https://www.npmjs.com/package/@listenrightmeeow/newk-core)
[![License: BSD-3-Clause](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

Core infrastructure for the NEWK optimization platform, providing event-driven architecture, plugin management, and staging capabilities.

## Installation

```bash
npm install @listenrightmeeow/newk-core
```

## Features

- **Event-Driven Architecture**: Built-in EventBus for decoupled communication
- **Plugin System**: Dynamic plugin discovery and loading
- **Staging Manager**: Safe file operations in isolated environments
- **Port Management**: Intelligent port allocation for services
- **Logging System**: Comprehensive logging with multiple levels
- **Cache Management**: Built-in caching for optimization operations
- **Server Management**: Static server and dev server capabilities

## Usage

### Event Bus

```javascript
import { EventBus } from '@listenrightmeeow/newk-core';

const eventBus = EventBus.getInstance();

// Listen to events
eventBus.on('optimization.started', (event) => {
  console.log('Optimization started:', event.sessionId);
});

// Emit events
eventBus.emit('optimization.started', {
  sessionId: 'abc-123',
  timestamp: Date.now()
});
```

### Logger

```javascript
import { Logger } from '@listenrightmeeow/newk-core';

const logger = Logger.create('my-module');

logger.info('Starting process');
logger.debug('Debug information');
logger.warn('Warning message');
logger.error('Error occurred');
```

### Staging Manager

```javascript
import { StagingManager } from '@listenrightmeeow/newk-core';

const stagingManager = new StagingManager({
  projectPath: process.cwd(),
  stagingPath: '.newk/staging'
});

// Prepare staging environment
await stagingManager.prepareStaging();

// Get staging paths
const paths = stagingManager.getStagingPaths();
console.log('Client staging:', paths.client);
console.log('Server staging:', paths.server);

// Cleanup
await stagingManager.cleanup();
```

### Plugin System

```javascript
import { PluginLoader, PluginRegistry } from '@listenrightmeeow/newk-core';

// Initialize registry
const registry = PluginRegistry.getInstance();
registry.initialize(process.cwd());

// Load plugins
const loader = new PluginLoader();
const plugins = await loader.loadPlugins(['@listenrightmeeow/newk-plugin-mppo']);

// Use plugins
for (const plugin of plugins) {
  await plugin.initialize();
  const result = await plugin.optimize({
    projectPath: process.cwd()
  });
}
```

### Port Manager

```javascript
import { PortManager } from '@listenrightmeeow/newk-core';

const portManager = PortManager.getInstance();

// Allocate a port
const port = await portManager.allocatePort('dev-server');
console.log('Allocated port:', port);

// Release when done
await portManager.releasePort('dev-server');
```

## API Reference

### Classes

- `EventBus` - Central event management system
- `Logger` - Logging utility with multiple levels
- `StagingManager` - File staging and isolation
- `PluginLoader` - Dynamic plugin loading
- `PluginRegistry` - Plugin registration and management
- `PortManager` - Port allocation and management
- `CacheManager` - Cache operations
- `ServerManager` - Static server management

### Types

All TypeScript types are exported and available for use:

```typescript
import {
  Plugin,
  EventBusEvent,
  LogLevel,
  PluginMetadata
} from '@listenrightmeeow/newk-core';
```

## Development

```bash
# Install dependencies
npm install

# Build
npm run build

# Test
npm test

# Lint
npm run lint
```

## License

BSD-3-Clause © Mike Dyer

## Links

- [GitHub Repository](https://github.com/listenrightmeow/newk)
- [NPM Package](https://www.npmjs.com/package/@listenrightmeeow/newk-core)
- [Documentation](https://github.com/listenrightmeow/newk/tree/main/packages/newk-core)