diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 70e3b0cd0..680936f13 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -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']) diff --git a/src/less-compile-cache.coffee b/src/less-compile-cache.coffee index 751dc2f31..c262270c3 100644 --- a/src/less-compile-cache.coffee +++ b/src/less-compile-cache.coffee @@ -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) diff --git a/tasks/prebuild-less-task.coffee b/tasks/prebuild-less-task.coffee new file mode 100644 index 000000000..9aacf8040 --- /dev/null +++ b/tasks/prebuild-less-task.coffee @@ -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)