mirror of https://github.com/embarklabs/embark.git
refactor watch
This commit is contained in:
parent
eb95ae7fd6
commit
f6c8b7a301
|
@ -2,4 +2,5 @@ node_modules
|
|||
TODO
|
||||
.node-xmlhttprequest-sync-*
|
||||
demo/dist/
|
||||
demo/.embark/development/
|
||||
boilerplate/dist/
|
||||
|
|
35
lib/index.js
35
lib/index.js
|
@ -13,6 +13,8 @@ var ContractsManager = require('./contracts.js');
|
|||
var ABIGenerator = require('./abi.js');
|
||||
var TemplateGenerator = require('./template_generator.js');
|
||||
var Blockchain = require('./blockchain.js');
|
||||
var Server = require('./server.js');
|
||||
var Watch = require('./watch.js');
|
||||
|
||||
var Embark = {
|
||||
|
||||
|
@ -35,9 +37,10 @@ var Embark = {
|
|||
run: function(env) {
|
||||
Embark.deploy(function(abi) {
|
||||
Embark.buildAssets(abi);
|
||||
var server = new Server();
|
||||
var server = new Server({});
|
||||
server.start(function() {
|
||||
Embark.watch();
|
||||
var watch = new Watch();
|
||||
watch.start();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
@ -114,34 +117,6 @@ var Embark = {
|
|||
//console.log(content);
|
||||
fs.writeFileSync("dist/" + targetFile, content);
|
||||
}
|
||||
},
|
||||
|
||||
server: function(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!");
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
var fs = require('fs');
|
||||
var chokidar = require('chokidar');
|
||||
|
||||
var Watch = function(options) {
|
||||
this.options = options;
|
||||
};
|
||||
|
||||
Watch.prototype.start = function() {
|
||||
var embarkConfig = JSON.parse(fs.readFileSync("embark.json"));
|
||||
|
||||
var appConfig = embarkConfig.app;
|
||||
var filesToWatch = [];
|
||||
|
||||
for(var targetFile in appConfig) {
|
||||
filesToWatch.push(appConfig[targetFile]);
|
||||
}
|
||||
|
||||
// TODO: add callback to ready
|
||||
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 = Watch;
|
Loading…
Reference in New Issue