Ind.ie is now Small Technology Foundation.
Commit 12134dce authored by Aral Balkan's avatar Aral Balkan

Removed file are deleted from build when using the cache

* Also cleaned up the log messages
parent 820eb38a
......@@ -100,7 +100,7 @@ class App
logger.extend @
@debug "App initiated. Logs at #{logFile}"
@info "▲❤ Better is initialising…"
@info "\n▲❤ Better is initialising.\n"
# Load the configuration
......@@ -218,7 +218,7 @@ class App
Promise.try =>
startTime = new Date
if @weNeedToGenerateThemes()
@info 'Generating themes.'
@info "\t ✓ Generating theme…"
fs.removeAsync @themeForAppDataDirectory
.then => fs.removeAsync @themeForSiteDataDirectory
......@@ -228,15 +228,15 @@ class App
.then => fs.copyAsync @siteThemeDirectory, @themeForSiteDataDirectory
.then => @generateStylesForThemeAtDirectory @themeForAppDataDirectory
.then => @generateStylesForThemeAtDirectory @themeForSiteDataDirectory
.then => endTime = new Date; @info "Took: #{endTime - startTime} ms"
.then => endTime = new Date; @info "\t ✓ Theme generated. (#{endTime - startTime} ms)"
.catch (e) =>
@error "Fatal: Could not generate themes.\n\n#{e}"
console.trace()
process.exit 1
else
@info "Theme hasn’t changed. Not re-generating it."
endTime = new Date
@info "Took: #{endTime - startTime} ms"
@info "\t✓ Theme unchanged; not re-generating."
#endTime = new Date
#@info "Took: #{endTime - startTime} ms"
return true
......
......@@ -136,7 +136,7 @@ class Blockdown
themeCachePreviousModifiedTimes = fs.readFileSync themeCachePreviousModifiedTimesFile, 'utf-8'
if themeCacheCurrentModifiedTimes == themeCachePreviousModifiedTimes
console.log "Decide cache policy: Theme hasn’t changed, use the content cache when possible."
#@info "Decide cache policy: Theme hasn’t changed, use the content cache when possible."
@useContentCache = true
contentCacheCurrentModifiedTimesFile = path.join cacheDirectory, 'current-modified-times', 'content.json'
......@@ -150,10 +150,14 @@ class Blockdown
@contentCurrentModifiedTimes = JSON.parse(_contentCurrentModifiedTimes)
@contentPreviousModifiedTimes = JSON.parse(_contentPreviousModifiedTimes)
console.log "\t✓ Using cache"
else
console.log "Decide cache policy: Theme has changed. Do not use content cache."
# @info "Decide cache policy: Theme has changed. Do not use content cache."
@useContentCache = false
console.log "\t✓ Not using cache"
#
# Render data for site.
......@@ -184,10 +188,10 @@ class Blockdown
Promise.try =>
# Clean the data directory before starting only if we’re not using the cache.
if @useContentCache
@info "Using cache: returning true from Promise.try"
#console.log "\t✓ Using cache"
return true
else
@info "Not using cache: returning promise to delete the data for site directory from Promise.try"
# @info "Not using cache: returning promise to delete the data for site directory from Promise.try"
return fs.removeAsync "#{app.dataForSiteDirectory}/*"
.then =>
@renderBlockdown app.contentDirectory, app.dataForSiteDirectory, app.siteTheme
......@@ -211,6 +215,10 @@ class Blockdown
return
else
@copyAssets @themeForSiteDataAssets(), app.dataForSiteDirectory
.then =>
Promise.try =>
if @useContentCache
@removeDeletedFiles()
.catch (e) =>
throw new Error "[Blockdown: site data] #{e} #{e.stack}"
......@@ -243,10 +251,10 @@ class Blockdown
Promise.try =>
# Clean the data directory before starting only if we’re not using the cache.
if @useContentCache
@info "Using cache: returning true from Promise.try"
# @info "Using cache: returning true from Promise.try"
return true
else
@info "Not using cache: returning promise to delete the data for app directory from Promise.try"
# @info "Not using cache: returning promise to delete the data for app directory from Promise.try"
return fs.removeAsync "#{app.dataForAppDirectory}/*"
.then =>
@renderBlockdown app.contentDirectory, app.dataForAppDirectory, app.appTheme
......@@ -264,6 +272,10 @@ class Blockdown
return
else
@copyAssets @themeForAppDataAssets(), app.dataForAppDirectory
.then =>
Promise.try =>
if @useContentCache
@removeDeletedFiles()
.catch (e) =>
throw new Error "[Blockdown: app data] #{e} #{e.stack}"
......@@ -342,6 +354,52 @@ class Blockdown
fs.copyAsync file, destinationPathForFile
# Returns whether str ends with str2
endsWith: (str, str2) ->
str.indexOf(str2) == str.length - str2.length
#
# Removes deleted files (when using the cache)
#
removeDeletedFiles: =>
# @info "Looking for deleted files in the content…"
# Only relevant for content at the moment (as we do a complete rebuild
# whenever the theme changes and this will not even get called).
for file of @contentPreviousModifiedTimes
if @contentCurrentModifiedTimes[file] == undefined
# File has been deleted. Make sure its compiled assets are removed
# from the build also.
console.log "\t✓ Source file #{file} was deleted; removing from build."
# Set the base of the path of the item to delete
pathToDelete = if @isRenderingDataForApp then app.dataForAppDirectory else app.dataForSiteDirectory
if @endsWith file, 'index.md'
#
# If the index.md of an entry is removed, we assume that the entry itself was
# removed and delete its folder from the build.
#
filePathComponents = file.split('/')
filePathComponents.pop()
_file = filePathComponents.join('/')
pathToDelete = path.join pathToDelete, _file
else
#
# For all other files, just remove them directly
#
pathToDelete = path.join pathToDelete, file
# @info "About to delete #{pathToDelete} from the build folder (data)."
fs.removeSync pathToDelete
#
# Renders Blockdown from content path to data path.
#
......
......@@ -88,7 +88,7 @@ class Builder
.then @renderBlockdown
.then @updateRepositories
.then =>
@info '❤ Blockdown content is ready.'
@info "\t✓ Blockdown content ready."
# If the app is running in development, fire off a
# notification to let people know that rendering is done.
......@@ -121,7 +121,7 @@ class Builder
startTime = new Date
@info 'Rendering content…'
# @info 'Rendering content…'
blockdown = new Blockdown
blockdown.renderDataForSite()
.then =>
......@@ -129,9 +129,14 @@ class Builder
blockdown.renderDataForApp()
.then =>
@info "\t✓ Rendered content for data."
duration = ((new Date) - startTime)/1000
duration = ((new Date) - startTime)
@info "Took: #{duration} seconds."
durationUnit = "ms"
if duration > 1000
duration = duration / 1000
durationUnit = "seconds"
@info "\t✓ Render complete. (#{duration} #{durationUnit})"
#
......@@ -180,13 +185,13 @@ class Builder
#
updateRepositories: =>
@info 'Updating the data repositories for the app and the site…'
# @info 'Updating the data repositories for the app and the site…'
@updateRepository app.dataForSiteDirectory
.then =>
@updateRepository app.dataForAppDirectory
.then =>
@info "\t ✓ Data repository updates complete."
@info "\t✓ Data repository updates complete."
#
......
......@@ -30,7 +30,7 @@ class Cache
@cacheContent @themesDirectory
.then =>
duration = (new Date) - startTime
console.log "Generated cache. Took: #{duration} ms"
console.log "\t✓ Cache ready. (#{duration} ms)"
.catch (e) =>
console.log "Cache build error: #{e}"
......
......@@ -108,7 +108,7 @@ class GitlabWebhookServer
@server = http.createServer express
@server.listen port, () =>
@info "❤ Gitlab Webhook Server runnning at http://localhost:#{port}"
@info "❤ Gitlab Webhook Server runnning at http://localhost:#{port}\n"
@express = express
......
......@@ -38,7 +38,7 @@ startTime = new Date
.then ->
new GitlabWebhookServer
endTime = new Date
console.log "Took: #{(endTime - startTime)/1000} seconds."
console.log "\n❤ Better is ready. (#{(endTime - startTime)/1000} seconds)\n"
.catch (e) ->
# Fail catastrophically whenever you can to aid in debugging during development.
console.error e.stack
......
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