From 7159a41ad3f8bf890fb2f3b95677639d32a2fa1c Mon Sep 17 00:00:00 2001 From: Tim Fechner <tim.fechner@hs-hannover.de> Date: Tue, 7 Mar 2017 10:11:13 +0100 Subject: [PATCH] Repair buildassets command --- hshassets/management/commands/buildassets.py | 10 +++------- hshassets/utils.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hshassets/management/commands/buildassets.py b/hshassets/management/commands/buildassets.py index d5116329..b8207ae6 100644 --- a/hshassets/management/commands/buildassets.py +++ b/hshassets/management/commands/buildassets.py @@ -14,11 +14,7 @@ class Command(BaseCommand): help = 'Builds the projects assets' def handle(self, *args, **options): - asset_apps = utils.get_asset_directories() - for name, directories in asset_apps.items(): - if not os.path.isdir(directories['static_path']): - os.makedirs(directories['static_path']) - - utils.build_scss_per_app(asset_apps) - utils.build_javascript_per_app(asset_apps) + print('Doing asset magic ...') + utils.do_everything() + print('Everything finished! \033[92m(ಠ‿↼)\033[0m\n') diff --git a/hshassets/utils.py b/hshassets/utils.py index 9333a752..cb9d76af 100644 --- a/hshassets/utils.py +++ b/hshassets/utils.py @@ -72,10 +72,13 @@ def build_javascript(app_name, app_directories, verbose=True): minified_javascript = jsmin.jsmin(concatenated_javascript) - with open(app_directories['static_path'] + '/script.js', 'w') as outfile: - outfile.write(concatenated_javascript) - with open(app_directories['static_path'] + '/script.min.js', 'w') as outfile: - outfile.write(minified_javascript) + if concatenated_javascript: + with open(app_directories['static_path'] + '/script.js', 'w') as outfile: + outfile.write(concatenated_javascript) + + if minified_javascript: + with open(app_directories['static_path'] + '/script.min.js', 'w') as outfile: + outfile.write(minified_javascript) if verbose: print('Finished after {:.3f} seconds\n'.format(time.time() - start)) @@ -134,10 +137,11 @@ def discover_app(file_path): def do_everything(): for app_name, app_directories in get_asset_directories().items(): + if os.path.isdir(app_directories['static_path']): shutil.rmtree(app_directories['static_path']) - if not os.path.isdir(app_directories['static_path']): - os.makedirs(app_directories['static_path']) + + os.makedirs(app_directories['static_path']) build_scss(app_name, app_directories, verbose=False) build_javascript(app_name, app_directories, verbose=False) -- GitLab