chromium/ash/webui/camera_app_ui/resources/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/camera_app_ui/resources/images/images.gni")
import("//ash/webui/camera_app_ui/resources/js/js.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//tools/grit/preprocess_if_expr.gni")
import("//tools/typescript/webui_ts_library.gni")

assert(is_chromeos_ash)

action("gen_preload_images_js") {
  script = "utils/gen_preload_images_js.py"

  in_app_image_paths = []
  foreach(image, in_app_images) {
    in_app_image_paths += [ "images/$image" ]
  }

  inputs = in_app_image_paths
  foreach(image, standalone_images) {
    inputs += [ "images/$image" ]
  }

  outputs = [ "$target_gen_dir/js/preload_images.js" ]
  response_file_contents = rebase_path(in_app_image_paths)
  args = [
           "--output_file",
           rebase_path(outputs[0], root_build_dir),
           "--in_app_images_file={{response_file_name}}",
           "--standalone_images",
         ] + standalone_images
}

copy("copy_sources") {
  sources = []
  foreach(js, compile_js_files) {
    sources += [ "js/$js" ]
  }
  outputs = [ "{{source_gen_dir}}/{{source_file_part}}" ]
}

mojo_files = [
  "ash/components/arc/mojom/camera_intent.mojom-webui.ts",
  "ash/webui/camera_app_ui/camera_app_helper.mojom-webui.ts",
  "ash/webui/camera_app_ui/events_sender.mojom-webui.ts",
  "ash/webui/camera_app_ui/ocr.mojom-webui.ts",
  "ash/webui/camera_app_ui/pdf_builder.mojom-webui.ts",
  "ash/webui/camera_app_ui/types.mojom-webui.ts",
  "chromeos/services/machine_learning/public/mojom/document_scanner_param_types.mojom-webui.ts",
  "media/capture/mojom/image_capture.mojom-webui.ts",
  "media/capture/video/chromeos/mojom/camera3.mojom-webui.ts",
  "media/capture/video/chromeos/mojom/camera_app.mojom-webui.ts",
  "media/capture/video/chromeos/mojom/camera_common.mojom-webui.ts",
  "media/capture/video/chromeos/mojom/camera_features.mojom-webui.ts",
  "media/capture/video/chromeos/mojom/camera_metadata.mojom-webui.ts",
  "media/capture/video/chromeos/mojom/camera_metadata_tags.mojom-webui.ts",
]

mojo_files_deps = [
  "//ash/components/arc/mojom:camera_intent_ts__generator",
  "//ash/webui/camera_app_ui:mojo_bindings_ts__generator",
  "//ash/webui/camera_app_ui:ocr_ts__generator",
  "//ash/webui/camera_app_ui:pdf_builder_ts__generator",
  "//chromeos/services/machine_learning/public/mojom:document_scanner_param_types_ts__generator",
  "//media/capture/mojom:image_capture_ts__generator",
  "//media/capture/video/chromeos/mojom:cros_camera_common_ts__generator",
]

preprocess_if_expr("copy_mojo_ts") {
  visibility = [
    ":build_ts",
    ":build_ts__ts_library",
  ]
  deps = mojo_files_deps
  in_folder = root_gen_dir
  out_folder = "$target_gen_dir/mojom"
  in_files = mojo_files
}

webui_ts_library("build_ts") {
  deps = [
    "//third_party/cros-components:cros_components_ts",
    "//third_party/material_web_components:bundle_lit_ts",
    "//third_party/material_web_components:library",
    "//ui/webui/resources/cr_components/color_change_listener:build_ts",
    "//ui/webui/resources/js:build_ts",
    "//ui/webui/resources/mojo:build_ts",
  ]

  tsconfig_base = "tsconfig_base.json"
  root_dir = target_gen_dir
  out_dir = "$target_gen_dir/tsc"

  extra_deps = [
    ":copy_mojo_ts",
    ":copy_sources",
    ":gen_preload_images_js",
  ]

  definitions = [
    "js/externs/types.d.ts",
    "js/lib/ffmpeg.d.ts",
    "//tools/typescript/definitions/pending.d.ts",
  ]

  mojo_files_rebased = []
  foreach(mojo, mojo_files) {
    mojo_files_rebased += [ "mojom/$mojo" ]
  }

  manifest_excludes = []
  foreach(js, local_dev_js_files) {
    manifest_excludes += [ "js/$js" ]
  }

  in_files =
      mojo_files_rebased +
      rebase_path(get_target_outputs(":copy_sources"), root_dir, root_build_dir)
}