Verified Commit 01b42080 authored by Aral Balkan's avatar Aral Balkan
Browse files

Make sure that rule-partials exist before using the cache

With this fix, you can now nuke the ~/better.fyi/.private/cache folder without impacting future build integrity. (The cache, including rule partials, will be re-created if it doesn’t already exist.)
parent 4a7c174f
......@@ -133,24 +133,33 @@ class Blockdown
#
setupCache: =>
cacheDirectory = path.join app.homeDirectory, '.private', 'cache'
cacheDirectory = app.cacheDirectory
rulePartialsDirectory = path.join cacheDirectory, 'rule-partials'
themeCacheCurrentModifiedTimesFile = path.join cacheDirectory, 'current-modified-times', 'themes.json'
themeCachePreviousModifiedTimesFile = path.join cacheDirectory, 'previous-modified-times', 'themes.json'
themeCacheCurrentModifiedTimes = fs.readJsonSync themeCacheCurrentModifiedTimesFile, 'utf-8'
themeCachePreviousModifiedTimes = fs.readJsonSync themeCachePreviousModifiedTimesFile, 'utf-8'
# Check if there are any template changes (if there are, this will require a full rebuild),
# otherwise, we can use the cache and we won’t need to re-render the content.
@useContentCache = true
for fileName, lastModifiedDate of themeCachePreviousModifiedTimes
if (fileName.indexOf '/templates/') != -1
# This is a template, check if it has changed
if lastModifiedDate != themeCacheCurrentModifiedTimes[fileName]
# There are changes to a theme template, do not use the cache.
@log.info "\t✓ Theme template changed (#{fileName}), *not* using cache."
@useContentCache = false
break
# Make sure that the rule partials directory exists before
# using the cache. Otherwise, it will have to be recreated or
# we will end up with empty blocker list files.
if fs.existsSync rulePartialsDirectory
# Check if there are any template changes (if there are, this will require a full rebuild),
# otherwise, we can use the cache and we won’t need to re-render the content.
@useContentCache = true
for fileName, lastModifiedDate of themeCachePreviousModifiedTimes
if (fileName.indexOf '/templates/') != -1
# This is a template, check if it has changed
if lastModifiedDate != themeCacheCurrentModifiedTimes[fileName]
# There are changes to a theme template, do not use the cache.
@log.info "\t✓ Theme template changed (#{fileName}), *not* using cache."
@useContentCache = false
break
else
@log.info "\t ⚠ Rule partials folder does not exist. Not using cache!"
@useContentCache = false
# Set up the content cache (we will use it, if nothing else, to calculate
# the last modified time for the metadata).
......@@ -167,7 +176,7 @@ class Blockdown
# Inform person if we are using the content cache.
if @useContentCache
console.log "\t✓ No changes to theme templates; using cache."
console.log "\t✓ No changes to theme templates and cache safe to use; using cache."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment