1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createFileWatch = void 0;
|
4 | const path = require("path");
|
5 | const chokidar = require("chokidar");
|
6 | const rxjs_1 = require("rxjs");
|
7 | const path_1 = require("../utils/path");
|
8 | const log = require("../utils/log");
|
9 | function createFileWatch(projectPath, ignoredPaths = []) {
|
10 | log.debug(`Watching for changes: projectPath: ${projectPath}, ignoredPaths: ${ignoredPaths}`);
|
11 | const watch = chokidar.watch(projectPath, {
|
12 | ignoreInitial: true,
|
13 | ignored: [...ignoredPaths, /((^[\/\\])\..)|(\.js$)|(\.map$)|(\.metadata\.json|node_modules)/],
|
14 | persistent: true,
|
15 | });
|
16 | const handleFileChange = (event, filePath, observer) => {
|
17 | log.debug(`Watch: Path changed. Event: ${event}, Path: ${filePath}`);
|
18 | if (event === 'unlinkDir' || event === 'addDir') {
|
19 |
|
20 | return;
|
21 | }
|
22 | observer.next({
|
23 | filePath: path_1.ensureUnixPath(path.resolve(filePath)),
|
24 | event,
|
25 | });
|
26 | };
|
27 | return rxjs_1.Observable.create((observer) => {
|
28 | watch.on('all', (event, filePath) => handleFileChange(event, filePath, observer));
|
29 | return () => watch.close();
|
30 | });
|
31 | }
|
32 | exports.createFileWatch = createFileWatch;
|
33 |
|
\ | No newline at end of file |