From e58aee04eec70c8a1af6612558ae6a017bcf90a6 Mon Sep 17 00:00:00 2001 From: Dan Gray Date: Wed, 6 Jul 2016 12:03:49 +0100 Subject: [PATCH] Add grunt languages option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To build specific language folders: grunt build —languages=“fr,de” --- grunt/config/copy.js | 4 ++-- grunt/config/jsonlint.js | 2 +- grunt/config/watch.js | 2 +- grunt/helpers.js | 11 +++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/grunt/config/copy.js b/grunt/config/copy.js index 9d1f51330..2c45f816c 100644 --- a/grunt/config/copy.js +++ b/grunt/config/copy.js @@ -15,7 +15,7 @@ module.exports = function (grunt, options) { files: [ { expand: true, - src: ['**/*', '!**/*.json'], + src: ['<%=languages%>/**/*', '!**/*.json'], cwd: '<%= sourcedir %>course/', dest: '<%= outputdir %>course/' } @@ -25,7 +25,7 @@ module.exports = function (grunt, options) { files: [ { expand: true, - src: ['**/*.json'], + src: ['<%=languages%>/*.json'], cwd: '<%= sourcedir %>course/', dest: '<%= outputdir %>course/' } diff --git a/grunt/config/jsonlint.js b/grunt/config/jsonlint.js index f5a3bf801..9cc9e6099 100644 --- a/grunt/config/jsonlint.js +++ b/grunt/config/jsonlint.js @@ -1,3 +1,3 @@ module.exports = { - src: [ '<%= sourcedir %>course/**/*.json' ] + src: [ '<%= sourcedir %>course/<%=languages%>/*.json' ] } diff --git a/grunt/config/watch.js b/grunt/config/watch.js index 2d1b85283..97f8863c1 100644 --- a/grunt/config/watch.js +++ b/grunt/config/watch.js @@ -13,7 +13,7 @@ module.exports = { tasks : ['jsonlint', 'check-json', 'copy:courseJson'] }, courseAssets: { - files: ['<%= sourcedir %>course/**/*', '!<%= sourcedir %>course/**/*.json'], + files: ['<%= sourcedir %>course/<%=languages%>/*', '!<%= sourcedir %>course/<%=languages%>/*.json'], tasks : ['copy:courseAssets'] }, js: { diff --git a/grunt/helpers.js b/grunt/helpers.js index 9e9956ba3..18486ecb4 100644 --- a/grunt/helpers.js +++ b/grunt/helpers.js @@ -37,6 +37,7 @@ module.exports = function(grunt) { grunt.log.ok('Building to "' + grunt.config('outputdir') + '"'); if (grunt.config('theme') !== '**') grunt.log.ok('Using theme "' + grunt.config('theme') + '"'); if (grunt.config('menu') !== '**') grunt.log.ok('Using menu "' + grunt.config('menu') + '"'); + if (grunt.config('languages') !== '**') grunt.log.ok('The following languages will be included in the build "' + grunt.config('languages') + '"'); }); // privates @@ -77,6 +78,7 @@ module.exports = function(grunt) { outputdir: process.cwd() + path.sep + 'build' + path.sep, theme: '**', menu: '**', + languages: '**', includes: [ ], @@ -113,12 +115,21 @@ module.exports = function(grunt) { }; exports.generateConfigData = function() { + + var languageFolders = ""; + if (grunt.option('languages') && grunt.option('languages').split(',').length > 1) { + languageFolders = "{" + grunt.option('languages') + "}"; + } else { + languageFolders = grunt.option('languages'); + } + var data = { root: __dirname.split(path.sep).slice(0,-1).join(path.sep), sourcedir: appendSlash(grunt.option('sourcedir')) || exports.defaults.sourcedir, outputdir: appendSlash(grunt.option('outputdir')) || exports.defaults.outputdir, theme: grunt.option('theme') || exports.defaults.theme, menu: grunt.option('menu') || exports.defaults.menu, + languages: languageFolders || exports.defaults.languages }; // Selectively load the course.json ('outputdir' passed by server-build)