Esempio n. 1
0
    def setup(self):
        try:
            self.jar = self.get_config('CLOSURE_COMPRESSOR_PATH',
                                       what='Google Closure Compiler')
        except EnvironmentError:
            try:
                import closure
                self.jar = closure.get_jar_filename()
            except ImportError:
                raise EnvironmentError(
                    "\nClosure Compiler jar can't be found."
                    "\nPlease either install the closure package:"
                    "\n\n    pip install closure\n"
                    "\nor provide a CLOSURE_COMPRESSOR_PATH setting "
                    "or an environment variable with the full path to "
                    "the Closure compiler jar."
                )

        self.opt = self.get_config('CLOSURE_COMPRESSOR_OPTIMIZATION',
                                   require=False,
                                   what='Google Closure optimization level')
        if not self.opt:
            self.opt = 'WHITESPACE_ONLY'
        self.extra_args = self.get_config('CLOSURE_EXTRA_ARGS',
                                          require=False)
        self.java_setup()
Esempio n. 2
0
    def setup(self):
        super(ClosureJS, self).setup()

        try:
            self.jar = self.get_config('CLOSURE_COMPRESSOR_PATH',
                                       what='Google Closure Compiler')
        except EnvironmentError:
            try:
                import closure
                self.jar = closure.get_jar_filename()
            except ImportError:
                raise EnvironmentError(
                    "\nClosure Compiler jar can't be found."
                    "\nPlease either install the closure package:"
                    "\n\n    pip install closure\n"
                    "\nor provide a CLOSURE_COMPRESSOR_PATH setting "
                    "or an environment variable with the full path to "
                    "the Closure compiler jar.")
Esempio n. 3
0
def jsmin(code):  # need java & pip/closure
    """ JS-minimize (transpile to ES5 JS compliant) with closure-compiler
        (pip package 'closure', need java !)
    """
    if hasClosure:
        import closure  # py2 or py3
    else:
        raise VBuildException("jsmin error: closure is not installed (sudo pip closure)")
    cmd = ["java", "-jar", closure.get_jar_filename()]
    try:
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
    except Exception as e:
        raise VBuildException("jsmin error: %s" % e)
    out, err = p.communicate(code.encode("utf8"))
    if p.returncode == 0:
        return out.decode("utf8")
    else:
        raise VBuildException("jsmin error:" + err.decode("utf8"))
Esempio n. 4
0
    def setup(self):
        super(ClosureJS, self).setup()

        try:
            self.jar = self.get_config('CLOSURE_COMPRESSOR_PATH',
                                       what='Google Closure Compiler')
        except EnvironmentError:
            try:
                import closure
                self.jar = closure.get_jar_filename()
            except ImportError:
                raise EnvironmentError(
                    "\nClosure Compiler jar can't be found."
                    "\nPlease either install the closure package:"
                    "\n\n    pip install closure\n"
                    "\nor provide a CLOSURE_COMPRESSOR_PATH setting "
                    "or an environment variable with the full path to "
                    "the Closure compiler jar."
                )
Esempio n. 5
0
    def setup(self):
        try:
            self.jar = self.get_config('CLOSURE_COMPRESSOR_PATH',
                                       what='Google Closure Compiler')
        except EnvironmentError:
            try:
                import closure
                self.jar = closure.get_jar_filename()
            except ImportError:
                raise EnvironmentError(
                    "\nClosure Compiler jar can't be found."
                    "\nPlease either install the closure package:"
                    "\n\n    pip install closure\n"
                    "\nor provide a CLOSURE_COMPRESSOR_PATH setting "
                    "or an environment variable with the full path to "
                    "the Closure compiler jar.")

        self.opt = self.get_config('CLOSURE_COMPRESSOR_OPTIMIZATION',
                                   require=False,
                                   what='Google Closure optimization level')
        if not self.opt:
            self.opt = 'WHITESPACE_ONLY'
        self.extra_args = self.get_config('CLOSURE_EXTRA_ARGS', require=False)
        self.java_setup()
Esempio n. 6
0
#!/usr/bin/env python
import argparse
import subprocess
import sys
from pathlib import Path

try:
    import closure
except ImportError:
    closure_compiler = None
else:
    closure_compiler = closure.get_jar_filename()

js_path = Path(__file__).parent.parent / 'static' / 'admin' / 'js'


def main():
    description = """With no file paths given this script will automatically
compress all jQuery-based files of the admin app. Requires the Google Closure
Compiler library and Java version 6 or later."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('file', nargs='*')
    parser.add_argument(
        "-c",
        dest="compiler",
        default="~/bin/compiler.jar",
        help="path to Closure Compiler jar file",
    )
    parser.add_argument("-v", "--verbose", action="store_true", dest="verbose")
    parser.add_argument("-q", "--quiet", action="store_false", dest="verbose")
    options = parser.parse_args()
Esempio n. 7
0
#!/usr/bin/env python
import argparse
import subprocess
import sys
from pathlib import Path

try:
    import closure
except ImportError:
    closure_compiler = None
else:
    closure_compiler = closure.get_jar_filename()

js_path = Path(__file__).parent.parent / 'static' / 'admin' / 'js'


def main():
    description = """With no file paths given this script will automatically
compress all jQuery-based files of the admin app. Requires the Google Closure
Compiler library and Java version 6 or later."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('file', nargs='*')
    parser.add_argument(
        "-c", dest="compiler", default="~/bin/compiler.jar",
        help="path to Closure Compiler jar file",
    )
    parser.add_argument("-v", "--verbose", action="store_true", dest="verbose")
    parser.add_argument("-q", "--quiet", action="store_false", dest="verbose")
    options = parser.parse_args()

    compiler = Path(closure_compiler or options.compiler).expanduser()