Skip to main content
Glama
watch.ts2.25 kB
import { runParallel, watch } from '@intlayer/chokidar'; import { type GetConfigurationOptions, getAppLogger, getConfiguration, } from '@intlayer/config'; type WatchOptions = { skipPrepare?: boolean; with?: string | string[]; configOptions?: GetConfigurationOptions; }; /** * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory. * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs} */ export const watchContentDeclaration = async (options?: WatchOptions) => { const config = getConfiguration(options?.configOptions); const appLogger = getAppLogger(config); // Store references to the child process let parallelProcess: ReturnType<typeof runParallel> | undefined; if (options?.with) { parallelProcess = runParallel(options.with); // Handle the promise to avoid unhandled rejection parallelProcess.result.catch(() => { // Parallel process failed or was terminated process.exit(1); }); } appLogger('Watching Intlayer content declarations'); // Capture the watcher instance const watcher = watch({ persistent: true, skipPrepare: options?.skipPrepare ?? false, }); // Define a Graceful Shutdown function const handleShutdown = async () => { // Prevent multiple calls process.off('SIGINT', handleShutdown); process.off('SIGTERM', handleShutdown); appLogger('Stopping Intlayer watcher...'); try { // Close the file watcher immediately to stop "esbuild service not running" errors await watcher.close(); // If runParallel exposes the child process, we can try to kill it explicitly. // Even if it doesn't, process.exit() below usually cleans up attached children. if (parallelProcess && 'child' in parallelProcess) { // @ts-ignore - Assuming child exists on the return type if runParallel is based on spawn/exec parallelProcess.child?.kill('SIGTERM'); } } catch (error) { console.error('Error during shutdown:', error); } finally { process.exit(0); } }; // Attach Signal Listeners process.on('SIGINT', handleShutdown); process.on('SIGTERM', handleShutdown); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server