Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions lib/core/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,11 @@ class Engine {
self.currentAbi = abi;
self.contractsJSON = contractsJSON;
pipeline.build(abi, contractsJSON, null, function() {
self.watch.restart(); // Necessary because changing a file while it is writing can stop it from being watched
self.events.emit('outputDone');
});
});
});
// TODO: still need to redeploy contracts because the original contracts
// config is being corrupted
this.events.on('file-event', function(fileType, _path) {
if (fileType === 'asset') {
self.events.emit('asset-changed', self.contractsManager);
}
});
}

codeGeneratorService(_options) {
Expand Down Expand Up @@ -213,6 +207,11 @@ class Engine {
});

this.events.on('file-event', function (fileType) {
// TODO: still need to redeploy contracts because the original contracts
// config is being corrupted
if (fileType === 'asset') {
self.events.emit('asset-changed', self.contractsManager);
}
// TODO: for now need to deploy on asset chanes as well
// because the contractsManager config is corrupted after a deploy
if (fileType === 'contract' || fileType === 'config') {
Expand All @@ -225,8 +224,8 @@ class Engine {

fileWatchService(_options) {
this.events.emit("status", "Watching for changes");
let watch = new Watch({logger: this.logger, events: this.events});
watch.start();
this.watch = new Watch({logger: this.logger, events: this.events});
this.watch.start();
}

webServerService() {
Expand Down
15 changes: 15 additions & 0 deletions lib/pipeline/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Watch {
constructor(options) {
this.logger = options.logger;
this.events = options.events;
this.fileWatchers = [];
}

start() {
Expand All @@ -32,6 +33,19 @@ class Watch {
this.logger.info("ready to watch file changes");
}

restart() {
this.stop();
this.start();
}

stop() {
this.fileWatchers.forEach(fileWatcher => {
fileWatcher.close();
fileWatcher = null;
});
this.fileWatchers = [];
}

watchAssets(embarkConfig, callback) {
let self = this;
let appConfig = embarkConfig.app;
Expand Down Expand Up @@ -102,6 +116,7 @@ class Watch {
let configWatcher = chokidar.watch(files, {
ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
});
this.fileWatchers.push(configWatcher);

configWatcher
.on('add', path => changeCallback('add', path))
Expand Down
Loading