我是nodejs新手 我需要在两个子目录上观察文件更改,当发生任何更改时我需要更新服务工作者
一切正常,但为什么lista数组是空的?
var gulp = require('gulp');
var watch = require('gulp-watch');
var path = require('path');
var fs = require('fs');
root = '/var/www/website.it';
dest = root + '/var/cache/misc/assets/'
var dests = [dest + 'js/tygh/*.js', dest + 'design/themes/responsive/css/*.css'];
gulp.task('default', function(){
watch(dests, function () {
var lista = [];
dests.forEach(function(dirname){
dirname = path.dirname(dirname);
fs.readdir(dirname, (err, files) => {
files.forEach(file => {
lista.push(dirname + '/' + file);
});
});
console.log(lista); // here print list of files
});
console.log(lista); // here print empty array []
});
});