diff --git a/grunt/tasks/build.js b/grunt/tasks/build.js index 2a9543412..9b738f506 100644 --- a/grunt/tasks/build.js +++ b/grunt/tasks/build.js @@ -5,6 +5,7 @@ module.exports = function(grunt) { grunt.registerTask('build', 'Creates a production-ready build of the course', [ '_log-vars', 'check-json', + 'check-plugins', 'clean:output', 'build-config', 'tracking-insert', diff --git a/grunt/tasks/check-json.js b/grunt/tasks/check-json.js index 383b25507..b4d09bd6b 100644 --- a/grunt/tasks/check-json.js +++ b/grunt/tasks/check-json.js @@ -3,6 +3,7 @@ module.exports = function(grunt) { grunt.registerTask('check-json', 'Validates the course json, checks for duplicate IDs, and that each element has a parent', function() { // validates JSON files grunt.task.run('jsonlint'); + grunt.task.run('check-plugins'); const data = Helpers.getFramework().getData(); data.checkIds(); }); diff --git a/grunt/tasks/check-plugins.js b/grunt/tasks/check-plugins.js new file mode 100644 index 000000000..745c32d34 --- /dev/null +++ b/grunt/tasks/check-plugins.js @@ -0,0 +1,27 @@ +module.exports = function(grunt) { + const Helpers = require('../helpers')(grunt); + grunt.registerTask('check-plugins', 'Checks that only one theme is active in the build', function() { + // A specific theme was selected via CLI flag (e.g. --theme=X), + // so only that one will be compiled regardless of what's installed + if (grunt.config('theme') !== '**') return; + + const includes = grunt.config('includes'); + const excludes = [ + ...(grunt.config('excludes') || []), + ...(grunt.config('type') === 'production' ? (grunt.config('productionExcludes') || []) : []) + ]; + + const installed = Helpers.getInstalledPluginsByType('theme'); + const active = includes + ? installed.filter(name => includes.includes(name)) + : installed.filter(name => !excludes.includes(name)); + + if (active.length <= 1) return; + + grunt.fail.fatal( + `More than one theme is active in this build: ${active.join(', ')}.\n` + + `Add the extras to build.excludes in config.json, e.g.:\n` + + ` "build": { "excludes": ["${active.slice(1).join('", "')}"] }` + ); + }); +}; diff --git a/grunt/tasks/dev.js b/grunt/tasks/dev.js index 7c7335add..0797144fe 100644 --- a/grunt/tasks/dev.js +++ b/grunt/tasks/dev.js @@ -5,6 +5,7 @@ module.exports = function(grunt) { grunt.registerTask('dev', 'Creates a developer-friendly build of the course', [ '_log-vars', 'check-json', + 'check-plugins', 'build-config', 'tracking-insert', 'copy',