mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Merge pull request #882 from hgiesel/copyfiles
Implement copy_select_files for removing duplication in js dep Bazel recipes
This commit is contained in:
commit
13994973cb
7 changed files with 85 additions and 76 deletions
|
@ -120,7 +120,7 @@ const _flagColours = {
|
|||
4: "#77aaff",
|
||||
};
|
||||
|
||||
function _drawFlag(flag: 0 | 1 | 2 | 3): void {
|
||||
function _drawFlag(flag: 0 | 1 | 2 | 3 | 4): void {
|
||||
var elem = $("#_flag");
|
||||
if (flag === 0) {
|
||||
elem.hide();
|
||||
|
|
25
ts/copy.bzl
25
ts/copy.bzl
|
@ -26,3 +26,28 @@ def copy_files(ctx, files):
|
|||
)
|
||||
|
||||
return [DefaultInfo(files = depset(outputs))]
|
||||
|
||||
def remove_prefix(text, prefix):
|
||||
if text.startswith(prefix):
|
||||
return text[len(prefix):]
|
||||
return text
|
||||
|
||||
def copy_select_files(ctx, files, include, exclude, base, unwanted_prefix):
|
||||
wanted = []
|
||||
for f in files.to_list():
|
||||
path = remove_prefix(f.path, base)
|
||||
want = True
|
||||
|
||||
for substr in exclude:
|
||||
if path.startswith(substr):
|
||||
want = False
|
||||
continue
|
||||
if not want:
|
||||
continue
|
||||
|
||||
for substr in include:
|
||||
if path.startswith(substr):
|
||||
output = remove_prefix(path, 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."
|
||||
|
||||
|
@ -6,20 +6,18 @@ _include = [
|
|||
"css_browser_selector.min.js",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/css-browser-selector/"
|
||||
_base = "external/npm/node_modules/css-browser-selector/"
|
||||
_unwanted_prefix = ""
|
||||
|
||||
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,
|
||||
[],
|
||||
_base,
|
||||
_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."
|
||||
|
||||
|
@ -6,20 +6,18 @@ _include = [
|
|||
"jquery-ui.min.js",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/jquery-ui-dist/"
|
||||
_base = "external/npm/node_modules/jquery-ui-dist/"
|
||||
_unwanted_prefix = ""
|
||||
|
||||
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,
|
||||
[],
|
||||
_base,
|
||||
_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."
|
||||
|
||||
|
@ -6,20 +6,18 @@ _include = [
|
|||
"dist/jquery.min.js"
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/jquery/dist/"
|
||||
_base = "external/npm/node_modules/jquery/"
|
||||
_unwanted_prefix = "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,
|
||||
[],
|
||||
_base,
|
||||
_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,22 @@ _include = [
|
|||
"es5/sre",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/mathjax/es5/"
|
||||
_exclude = [
|
||||
"es5/sre/mathmaps/mathmaps_ie.js",
|
||||
]
|
||||
|
||||
_base = "external/npm/node_modules/mathjax/"
|
||||
_unwanted_prefix = "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,
|
||||
_base,
|
||||
_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."
|
||||
|
||||
|
@ -6,20 +6,18 @@ _include = [
|
|||
"dist/protobuf.min.js",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/protobufjs/dist/"
|
||||
_base = "external/npm/node_modules/protobufjs/"
|
||||
_unwanted_prefix = "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,
|
||||
[],
|
||||
_base,
|
||||
_unwanted_prefix,
|
||||
)
|
||||
|
||||
copy_protobufjs = rule(
|
||||
implementation = _copy_protobufjs_impl,
|
||||
|
|
Loading…
Reference in a new issue