diff --git a/hshassets/management/commands/buildassets.py b/hshassets/management/commands/buildassets.py index d51163292c503382299c6a0d5742319f71f5d3eb..b8207ae629e6d1624de2b609e54d67ccb63d87a8 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 9333a752a93c58bf27a06fe24589b9efb73fe34f..cb9d76af8daf965d360e3713e9f9b64ff51cf7fb 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)