1# Copyright (c) 2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15import("//foundation/arkui/ace_engine/ace_config.gni")
16
17install_path = "SADialog"
18template("gen_sa_dialog_js") {
19  forward_variables_from(invoker, "*")
20
21  action("build_dialog_js") {
22    nodejs_path = "//prebuilts/build-tools/common/nodejs/current/bin"
23
24    project_path = invoker.project_path
25    script = "//foundation/arkui/ace_engine/build/tools/build_js.py"
26    outputs = [
27      target_out_dir + "/default/app.js",
28      target_out_dir + "/default/pages/index/index.js",
29      target_out_dir + "/default/manifest.json",
30    ]
31
32    if (defined(i18n_files)) {
33      foreach(i18n_file, i18n_files) {
34        outputs += [ target_out_dir + "/default/" + i18n_file ]
35      }
36    }
37
38    if (defined(common_files)) {
39      foreach(common_file, common_files) {
40        outputs += [ target_out_dir + "/default/" + common_file ]
41      }
42    }
43
44    args = [
45      rebase_path(project_path, root_build_dir),
46      rebase_path(target_out_dir, root_build_dir),
47      rebase_path(nodejs_path, root_build_dir),
48      rebase_path("//developtools/ace_js2bundle", root_build_dir),
49      rebase_path("//interface", root_build_dir),
50      rebase_path("//third_party/parse5", root_build_dir),
51      rebase_path("//third_party/weex-loader", root_build_dir),
52    ]
53  }
54
55  ohos_prebuilt_etc("dialog_js_files_app") {
56    deps = [ ":build_dialog_js" ]
57    relative_install_dir = "$install_path/$dialog_name"
58    source = target_out_dir + "/default/app.js"
59  }
60
61  ohos_prebuilt_etc("dialog_js_files_index") {
62    deps = [ ":build_dialog_js" ]
63    relative_install_dir = "$install_path/$dialog_name/pages/index"
64    source = target_out_dir + "/default/pages/index/index.js"
65  }
66
67  if (defined(i18n_files)) {
68    foreach(i18n_file, i18n_files) {
69      name = string_replace(i18n_file, "/", "_")
70      ohos_prebuilt_etc("dialog_js_files_$name") {
71        deps = [ ":build_dialog_js" ]
72        relative_install_dir = "$install_path/$dialog_name/i18n"
73        source = target_out_dir + "/default/$i18n_file"
74      }
75    }
76  }
77
78  if (defined(common_files)) {
79    foreach(common_file, common_files) {
80      name = string_replace(common_file, "/", "_")
81      ohos_prebuilt_etc("dialog_js_files_$name") {
82        deps = [ ":build_dialog_js" ]
83        relative_install_dir = "$install_path/$dialog_name/common"
84        source = target_out_dir + "/default/$common_file"
85      }
86    }
87  }
88
89  ohos_prebuilt_etc("dialog_js_files_manifest") {
90    deps = [ ":build_dialog_js" ]
91    relative_install_dir = "$install_path/$dialog_name"
92    source = target_out_dir + "/default/manifest.json"
93  }
94
95  group(target_name) {
96    deps = [
97      ":dialog_js_files_app",
98      ":dialog_js_files_index",
99      ":dialog_js_files_manifest",
100    ]
101    if (defined(i18n_files)) {
102      foreach(i18n_file, i18n_files) {
103        name = string_replace(i18n_file, "/", "_")
104        deps += [ ":dialog_js_files_$name" ]
105      }
106    }
107    if (defined(common_files)) {
108      foreach(common_file, common_files) {
109        name = string_replace(common_file, "/", "_")
110        deps += [ ":dialog_js_files_$name" ]
111      }
112    }
113  }
114}
115