mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Remove jquery from Anki repo and replace with Bazel BUILD
This commit is contained in:
parent
aa816177d0
commit
0c95cb3514
8 changed files with 76 additions and 36 deletions
5
qt/aqt/data/web/js/vendor/BUILD.bazel
vendored
5
qt/aqt/data/web/js/vendor/BUILD.bazel
vendored
|
@ -1,5 +1,8 @@
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "vendor",
|
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__"],
|
visibility = ["//qt:__subpackages__"],
|
||||||
)
|
)
|
||||||
|
|
5
qt/aqt/data/web/js/vendor/jquery.js
vendored
5
qt/aqt/data/web/js/vendor/jquery.js
vendored
File diff suppressed because one or more lines are too long
6
qt/aqt/data/web/js/vendor/jquery/BUILD.bazel
vendored
Normal file
6
qt/aqt/data/web/js/vendor/jquery/BUILD.bazel
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
load("//ts:jquery.bzl", "copy_jquery")
|
||||||
|
|
||||||
|
copy_jquery(
|
||||||
|
name = "jquery",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
28
ts/copy.bzl
Normal file
28
ts/copy.bzl
Normal 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
29
ts/jquery.bzl
Normal 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"),
|
||||||
|
},
|
||||||
|
)
|
|
@ -1,3 +1,5 @@
|
||||||
|
load("//ts:copy.bzl", "copy_files")
|
||||||
|
|
||||||
"Rule to copy mathjax subset from node_modules to vendor folder."
|
"Rule to copy mathjax subset from node_modules to vendor folder."
|
||||||
|
|
||||||
_exclude = [
|
_exclude = [
|
||||||
|
@ -14,35 +16,6 @@ _include = [
|
||||||
|
|
||||||
_unwanted_prefix = "external/npm/node_modules/mathjax/es5/"
|
_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):
|
def _copy_mathjax_impl(ctx):
|
||||||
wanted = []
|
wanted = []
|
||||||
for f in ctx.attr.mathjax.files.to_list():
|
for f in ctx.attr.mathjax.files.to_list():
|
||||||
|
@ -60,7 +33,7 @@ def _copy_mathjax_impl(ctx):
|
||||||
output = path.replace(_unwanted_prefix, "")
|
output = path.replace(_unwanted_prefix, "")
|
||||||
wanted.append((f, output))
|
wanted.append((f, output))
|
||||||
|
|
||||||
return _copy_files(ctx, wanted)
|
return copy_files(ctx, wanted)
|
||||||
|
|
||||||
copy_mathjax = rule(
|
copy_mathjax = rule(
|
||||||
implementation = _copy_mathjax_impl,
|
implementation = _copy_mathjax_impl,
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
"intl-pluralrules": "^1.2.2",
|
"intl-pluralrules": "^1.2.2",
|
||||||
"lodash.debounce": "^4.0.8",
|
"lodash.debounce": "^4.0.8",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
|
"jquery": "^3.5.1",
|
||||||
"mathjax": "^3.1.2",
|
"mathjax": "^3.1.2",
|
||||||
"protobufjs": "^6.10.1"
|
"protobufjs": "^6.10.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1622,6 +1622,11 @@ jest-worker@^26.2.1:
|
||||||
merge-stream "^2.0.0"
|
merge-stream "^2.0.0"
|
||||||
supports-color "^7.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:
|
js-tokens@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
|
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
|
||||||
|
|
Loading…
Reference in a new issue