chromium/ash/webui/media_app_ui/resources/js/BUILD.gn

# Copyright 2019 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//ash/webui/media_app_ui/media_app_files.gni")
import("//ash/webui/web_applications/system_apps.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/typescript/ts_definitions.gni")
import("//ui/webui/resources/tools/optimize_webui.gni")

assert(is_chromeos_ash)

# Where files are staged for rollup. .ts files should never be put here.
stage_folder = "$root_gen_dir/ash/webui/media_app_ui/stage_rollup"

# Move files to the stage folder to combine all resources in the same folder for
# JS bundling with rollup.
# This is for files direct from the src/:  input_folder="./".
copy("stage_static") {
  sources = media_app_unconverted_js_sources +
            [ "//ash/webui/system_apps/public/js/sandboxed_load_time_data.js" ]
  outputs = [ stage_folder + "/{{source_file_part}}" ]
}

# This is for files that are generated in "gen/", except TypeScript output.
copy("stage_generated") {
  sources = [
    "$root_gen_dir/ash/webui/media_app_ui/media_app_ui.mojom-lite.js",
    "$root_gen_dir/mojo/public/mojom/base/big_buffer.mojom-lite.js",
    "$root_gen_dir/mojo/public/mojom/base/unguessable_token.mojom-lite.js",
    "$root_gen_dir/skia/public/mojom/bitmap.mojom-lite.js",
    "$root_gen_dir/skia/public/mojom/image_info.mojom-lite.js",
    "$root_gen_dir/third_party/blink/public/mojom/file_system_access/file_system_access_transfer_token.mojom-lite.js",
    "$root_gen_dir/ui/gfx/geometry/mojom/geometry.mojom-lite.js",
    "$root_gen_dir/url/mojom/url.mojom-lite.js",
  ]

  outputs = [ stage_folder + "/{{source_file_part}}" ]

  deps = [
    "//ash/webui/media_app_ui:mojo_bindings_js",
    "//third_party/blink/public/mojom:mojom_platform_js",
    "//url/mojom:url_mojom_gurl_js",
  ]
}

# Takes the JS emitted by the `ts_library` targets and places it with other JS
# files in the staging folder for `rollup` to consume.
copy("stage_compiled_ts") {
  sources = media_app_compiled_sources +
            [ "$root_gen_dir/ash/webui/media_app_ui/tsc/piex_loader.js" ]
  outputs = [ stage_folder + "/{{source_file_part}}" ]
  deps = [ "//ash/webui/media_app_ui:build_ts" ]
}

copy("stage_for_tsc") {
  # Note only converted .ts and handcrafted .d.ts files are staged here.
  # Generated .d.ts emit directly to `ts_root_dir`. Confusingly, unconverted JS
  # files must also appear here even though tsc ignores them: this is necessary
  # to engage logic in ts_library.py that handles clearing out old build
  # dependencies.
  sources = media_app_converted_ts_sources + media_app_static_defs +
            media_app_unconverted_js_sources +
            [ "//ui/file_manager/image_loader/piex_loader.ts" ]
  outputs = [ ts_root_dir + "/{{source_file_part}}" ]
}

ts_definitions("generate_definitions") {
  root_dir = "."
  out_dir = ts_root_dir
  js_files = media_app_unconverted_js_sources
}

system_apps_dir =
    rebase_path("$root_gen_dir/ash/webui/system_apps/public/js", root_build_dir)

optimize_webui("launch_rollup") {
  host = "media-app"
  js_module_in_files = [ "launch.js" ]
  input = rebase_path(stage_folder, root_build_dir)
  deps = [
    ":stage_compiled_ts",
    ":stage_generated",
    ":stage_static",
    "//ash/webui/system_apps/public/js:build_ts",
  ]
  external_paths = [ "//system_apps/|$system_apps_dir" ]
}

optimize_webui("receiver_rollup") {
  host = "chrome-untrusted://media-app"
  js_module_in_files = [ "receiver.js" ]
  input = rebase_path(stage_folder, root_build_dir)
  deps = [
    ":stage_compiled_ts",
    ":stage_generated",
    ":stage_static",
    "//ash/webui/system_apps/public/js:build_ts",
    "//ui/webui/resources/cr_components/color_change_listener:build_ts",
  ]
  external_paths = [ "//system_apps/|$system_apps_dir" ]
}

optimize_webui("piex_rollup") {
  host = "media-app"
  js_module_in_files = [ "piex_module.js" ]
  input = rebase_path(stage_folder, root_build_dir)
  deps = [
    ":stage_compiled_ts",
    ":stage_generated",
    ":stage_static",
  ]
}

# Build rules below here are just used for typechecking and don't influence what
# is shipped to resources.pak.

media_closure_flags = system_app_closure_flags_strict + [
                        "hide_warnings_for=ash/webui/media_app_ui/media_app_ui.mojom-lite-for-compile.js",

                        # For all js module in source tree.
                        "js_module_root=" + rebase_path(".", root_build_dir),

                        # For all dynamic generated js module.
                        "js_module_root=" +
                            rebase_path(target_gen_dir, root_build_dir),
                      ]

group("closure_compile") {
  deps = [ ":closure_compile_index" ]
}

js_type_check("closure_compile_index") {
  closure_flags = media_closure_flags
  deps = [ ":mojo_api_bootstrap" ]
}

js_library("mojo_api_bootstrap") {
  sources = [
    "$root_gen_dir/third_party/blink/public/mojom/file_system_access/file_system_access_transfer_token.mojom-lite-for-compile.js",
    "$target_gen_dir/../../media_app_ui.mojom-lite-for-compile.js",
  ]

  deps = [
    "//mojo/public/mojom/base:base_js_library_for_compile",
    "//url/mojom:url_mojom_gurl_js_library_for_compile",
  ]

  extra_deps = [
    # We can't depend on the `_js_library_for_compile` target for the following
    # without needing to depend on many unrelated closure definitions under the
    # `//third_party/blink/public/mojom:mojom_platform` target.
    "//ash/webui/media_app_ui:mojo_bindings_js",
    "//third_party/blink/public/mojom:mojom_platform_js",
  ]
}