Permalink
Browse files

🤫🚨 `@phenomic/core`: Fix fail introduced with support for multiple `c…

…ontent` option
  • Loading branch information...
MoOx committed May 2, 2018
1 parent 4df49e3 commit c79b572fa9c54cf88419dac1f6367e3cd5a5c0ef
Showing with 25 additions and 10 deletions.
  1. +25 −10 packages/core/src/commands/start.js
@@ -66,6 +66,8 @@ async function start(config: PhenomicConfig) {
}
const io = socketIO(config.socketPort);
const filesPerContentKey = {};
await Promise.all(
Object.keys(config.content).map(async contentKey => {
try {
@@ -98,26 +100,39 @@ async function start(config: PhenomicConfig) {
patterns: globs
});
watcher.onChange(async function(files) {
watcher.onChange(async function(files /* deletedFiles */) {
// currently our db is stupid: we don't do removal
// so instead we nuke the db each times there is a tiny change
// for now it's not creating any problem, but it's clearly something
// we need to improve for HUGE website
// @todo: don't nuke the db and think about a way to remove deleted
// files & related injected data (see collector-files)
filesPerContentKey[contentKey] = files;
debug("watcher onChange event");
try {
await db.destroy();
await Promise.all(
files.map(file => {
return processFile({
db,
fileKey: contentKey,
file,
transformers,
collectors
});
})
Object.keys(filesPerContentKey).map(
async localContentKey =>
await Promise.all(
filesPerContentKey[localContentKey].map(file => {
return processFile({
db,
fileKey: localContentKey,
file,
transformers,
collectors
});
})
)
)
);
} catch (e) {
setTimeout(() => {
throw e;
}, 1);
}
// note: we could emit faster but does it's worth it?
io.emit("change");
});
} catch (e) {

0 comments on commit c79b572

Please sign in to comment.