-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: include only some files #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xpl Since we generate |
||
|
||
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) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please clarify what that line does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xpl It checks if the user has specified any required
includes
, and if so, checks if not all of the files specified for inclusion actually exist in this timeout cycle - if any of the specified includes don't exist, it short-circuits so that we will wait for the next cycle to check again, hoping all the required files will exist then.