Пример #1
0
def minify_package(path, path_combined, suffix):
    uglify_path = npm.package_installed("uglifyjs")
    cssmin_path = npm.package_installed("cssmin")

    path_compressed = os.path.join(path, COMPRESSED_FILENAME + suffix)
    print "Compressing %s into %s" % (path_combined, path_compressed)

    if suffix == ".js":
        print popen_results([
            uglify_path, '-b', '-i', '0', '-nc', '-o', path_compressed,
            path_combined
        ])
    elif suffix == ".css":
        compressed = popen_results([cssmin_path, path_combined])
        if compressed:
            f = open(path_compressed, 'w')
            f.write(compressed)
            f.close()
    else:
        raise Exception("Unable to compress %s files" % suffix)

    if not os.path.exists(path_compressed):
        raise Exception("Unable to compress: %s" % path_combined)

    return path_compressed
Пример #2
0
def check_deps():
    """check for node and friends"""
    uglify_path = npm.package_installed("uglifyjs")
    cssmin_path = npm.package_installed("cssmin")

    if uglify_path and cssmin_path:
        return True
    else:
        print "uglify and cssmin not found :("
        return False
Пример #3
0
def check_deps():
    """check for node and friends"""
    uglify_path = npm.package_installed("uglifyjs")
    cssmin_path = npm.package_installed("cssmin")

    if uglify_path and cssmin_path:
        return True
    else:
        print "uglify and cssmin not found :("
        return False
Пример #4
0
def file_size_report():
    # only works on js for now
    package = packages.javascript
    path = os.path.join("..", "javascript")
    suffix = '.js'
    uglify_path = npm.package_installed("uglifyjs")

    print "Uglifying and gzipping all packages..."
    file_sizes = []
    for package_name, path, files in resolve_files(path, package, suffix):
        for file in files:
            if file in packages.transformations:
                file = packages.transformations[file]
            file_path = os.path.normpath(os.path.join(path, file))
            file_path_min = file_path[:-len(suffix)] + '.min' + suffix
            popen_results([uglify_path, '-o', file_path_min, file_path])
            subprocess.Popen(['gzip', '-f', file_path_min]).wait()
            file_path_gz = file_path_min + '.gz'

            file_size = os.stat(file_path_gz).st_size
            file_sizes.append((package_name, file, file_size))

            # Clean up. The minified file is already deleted by gzip.
            os.remove(file_path_gz)

    file_sizes.sort(key=lambda f: f[2], reverse=True)  # size
    file_sizes.sort(key=lambda f: f[0])  # package

    for package_name, file, size in file_sizes:
        print '\t'.join(map(str, [size, package_name, file]))
Пример #5
0
def file_size_report():
    # only works on js for now
    package = packages.javascript
    path = os.path.join("..", "javascript")
    suffix = '.js'
    uglify_path = npm.package_installed("uglifyjs")


    print "Uglifying and gzipping all packages..."
    file_sizes = []
    for package_name, path, files in resolve_files(path, package, suffix):
        for file in files:
            if file in packages.transformations:
                file = packages.transformations[file]
            file_path = os.path.normpath(os.path.join(path, file))
            file_path_min = file_path[:-len(suffix)] + '.min' + suffix
            popen_results([uglify_path, '-b', '-i', '0', '-nc', '-o', file_path_min, file_path])
            subprocess.Popen(['gzip', '-f', file_path_min]).wait()
            file_path_gz = file_path_min + '.gz'

            file_size = os.stat(file_path_gz).st_size
            file_sizes.append((package_name, file, file_size))

            # Clean up. The minified file is already deleted by gzip.
            os.remove(file_path_gz)

    file_sizes.sort(key=lambda f: f[2], reverse=True) # size
    file_sizes.sort(key=lambda f: f[0]) # package

    for package_name, file, size in file_sizes:
        print '\t'.join(map(str, [size, package_name, file]))
Пример #6
0
def validate_env():
    path = npm.package_installed("lessc")
    if path:
        subprocess.call([path],
                        stderr=subprocess.STDOUT,
                        stdout=subprocess.PIPE)
    else:
        sys.exit("Can't find less compiler. Check that it's installed.")
Пример #7
0
def validate_env():
    path = npm.package_installed("lessc")
    if path:
        subprocess.call([path],
                        stderr=subprocess.STDOUT,
                        stdout=subprocess.PIPE)
    else:
        sys.exit("Can't find less compiler. Check that it's installed.")
Пример #8
0
def compile_template(dir_path, file_name):
    less_path = npm.package_installed("lessc")

    input_path = os.path.join(dir_path, file_name)
    output_path = "%s.css" % os.path.join(dir_path, file_name)

    try:
        subprocess.check_call([less_path, input_path, output_path])
    except subprocess.CalledProcessError, e:
        sys.exit(e.returncode)
