def _rollup_module(self, module_name, modules):
        js_entrypoint = join(self.application_dir, module_name,
                             module_name + '.js')
        out = ''
        if self.use_rollup:
            rollup_process = subprocess.Popen(
                [devtools_paths.node_path(),
                 devtools_paths.rollup_path()] + ROLLUP_ARGS +
                ['--input', js_entrypoint],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            out, error = rollup_process.communicate()
        else:
            out = read_file(js_entrypoint)
        write_file(join(self.output_dir, module_name, module_name + '.js'),
                   minify_js(out))

        legacyFileName = module_name + '-legacy.js'
        if legacyFileName in modules:
            write_file(
                join(self.output_dir, module_name, legacyFileName),
                minify_js(
                    read_file(
                        join(self.application_dir, module_name,
                             legacyFileName))))
Ejemplo n.º 2
0
def concatenate_application_script(application_name, descriptors,
                                   application_dir, output_dir, minify):
    application_loader_name = application_name + '.js'
    output = StringIO()
    runtime_contents = read_file(path.join(application_dir, 'Runtime.js'))
    runtime_contents = re.sub(
        'var allDescriptors = \[\];', 'var allDescriptors = %s;' %
        release_module_descriptors(descriptors.modules).replace("\\", "\\\\"),
        runtime_contents, 1)
    output.write('/* Runtime.js */\n')
    output.write(runtime_contents)
    output.write('\n/* Autostart modules */\n')
    concatenate_autostart_modules(descriptors, application_dir, output_dir,
                                  output)
    output.write('/* Application descriptor %s */\n' %
                 (application_name + '.json'))
    output.write('applicationDescriptor = ')
    output.write(descriptors.application_json)
    output.write(';\n/* Application loader */\n')
    output.write(read_file(path.join(application_dir,
                                     application_loader_name)))

    write_file(path.join(output_dir, application_loader_name),
               minify_if_needed(output.getvalue(), minify))
    output.close()
Ejemplo n.º 3
0
    def _rollup_module(self, module_name, modules):
        js_entrypoint = join(self.application_dir, module_name,
                             module_name + '.js')
        out = ''
        if self.use_rollup:
            rollup_process = subprocess.Popen([
                devtools_paths.node_path(),
                devtools_paths.rollup_path(), '--config',
                join(FRONT_END_DIRECTORY, 'rollup.config.js'), '--input',
                js_entrypoint, '--external', EXTERNAL_MODULE_LIST
            ],
                                              stdout=subprocess.PIPE,
                                              stderr=subprocess.PIPE)
            out, error = rollup_process.communicate()
            if rollup_process.returncode != 0:
                print(error)
                sys.exit(rollup_process.returncode)
        else:
            out = read_file(js_entrypoint)
        write_file(join(self.output_dir, module_name, module_name + '.js'),
                   minify_js(out))

        legacyFileName = module_name + '-legacy.js'
        if legacyFileName in modules:
            write_file(
                join(self.output_dir, module_name, legacyFileName),
                minify_js(
                    read_file(
                        join(self.application_dir, module_name,
                             legacyFileName))))
    def _rollup_module(self, module_name, modules, skip_rollup):
        legacyFileName = module_name + '-legacy.js'
        if legacyFileName in modules:
            write_file(
                join(self.output_dir, module_name, legacyFileName),
                minify_js(
                    read_file(
                        join(self.application_dir, module_name,
                             legacyFileName))))

        # Temporary hack, as we use `devtools_entrypoint` for this module now
        # TODO(crbug.com/1101738): remove once all folders are migrated
        if skip_rollup:
            return

        js_entrypoint = join(self.application_dir, module_name,
                             module_name + '.js')
        out = ''
        if self.use_rollup:
            rollup_process = subprocess.Popen([
                devtools_paths.node_path(),
                devtools_paths.rollup_path(), '--config',
                join(FRONT_END_DIRECTORY, 'rollup.config.js'), '--input',
                js_entrypoint
            ],
                                              stdout=subprocess.PIPE,
                                              stderr=subprocess.PIPE)
            out, error = rollup_process.communicate()
            if rollup_process.returncode != 0:
                print(error)
                sys.exit(rollup_process.returncode)
        else:
            out = read_file(js_entrypoint)
        write_file(join(self.output_dir, module_name, module_name + '.js'),
                   minify_js(out))
Ejemplo n.º 5
0
    def _concatenate_application_script(self, output):
        if not self.descriptors.extends:
            runtime_contents = read_file(
                join(self.application_dir, 'Runtime.js'))
            output.write('/* Runtime.js */\n')
            output.write(runtime_contents)
            output.write('allDescriptors.push(...%s);' %
                         self._release_module_descriptors())
            output.write('/* Application descriptor %s */\n' %
                         self.app_file('json'))
            output.write('applicationDescriptor = ')
            output.write(self.descriptors.application_json())
        else:
            output.write('/* Additional descriptors */\n')
            output.write('allDescriptors.push(...%s);' %
                         self._release_module_descriptors())
            output.write('/* Additional descriptors %s */\n' %
                         self.app_file('json'))
            output.write('applicationDescriptor.modules.push(...%s)' %
                         json.dumps(self.descriptors.application.values()))

        output.write('\n/* Autostart modules */\n')
        self._concatenate_autostart_modules(output)
        output.write(';\n/* Autostart resources */\n')
        self._write_module_resources(self.autorun_resource_names(), output)
        if not self.descriptors.has_html:
            js_file = join(self.application_dir, self.app_file('js'))
            if path.exists(js_file):
                output.write(';\n/* Autostart script for worker */\n')
                output.write(read_file(js_file))
Ejemplo n.º 6
0
 def _concatenate_application_script(self, output):
     runtime_contents = read_file(join(self.application_dir, 'Runtime.js'))
     runtime_contents = re.sub('var allDescriptors = \[\];', 'var allDescriptors = %s;' % self._release_module_descriptors().replace('\\', '\\\\'), runtime_contents, 1)
     output.write('/* Runtime.js */\n')
     output.write(runtime_contents)
     output.write('\n/* Autostart modules */\n')
     self._concatenate_autostart_modules(output)
     output.write('/* Application descriptor %s */\n' % self.app_file('json'))
     output.write('applicationDescriptor = ')
     output.write(self.descriptors.application_json())
     output.write(';\n/* Core resources */\n')
     self._write_module_resources(self.core_resource_names(), output)
     output.write('\n/* Application loader */\n')
     output.write(read_file(join(self.application_dir, self.app_file('js'))))
Ejemplo n.º 7
0
def concatenate_worker(module_name, descriptors, application_dir, output_dir,
                       minify):
    descriptor = descriptors.modules[module_name]
    scripts = descriptor.get('scripts')
    if not scripts:
        return
    worker_dir = path.join(application_dir, module_name)
    output_file_path = path.join(output_dir, module_name + '_module.js')

    output = StringIO()
    output.write('/* Worker %s */\n' % module_name)
    output.write('/* Runtime.js */\n')
    output.write(read_file(path.join(application_dir, 'Runtime.js')))
    dependencies = descriptors.sorted_dependencies_closure(module_name)
    dep_descriptors = []
    for dep_name in dependencies:
        dep_descriptor = descriptors.modules[dep_name]
        dep_descriptors.append(dep_descriptor)
        scripts = dep_descriptor.get('scripts')
        if scripts:
            output.write('\n/* Module %s */\n' % dep_name)
            modular_build.concatenate_scripts(
                scripts, path.join(application_dir, dep_name), output_dir,
                output)

    write_file(output_file_path, minify_if_needed(output.getvalue(), minify))
    output.close()
Ejemplo n.º 8
0
def main(argv):
    try:
        input_path_flag_index = argv.index('--input_path')
        input_path = argv[input_path_flag_index + 1]
        output_path_flag_index = argv.index('--output_path')
        output_path = argv[output_path_flag_index + 1]
        rollup_plugin_index = argv.index('--rollup_plugin')
        rollup_plugin = argv[rollup_plugin_index + 1]

        file_names_with_sizes = to_pairs(argv[1:input_path_flag_index])
        for filename, max_size in file_names_with_sizes:
            max_size = int(max_size)
            if filename.endswith(".js"):
                rollup(input_path, output_path, filename, max_size,
                       rollup_plugin)
            if filename.endswith(".css"):
                css_file = read_file(join(input_path, filename))
                check_size(filename, css_file, max_size)
                write_file(join(output_path, filename), css_file)

    except:
        print(
            'Usage: %s filename_1 max_size_1 filename_2 max_size_2 ... filename_N max_size_N --input_path <input_path> --output_path <output_path>'
            % argv[0])
        raise
def concatenate_application_script(application_name, descriptors, application_dir, output_dir, minify):
    application_loader_name = application_name + '.js'
    output = StringIO()
    runtime_contents = read_file(path.join(application_dir, 'Runtime.js'))
    runtime_contents = re.sub('var allDescriptors = \[\];', 'var allDescriptors = %s;' % release_module_descriptors(descriptors.modules).replace("\\", "\\\\"), runtime_contents, 1)
    output.write('/* Runtime.js */\n')
    output.write(runtime_contents)
    output.write('\n/* Autostart modules */\n')
    concatenate_autostart_modules(descriptors, application_dir, output_dir, output)
    output.write('/* Application descriptor %s */\n' % (application_name + '.json'))
    output.write('applicationDescriptor = ')
    output.write(descriptors.application_json)
    output.write(';\n/* Application loader */\n')
    output.write(read_file(path.join(application_dir, application_loader_name)))

    write_file(path.join(output_dir, application_loader_name), minify_if_needed(output.getvalue(), minify))
    output.close()
Ejemplo n.º 10
0
 def _write_module_resources(self, resource_names, output):
     for resource_name in resource_names:
         resource_name = path.normpath(resource_name).replace('\\', '/')
         output.write('Runtime.cachedResources["%s"] = "' % resource_name)
         resource_content = read_file(path.join(self.application_dir, resource_name)) + resource_source_url(resource_name)
         resource_content = resource_content.replace('\\', '\\\\')
         resource_content = resource_content.replace('\n', '\\n')
         resource_content = resource_content.replace('"', '\\"')
         output.write(resource_content)
         output.write('";\n')
 def _write_module_css_styles(self, css_names, output):
     for css_name in css_names:
         css_name = path.normpath(css_name).replace('\\', '/')
         output.write('Runtime.cachedResources["%s"] = "' % css_name)
         css_content = read_file(path.join(self.application_dir, css_name)) + css_source_url(css_name)
         css_content = css_content.replace('\\', '\\\\')
         css_content = css_content.replace('\n', '\\n')
         css_content = css_content.replace('"', '\\"')
         output.write(css_content)
         output.write('";\n')
    def _concatenate_application_script(self, output):
        output.write('Root.allDescriptors.push(...%s);' % self._release_module_descriptors())
        if self.descriptors.extends:
            output.write('Root.applicationDescriptor.modules.push(...%s);' % json.dumps(self.descriptors.application.values()))
        else:
            output.write('Root.applicationDescriptor = %s;' % self.descriptors.application_json())

        output.write(minify_js(read_file(join(self.application_dir, self.app_file('js')))))
        self._concatenate_autostart_modules(output)

        self._write_module_resources(self.autorun_resource_names(), output)
 def build_app(self):
     if self.descriptors.has_html:
         html_entrypoint = self.app_file('html')
         write_file(join(self.output_dir, html_entrypoint),
                    read_file(join(self.application_dir, html_entrypoint)))
     self._build_app_script()
     for module in filter(
             lambda desc:
         (not desc.get('type') or desc.get('type') == 'remote'),
             self.descriptors.application.values()):
         self._concatenate_dynamic_module(module['name'])
 def _rollup_module(
     self,
     module_name,
     modules,
 ):
     legacyFileName = module_name + '-legacy.js'
     if legacyFileName in modules:
         write_file(
             join(self.output_dir, module_name, legacyFileName),
             minify_js(
                 read_file(
                     join(self.application_dir, module_name,
                          legacyFileName))))
Ejemplo n.º 15
0
def concatenate_application_script(application_name, descriptors,
                                   application_dir, output_dir, minify):
    application_loader_name = application_name + '.js'
    output = StringIO()
    output.write('/* Runtime.js */\n')
    output.write(read_file(path.join(application_dir, 'Runtime.js')))
    output.write('\n/* Autostart modules */\n')
    concatenate_autostart_modules(descriptors, application_dir, output_dir,
                                  output)
    output.write('/* Application descriptor %s */\n' %
                 (application_name + '.json'))
    output.write('applicationDescriptor = ')
    output.write(descriptors.application_json)
    output.write(';\n/* Module descriptors */\n')
    output.write('allDescriptors = ')
    output.write(json.dumps(descriptors.modules.values()))
    output.write(';\n/* Application loader */\n')
    output.write(read_file(path.join(application_dir,
                                     application_loader_name)))

    write_file(path.join(output_dir, application_loader_name),
               minify_if_needed(output.getvalue(), minify))
    output.close()
 def _write_module_resources(self, resource_names, output):
     for resource_name in resource_names:
         resource_name = path.normpath(resource_name).replace('\\', '/')
         output.write('self.Runtime.cachedResources["%s"] = "' % resource_name)
         resource_content = read_file(path.join(self.application_dir, resource_name))
         if not (resource_name.endswith('.html')
                 or resource_name.endswith('md')):
             resource_content += resource_source_url(resource_name).encode(
                 'utf-8')
         resource_content = resource_content.replace('\\', '\\\\')
         resource_content = resource_content.replace('\n', '\\n')
         resource_content = resource_content.replace('"', '\\"')
         output.write(resource_content)
         output.write('";\n')
Ejemplo n.º 17
0
def main(argv):
    try:
        input_path_flag_index = argv.index('--input_path')
        input_path = argv[input_path_flag_index + 1]
        output_path_flag_index = argv.index('--output_path')
        output_path = argv[output_path_flag_index + 1]
        devtools_modules = argv[1:input_path_flag_index]
    except:
        print('Usage: %s module_1 module_2 ... module_N --input_path <input_path> --output_path <output_path>' % argv[0])
        raise

    for file_name in devtools_modules:
        file_content = read_file(join(input_path, file_name))
        minified = rjsmin.jsmin(file_content)
        write_file(join(output_path, relpath(file_name, 'front_end')), minified)
Ejemplo n.º 18
0
def unclosure_injected_script(sourceFileName, outFileName):

    source = read_file(sourceFileName)

    def replace_function(matchobj):
        return re.sub(r'@param', 'param', matchobj.group(1) or '') + '\n//' + matchobj.group(2)

    # Comment out the closure function and its jsdocs
    source = re.sub(r'(/\*\*(?:[\s\n]*\*\s*@param[^\n]+\n)+\s*\*/\s*)?\n(\(function)', replace_function, source, count=1)

    # Comment out its return statement
    source = re.sub(r'\n(\s*return\s+[^;]+;\s*\n\}\)\s*)$', '\n/*\\1*/', source)

    # Replace the "var Object" override with a "self.Object" one
    source = re.sub(r'\nvar Object =', '\nself.Object =', source, count=1)

    write_file(outFileName, source)
Ejemplo n.º 19
0
def unclosure_injected_script(sourceFileName, outFileName):

    source = read_file(sourceFileName)

    def replace_function(matchobj):
        return re.sub(r'@param', 'param', matchobj.group(1) or '') + '\n//' + matchobj.group(2)

    # Comment out the closure function and its jsdocs
    source = re.sub(r'(/\*\*(?:[\s\n]*\*\s*@param[^\n]+\n)+\s*\*/\s*)?\n(\(function)', replace_function, source, count=1)

    # Comment out its return statement
    source = re.sub(r'\n(\s*return\s+[^;]+;\s*\n\}\)\s*)$', '\n/*\\1*/', source)

    # Replace the "var Object" override with a "self.Object" one
    source = re.sub(r'\nvar Object =', '\nself.Object =', source, count=1)

    write_file(outFileName, source)
Ejemplo n.º 20
0
    def _build_html(self):
        html_name = self.app_file('html')
        output = StringIO()
        with open(join(self.application_dir, html_name),
                  'r') as app_input_html:
            for line in app_input_html:
                if '<script ' in line or '<link ' in line:
                    continue
                if '</head>' in line:
                    self._write_include_tags(self.descriptors, output)
                    js_file = join(self.application_dir, self.app_file('js'))
                    if path.exists(js_file):
                        output.write('    <script>%s</script>\n' %
                                     minify_js(read_file(js_file)))
                output.write(line)

        write_file(join(self.output_dir, html_name), output.getvalue())
        output.close()
Ejemplo n.º 21
0
    def _build_html(self):
        html_name = self.app_file('html')
        output = StringIO()
        with open(join(self.application_dir, html_name), 'r') as app_input_html:
            for line in app_input_html:
                if ('<script ' in line and 'type="module"' not in line) or '<link ' in line:
                    continue
                if '</head>' in line:
                    self._write_include_tags(self.descriptors, output)
                    js_file = join(self.application_dir, self.app_file('js'))
                    if path.exists(js_file):
                        boot_js_file = self.app_file('boot.js')
                        minified_js = minify_js(read_file(js_file))
                        output.write('    <script type="module" src="%s"></script>\n' % boot_js_file)
                        write_file(join(self.output_dir, boot_js_file), minified_js)
                output.write(line)

        write_file(join(self.output_dir, html_name), output.getvalue())
        output.close()
def main(argv):
    try:
        file_list_arg_index = argv.index('--file_list')
        file_list_filename = argv[file_list_arg_index + 1]
        input_path_flag_index = argv.index('--input_path')
        input_path = argv[input_path_flag_index + 1]
        output_path_flag_index = argv.index('--output_path')
        output_path = argv[output_path_flag_index + 1]

        file_list_file = open(file_list_filename, 'r')
        file_list_contents = file_list_file.read()
        devtools_modules = shlex.split(file_list_contents)
    except:
        print(
            'Usage: %s --file_list <response_file_path> --input_path <input_path> --output_path <output_path>'
            % argv[0])
        raise

    for file_name in devtools_modules:
        file_content = read_file(join(input_path, file_name))
        write_file(join(output_path, relpath(file_name, 'front_end')),
                   file_content)
 def copy_file(file_name):
     write_file(join(output_path, file_name),
                minify_js(read_file(join(input_path, file_name))))