Mailspring/src/less-compile-cache.coffee
Juan Tejada ecb1464648 fix(themes): Properly set theme on the hot window
- First composer window you open after changing the theme will now have
the correct theme
2016-06-09 14:12:44 -07:00

38 lines
1.3 KiB
CoffeeScript

_ = require 'underscore'
path = require 'path'
LessCache = require 'less-cache'
# {LessCache} wrapper used by {ThemeManager} to read stylesheets.
module.exports =
class LessCompileCache
constructor: ({configDirPath, resourcePath, importPaths}) ->
@lessSearchPaths = [
path.join(resourcePath, 'static', 'variables')
path.join(resourcePath, 'static')
]
if importPaths?
importPaths = importPaths.concat(@lessSearchPaths)
else
importPaths = @lessSearchPaths
@cache = new LessCache
cacheDir: path.join(configDirPath, 'compile-cache', 'less')
importPaths: importPaths
resourcePath: resourcePath
fallbackDir: path.join(resourcePath, 'less-compile-cache')
# Setting the import paths is a VERY expensive operation (200ms +)
# because it walks the entire file tree and does a file state for each
# and every importPath. If we already have the imports, then load it
# from our backend FileListCache.
setImportPaths: (importPaths=[]) ->
fullImportPaths = importPaths.concat(@lessSearchPaths)
if not _.isEqual(fullImportPaths, @cache.importPaths)
@cache.setImportPaths(fullImportPaths)
read: (stylesheetPath) ->
@cache.readFileSync(stylesheetPath)
cssForFile: (stylesheetPath, lessContent) ->
@cache.cssForFile(stylesheetPath, lessContent)