mirror of https://github.com/zulip/zulip.git
Create minified_assets.json in the deployment root
This file is a dict mapping filenames like "min/api.js" to "min/api.HEX_HASH_HERE.js". This will be useful later for figuring out which hashed version of a generated file belongs to a specific deploy, for reuse in future deploys with the same source files. (imported from commit d03c408b37a4e2d494abd4b1577a70b5ff5c2e34)
This commit is contained in:
parent
6b8bc74b4e
commit
9ca7d58cac
|
@ -2,6 +2,7 @@ from django.conf import settings
|
||||||
from django.contrib.staticfiles.storage import CachedFilesMixin, StaticFilesStorage
|
from django.contrib.staticfiles.storage import CachedFilesMixin, StaticFilesStorage
|
||||||
from pipeline.storage import PipelineMixin
|
from pipeline.storage import PipelineMixin
|
||||||
import os.path
|
import os.path
|
||||||
|
import ujson
|
||||||
|
|
||||||
class AddHeaderMixin(object):
|
class AddHeaderMixin(object):
|
||||||
def post_process(self, paths, dry_run=False, **kwargs):
|
def post_process(self, paths, dry_run=False, **kwargs):
|
||||||
|
@ -55,5 +56,35 @@ class AddHeaderMixin(object):
|
||||||
|
|
||||||
return ret_dict.itervalues()
|
return ret_dict.itervalues()
|
||||||
|
|
||||||
class HumbugStorage(PipelineMixin, AddHeaderMixin, CachedFilesMixin, StaticFilesStorage):
|
|
||||||
|
class DumpManifestMixin(object):
|
||||||
|
""" This mixin creates a JSON manifest file in the deployment root
|
||||||
|
with a dict mapping generated files' base names (like api.js) to their
|
||||||
|
names with the hash for the most recent version (api.HEX_HASH_HERE.js).
|
||||||
|
"""
|
||||||
|
def post_process(self, paths, dry_run=False, **kwargs):
|
||||||
|
if dry_run:
|
||||||
|
return
|
||||||
|
|
||||||
|
super_class = super(DumpManifestMixin, self)
|
||||||
|
if hasattr(super_class, 'post_process'):
|
||||||
|
super_ret = super_class.post_process(paths, dry_run, **kwargs)
|
||||||
|
else:
|
||||||
|
super_ret = []
|
||||||
|
|
||||||
|
hashed_versions = {} # Latest hashed version of each file.
|
||||||
|
for old_path, new_path, processed in super_ret:
|
||||||
|
if old_path[:4] == 'min/':
|
||||||
|
hashed_versions[old_path] = new_path
|
||||||
|
|
||||||
|
manifest_filename = os.path.join(settings.DEPLOY_ROOT,
|
||||||
|
'minified_assets.json')
|
||||||
|
with open(manifest_filename, 'w') as manifest_file:
|
||||||
|
manifest_file.write(ujson.dumps(hashed_versions))
|
||||||
|
|
||||||
|
return super_ret
|
||||||
|
|
||||||
|
|
||||||
|
class HumbugStorage(PipelineMixin, AddHeaderMixin, DumpManifestMixin,
|
||||||
|
CachedFilesMixin, StaticFilesStorage):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue