Example #1
0
def compress(data, type=TYPE_JS, level=None):
    """
    Compresses a wad of data and gives it back to you.
    """
    COMPRESSOR_COMMAND = common.java_command(YUICOMPRESSOR_PATH)
    
    proc = subprocess.Popen(COMPRESSOR_COMMAND + [TYPE_SWITCH, type], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    compressed_data, error = proc.communicate(data)
    return compressed_data
Example #2
0
def compress_local(out_file, input_fnames, level=DEFAULT_LEVEL, verbose=False, pretty=False):
    """
    Compresses locally using closure.jar. You need to download it and create an
    environment variable called CLOSURE_PATH which points to the jar.
    """

    out_file = out_file or OUT_FILE

    command = common.java_command(CLOSURE_PATH)

    #java -jar closure.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
    p('Compressing %s at level %s ...' % (out_file, level), verbose)

    fnames = ['--js=%s' % fn for fn in input_fnames]
    outfile = '--js_output_file=%s' % out_file
    complevel = ['--compilation_level=%s' % (COMPILATION_LEVELS[level])]
    if pretty:
        formatting = ['--formatting=PRETTY_PRINT']
    else:
        formatting = []
    #source_map = ['--create_source_map=%s.map' % out_file, '--source_map_format=V3']
    return subprocess.call(command + fnames + [outfile] + complevel + formatting)