| # Copyright 2021 The Chromium Authors | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| import("//build/timestamp.gni") | |
| import("./node.gni") | |
| import("./vars.gni") | |
| template("generate_css") { | |
| assert(defined(invoker.sources), | |
| "You must define the 'sources' for a generate_css target") | |
| _action_target_name = "${target_name}_action" | |
| _tsconfig_ref_target = "${target_name}_tsconfig_ref" | |
| _tsconfig_ref_file = "$target_gen_dir/$target_name-tsconfig.ref.json" | |
| _tsconfig_target = "${target_name}_tsconfig" | |
| _tsconfig_file = "$target_gen_dir/$target_name-tsconfig.json" | |
| _css_outputs = [] | |
| _js_files = [] | |
| foreach(_input, invoker.sources) { | |
| _css_outputs += [ "$target_gen_dir/$_input.js" ] | |
| _js_files += [ "$_input.js" ] | |
| } | |
| generated_file(_tsconfig_ref_target) { | |
| outputs = [ _tsconfig_ref_file ] | |
| output_conversion = "json" | |
| contents = { | |
| compilerOptions = { | |
| composite = true | |
| declaration = true | |
| emitDeclarationOnly = true | |
| skipLibCheck = true | |
| outDir = "." | |
| declarationDir = "." | |
| } | |
| files = _js_files | |
| } | |
| if (defined(invoker.testonly)) { | |
| testonly = invoker.testonly | |
| } | |
| } | |
| generated_file(_tsconfig_target) { | |
| outputs = [ _tsconfig_file ] | |
| output_conversion = "json" | |
| contents = { | |
| compilerOptions = { | |
| composite = true | |
| outDir = "." | |
| } | |
| files = _js_files | |
| } | |
| if (defined(invoker.testonly)) { | |
| testonly = invoker.testonly | |
| } | |
| } | |
| node_action(_action_target_name) { | |
| forward_variables_from(invoker, [ "sources" ]) | |
| script = "scripts/build/generate_css_js_files.js" | |
| _src = rebase_path(".", root_build_dir) | |
| _dest = rebase_path(target_gen_dir, root_build_dir) | |
| inputs += | |
| [ devtools_location_prepend + "node_modules/cssnano/package.json" ] | |
| args = [ | |
| "--build-timestamp", | |
| build_timestamp, | |
| "--src-dir", | |
| _src, | |
| "--target-gen-dir", | |
| _dest, | |
| "--files", | |
| string_join(",", sources), | |
| ] | |
| if (is_debug) { | |
| args += [ "--debug" ] | |
| } | |
| outputs = _css_outputs | |
| if (defined(invoker.testonly)) { | |
| testonly = invoker.testonly | |
| } | |
| } | |
| group(target_name) { | |
| public_deps = [ | |
| ":$_action_target_name", | |
| ":$_tsconfig_ref_target", | |
| ":$_tsconfig_target", | |
| ] | |
| data = _css_outputs | |
| if (!devtools_bundle) { | |
| metadata = { | |
| grd_files = _css_outputs | |
| } | |
| } | |
| if (defined(invoker.testonly)) { | |
| testonly = invoker.testonly | |
| } | |
| if (defined(invoker.visibility)) { | |
| visibility = invoker.visibility | |
| } | |
| } | |
| } |