From ec0874503e28c811a2b9b4b055bac70913bbacab Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 4 Mar 2016 09:13:40 +0800 Subject: [PATCH] Add support for grunt css from 29 onwards --- mdk/commands/css.py | 4 ++++ mdk/commands/doctor.py | 2 +- mdk/config-dist.json | 2 ++ mdk/css.py | 24 ++++++++++++++++++++++-- mdk/scripts/less.sh | 17 +---------------- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/mdk/commands/css.py b/mdk/commands/css.py index 8ad4627..631c4ec 100644 --- a/mdk/commands/css.py +++ b/mdk/commands/css.py @@ -124,6 +124,10 @@ class CssCommand(Command): processor.setDebug(args.debug) if args.debug: processor.setCompiler('lessc') + elif M.branch_compare(29, '<'): + # Grunt was only introduced for 2.9. + processor.setCompiler('recess') + processor.compile(theme=args.theme, sheets=args.sheets) # Setting up watchdog. This code should be improved when we will have more than a compile option. diff --git a/mdk/commands/doctor.py b/mdk/commands/doctor.py index 0f75cd4..5a16fa8 100644 --- a/mdk/commands/doctor.py +++ b/mdk/commands/doctor.py @@ -238,7 +238,7 @@ class DoctorCommand(Command): # Check binaries. hasErrors = False - for k in ['git', 'php', 'java', 'recess', 'lessc', 'shifter', 'yuidoc']: + for k in ['git', 'php', 'java', 'recess', 'grunt', 'lessc', 'shifter', 'yuidoc']: path = self.C.get(k) if not path or not os.path.isfile(path): print ' The path to \'%s\' is invalid: %s' % (k, path) diff --git a/mdk/config-dist.json b/mdk/config-dist.json index 87b0103..0e5092e 100644 --- a/mdk/config-dist.json +++ b/mdk/config-dist.json @@ -211,6 +211,8 @@ "php": "/usr/bin/php", // Path to Java "java": "/usr/bin/java", + // Path to Grunt + "grunt": "/usr/local/bin/grunt", // Path to recess "recess": "/usr/local/bin/recess", // Path to lessc diff --git a/mdk/css.py b/mdk/css.py index b1f86da..25a3881 100644 --- a/mdk/css.py +++ b/mdk/css.py @@ -36,7 +36,7 @@ class Css(object): _M = None _debug = False - _compiler = 'recess' + _compiler = 'grunt' def __init__(self, M): self._M = M @@ -70,6 +70,9 @@ class Css(object): hadErrors = False + if self._compiler == 'grunt': + sheets = ['moodle'] + for name in sheets: sheet = name + '.less' destSheet = name + '.css' @@ -80,7 +83,9 @@ class Css(object): continue try: - if self._compiler == 'recess': + if self._compiler == 'grunt': + compiler = Grunt(source, os.path.join(source, sheet), os.path.join(dest, destSheet)) + elif self._compiler == 'recess': compiler = Recess(source, os.path.join(source, sheet), os.path.join(dest, destSheet)) elif self._compiler == 'lessc': compiler = Lessc(self.getThemeDir(), os.path.join(source, sheet), os.path.join(dest, destSheet)) @@ -134,6 +139,21 @@ class Compiler(object): self._debug = debug +class Grunt(Compiler): + """Grunt compiler""" + + def execute(self): + executable = C.get('grunt') + if not executable: + raise Exception('Could not find executable path') + + cmd = [executable, 'css'] + + (code, out, err) = process(cmd, self._cwd) + if code != 0 or len(out) == 0: + raise CssCompileFailed('Error during compile') + + class Recess(Compiler): """Recess compiler""" diff --git a/mdk/scripts/less.sh b/mdk/scripts/less.sh index 75de09c..76fb39d 100644 --- a/mdk/scripts/less.sh +++ b/mdk/scripts/less.sh @@ -8,19 +8,4 @@ echo "This script is deprecated, please use:" echo " mdk css --compile" echo "" -P=`mdk info -v path` -if [[ -z "$(which recess)" ]]; then - echo "Recess could not be found. Aborting..." - exit 1 -fi - -DIR="$P/theme/bootstrapbase/less" -if [[ ! -d "$DIR" ]]; then - echo "Could not find theme/boostrapbase. Aborting..." - exit 2 -fi - -echo "Compiling theme/bootstrapbase CSS" -cd "$DIR" -recess --compile --compress moodle.less > ../style/moodle.css -recess --compile --compress editor.less > ../style/editor.css +mdk css --compile -- 2.11.0