Remove duplicated logic in ts bzl files by using copy_select_files
This commit is contained in:
parent
eecdc07c68
commit
8e8a3e220b
20
ts/copy.bzl
20
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)
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user