From e8d7df5bf26cf9fe604e0cd0ea9c3a997016a9fb Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Fri, 30 Oct 2015 14:28:58 +0000 Subject: [PATCH 1/8] Added custom less compiler and sourcemapper --- grunt/config/concat.js | 17 -------- grunt/config/less.js | 46 +++++++++++++++++++--- grunt/tasks/build.js | 3 +- grunt/tasks/create-json-config.js | 6 ++- grunt/tasks/dev.js | 3 +- grunt/tasks/less.js | 64 +++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 28 deletions(-) delete mode 100644 grunt/config/concat.js create mode 100644 grunt/tasks/less.js diff --git a/grunt/config/concat.js b/grunt/config/concat.js deleted file mode 100644 index 677ee9c11..000000000 --- a/grunt/config/concat.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = function (grunt, options) { - return { - less: { - src: [ - '<%= sourcedir %>core/less/*.less', - '<%= sourcedir %>menu/<%= menu %>/**/*.less', - '<%= sourcedir %>components/**/*.less', - '<%= sourcedir %>extensions/**/*.less', - '<%= sourcedir %>theme/<%= theme %>/**/*.less' - ], - dest: '<%= sourcedir %>less/adapt.less', - filter: function(filepath) { - return grunt.config('helpers').includedFilter(filepath); - } - } - } -} diff --git a/grunt/config/less.js b/grunt/config/less.js index a566dec3c..fb2a50e89 100644 --- a/grunt/config/less.js +++ b/grunt/config/less.js @@ -1,10 +1,46 @@ -module.exports = { +module.exports = function (grunt, options) { + return { + dev: { options:{ - compress:true + mandatory: [ + '<%= sourcedir %>core/less/*.less' + ], + src: [ + '<%= sourcedir %>menu/<%= menu %>/**/*.less', + '<%= sourcedir %>components/**/*.less', + '<%= sourcedir %>extensions/**/*.less', + '<%= sourcedir %>theme/<%= theme %>/**/*.less' + ], + sourcemaps:true, + compress:false, + dest: '<%= outputdir %>adapt/css/', + cssFilename: "adapt.css", + mapFilename: "adapt.css.map", + filter: function(filepath) { + return grunt.config('helpers').includedFilter(filepath); + } + } }, - dist: { - files: { - '<%= outputdir %>adapt/css/adapt.css' : '<%= sourcedir %>less/adapt.less' + compile: { + options: { + mandatory: [ + '<%= sourcedir %>core/less/*.less' + ], + src: [ + '<%= sourcedir %>menu/<%= menu %>/**/*.less', + '<%= sourcedir %>components/**/*.less', + '<%= sourcedir %>extensions/**/*.less', + '<%= sourcedir %>theme/<%= theme %>/**/*.less' + ], + sourcemaps: false, + compress:true, + dest: '<%= outputdir %>adapt/css/', + cssFilename: "adapt.css", + mapFilename: "adapt.css.map", + filter: function(filepath) { + return grunt.config('helpers').includedFilter(filepath); + } + } } } } diff --git a/grunt/tasks/build.js b/grunt/tasks/build.js index 774f77e8b..afea89a8c 100644 --- a/grunt/tasks/build.js +++ b/grunt/tasks/build.js @@ -8,8 +8,7 @@ module.exports = function(grunt) { 'check-json', 'clean:output', 'copy', - 'concat', - 'less', + 'less:compile', 'handlebars', 'bower', 'requirejs-bundle', diff --git a/grunt/tasks/create-json-config.js b/grunt/tasks/create-json-config.js index f7e7ee2a5..3fea0993a 100644 --- a/grunt/tasks/create-json-config.js +++ b/grunt/tasks/create-json-config.js @@ -10,14 +10,16 @@ module.exports = function(grunt) { customItems.forEach(function (customItem) { // As any theme folder may be used, we need to first find the location of the // theme.json file + var customItemJsonFile; grunt.file.recurse(grunt.config('sourcedir') + customItem + '/', function(abspath, rootdir, subdir, filename) { if (filename == customItem + '.json') { customItemJsonFile = rootdir + subdir + '/' + filename; } }); - if (customItemJsonFile == '') { - grunt.fail.fatal('Unable to locate ' + customItem + '.json, please ensure a valid ' + customItem + ' exists'); + if (!customItemJsonFile) { + return; + //grunt.fail.fatal('Unable to locate ' + customItem + '.json, please ensure a valid ' + customItem + ' exists'); } var customItemJson = grunt.file.readJSON(customItemJsonFile); diff --git a/grunt/tasks/dev.js b/grunt/tasks/dev.js index 42f49de5d..b7146da3c 100644 --- a/grunt/tasks/dev.js +++ b/grunt/tasks/dev.js @@ -7,8 +7,7 @@ module.exports = function(grunt) { 'jsonlint', 'check-json', 'copy', - 'concat', - 'less', + 'less:dev', 'handlebars', 'bower', 'requirejs-bundle', diff --git a/grunt/tasks/less.js b/grunt/tasks/less.js new file mode 100644 index 000000000..c0de4c7a3 --- /dev/null +++ b/grunt/tasks/less.js @@ -0,0 +1,64 @@ +module.exports = function(grunt) { + grunt.registerMultiTask('less', 'Compile LESS files to CSS', function() { + var less = require('less'); + var _ = require('underscore'); + var path = require("path"); + var done = this.async(); + var options = this.options({}); + + var imports = ""; + + if (options.mandatory) { + for (var i = 0, l = options.mandatory.length; i < l; i++) { + var src = options.mandatory[i]; + grunt.file.expand({}, src).forEach(function(path) { + imports+= "@import '" + path + "';\n"; + }); + } + } + + if (options.src) { + for (var i = 0, l = options.src.length; i < l; i++) { + var src = options.src[i]; + grunt.file.expand({filter: options.filter}, src).forEach(function(path) { + imports+= "@import '" + path + "';\n"; + }); + } + } + + var sourcemaps; + if (options.sourcemaps) { + sourcemaps = { + "sourceMap": { + "sourceMapFileInline": false, + "outputSourceFiles": true, + "sourceMapBasepath": "src", + "sourceMapURL": options.mapFilename, + } + }; + } else { + var sourceMapPath = path.join(options.dest, options.mapFilename); + if (grunt.file.exists(sourceMapPath)) grunt.file.delete(sourceMapPath, {force:true}); + if (grunt.file.exists(sourceMapPath+".imports")) grunt.file.delete(sourceMapPath+".imports", {force:true}); + } + + var lessOptions = _.extend({ "compress": options.compress }, sourcemaps); + + less.render(imports, lessOptions, complete); + + function complete(error, output) { + if (error) { + grunt.fail.fatal(JSON.stringify(error, false, " ")); + return; + } + + grunt.file.write(path.join(options.dest, options.cssFilename), output.css); + + if (output.map) { + grunt.file.write(path.join(options.dest, options.mapFilename)+".imports", imports); + grunt.file.write(path.join(options.dest, options.mapFilename), output.map); + } + done(); + } + }); +} From 78fa4d3d93a2b5d294e0cd651972f9429a7e78df Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Mon, 2 Nov 2015 12:53:48 +0000 Subject: [PATCH 2/8] Updated package.json for less compiler --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 21ccdd2b0..5f1b39bf6 100755 --- a/package.json +++ b/package.json @@ -134,17 +134,16 @@ "grunt-bower-requirejs": "~1.1.0", "grunt-concurrent": "~1.0.0", "grunt-contrib-clean": "~0.6.0", - "grunt-contrib-concat": "~0.5.0", "grunt-contrib-connect": "~0.8.0", "grunt-contrib-copy": "~0.6.0", "grunt-contrib-handlebars": "^0.9.2", - "grunt-contrib-less": "~0.11.4", "grunt-contrib-requirejs": "~0.4.4", "grunt-contrib-watch": "~0.6.1", "grunt-jsonlint": "~1.0.4", "grunt-open": "~0.2.3", "grunt-requirejs-bundle": "*", "jit-grunt": "^0.9.1", + "less": "^2.5.3", "load-grunt-config": "^0.17.2", "lodash": "~2.4.1", "matchdep": "~0.3.0", From 078cc1524f8a9d6a665f3f509125b39e8764b2dc Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Mon, 2 Nov 2015 12:55:45 +0000 Subject: [PATCH 3/8] Indentation fix --- grunt/config/less.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grunt/config/less.js b/grunt/config/less.js index fb2a50e89..bba58f87b 100644 --- a/grunt/config/less.js +++ b/grunt/config/less.js @@ -12,7 +12,7 @@ module.exports = function (grunt, options) { '<%= sourcedir %>theme/<%= theme %>/**/*.less' ], sourcemaps:true, - compress:false, + compress:false, dest: '<%= outputdir %>adapt/css/', cssFilename: "adapt.css", mapFilename: "adapt.css.map", From 82872b87de9da7a7c18d44d438d01215e7b7d5d9 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Mon, 2 Nov 2015 12:58:44 +0000 Subject: [PATCH 4/8] Indentation fix --- grunt/config/less.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grunt/config/less.js b/grunt/config/less.js index bba58f87b..413c5a127 100644 --- a/grunt/config/less.js +++ b/grunt/config/less.js @@ -1,7 +1,7 @@ module.exports = function (grunt, options) { return { dev: { - options:{ + options:{ mandatory: [ '<%= sourcedir %>core/less/*.less' ], @@ -12,7 +12,7 @@ module.exports = function (grunt, options) { '<%= sourcedir %>theme/<%= theme %>/**/*.less' ], sourcemaps:true, - compress:false, + compress:false, dest: '<%= outputdir %>adapt/css/', cssFilename: "adapt.css", mapFilename: "adapt.css.map", @@ -20,7 +20,7 @@ module.exports = function (grunt, options) { return grunt.config('helpers').includedFilter(filepath); } } - }, + }, compile: { options: { mandatory: [ From 2c149e9b3b20633cfbc354e6d8d0346141a9f985 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Fri, 6 Nov 2015 14:07:44 +0000 Subject: [PATCH 5/8] less/ABU-680: removed concat from task list --- grunt/tasks/server-build.js | 1 - 1 file changed, 1 deletion(-) diff --git a/grunt/tasks/server-build.js b/grunt/tasks/server-build.js index cdc81c02d..b35dbd6ad 100644 --- a/grunt/tasks/server-build.js +++ b/grunt/tasks/server-build.js @@ -8,7 +8,6 @@ module.exports = function(grunt) { grunt.task.run([ '_log-vars', 'copy', - 'concat', 'less', 'handlebars', 'bower', From fa307bd411d119750bed6a0fb487a6acafaa6480 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Fri, 6 Nov 2015 14:08:45 +0000 Subject: [PATCH 6/8] less/ABU-680: appended requireMode to less task --- grunt/tasks/server-build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grunt/tasks/server-build.js b/grunt/tasks/server-build.js index b35dbd6ad..6e8778bf4 100644 --- a/grunt/tasks/server-build.js +++ b/grunt/tasks/server-build.js @@ -8,7 +8,7 @@ module.exports = function(grunt) { grunt.task.run([ '_log-vars', 'copy', - 'less', + 'less:' + requireMode, 'handlebars', 'bower', 'requirejs-bundle', From a4f8c90a838d4842d100b6d54dea155574f1cc89 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Mon, 9 Nov 2015 10:31:11 +0000 Subject: [PATCH 7/8] less/ABU-680: fix watch task for less --- grunt/config/watch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grunt/config/watch.js b/grunt/config/watch.js index 77a0c501e..b09a44bab 100644 --- a/grunt/config/watch.js +++ b/grunt/config/watch.js @@ -2,7 +2,7 @@ module.exports = { less: { files: ['<%= sourcedir %>**/*.less'], - tasks: ['concat', 'less'] + tasks: ['less:dev'] }, handlebars: { files: ['<%= sourcedir %>**/*.hbs'], From 465f8877d4bc54bd36127e6c60f19cad29fe993d Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Mon, 9 Nov 2015 11:00:39 +0000 Subject: [PATCH 8/8] less/ABU-680: confirmed works on windows --- Gruntfile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 7b9b47821..8415378ce 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,5 @@ var path = require('path'); -// TODO: check this on windows var appendSlash = function(dir) { if (dir) { var lastChar = dir.substring(dir.length - 1, dir.length);