2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-03-27 18:40:17 +01:00
|
|
|
from django.conf import settings
|
|
|
|
from hashlib import sha1
|
|
|
|
from os import path
|
|
|
|
|
|
|
|
from pipeline.compressors import SubProcessCompressor
|
|
|
|
|
|
|
|
class ClosureSourceMapCompressor(SubProcessCompressor):
|
|
|
|
def compress_js(self, js):
|
|
|
|
# js is the full text of the JavaScript source, and we can't
|
|
|
|
# easily get either the input file names or the output file
|
|
|
|
# name. So we just pick a unique arbitrary name. This is
|
|
|
|
# okay because we can figure out from the source map file
|
2013-04-05 23:52:13 +02:00
|
|
|
# contents which JavaScript files it corresponds to. But we
|
|
|
|
# use a special comment to identify app.js, so that automatic
|
|
|
|
# source mapping works.
|
2013-03-27 22:10:58 +01:00
|
|
|
|
2013-04-05 23:52:13 +02:00
|
|
|
if 'MINIFY-FILE-ID: zephyr.js' in js:
|
2013-03-27 22:10:58 +01:00
|
|
|
source_map_name = 'app.js.map'
|
|
|
|
else:
|
|
|
|
source_map_name = sha1(js).hexdigest() + '.map'
|
|
|
|
|
|
|
|
source_map = path.join(
|
|
|
|
settings.PIPELINE_CLOSURE_SOURCE_MAP_DIR, source_map_name)
|
2013-03-27 18:40:17 +01:00
|
|
|
|
2013-04-05 23:29:58 +02:00
|
|
|
command = '%s --language_in ECMASCRIPT5 --create_source_map %s' % (
|
2013-03-27 18:40:17 +01:00
|
|
|
settings.PIPELINE_CLOSURE_BINARY, source_map)
|
|
|
|
return self.execute_command(command, js)
|