示例#1
0
def _calculate_deps(js_entrypoint_file_path):
    js_sources = set()
    source_files = set()
    logging.info("Scanning paths for Javascript files...")
    for js_path in loader.locate("*.js"):
        if not js_path.startswith(coverage.INSTRUMENTED_CODE_PATH):
            source_files.add(js_path)

    for js_path in source_files:
        js_sources.add(closurebuilder._PathSource(js_path))

    logging.info("Done")
    logging.info("Building dependency tree..")
    tree = depstree.DepsTree(js_sources)

    # find the namespace of entrypoint
    entrypoint_source = closurebuilder._PathSource(js_entrypoint_file_path)
    if entrypoint_source.provides:
        namespace = entrypoint_source.provides
    else:
        namespace = entrypoint_source.requires

    # namespace = [closurebuilder._PathSource(js_entrypoint_file_path).provides.pop()]
    # The Closure Library base file must go first.
    base = closurebuilder._GetClosureBaseFile(js_sources)
    deps = [base] + tree.GetDependencies(namespace)
    logging.info("Done")
    return deps
示例#2
0
    def _get_shared_commands(self):
        shared_files = loader.locate("shared.py")
        commands = set()
        for file in shared_files:
            commands.update(self._get_shared_commands_for_file(file))

        return commands
示例#3
0
    def run(self, build_path):
        files = [x for x in loader.locate("entrypoint.js")]
        css_deps, js_deps = calculate_deps(files[0])

        file = open("%s/%s" % (build_path, "generated/index.html"), "w")
        vars = {
            "entrypoint": loader._get_module_name(files[0]),
            "js_deps": ["/generated/client/compiled.js"],
            "css_deps": css_deps,
        }
        file.write(template.render("%stic/web/templates/index_compiled.html" % loader.root_path(), vars))
示例#4
0
    def _get_dojo_modules(self):
        from tic.loader import locate
        modules = []
        for file in locate('*.js'):
            if '/client/' in file:
                logging.debug(file)
                logging.debug(file.replace(os.path.abspath(os.curdir), '').split('/'))
                m = file.replace(os.path.abspath(os.curdir), '').split('/')[1]

                modules.append(m)
        return set(modules)
示例#5
0
def compile_closure_files():
    """Compiles the javascript files
    """
    files = [f for f in loader.locate("entrypoint.js")]

    deps = _calculate_deps(files[0])
    compiled_source = jscompiler.Compile(
        "/Users/selkhateeb/Development/Projects/CarsSearchEngine/tools/closure-compiler/compiler.jar",
        [js_source.GetPath() for js_source in deps],
        [
            "--compilation_level=ADVANCED_OPTIMIZATIONS",
            #         '--create_source_map=example-map',
            "--formatting=pretty_print",
            "--debug",
        ],
    )
    out = open("generated/client/compiled.js", "w")
    out.write(compiled_source)
示例#6
0
文件: env.py 项目: selkhateeb/tic
    def auto_detect_js_toolkit(self):
        if settings.JAVASCRIPT_TOOLKIT == 'autodetect':
            files = []
            for file in locate("entrypoint.js"):
                files.append(file)

            if len(files) > 1:
                #TODO: raise EnvironmentException
                raise Exception('More than one entry point defined\n%s' % '\n'.join(files))

            if not len(files):
                #TODO: raise EnvironmentException
                raise Exception('No entry point defined\n')

            if self._is_dojo(files[0]):
                settings.JAVASCRIPT_TOOLKIT = 'dojo' # TODO: enum this

            elif self._is_closure(files[0]):
                settings.JAVASCRIPT_TOOLKIT = 'closure' # TODO: enum this
示例#7
0
def calculate_deps(js_entrypoint_file_path):
    """TODO Documentation"""

    deps = _calculate_deps(js_entrypoint_file_path)

    js_deps = [loader.get_relative_path(js_source.GetPath()) for js_source in deps]

    #    js_deps = ["tic/web/client/tic.js"] + js_deps
    # calculate css deps
    css_source_to_path = dict()
    for css_path in loader.locate("*.css"):
        provide = source.CssSource(source.GetFileContents(css_path)).getProvideCssRule()
        if provide:
            css_source_to_path[provide] = css_path

    css_requires = set()
    css_deps = set()
    for js_source in deps:
        css_requires.update(js_source.require_csses)

    for css_req in css_requires:
        css_deps.add(loader.get_relative_path(css_source_to_path[css_req]))

    return (css_deps, js_deps)  # [loader.get_relative_path(js_source.GetPath()) for js_source in deps]
示例#8
0
 def _get_soy_files(self, build_path):
     return [x for x in loader.locate('*.soy', build_path)]
示例#9
0
 def _get_js_files_except_compiled(self, build_path):
     return [x for x in loader.locate('*.js', build_path) if 'compiled.js' not in x]
示例#10
0
def compile_soy_templates(templates=None):
    """
  Compiles the soy files
  TODO: cannot do this in appengine dev server since os.popen is not defined
  so a better approach would be to run a deamon that that monitors the file
  system and generates all needed stuff JIT
  """

    if templates == None:
        logging.info("Scanning for soy template files...")
        template_files = set()
        for template_file in loader.locate("*.soy"):
            template_files.add(template_file)
            logging.info(template_file)

        if not template_files:
            logging.info("No templates found.")
            return
    else:
        template_files = set(templates)

    if not template_files:
        return

    generated_path = "%sgenerated/client/templates/" % loader.root_path()
    SoyToJsSrcCompiler_path = "%s/../tools/closure-templates/SoyToJsSrcCompiler.jar" % loader.root_path()

    logging.info("Found %s template(s)" % len(template_files))

    logging.info("compiling ...")
    a = os.popen(
        "java -jar %(soy_to_js_compiler)s --outputPathFormat %(generated_path)s%(tmp)s{INPUT_DIRECTORY}{INPUT_FILE_NAME_NO_EXT}.js %(options)s %(templates)s"
        % {
            "soy_to_js_compiler": SoyToJsSrcCompiler_path,
            "generated_path": generated_path,
            "tmp": "tmp",
            "templates": " ".join(template_files),
            "options": " ".join(["--shouldGenerateJsdoc", "--shouldProvideRequireSoyNamespaces"]),
        }
    )
    if a.close():
        logging.info("Failed to compile... check error message")
        return

    #    logging.info('Generated files:')
    #    for fname in os.listdir(generated_path):
    #        logging.info('\t%s%s' % (generated_path, fname))

    #  src = '%stmp%s' % (generated_path, loader.root_path())
    #  for directory in os.listdir(src):
    #    shutil.move('%s%s' % (src,directory), generated_path)

    src_root = "%stmp" % generated_path
    for f in template_files:
        l = len(loader.root_path().split("/"))
        filename = "".join([".".join(f.split("/")[l - 1 :]).rstrip(".soy").strip("."), ".js"])
        src = "".join([src_root, f.rstrip(".soy"), ".js"])
        dst = "".join([generated_path, filename])
        logging.info(filename)
        logging.info(src)
        logging.info(dst)
        shutil.copy2(src, dst)

    #    shutil.move(directory, generated_path)

    shutil.rmtree("%stmp" % generated_path)

    logging.info("Done.")
    return template_files
示例#11
0
 def run(self):
     for f in loader.locate('*_test.js'):
         #TODO: find a way not to skip entrypoint for now
         #      wich causes a more than one entrypoint defined   
         if not 'entrypoint' in f:
             generate_instrumented_file(f.replace('_test.js', '.js'))