Remove jquery from Anki repo and replace with Bazel BUILD

This commit is contained in:
Henrik Giesel 2020-12-20 20:10:45 +01:00
parent aa816177d0
commit 0c95cb3514
8 changed files with 76 additions and 36 deletions

View File

@ -1,5 +1,8 @@
filegroup(
name = "vendor",
srcs = glob(["*.js"]) + ["//qt/aqt/data/web/js/vendor/mathjax"],
srcs = glob(["*.js"]) + [
"//qt/aqt/data/web/js/vendor/mathjax",
"//qt/aqt/data/web/js/vendor/jquery",
],
visibility = ["//qt:__subpackages__"],
)

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,6 @@
load("//ts:jquery.bzl", "copy_jquery")
copy_jquery(
name = "jquery",
visibility = ["//visibility:public"],
)

28
ts/copy.bzl Normal file
View File

@ -0,0 +1,28 @@
def copy_files(ctx, files):
cmds = []
inputs = []
outputs = []
for (src, dst) in files:
inputs.append(src)
dst = ctx.actions.declare_file(dst)
outputs.append(dst)
cmds.append("cp -f {} {}".format(src.path, dst.path))
shell_fname = ctx.label.name + "-cp.sh"
shell_file = ctx.actions.declare_file(shell_fname)
ctx.actions.write(
output = shell_file,
content = "#!/bin/bash\nset -e\n" + "\n".join(cmds),
is_executable = True,
)
ctx.actions.run(
inputs = inputs,
executable = "bash",
tools = [shell_file],
arguments = [shell_file.path],
outputs = outputs,
mnemonic = "CopyFile",
use_default_shell_env = True,
)
return [DefaultInfo(files = depset(outputs))]

29
ts/jquery.bzl Normal file
View File

@ -0,0 +1,29 @@
load("//ts:copy.bzl", "copy_files")
"Rule to copy jquery subset from node_modules to vendor folder."
_include = [
"dist/jquery.min.js"
]
_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)
copy_jquery = rule(
implementation = _copy_jquery_impl,
attrs = {
"jquery": attr.label(default = "@npm//jquery:jquery__files"),
},
)

View File

@ -1,3 +1,5 @@
load("//ts:copy.bzl", "copy_files")
"Rule to copy mathjax subset from node_modules to vendor folder."
_exclude = [
@ -14,35 +16,6 @@ _include = [
_unwanted_prefix = "external/npm/node_modules/mathjax/es5/"
def _copy_files(ctx, files):
cmds = []
inputs = []
outputs = []
for (src, dst) in files:
inputs.append(src)
dst = ctx.actions.declare_file(dst)
outputs.append(dst)
cmds.append("cp -f {} {}".format(src.path, dst.path))
shell_fname = ctx.label.name + "-cp.sh"
shell_file = ctx.actions.declare_file(shell_fname)
ctx.actions.write(
output = shell_file,
content = "#!/bin/bash\nset -e\n" + "\n".join(cmds),
is_executable = True,
)
ctx.actions.run(
inputs = inputs,
executable = "bash",
tools = [shell_file],
arguments = [shell_file.path],
outputs = outputs,
mnemonic = "CopyFile",
use_default_shell_env = True,
)
return [DefaultInfo(files = depset(outputs))]
def _copy_mathjax_impl(ctx):
wanted = []
for f in ctx.attr.mathjax.files.to_list():
@ -60,7 +33,7 @@ def _copy_mathjax_impl(ctx):
output = path.replace(_unwanted_prefix, "")
wanted.append((f, output))
return _copy_files(ctx, wanted)
return copy_files(ctx, wanted)
copy_mathjax = rule(
implementation = _copy_mathjax_impl,

View File

@ -64,6 +64,7 @@
"intl-pluralrules": "^1.2.2",
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"jquery": "^3.5.1",
"mathjax": "^3.1.2",
"protobufjs": "^6.10.1"
},

View File

@ -1622,6 +1622,11 @@ jest-worker@^26.2.1:
merge-stream "^2.0.0"
supports-color "^7.0.0"
jquery@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.5.1.tgz#d7b4d08e1bfdb86ad2f1a3d039ea17304717abb5"
integrity sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==
js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"