From 4e7bb577bf318fbf96eb1131684f8d164275f338 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 14 Aug 2023 11:36:32 +0300 Subject: [PATCH] Add check:scss task and use it in QA to avoid writing out the compiled files. --- Gruntfile.js | 74 ++++++++++++++++++++++++++++++++-------------------- build.xml | 2 +- package.json | 1 + 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 7958984c8bf..e3c3bf2b4ea 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -75,10 +75,14 @@ module.exports = function(grunt) { scss: { sass: { options: { - style: 'compress' + outputStyle: 'compressed', } } }, + 'check:scss': { + sass: { + } + }, // Convert LESS to SASS, mostly for development team use lessToSass: { @@ -203,35 +207,12 @@ module.exports = function(grunt) { }); grunt.registerMultiTask('scss', function sassScan() { - var sassConfig = {}, - path = require('path'), - themeList = fs.readdirSync(path.resolve('themes')).filter(function (theme) { - return fs.existsSync(path.resolve('themes/' + theme + '/scss/compiled.scss')); - }); - - for (var i in themeList) { - var config = { - options: { - implementation: require("node-sass"), - outputStyle: 'compressed' - }, - files: [{ - expand: true, - cwd: path.join('themes', themeList[i], 'scss'), - src: ['compiled.scss'], - dest: path.join('themes', themeList[i], 'css'), - ext: '.css' - }] - }; - for (var key in this.data.options) { - config.options[key] = this.data.options[key] + ''; - } - config.options.includePaths = getLoadPaths('themes/' + themeList[i] + '/scss/compiled.scss'); - - sassConfig[themeList[i]] = config; - } + grunt.config.set('sass', getSassConfig(this.data.options, false)); + grunt.task.run('sass'); + }); - grunt.config.set('sass', sassConfig); + grunt.registerMultiTask('check:scss', function sassCheck() { + grunt.config.set('sass', getSassConfig(this.data.options, true)); grunt.task.run('sass'); }); @@ -241,10 +222,45 @@ module.exports = function(grunt) { - grunt less = compile and compress all themes' LESS files to css. - grunt scss = compile and map all themes' SASS files to css. - grunt lessdev = compile and map all themes' LESS files to css. + - grunt check:scss = check all themes' SASS files. - grunt watch:[cmd] = continuous monitor source files and run command when changes are detected. - grunt watch:less - grunt watch:scss - grunt watch:lessdev - grunt lessToSass = transpile all LESS files to SASS.`); }); + + function getSassConfig(additionalOptions, checkOnly) { + var sassConfig = {}, + path = require('path'), + themeList = fs.readdirSync(path.resolve('themes')).filter(function (theme) { + return fs.existsSync(path.resolve('themes/' + theme + '/scss/compiled.scss')); + }); + + for (var i in themeList) { + if (Object.prototype.hasOwnProperty.call(themeList, i)) { + var config = { + options: { + implementation: require("node-sass"), + }, + files: [{ + expand: true, + cwd: path.join('themes', themeList[i], 'scss'), + src: ['compiled.scss'], + dest: checkOnly ? null : path.join('themes', themeList[i], 'css'), + ext: '.css' + }] + }; + for (var key in additionalOptions) { + if (Object.prototype.hasOwnProperty.call(additionalOptions, key)) { + config.options[key] = additionalOptions[key]; + } + } + config.options.includePaths = getLoadPaths('themes/' + themeList[i] + '/scss/compiled.scss'); + + sassConfig[themeList[i]] = config; + } + } + return sassConfig; + } }; diff --git a/build.xml b/build.xml index d583995849b..48656043fe1 100644 --- a/build.xml +++ b/build.xml @@ -201,7 +201,7 @@ - + diff --git a/package.json b/package.json index d930083ad26..5fe15fc099c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "watch-dev:less": "grunt watch:lessdev", "build:scss": "grunt scss", + "check:scss": "grunt check:scss", "watch:scss": "grunt watch:scss", "lessToSass": "grunt lessToSass",