set reasonable SERVICE_VARIANT based on command line; ensure theme passed to coffeescript also;
This commit is contained in:
@@ -11,11 +11,24 @@ import traceback
|
||||
from .utils.envs import Env
|
||||
from .utils.cmd import cmd, django_cmd
|
||||
|
||||
# setup baseline paths
|
||||
|
||||
COFFEE_DIRS = ['lms', 'cms', 'common']
|
||||
SASS_LOAD_PATHS = ['./common/static/sass']
|
||||
SASS_UPDATE_DIRS = ['*/static']
|
||||
SASS_CACHE_PATH = '/tmp/sass-cache'
|
||||
|
||||
THEME_COFFEE_PATHS = []
|
||||
THEME_SASS_PATHS = []
|
||||
|
||||
edxapp_env = Env()
|
||||
if edxapp_env.feature_flags.get('USE_CUSTOM_THEME', False):
|
||||
theme_name = edxapp_env.env_tokens.get('THEME_NAME', '')
|
||||
parent_dir = path(edxapp_env.REPO_ROOT).abspath().parent
|
||||
theme_root = parent_dir / "themes" / theme_name
|
||||
THEME_COFFEE_PATHS = [theme_root]
|
||||
THEME_SASS_PATHS = [theme_root / "static" / "sass"]
|
||||
|
||||
|
||||
class CoffeeScriptWatcher(PatternMatchingEventHandler):
|
||||
"""
|
||||
@@ -54,7 +67,7 @@ class SassWatcher(PatternMatchingEventHandler):
|
||||
"""
|
||||
register files with observer
|
||||
"""
|
||||
for dirname in SASS_LOAD_PATHS + SASS_UPDATE_DIRS + theme_sass_paths():
|
||||
for dirname in SASS_LOAD_PATHS + SASS_UPDATE_DIRS + THEME_SASS_PATHS:
|
||||
paths = []
|
||||
if '*' in dirname:
|
||||
paths.extend(glob.glob(dirname))
|
||||
@@ -92,27 +105,11 @@ class XModuleSassWatcher(SassWatcher):
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
def theme_sass_paths():
|
||||
"""
|
||||
Return the a list of paths to the theme's sass assets,
|
||||
or an empty list if no theme is configured.
|
||||
"""
|
||||
edxapp_env = Env()
|
||||
|
||||
if edxapp_env.feature_flags.get('USE_CUSTOM_THEME', False):
|
||||
theme_name = edxapp_env.env_tokens.get('THEME_NAME', '')
|
||||
parent_dir = path(edxapp_env.REPO_ROOT).abspath().parent
|
||||
theme_root = parent_dir / "themes" / theme_name
|
||||
return [theme_root / "static" / "sass"]
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
def coffeescript_files():
|
||||
"""
|
||||
return find command for paths containing coffee files
|
||||
"""
|
||||
dirs = " ".join([Env.REPO_ROOT / coffee_dir for coffee_dir in COFFEE_DIRS])
|
||||
dirs = " ".join(THEME_COFFEE_PATHS + [Env.REPO_ROOT / coffee_dir for coffee_dir in COFFEE_DIRS])
|
||||
return cmd('find', dirs, '-type f', '-name \"*.coffee\"')
|
||||
|
||||
|
||||
@@ -131,7 +128,7 @@ def compile_sass(debug=False):
|
||||
"""
|
||||
Compile Sass to CSS.
|
||||
"""
|
||||
theme_paths = theme_sass_paths()
|
||||
theme_paths = THEME_SASS_PATHS
|
||||
sh(cmd(
|
||||
'sass', '' if debug else '--style compressed',
|
||||
"--cache-location {cache}".format(cache=SASS_CACHE_PATH),
|
||||
|
||||
@@ -21,6 +21,16 @@ class Env(object):
|
||||
# We use this to determine which envs.json file to load.
|
||||
SERVICE_VARIANT = os.environ.get('SERVICE_VARIANT', None)
|
||||
|
||||
# If service variant not configured in env, then pass the correct
|
||||
# environment for lms / cms
|
||||
if not SERVICE_VARIANT: # this will intentionally catch "";
|
||||
args = sys.argv[1:]
|
||||
if 'lms' in args:
|
||||
SERVICE_VARIANT = 'lms'
|
||||
elif any(i in args for i in ('cms', 'studio')):
|
||||
SERVICE_VARIANT = 'cms'
|
||||
|
||||
|
||||
@lazy
|
||||
def env_tokens(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user