implement watch functionality

This commit is contained in:
Iuri Matias 2016-08-14 12:26:49 -04:00
parent 00a7dbe2f1
commit 421a0af41e
2 changed files with 35 additions and 4 deletions

View File

@ -1,9 +1,11 @@
/*jshint esversion: 6 */
var async = require('async'); var async = require('async');
var Web3 = require('web3'); var Web3 = require('web3');
var fs = require('fs'); var fs = require('fs');
var grunt = require('grunt'); var grunt = require('grunt');
var mkdirp = require('mkdirp'); var mkdirp = require('mkdirp');
var colors = require('colors'); var colors = require('colors');
var chokidar = require('chokidar');
var Deploy = require('./deploy.js'); var Deploy = require('./deploy.js');
var ContractsManager = require('./contracts.js'); var ContractsManager = require('./contracts.js');
@ -71,7 +73,7 @@ var Embark = {
} }
}, },
server: function() { server: function(callback) {
var finalhandler = require('finalhandler'); var finalhandler = require('finalhandler');
var http = require('http'); var http = require('http');
var serveStatic = require('serve-static'); var serveStatic = require('serve-static');
@ -85,13 +87,41 @@ var Embark = {
}); });
// Listen // Listen
console.log("listening on port 8000".underline.bgWhite.green); console.log("listening on port 8000".underline.green);
server.listen(8000) ; server.listen(8000) ;
callback();
},
watch: function() {
var embarkConfig = JSON.parse(fs.readFileSync("embark.json"));
var appConfig = embarkConfig.app;
var filesToWatch = [];
for(var targetFile in appConfig) {
filesToWatch.push(appConfig[targetFile]);
}
console.log(filesToWatch);
var watcher = chokidar.watch(filesToWatch, {
ignored: /[\/\\]\./,
persistent: true,
ignoreInitial: true,
followSymlinks: true
});
watcher
.on('add', path => console.log(`File ${path} has been added`))
.on('change', path => console.log(`File ${path} has been changed`))
.on('unlink', path => console.log(`File ${path} has been removed`))
.on('ready', () => console.log('ready to watch changes'));
console.log("done!");
} }
}; };
//module.exports = Embark; //module.exports = Embark;
//Embark.buildAssets(); Embark.buildAssets();
//Embark.server() Embark.server(function() {
Embark.watch();
});

View File

@ -15,6 +15,7 @@
"dependencies": { "dependencies": {
"async": "^2.0.1", "async": "^2.0.1",
"bignumber.js": "debris/bignumber.js#master", "bignumber.js": "debris/bignumber.js#master",
"chokidar": "^1.6.0",
"colors": "^1.1.2", "colors": "^1.1.2",
"commander": "^2.8.1", "commander": "^2.8.1",
"finalhandler": "^0.5.0", "finalhandler": "^0.5.0",