diff --git a/ts/copy.bzl b/ts/copy.bzl index e62d7a044..2b5302671 100644 --- a/ts/copy.bzl +++ b/ts/copy.bzl @@ -26,3 +26,23 @@ def copy_files(ctx, files): ) return [DefaultInfo(files = depset(outputs))] + +def copy_select_files(ctx, files, include, exclude, unwanted_prefix): + wanted = [] + for f in files.to_list(): + path = f.path + want = True + + for substr in exclude: + if substr in path: + want = False + continue + if not want: + continue + + for substr in include: + if substr in path: + output = path.replace(unwanted_prefix, "") + wanted.append((f, output)) + + return copy_files(ctx, wanted) diff --git a/ts/css-browser-selector.bzl b/ts/css-browser-selector.bzl index ad2c4578b..d03ee3315 100644 --- a/ts/css-browser-selector.bzl +++ b/ts/css-browser-selector.bzl @@ -1,4 +1,4 @@ -load("//ts:copy.bzl", "copy_files") +load("//ts:copy.bzl", "copy_select_files") "Rule to copy css-browser-selector subset from node_modules to vendor folder." @@ -9,17 +9,13 @@ _include = [ _unwanted_prefix = "external/npm/node_modules/css-browser-selector/" def _copy_css_browser_selector_impl(ctx): - wanted = [] - for f in ctx.attr.css_browser_selector.files.to_list(): - path = f.path - want = True - - for substr in _include: - if substr in path: - output = path.replace(_unwanted_prefix, "") - wanted.append((f, output)) - - return copy_files(ctx, wanted) + return copy_select_files( + ctx, + ctx.attr.css_browser_selector.files, + _include, + [], + _unwanted_prefix, + ) copy_css_browser_selector = rule( implementation = _copy_css_browser_selector_impl, diff --git a/ts/jquery-ui.bzl b/ts/jquery-ui.bzl index f99e1cef7..482aa6985 100644 --- a/ts/jquery-ui.bzl +++ b/ts/jquery-ui.bzl @@ -1,4 +1,4 @@ -load("//ts:copy.bzl", "copy_files") +load("//ts:copy.bzl", "copy_select_files") "Rule to copy jquery-ui subset from node_modules to vendor folder." @@ -9,17 +9,13 @@ _include = [ _unwanted_prefix = "external/npm/node_modules/jquery-ui-dist/" def _copy_jquery_ui_impl(ctx): - wanted = [] - for f in ctx.attr.jquery_ui.files.to_list(): - path = f.path - want = True - - for substr in _include: - if substr in path: - output = path.replace(_unwanted_prefix, "") - wanted.append((f, output)) - - return copy_files(ctx, wanted) + return copy_select_files( + ctx, + ctx.attr.jquery_ui.files, + _include, + [], + _unwanted_prefix, + ) copy_jquery_ui = rule( implementation = _copy_jquery_ui_impl, diff --git a/ts/jquery.bzl b/ts/jquery.bzl index 86025d04a..f7a3542d8 100644 --- a/ts/jquery.bzl +++ b/ts/jquery.bzl @@ -1,4 +1,4 @@ -load("//ts:copy.bzl", "copy_files") +load("//ts:copy.bzl", "copy_select_files") "Rule to copy jquery subset from node_modules to vendor folder." @@ -9,17 +9,13 @@ _include = [ _unwanted_prefix = "external/npm/node_modules/jquery/dist/" def _copy_jquery_impl(ctx): - wanted = [] - for f in ctx.attr.jquery.files.to_list(): - path = f.path - want = True - - for substr in _include: - if substr in path: - output = path.replace(_unwanted_prefix, "") - wanted.append((f, output)) - - return copy_files(ctx, wanted) + return copy_select_files( + ctx, + ctx.attr.jquery.files, + _include, + [], + _unwanted_prefix, + ) copy_jquery = rule( implementation = _copy_jquery_impl, diff --git a/ts/mathjax.bzl b/ts/mathjax.bzl index 81f22365c..f50d3cf81 100644 --- a/ts/mathjax.bzl +++ b/ts/mathjax.bzl @@ -1,11 +1,7 @@ -load("//ts:copy.bzl", "copy_files") +load("//ts:copy.bzl", "copy_select_files") "Rule to copy mathjax subset from node_modules to vendor folder." -_exclude = [ - "mathmaps_ie.js", -] - _include = [ "es5/tex-chtml.js", "es5/input/tex/extensions", @@ -14,26 +10,20 @@ _include = [ "es5/sre", ] +_exclude = [ + "mathmaps_ie.js", +] + _unwanted_prefix = "external/npm/node_modules/mathjax/es5/" def _copy_mathjax_impl(ctx): - wanted = [] - for f in ctx.attr.mathjax.files.to_list(): - path = f.path - want = True - for substr in _exclude: - if substr in path: - want = False - continue - if not want: - continue - - for substr in _include: - if substr in path: - output = path.replace(_unwanted_prefix, "") - wanted.append((f, output)) - - return copy_files(ctx, wanted) + return copy_select_files( + ctx, + ctx.attr.mathjax.files, + _include, + _exclude, + _unwanted_prefix, + ) copy_mathjax = rule( implementation = _copy_mathjax_impl, diff --git a/ts/protobufjs.bzl b/ts/protobufjs.bzl index 218d2ac65..80a26f26c 100644 --- a/ts/protobufjs.bzl +++ b/ts/protobufjs.bzl @@ -1,4 +1,4 @@ -load("//ts:copy.bzl", "copy_files") +load("//ts:copy.bzl", "copy_select_files") "Rule to copy protobufjs subset from node_modules to vendor folder." @@ -9,17 +9,13 @@ _include = [ _unwanted_prefix = "external/npm/node_modules/protobufjs/dist/" def _copy_protobufjs_impl(ctx): - wanted = [] - for f in ctx.attr.protobufjs.files.to_list(): - path = f.path - want = True - - for substr in _include: - if substr in path: - output = path.replace(_unwanted_prefix, "") - wanted.append((f, output)) - - return copy_files(ctx, wanted) + return copy_select_files( + ctx, + ctx.attr.protobufjs.files, + _include, + [], + _unwanted_prefix, + ) copy_protobufjs = rule( implementation = _copy_protobufjs_impl,