From 95d25a5fb867d4eb906000fbfe214c33b8b83f7f Mon Sep 17 00:00:00 2001 From: bridiver Date: Sat, 4 Aug 2018 16:11:58 -0700 Subject: [PATCH] let each component handle its own transpiling --- components/brave_adblock_ui/BUILD.gn | 18 ++++++++++++ components/brave_new_tab_ui/BUILD.gn | 22 +++++++++++++++ components/brave_rewards_ui/BUILD.gn | 17 +++++++++++ components/brave_welcome_ui/BUILD.gn | 24 ++++++++++++++++ components/common/typescript.gni | 42 ++++++++++++++++++++++++++++ components/resources/BUILD.gn | 40 ++++---------------------- components/webpack/dev.config.js | 2 +- components/webpack/prod.config.js | 2 +- 8 files changed, 131 insertions(+), 36 deletions(-) create mode 100644 components/brave_adblock_ui/BUILD.gn create mode 100644 components/brave_new_tab_ui/BUILD.gn create mode 100644 components/brave_rewards_ui/BUILD.gn create mode 100644 components/brave_welcome_ui/BUILD.gn create mode 100644 components/common/typescript.gni diff --git a/components/brave_adblock_ui/BUILD.gn b/components/brave_adblock_ui/BUILD.gn new file mode 100644 index 000000000000..c07456599c83 --- /dev/null +++ b/components/brave_adblock_ui/BUILD.gn @@ -0,0 +1,18 @@ +import("//brave/components/common/typescript.gni") + +transpile_web_ui("brave_adblock_ui") { + inputs = [ + "brave_adblock.html", + "brave_adblock.tsx", + "storage.ts", + "store.ts", + "actions/adblock_actions.ts", + "components/app.tsx", + "components/numBlockedStat.tsx", + "components/regionalAdBlockEnabled.tsx", + "constants/adblock_types.ts", + "reducers/adblock_reducer.ts", + ] + + bundle_name = "brave_adblock.bundle.js" +} diff --git a/components/brave_new_tab_ui/BUILD.gn b/components/brave_new_tab_ui/BUILD.gn new file mode 100644 index 000000000000..1a3a4777269f --- /dev/null +++ b/components/brave_new_tab_ui/BUILD.gn @@ -0,0 +1,22 @@ +import("//brave/components/common/typescript.gni") + +transpile_web_ui("brave_new_tab_ui") { + inputs = [ + "brave_new_tab.html", + "brave_new_tab.tsx", + "storage.ts", + "store.ts", + "actions/new_tab_actions.ts", + "components/app.tsx", + "components/block.tsx", + "components/footerInfo.tsx", + "components/siteRemovalNotification.tsx", + "components/stats.tsx", + "constants/backgrounds.ts", + "constants/new_tab_types.ts", + "constants/theme.ts", + "reducers/index.ts", + "reducers/new_tab_reducer.tsx", + ] + bundle_name = "brave_new_tab.bundle.js" +} diff --git a/components/brave_rewards_ui/BUILD.gn b/components/brave_rewards_ui/BUILD.gn new file mode 100644 index 000000000000..137fc8c2ea15 --- /dev/null +++ b/components/brave_rewards_ui/BUILD.gn @@ -0,0 +1,17 @@ +import("//brave/components/common/typescript.gni") + +transpile_web_ui("brave_rewards_ui") { + inputs = [ + "brave_rewards.html", + "brave_rewards.tsx", + "storage.ts", + "store.ts", + "actions/rewards_actions.ts", + "components/app.tsx", + "constants/rewards_types.ts", + "reducers/index.ts", + "reducers/rewards_reducer.ts", + ] + + bundle_name = "brave_rewards.bundle.js" +} diff --git a/components/brave_welcome_ui/BUILD.gn b/components/brave_welcome_ui/BUILD.gn new file mode 100644 index 000000000000..709e51140626 --- /dev/null +++ b/components/brave_welcome_ui/BUILD.gn @@ -0,0 +1,24 @@ +import("//brave/components/common/typescript.gni") + +transpile_web_ui("brave_welcome_ui") { + inputs = [ + "brave_welcome.html", + "brave_welcome.tsx", + "storage.ts", + "store.ts", + "actions/welcome_actions.ts", + "components/app.tsx", + "components/braveScreen.tsx", + "components/featuresScreen.tsx", + "components/footer.tsx", + "components/importScreen.tsx", + "components/rewardsScreen.tsx", + "components/shieldsScreen.tsx", + "constants/theme.ts", + "constants/welcome_types.ts", + "reducers/index.ts", + "reducers/welcome_reducer.ts", + ] + + bundle_name = "brave_welcome.bundle.js" +} diff --git a/components/common/typescript.gni b/components/common/typescript.gni new file mode 100644 index 000000000000..b542b461db18 --- /dev/null +++ b/components/common/typescript.gni @@ -0,0 +1,42 @@ +brave_common_typescript_includes = [ + rebase_path("classSet.ts"), + rebase_path("debounce.ts"), + rebase_path("locale.ts"), +] + +template("transpile_web_ui") { + bundle_name = invoker.bundle_name + + action(target_name) { + script = "//brave/script/transpile-web-ui.py" + + inputs = brave_common_typescript_includes + if (defined(invoker.inputs)) { + inputs += invoker.inputs + } + + output_dir = "$root_gen_dir/brave" + + outputs = [ + "$output_dir/$bundle_name" + ] + + gen_dir = rebase_path(output_dir) + args = [ + "--target_gen_dir=$gen_dir" + ] + if (is_official_build) { + args += [ + "--production", + ] + } + + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "testonly", + "visibility", + ]) + } +} diff --git a/components/resources/BUILD.gn b/components/resources/BUILD.gn index 28cc1fd2659a..d5233b65baaf 100644 --- a/components/resources/BUILD.gn +++ b/components/resources/BUILD.gn @@ -1,48 +1,20 @@ import("//tools/grit/grit_rule.gni") -transpile_includes = [ - # Brave Adblock Page - "../brave_adblock_ui/brave_adblock.html", - # Brave New Tab - "../brave_new_tab_ui/brave_new_tab.html", - # Brave Rewards - "../brave_rewards_ui/brave_rewards.html", - # Brave Welcome Page - "../brave_welcome_ui/brave_welcome.html" -] - -action("transpile_web_uis") { - script = "//brave/script/transpile-web-ui.py" - inputs = transpile_includes - outputs = [ - "$target_out_dir/brave_new_tab.bundle.js", - "$target_out_dir/brave_rewards.bundle.js", - "$target_out_dir/brave_welcome.bundle.js", - "$target_out_dir/brave_adblock.bundle.js", - ] - gen_dir = rebase_path(root_gen_dir, "//") - args = [ - "--target_gen_dir=$gen_dir" - ] - if (is_official_build) { - args += [ - "--production", - ] - } -} - grit("brave_components_resources_grit") { source = "brave_components_resources.grd" output_name = "brave_components_resources_new" - inputs = get_target_outputs(":transpile_web_uis") - inputs += transpile_includes outputs = [ "grit/brave_components_resources.h", "brave_components_resources.pak", ] - deps = [ ":transpile_web_uis" ] + deps = [ + "//brave/components/brave_adblock_ui", + "//brave/components/brave_new_tab_ui", + "//brave/components/brave_rewards_ui", + "//brave/components/brave_welcome_ui", + ] grit_flags = [ "-E", "root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir), diff --git a/components/webpack/dev.config.js b/components/webpack/dev.config.js index 503e853e6da6..4098c611bb4d 100644 --- a/components/webpack/dev.config.js +++ b/components/webpack/dev.config.js @@ -11,7 +11,7 @@ module.exports = { brave_welcome: path.join(__dirname, '../brave_welcome_ui/brave_welcome') }, output: { - path: path.join(__dirname, '..', '..', '..', process.env.TARGET_GEN_DIR, 'brave'), + path: process.env.TARGET_GEN_DIR, filename: '[name].bundle.js', chunkFilename: '[id].chunk.js' }, diff --git a/components/webpack/prod.config.js b/components/webpack/prod.config.js index c30d99ff46c7..8f6a7aaa5274 100644 --- a/components/webpack/prod.config.js +++ b/components/webpack/prod.config.js @@ -11,7 +11,7 @@ module.exports = { brave_welcome: path.join(__dirname, '../brave_welcome_ui/brave_welcome') }, output: { - path: path.join(__dirname, '..', '..', '..', process.env.TARGET_GEN_DIR, 'brave'), + path: process.env.TARGET_GEN_DIR, filename: '[name].bundle.js', chunkFilename: '[id].chunk.js' },