diff --git a/hot-reload.js b/hot-reload.js index de5e58c..f0865da 100644 --- a/hot-reload.js +++ b/hot-reload.js @@ -1,3 +1,5 @@ +const includes = [] + const filesInDirectory = dir => new Promise (resolve => dir.createReader ().readEntries (entries => @@ -13,9 +15,15 @@ const filesInDirectory = dir => new Promise (resolve => ) ) -const timestampForFilesInDirectory = dir => - filesInDirectory (dir).then (files => - files.map (f => f.name + f.lastModifiedDate).join ()) +const timestampForFilesInDirectory = dir => { + return filesInDirectory (dir).then (files => { + if (includes.length && !includes.every(i => files.some(f => i === f.name))) return; + + return files + .filter(f => includes.length ? includes.includes(f.name) : true) + .map (f => f.name + f.lastModifiedDate).join () + }) +} const reload = () => { @@ -31,7 +39,7 @@ const watchChanges = (dir, lastTimestamp) => { timestampForFilesInDirectory (dir).then (timestamp => { - if (!lastTimestamp || (lastTimestamp === timestamp)) { + if (!timestamp || !lastTimestamp || (lastTimestamp === timestamp)) { setTimeout (() => watchChanges (dir, timestamp), 1000) // retry after 1s @@ -50,3 +58,10 @@ chrome.management.getSelf (self => { chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir)) } }) + +if (typeof module === 'object') { + exports.include = (files) => { + includes.push(...files) + } +} +