Пример #9
0
def compile_template(dir_path, file_name):
    less_path = npm.package_installed("lessc")

    input_path = os.path.join(dir_path, file_name)
    output_path = "%s.css" % os.path.join(dir_path, file_name)

    try:
        subprocess.check_call([less_path, input_path, output_path])
    except subprocess.CalledProcessError, e:
        sys.exit(e.returncode)
def validate_env():
    """ Ensures that pre-requisites are met for compiling handlebar templates.
    
    TODO: point to documents when they're made.
    Handlebars doc: https://github.com/wycats/handlebars.js/
    """
    handlebars_path = npm.package_installed("handlebars")
    if handlebars_path:
        subprocess.call([handlebars_path], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    else:
        sys.exit("Can't find handlebars. Did you install it?")
def validate_env():
    """ Ensures that pre-requisites are met for compiling handlebar templates.
    
    TODO: point to documents when they're made.
    Handlebars doc: https://github.com/wycats/handlebars.js/
    """
    handlebars_path = npm.package_installed("handlebars")
    if handlebars_path:
        subprocess.call([handlebars_path],
                        stderr=subprocess.STDOUT,
                        stdout=subprocess.PIPE)
    else:
        sys.exit("Can't find handlebars. Did you install it?")
Пример #12
0
def minify_package(path, path_combined, suffix):
    uglify_path = npm.package_installed("uglifyjs")
    cssmin_path = npm.package_installed("cssmin")

    path_compressed = os.path.join(path, COMPRESSED_FILENAME + suffix)
    print "Compressing %s into %s" % (path_combined, path_compressed)

    if suffix == ".js":
        print popen_results([uglify_path, '-b', '-i', '0', '-nc', '-o', path_compressed, path_combined])
    elif suffix == ".css":
        compressed = popen_results([cssmin_path, path_combined])
        if compressed:
            f = open(path_compressed, 'w')
            f.write(compressed)
            f.close()
    else:
        raise Exception("Unable to compress %s files" % suffix)

    if not os.path.exists(path_compressed):
        raise Exception("Unable to compress: %s" % path_combined)

    return path_compressed
def compile_template(root_path, rel_path, file_name):
    """ Compiles a single template into an output that can be used by the
    JavaScript client.
    
    This logic is dependent on javascript/shared-package/templates.js
    
    """
    handlebars_path = npm.package_installed("handlebars")
    try:
        dir_path = os.path.join(root_path, rel_path)

        # Total hack to rename the file temporarily to be namespaced. There
        # is no way to tell handlebars to prefix the resulting template with
        # a namespace, so we need to rename the file temporarily.
        qualified_name = file_name
        while True:
            head, tail = os.path.split(rel_path)
            if tail:
                qualified_name = "%s_%s" % (tail, qualified_name)
            else:
                break
            rel_path = head

        input_path = os.path.join(dir_path, qualified_name)
        shutil.copyfile(os.path.join(dir_path, file_name), input_path)

        # Append ".js" to the template name for the output name.
        output_path = "%s.js" % os.path.join(dir_path, file_name)

        # "-m" for minified output
        # "-f" specifies output file
        ret = subprocess.call(
            [handlebars_path, "-m", "-f", output_path, input_path],
            stderr=subprocess.STDOUT,
            stdout=subprocess.PIPE)
        if ret:
            raise Exception("Error compiling handlebar: %s -m -f %s/%s" %
                            (handlebars_path, dir_path, file_name))
        os.remove(input_path)
        print "Compiled to %s" % output_path
    except subprocess.CalledProcessError:
        #sys.exit("Error compiling %s" % file_path)
        pass
Пример #14
0
def compile_template(root_path, rel_path, file_name):
    """ Compiles a single template into an output that can be used by the
    JavaScript client.
    
    This logic is dependent on javascript/shared-package/templates.js
    
    """
    handlebars_path = npm.package_installed("handlebars")
    try:
        dir_path = os.path.join(root_path, rel_path)
        
        # Total hack to rename the file temporarily to be namespaced. There
        # is no way to tell handlebars to prefix the resulting template with
        # a namespace, so we need to rename the file temporarily.
        qualified_name = file_name
        while True:
            head, tail = os.path.split(rel_path)
            if tail:
                qualified_name = "%s_%s" % (tail, qualified_name)
            else:
                break
            rel_path = head
        
        input_path = os.path.join(dir_path, qualified_name)
        shutil.copyfile(os.path.join(dir_path, file_name), input_path)
        
        # Append ".js" to the template name for the output name.
        output_path = "%s.js" % os.path.join(dir_path, file_name)
        
        # "-m" for minified output
        # "-f" specifies output file
        ret = subprocess.call([handlebars_path, "-m", "-f", output_path, input_path],
                        stderr=subprocess.STDOUT,
                        stdout=subprocess.PIPE)
        if ret:
            raise Exception("Error compiling handlebar: %s -m -f %s/%s" % (handlebars_path, dir_path, file_name))
        os.remove(input_path)
        print "Compiled to %s" % output_path
    except subprocess.CalledProcessError:
        #sys.exit("Error compiling %s" % file_path)
        pass