-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (52 loc) · 1.54 KB
/
index.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const Chokidar = require('chokidar');
const Path = require('path');
const log = console.log.bind(console);
const fs = require('fs');
const Container = require('./docker/container');
const artifactsDir = Path.join(__dirname, 'artifacts');
const watcher = Chokidar.watch(artifactsDir, {
ignored: /(^|[\/\\])\../,
persistent: true,
ignoreInitial: true,
usePolling: true,
awaitWriteFinish: {
pollInterval: 100,
stabilityThreshold: 250
},
});
const SpawnContainer = function (path, isDir) {
isDir = (isDir) ? true : false;
var dirName = path.replace(artifactsDir + Path.sep, '');
const segments = dirName.split(Path.sep);
if (!isDir) {
segments.pop();
}
if (segments.length !== 1) {
return;
}
Container.spawn(segments[0]);
}
watcher
.on('add', function (path) {
log('File', path, 'has been added');
SpawnContainer(path);
})
.on('addDir', function (path) {
log('Directory', path, 'has been added');
SpawnContainer(path, true);
})
.on('change', function (path) {
log('File', path, 'has been changed');
SpawnContainer(path);
})
.on('unlink', function (path) {
log('File', path, 'has been removed');
SpawnContainer(path);
})
.on('unlinkDir', function (path) {
log('Directory', path, 'has been removed');
SpawnContainer(path, true);
})
.on('error', function (error) { log('Error happened', error); })
.on('ready', function () { log('Initial scan complete. Ready for changes.'); })
.on('raw', function (event, path, details) { log('Raw event info:', event, path, details); })