mirror of https://github.com/embarklabs/embark.git
implement watch functionality
This commit is contained in:
parent
00a7dbe2f1
commit
421a0af41e
38
lib/index.js
38
lib/index.js
|
@ -1,9 +1,11 @@
|
|||
/*jshint esversion: 6 */
|
||||
var async = require('async');
|
||||
var Web3 = require('web3');
|
||||
var fs = require('fs');
|
||||
var grunt = require('grunt');
|
||||
var mkdirp = require('mkdirp');
|
||||
var colors = require('colors');
|
||||
var chokidar = require('chokidar');
|
||||
|
||||
var Deploy = require('./deploy.js');
|
||||
var ContractsManager = require('./contracts.js');
|
||||
|
@ -71,7 +73,7 @@ var Embark = {
|
|||
}
|
||||
},
|
||||
|
||||
server: function() {
|
||||
server: function(callback) {
|
||||
var finalhandler = require('finalhandler');
|
||||
var http = require('http');
|
||||
var serveStatic = require('serve-static');
|
||||
|
@ -85,13 +87,41 @@ var Embark = {
|
|||
});
|
||||
|
||||
// Listen
|
||||
console.log("listening on port 8000".underline.bgWhite.green);
|
||||
console.log("listening on port 8000".underline.green);
|
||||
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;
|
||||
|
||||
//Embark.buildAssets();
|
||||
//Embark.server()
|
||||
Embark.buildAssets();
|
||||
Embark.server(function() {
|
||||
Embark.watch();
|
||||
});
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
"dependencies": {
|
||||
"async": "^2.0.1",
|
||||
"bignumber.js": "debris/bignumber.js#master",
|
||||
"chokidar": "^1.6.0",
|
||||
"colors": "^1.1.2",
|
||||
"commander": "^2.8.1",
|
||||
"finalhandler": "^0.5.0",
|
||||
|
|
Loading…
Reference in New Issue