mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Prebuild LESS cache for common theme configurations
This commit is contained in:
@@ -45,6 +45,12 @@ module.exports = (grunt) ->
|
||||
dest: appDir
|
||||
ext: '.css'
|
||||
|
||||
prebuildLessConfig =
|
||||
src: [
|
||||
'static/**/*.less'
|
||||
'vendor/bootstrap/less/bootstrap.less'
|
||||
]
|
||||
|
||||
csonConfig =
|
||||
options:
|
||||
rootObject: true
|
||||
@@ -60,10 +66,11 @@ module.exports = (grunt) ->
|
||||
|
||||
for child in fs.readdirSync('node_modules') when child isnt '.bin'
|
||||
directory = path.join('node_modules', child)
|
||||
{engines} = grunt.file.readJSON(path.join(directory, 'package.json'))
|
||||
{engines, theme} = grunt.file.readJSON(path.join(directory, 'package.json'))
|
||||
if engines?.atom?
|
||||
coffeeConfig.glob_to_multiple.src.push("#{directory}/**/*.coffee")
|
||||
lessConfig.glob_to_multiple.src.push("#{directory}/**/*.less")
|
||||
prebuildLessConfig.src.push("#{directory}/**/*.less") unless theme
|
||||
csonConfig.glob_to_multiple.src.push("#{directory}/**/*.cson")
|
||||
|
||||
grunt.initConfig
|
||||
@@ -75,6 +82,8 @@ module.exports = (grunt) ->
|
||||
|
||||
less: lessConfig
|
||||
|
||||
'prebuild-less': prebuildLessConfig
|
||||
|
||||
cson: csonConfig
|
||||
|
||||
coffeelint:
|
||||
@@ -172,7 +181,7 @@ module.exports = (grunt) ->
|
||||
grunt.loadNpmTasks('grunt-shell')
|
||||
grunt.loadTasks('tasks')
|
||||
|
||||
grunt.registerTask('compile', ['coffee', 'cson'])
|
||||
grunt.registerTask('compile', ['coffee', 'prebuild-less', 'cson'])
|
||||
grunt.registerTask('lint', ['coffeelint', 'csslint', 'lesslint'])
|
||||
grunt.registerTask('test', ['shell:kill-atom', 'shell:test'])
|
||||
grunt.registerTask('ci', ['lint', 'update-atom-shell', 'build', 'set-development-version', 'test'])
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
path = require 'path'
|
||||
|
||||
_ = require 'underscore'
|
||||
LessCache = require 'less-cache'
|
||||
|
||||
|
||||
module.exports =
|
||||
class LessCompileCache
|
||||
_.extend @prototype, require('./subscriber')
|
||||
@@ -8,10 +11,12 @@ class LessCompileCache
|
||||
@cacheDir: '/tmp/atom-compile-cache/less'
|
||||
|
||||
constructor: ->
|
||||
importPaths =
|
||||
@cache = new LessCache
|
||||
cacheDir: @constructor.cacheDir
|
||||
importPaths: @getImportPaths()
|
||||
resourcePath: window.resourcePath
|
||||
fallbackDir: path.join(window.resourcePath, 'less-compile-cache')
|
||||
|
||||
@subscribe atom.themes, 'reloaded', => @cache.setImportPaths(@getImportPaths())
|
||||
|
||||
getImportPaths: -> atom.themes.getImportPaths().concat(config.lessSearchPaths)
|
||||
|
||||
35
tasks/prebuild-less-task.coffee
Normal file
35
tasks/prebuild-less-task.coffee
Normal file
@@ -0,0 +1,35 @@
|
||||
path = require 'path'
|
||||
|
||||
LessCache = require 'less-cache'
|
||||
|
||||
module.exports = (grunt) ->
|
||||
grunt.registerMultiTask 'prebuild-less', 'Prebuild cached of compiled LESS files', ->
|
||||
prebuiltConfigurations = [
|
||||
['atom-dark-ui', 'atom-dark-syntax']
|
||||
['atom-dark-ui', 'atom-light-syntax']
|
||||
['atom-light-ui', 'atom-light-syntax']
|
||||
['atom-light-ui', 'atom-dark-syntax']
|
||||
]
|
||||
|
||||
directory = path.join(grunt.config.get('atom.appDir'), 'less-compile-cache')
|
||||
|
||||
for configuration in prebuiltConfigurations
|
||||
importPaths = [
|
||||
path.resolve('static/variables')
|
||||
path.resolve('static')
|
||||
path.resolve('vendor')
|
||||
]
|
||||
for theme in configuration
|
||||
# TODO Using AtomPackage class once it runs outside of an Atom context
|
||||
themePath = path.resolve('node_modules', theme, 'stylesheets')
|
||||
importPaths.unshift(themePath) if grunt.file.isDir(themePath)
|
||||
|
||||
grunt.log.writeln("Building LESS cache for #{configuration.join(', ').yellow}")
|
||||
lessCache = new LessCache
|
||||
cacheDir: directory
|
||||
resourcePath: path.resolve('.')
|
||||
importPaths: importPaths
|
||||
|
||||
for file in @filesSrc
|
||||
grunt.log.writeln("File #{file.cyan} created in cache.")
|
||||
lessCache.readFileSync(file)
|
||||
Reference in New Issue
Block a user