mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
50 lines
1.8 KiB
CoffeeScript
50 lines
1.8 KiB
CoffeeScript
path = require 'path'
|
|
fs = require 'fs'
|
|
|
|
module.exports = (grunt) ->
|
|
grunt.registerMultiTask 'prebuild-less', 'Prebuild cached of compiled LESS files', ->
|
|
LessCache = require 'less-cache'
|
|
prebuiltConfigurations = [
|
|
['ui-light', 'ui-dark']
|
|
]
|
|
|
|
directory = path.join(grunt.config.get('nylasGruntConfig.appDir'), 'less-compile-cache')
|
|
|
|
for configuration in prebuiltConfigurations
|
|
importPaths = grunt.config.get('less.options.paths')
|
|
themeMains = []
|
|
for theme in configuration
|
|
themePath = path.resolve('node_modules', theme)
|
|
if fs.existsSync(themePath) is false
|
|
themePath = path.resolve('internal_packages', theme)
|
|
|
|
if fs.existsSync(path.join(themePath, 'stylesheets'))
|
|
stylesheetsDir = path.join(themePath, 'stylesheets')
|
|
else
|
|
stylesheetsDir = path.join(themePath, 'styles')
|
|
{main} = grunt.file.readJSON(path.join(themePath, 'package.json'))
|
|
main ?= 'index.less'
|
|
mainPath = path.join(themePath, main)
|
|
themeMains.push(mainPath) if grunt.file.isFile(mainPath)
|
|
importPaths.unshift(stylesheetsDir) if grunt.file.isDir(stylesheetsDir)
|
|
|
|
grunt.verbose.writeln("Building LESS cache for #{configuration.join(', ').yellow}")
|
|
lessCache = new LessCache
|
|
cacheDir: directory
|
|
resourcePath: path.resolve('.')
|
|
importPaths: importPaths
|
|
|
|
cssForFile = (file) ->
|
|
baseVarImports = """
|
|
@import "variables/ui-variables";
|
|
"""
|
|
less = fs.readFileSync(file, 'utf8')
|
|
lessCache.cssForFile(file, [baseVarImports, less].join('\n'))
|
|
|
|
for file in @filesSrc
|
|
grunt.verbose.writeln("File #{file.cyan} created in cache.")
|
|
cssForFile(file)
|
|
|
|
for file in themeMains
|
|
grunt.verbose.writeln("File #{file.cyan} created in cache.")
|
|
cssForFile(file)
|