Commit fa714d35e9d0ced3bda0533c404f11554bd5ad99
1 parent
ded337bfb5
Exists in
master
nombre del archivo
Showing
1 changed file
with
1 additions
and
0 deletions
Show diff stats
watch/index.js
| 1 | module.exports = function (dir, callback) { | 1 | module.exports = function (dir, callback) { |
| 2 | 2 | ||
| 3 | const chokidar = require('chokidar'); | 3 | const chokidar = require('chokidar'); |
| 4 | 4 | ||
| 5 | const watcher = chokidar.watch(dir, { ignored: [config.dirDestino, config.dirRecadv] }); | 5 | const watcher = chokidar.watch(dir, { ignored: [config.dirDestino, config.dirRecadv] }); |
| 6 | 6 | ||
| 7 | watcher.on('add', function(file) { | 7 | watcher.on('add', function(file) { |
| 8 | 8 | ||
| 9 | var extencion = file.split('.')[1]; | 9 | var extencion = file.split('.')[1]; |
| 10 | 10 | ||
| 11 | if (extencion == 'txt') { | 11 | if (extencion == 'txt') { |
| 12 | 12 | ||
| 13 | fs.readFile(file, 'utf8', function (err, fileString) { | 13 | fs.readFile(file, 'utf8', function (err, fileString) { |
| 14 | 14 | ||
| 15 | if (err) { | 15 | if (err) { |
| 16 | console.log('ERROR', err); | 16 | console.log('ERROR', err); |
| 17 | return; | 17 | return; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | console.log(`iniciando proceso ${file}`); | ||
| 20 | callback(fileString, file); | 21 | callback(fileString, file); |
| 21 | }); | 22 | }); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | }); | 25 | }); |
| 25 | 26 | ||
| 26 | }; | 27 | }; |
| 27 | 28 |