2013-10-10 21:37:26 +02:00
|
|
|
from __future__ import absolute_import
|
2016-04-07 21:51:29 +02:00
|
|
|
from typing import Any, Generator, Tuple
|
2013-10-10 21:37:26 +02:00
|
|
|
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
import re
|
2013-07-25 22:41:44 +02:00
|
|
|
from django.contrib.staticfiles.finders import FileSystemFinder
|
2013-06-12 19:33:53 +02:00
|
|
|
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
class ExcludeUnminifiedMixin(object):
|
|
|
|
""" Excludes unminified copies of our JavaScript code, templates
|
|
|
|
and stylesheets, so that these sources don't end up getting served
|
|
|
|
in production. """
|
|
|
|
|
2013-06-12 19:33:53 +02:00
|
|
|
def list(self, ignore_patterns):
|
2016-01-26 03:10:17 +01:00
|
|
|
# type: (Any) -> Generator[Tuple[str, str], None, None]
|
2013-06-12 19:33:53 +02:00
|
|
|
# We can't use ignore_patterns because the patterns are
|
|
|
|
# applied to just the file part, not the entire path
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
excluded = '^(js|styles|templates)/'
|
|
|
|
|
|
|
|
# source-map/ should also not be included.
|
|
|
|
# However, we work around that by moving it later,
|
2013-10-25 23:20:40 +02:00
|
|
|
# in update-prod-static.
|
2013-06-12 19:33:53 +02:00
|
|
|
|
2016-01-27 21:17:12 +01:00
|
|
|
super_class = super(ExcludeUnminifiedMixin, self) # type: ignore # https://github.com/JukkaL/mypy/issues/857
|
2013-06-12 19:33:53 +02:00
|
|
|
for path, storage in super_class.list(ignore_patterns):
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
if not re.search(excluded, path):
|
2013-06-12 19:33:53 +02:00
|
|
|
yield path, storage
|
|
|
|
|
2013-08-06 21:37:02 +02:00
|
|
|
class ZulipFinder(ExcludeUnminifiedMixin, FileSystemFinder):
|
2013-06-12 19:33:53 +02:00
|
|
|
pass
|