-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtasks-watch.ts
More file actions
42 lines (37 loc) · 996 Bytes
/
tasks-watch.ts
File metadata and controls
42 lines (37 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import chokidar = require('chokidar');
import path = require('path');
// todo: use observables?
export function tasksWatch({project, taskQueue, watch, paths}){
let isRunning = false;
let changedModule: number;
runTasks();
if (watch) {
chokidar.watch(project, {ignored: /[\/\\]\./})
.on('change', (event) => {
changedModule = paths.indexOf(event.split(path.sep)[0]);
console.log(`Changes detected: ${event}`);
runTasks();
});
}
return Promise.resolve();
function runTasks() {
if (isRunning) {
return;
}
isRunning = true;
taskQueue.tasks.forEach((task: any, i: number) => {
task.skip = () => changedModule && i !== changedModule;
});
return taskQueue.run()
.then(() => {
console.log(`\n-------------------------------------\n`);
isRunning = false;
})
.catch(err => {
if (err) {
console.error(err);
}
isRunning = false;
});
}
}