chromium/ui/file_manager/image_loader/BUILD.gn

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

import("//tools/typescript/webui_ts_library.gni")
import("//ui/file_manager/file_names.gni")
import("//ui/webui/resources/tools/optimize_webui.gni")
import("//ui/webui/webui_features.gni")

preprocess_folder = "$target_gen_dir/preprocessed"
tsc_folder = "$target_gen_dir/tsc"
files_app_path = rebase_path("$tsc_folder/file_manager", root_build_dir)
image_loader_path = rebase_path("$tsc_folder/image_loader", root_build_dir)

# image_loader_client.js depends on this file from Files app.
copy("from_files_app") {
  sources = [
    "$target_gen_dir/../file_manager/common/js/file_types_data.js",
    "../file_manager/common/js/file_types_base.ts",
    "../file_manager/common/js/lru_cache.ts",
  ]

  outputs = [ "$preprocess_folder/file_manager/common/js/{{source_file_part}}" ]
  deps = [ "//ui/file_manager/base/gn:file_types_data_gen_js" ]

  if (enable_webui_inline_sourcemaps) {
    deps += [ "//ui/file_manager:merge_source_maps" ]
  } else {
    deps += [ "//ui/file_manager:build_ts" ]
  }
}

copy("copy_src") {
  sources = rebase_path(image_loader_ts, ".", "..")
  outputs = [ "$preprocess_folder/image_loader/{{source_file_part}}" ]
}

dts_files = [
  "image_loader_private.d.ts",
  "overrides.d.ts",
  "//tools/typescript/definitions/chrome_event.d.ts",
  "//tools/typescript/definitions/runtime.d.ts",
]

webui_ts_library("build_ts") {
  root_dir = preprocess_folder
  out_dir = tsc_folder
  tsconfig_base = "tsconfig_base.json"
  composite = true

  deps = [
    "//ash/webui/common/resources:build_ts",
    "//ui/webui/resources/js:build_ts",
  ]

  extra_deps = [
    ":copy_src",
    ":from_files_app",
    "//ash/webui/common/resources:generate_definitions",
  ]

  in_files = image_loader_ts + [
               "file_manager/common/js/file_types_data.js",
               "file_manager/common/js/file_types_base.ts",
               "file_manager/common/js/lru_cache.ts",
             ]

  definitions = dts_files

  path_mappings =
      [ "chrome://file-manager/*|" +
        rebase_path("$preprocess_folder/file_manager/*", target_gen_dir) ]
}

optimize_webui("build") {
  host = "image_loader"

  input = image_loader_path
  js_module_in_files = [ "background.js" ]

  external_paths = [
    "chrome://file-manager|$files_app_path",
    "chrome-extension://pmfjbimdmchhbnneeidfognadeopoehp|$image_loader_path",
  ]

  deps = [
    ":build_ts",
    "//ui/file_manager:preprocess_generated",
    "//ui/file_manager:preprocess_static",
    "//ui/file_manager:preprocess_static_image_loader",
  ]
  if (enable_webui_inline_sourcemaps) {
    deps += [ "//ui/file_manager:merge_source_maps" ]
  } else {
    deps += [ "//ui/file_manager:build_ts" ]
  }
}