### Programmatic API Usage Source: https://github.com/catdad/electronmon/blob/master/README.md Require and use the electronmon API to control the monitoring process programmatically. This example starts the monitor with default options. ```javascript const electronmon = require('electronmon'); (async () => { const options = {...}; const app = await electronmon(options); })(); ``` -------------------------------- ### Start Electronmon CLI Source: https://context7.com/catdad/electronmon/llms.txt Use npx to run electronmon from the command line, replacing the standard 'electron' command. Specify the entry point or pass arguments as needed. ```bash npx electronmon . ``` ```bash npx electronmon ./src/main.js ``` ```bash npx electronmon . --enable-logging --remote-debugging-port=9222 ``` ```bash ELECTRONMON_LOGLEVEL=verbose npx electronmon . ``` -------------------------------- ### Run electronmon from CLI Source: https://github.com/catdad/electronmon/blob/master/README.md Use this command to start electronmon and watch your application files. It automatically restarts or reloads the app on changes. ```bash npx electronmon . ``` -------------------------------- ### Configure electronmon in package.json Source: https://github.com/catdad/electronmon/blob/master/README.md Add an 'electronmon' object to your package.json to customize watching patterns. This example ignores the 'test' directory. ```json { "electronmon": { "patterns": ["!test/**"] } } ``` -------------------------------- ### app.restart() Source: https://context7.com/catdad/electronmon/llms.txt Completely restarts the Electron application by closing the current process and starting a new one. ```APIDOC ## app.restart() ### Description Forces a complete restart of the Electron application. Use this when main process changes need to be applied. ``` -------------------------------- ### electronmon(options) Source: https://context7.com/catdad/electronmon/llms.txt Initializes the electronmon monitoring process with custom configuration options. ```APIDOC ## electronmon(options) ### Description Starts monitoring an Electron application with specified configuration options. ### Parameters #### Request Body - **cwd** (string) - Optional - Working directory path - **args** (array) - Optional - Arguments to pass to the Electron app - **env** (object) - Optional - Environment variables - **logLevel** (string) - Optional - Logging verbosity level - **electronPath** (string) - Optional - Custom path to the Electron binary - **patterns** (array) - Optional - Glob patterns for files to watch or ignore ### Request Example { "cwd": "/path/to/app", "args": [".", "--enable-logging"], "logLevel": "verbose" } ``` -------------------------------- ### Initialize Renderer Process Source: https://github.com/catdad/electronmon/blob/master/fixtures/index.html Loads the renderer script for the Electron application. ```javascript require('./renderer.js'); ``` -------------------------------- ### Structure Electron Main Process Source: https://context7.com/catdad/electronmon/llms.txt Standard boilerplate for an Electron main process file compatible with electronmon. ```javascript // main.js - Main process file const { app, BrowserWindow } = require('electron'); const path = require('path'); let mainWindow; function createWindow() { mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, contextIsolation: false } }); mainWindow.loadFile(path.join(__dirname, 'index.html')); mainWindow.on('closed', () => { mainWindow = null; }); } app.whenReady().then(createWindow); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); ``` -------------------------------- ### Apply CSS Styles to Electronmon Source: https://github.com/catdad/electronmon/blob/master/fixtures/index.html Sets the global layout, background color, and typography for the application window. ```css html, body { margin: 0; background: #2e2e2e; color: #eee; text-align: center; } * { font-size: 46px; font-family: sans-serif; } ``` -------------------------------- ### Electronmon API Usage Source: https://github.com/catdad/electronmon/blob/master/README.md This snippet demonstrates how to require and initialize electronmon within your Node.js application. ```APIDOC ## API Usage You can use electronmon programmatically by requiring it and calling the main function. ### Method `require('electronmon')` ### Parameters - **options** (Object) - Optional configuration object. - **cwd** (String) - The root directory of your application. - **args** (Array) - Arguments to pass to the electron process. - **env** (Object) - Environment variables for the electron process. - **patterns** (Array) - Additional glob patterns for watching files. Defaults to `['**/*', '!node_modules', '!node_modules/**/*', '!.*', '!**/*.map']`. - **logLevel** (String) - Logging level. Possible values: `verbose`, `info`, `error`, `quiet`. Defaults to `info`. - **electronPath** (String) - Path to the electron binary. ### Request Example ```javascript const electronmon = require('electronmon'); (async () => { const options = { cwd: './app', args: ['--remote-debugging-port=9222'], patterns: ['src/**/*.js', 'views/**/*.html'], logLevel: 'verbose' }; const app = await electronmon(options); })(); ``` ### API Methods Once electronmon is initialized, it returns an object with methods to control the electron process: - **`app.reload()`** → `Promise` - Reloads all open web views. - **`app.restart()`** → `Promise` - Restarts the entire electron process. - **`app.close()`** → `Promise` - Closes the electron process and waits for file changes to restart it. - **`app.destroy()`** → `Promise` - Closes the electron process and stops monitoring. ``` -------------------------------- ### Configure Electronmon in package.json Source: https://context7.com/catdad/electronmon/llms.txt Configure electronmon behavior by adding an 'electronmon' field to your package.json. The 'patterns' option allows specifying glob patterns for files to watch or ignore. ```json { "name": "my-electron-app", "version": "1.0.0", "main": "src/main.js", "scripts": { "dev": "electronmon .", "start": "electron ." }, "electronmon": { "patterns": [ "!test/**", "!coverage/**", "!docs/**", "!*.md", "!.git/**" ] }, "devDependencies": { "electron": "^23.0.0", "electronmon": "^2.0.4" } } ``` -------------------------------- ### Configure Electronmon Log Levels Source: https://context7.com/catdad/electronmon/llms.txt Adjust output verbosity using the logLevel option or environment variables. Supported levels include verbose, info, error, and quiet. ```javascript const electronmon = require('electronmon'); // Verbose logging - shows all file discoveries and changes const appVerbose = await electronmon({ cwd: process.cwd(), args: ['.'], logLevel: 'verbose' }); // Quiet mode - minimal output const appQuiet = await electronmon({ cwd: process.cwd(), args: ['.'], logLevel: 'quiet' }); // Via environment variable // ELECTRONMON_LOGLEVEL=verbose npx electronmon . ``` -------------------------------- ### Restart Electron Application Source: https://context7.com/catdad/electronmon/llms.txt Use the `app.restart()` method to completely restart the Electron application. This is necessary when changes are made to the main process files. ```javascript const electronmon = require('electronmon'); (async () => { const app = await electronmon({ cwd: process.cwd(), args: ['.'] }); // Force restart after configuration changes process.on('SIGUSR1', async () => { console.log('Restarting Electron app...'); await app.restart(); console.log('App restarted successfully'); }); })(); ``` -------------------------------- ### Programmatic API Usage Source: https://context7.com/catdad/electronmon/llms.txt Require and use electronmon programmatically for advanced control. The main module exports a function that accepts configuration options and returns a control object. ```javascript const electronmon = require('electronmon'); (async () => { // Start monitoring with custom options const app = await electronmon({ cwd: '/path/to/your/electron/app', args: ['.', '--enable-logging'], env: { NODE_ENV: 'development', DEBUG: 'app:*' }, logLevel: 'verbose', electronPath: '/custom/path/to/electron', patterns: ['!test/**', '!docs/**'] }); // The app object provides control methods console.log('Electronmon started successfully'); })(); ``` -------------------------------- ### Reload Browser Windows Source: https://context7.com/catdad/electronmon/llms.txt Use the `app.reload()` method to reload all open browser windows without restarting the main process. This is ideal for applying renderer-side changes. ```javascript const electronmon = require('electronmon'); (async () => { const app = await electronmon({ cwd: process.cwd(), args: ['.'] }); // Trigger reload after some event (e.g., external file sync) setTimeout(async () => { await app.reload(); console.log('All browser windows reloaded'); }, 5000); })(); ``` -------------------------------- ### app.reload() Source: https://context7.com/catdad/electronmon/llms.txt Reloads all open browser windows in the Electron application without restarting the main process. ```APIDOC ## app.reload() ### Description Reloads all open browser windows in the Electron application. Useful for applying renderer-side changes without a full restart. ``` -------------------------------- ### app.destroy() Source: https://context7.com/catdad/electronmon/llms.txt Stops the Electron application and terminates the file watcher. ```APIDOC ## app.destroy() ### Description Completely stops the Electron application and terminates the file watcher process for a clean shutdown. ``` -------------------------------- ### Control Application Reload/Restart Source: https://github.com/catdad/electronmon/blob/master/README.md The electronmon API exposes methods to manually reload, restart, or close the Electron application. These methods are asynchronous and return Promises. ```javascript app.reload() app.restart() app.close() app.destroy() ``` -------------------------------- ### Destroy Electronmon Process Source: https://context7.com/catdad/electronmon/llms.txt Use the `app.destroy()` method to completely stop the Electron application and terminate the file watcher. This is used for a clean shutdown of the monitoring process. ```javascript const electronmon = require('electronmon'); (async () => { const app = await electronmon({ cwd: process.cwd(), args: ['.'] }); // Graceful shutdown on process termination process.on('SIGTERM', async () => { console.log('Shutting down electronmon...'); await app.destroy(); console.log('Electronmon stopped'); process.exit(0); }); })(); ``` -------------------------------- ### app.close() Source: https://context7.com/catdad/electronmon/llms.txt Closes the Electron application while keeping the file watcher active. ```APIDOC ## app.close() ### Description Closes the Electron application. The monitoring process continues to run and will restart the app upon detecting file changes. ``` -------------------------------- ### Close Electron Application Source: https://context7.com/catdad/electronmon/llms.txt Use the `app.close()` method to stop the Electron application while continuing to monitor file changes. The app will restart automatically when a change is detected. ```javascript const electronmon = require('electronmon'); (async () => { const app = await electronmon({ cwd: process.cwd(), args: ['.'] }); // Close app but keep monitoring for changes setTimeout(async () => { await app.close(); console.log('App closed, waiting for file changes to restart...'); }, 10000); })(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.