Add support for grunt css from 29 onwards
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 4 Mar 2016 01:13:40 +0000 (09:13 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 4 Mar 2016 01:22:20 +0000 (09:22 +0800)
mdk/commands/css.py
mdk/commands/doctor.py
mdk/config-dist.json
mdk/css.py
mdk/scripts/less.sh

index 8ad4627..631c4ec 100644 (file)
@@ -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.
index 0f75cd4..5a16fa8 100644 (file)
@@ -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)
index 87b0103..0e5092e 100644 (file)
     "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
index b1f86da..25a3881 100644 (file)
@@ -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"""
 
index 75de09c..76fb39d 100644 (file)
@@ -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