-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (43 loc) · 1.38 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
'use strict';
var fs = require('fs'),
argsparser = require('argsparser'),
chokidar = require('chokidar'),
UnderscoreTemplateCompiler = require('./lib/underscore.template.compiler').UnderscoreCompiler,
compiler = new UnderscoreTemplateCompiler();
var compileFiles = function (files, inDir, outDir) {
var l = files.length,
file;
while (l--) {
file = files[l];
compiler.main([inDir, file].join(''), [outDir, file, '.js'].join(''));
}
};
var
args = process.argv,
params = argsparser.parse(args),
inDir = params['-i'],
outDir = params['-o'],
watch = params['-w'],
inFile, outFile, filename,
watcher;
watcher = chokidar.watch(inDir, {ignored: /^\./, persistent: true});
watcher
.on('add', function (path) {
console.log('File ', path, ' has been added');
filename = path.substr(path.indexOf(inDir) + inDir.length + 1),
outFile = [outDir, '/', filename, '.js'].join('');
compiler.main(path, outFile);
})
.on('change', function (path) {
console.log('File ', path, ' has been changed');
filename = path.substr(path.indexOf(inDir) + inDir.length + 1),
outFile = [outDir, '/', filename, '.js'].join('');
compiler.main(path, outFile);
})
.on('unlink', function (path) {
console.log('File ', path, ' has been removed');
})
.on('error', function (error) {
console.error('Error happened: ', error);
});
watcher.close();