UNPKG

@yandex/themekit

Version:

Build system of design-tokens for any platforms

29 lines (28 loc) 892 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.watch = void 0; const chokidar_1 = require("chokidar"); /** * Watches for selected paths and call `onChange` after files changed. */ function watch(paths, onChange) { console.log('\nWatching for changes...'); let isShutdown = false; const watcher = chokidar_1.watch(paths, { ignoreInitial: true, atomic: 500 }); const onChangeWrapper = () => { if (!isShutdown) { onChange(); } }; const onProcessStop = () => { isShutdown = true; console.log('\nShutting down watch'); watcher.close(); }; watcher.on('unlink', onChangeWrapper); watcher.on('add', onChangeWrapper); watcher.on('change', onChangeWrapper); process.once('SIGINT', onProcessStop); process.once('SIGTERM', onProcessStop); } exports.watch = watch;