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

Remove Cache.coffee (we are using Cache2)

parent f7dcaf4b
Pipeline #681 canceled with stages
#
# Builder cache
# Note: This is not being used. Builder includer Cache2.
# TODO: Why is this still around? If unused, delete.
#
fs = require 'fs-extra-as-promised'
path = require 'path'
osPath = require 'ospath'
Promise = require 'thrush'
crypto = require 'crypto'
glob = require 'glob'
globAsync = Promise.promisify glob
# app = require './App'
class Cache
homeDirectory: null
contentDirectory: null
themesDirectory: null
cacheCurrentChecksumsDirectory: null
constructor: ->
@homeDirectory = path.join osPath.home(), 'better.fyi'
@contentDirectory = path.join @homeDirectory, 'content'
@themesDirectory = path.join @homeDirectory, 'themes'
@cacheCurrentChecksumsDirectory = path.join @homeDirectory, '.private', 'cache', 'current'
startTime = new Date
@cacheContent @contentDirectory
.then =>
@cacheContent @themesDirectory
.then =>
duration = (new Date) - startTime
console.log "Took: #{duration} ms"
cacheContent: (directory) =>
(globAsync "#{directory}/**/*", {nodir: true})
.series (file) =>
fileComponents = file.split '/'
filePathFragment = fileComponents[4..(fileComponents.length-2)].join '/'
fileName = fileComponents[(fileComponents.length - 1)]
cacheFilePath = path.join @cacheCurrentChecksumsDirectory, filePathFragment
cacheFile = path.join cacheFilePath, fileName
fs.readFileAsync file, 'utf-8'
.then (content) =>
hash = checksum content
# console.log "#{hash} : #{cacheFilePath}"
fs.ensureDirAsync cacheFilePath
.then =>
fs.outputFileAsync cacheFile, hash
#
# Calculate checksum
#
checksum = (str) ->
return crypto
.createHash('md5')
.update(str, 'utf8')
.digest('hex')
new 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