##// END OF EJS Templates
Upgrade less and generate sourcemap files
Jason Grout -
Show More
@@ -10,29 +10,30 pjoin = os.path.join
10 static_dir = 'static'
10 static_dir = 'static'
11 components_dir = os.path.join(static_dir, 'components')
11 components_dir = os.path.join(static_dir, 'components')
12
12
13 min_less_version = '1.4.0'
13 min_less_version = '1.7.0'
14 max_less_version = '1.5.0' # exclusive
14 max_less_version = '1.8.0' # exclusive
15
15
16 def css(minify=True, verbose=False):
16 def css(minify=True, verbose=False):
17 """generate the css from less files"""
17 """generate the css from less files"""
18 for name in ('style', 'ipython'):
18 for name in ('style', 'ipython'):
19 source = pjoin('style', "%s.less" % name)
19 source = pjoin('style', "%s.less" % name)
20 target = pjoin('style', "%s.min.css" % name)
20 target = pjoin('style', "%s.min.css" % name)
21 _compile_less(source, target, minify, verbose)
21 sourcemap = pjoin('style', "%s.min.css.map" % name)
22 _compile_less(source, target, sourcemap, minify, verbose)
22
23
23 def _to_bool(b):
24 def _to_bool(b):
24 if not b in ['True', 'False', True, False]:
25 if not b in ['True', 'False', True, False]:
25 abort('boolean expected, got: %s' % b)
26 abort('boolean expected, got: %s' % b)
26 return (b in ['True', True])
27 return (b in ['True', True])
27
28
28 def _compile_less(source, target, minify=True, verbose=False):
29 def _compile_less(source, target, sourcemap, minify=True, verbose=False):
29 """Compile a less file by source and target relative to static_dir"""
30 """Compile a less file by source and target relative to static_dir"""
30 minify = _to_bool(minify)
31 minify = _to_bool(minify)
31 verbose = _to_bool(verbose)
32 verbose = _to_bool(verbose)
32 min_flag = '-x' if minify is True else ''
33 min_flag = '-x' if minify is True else ''
33 ver_flag = '--verbose' if verbose is True else ''
34 ver_flag = '--verbose' if verbose is True else ''
34
35
35 # pin less to 1.4
36 # pin less to version number from above
36 try:
37 try:
37 out = check_output(['lessc', '--version'])
38 out = check_output(['lessc', '--version'])
38 except OSError as err:
39 except OSError as err:
@@ -45,6 +46,7 def _compile_less(source, target, minify=True, verbose=False):
45 if V(less_version) >= V(max_less_version):
46 if V(less_version) >= V(max_less_version):
46 raise ValueError("lessc too new: %s >= %s. Use `$ npm install lesscss@X.Y.Z` to install a specific version of less" % (less_version, max_less_version))
47 raise ValueError("lessc too new: %s >= %s. Use `$ npm install lesscss@X.Y.Z` to install a specific version of less" % (less_version, max_less_version))
47
48
49 static_path = pjoin(os.getcwd(), static_dir)
48 with lcd(static_dir):
50 with lcd(static_dir):
49 local('lessc {min_flag} {ver_flag} {source} {target}'.format(**locals()))
51 local('lessc {min_flag} {ver_flag} --source-map={sourcemap} --source-map-basepath={static_path} --source-map-rootpath="../" {source} {target}'.format(**locals()))
50
52
General Comments 0
You need to be logged in to leave comments. Login now