mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
add rule to copy mathjax from node_modules
This commit is contained in:
parent
afc7bdf642
commit
8a80ffe53a
10 changed files with 86 additions and 27 deletions
|
@ -304,7 +304,7 @@ class CardLayout(QDialog):
|
||||||
jsinc = [
|
jsinc = [
|
||||||
"js/vendor/jquery.js",
|
"js/vendor/jquery.js",
|
||||||
"js/vendor/browsersel.js",
|
"js/vendor/browsersel.js",
|
||||||
"js/vendor/mathjax/conf.js",
|
"js/mathjax.js",
|
||||||
"js/vendor/mathjax/tex-chtml.js",
|
"js/vendor/mathjax/tex-chtml.js",
|
||||||
"js/reviewer.js",
|
"js/reviewer.js",
|
||||||
]
|
]
|
||||||
|
|
|
@ -26,16 +26,12 @@ filegroup(
|
||||||
output_group = "es5_sources",
|
output_group = "es5_sources",
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "vendor",
|
|
||||||
srcs = glob(["vendor/**"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "js",
|
name = "js",
|
||||||
srcs = [
|
srcs = [
|
||||||
"aqt_es5",
|
"aqt_es5",
|
||||||
"vendor",
|
"mathjax.js",
|
||||||
|
"//qt/aqt/data/web/js/vendor",
|
||||||
],
|
],
|
||||||
visibility = ["//qt:__subpackages__"],
|
visibility = ["//qt:__subpackages__"],
|
||||||
)
|
)
|
||||||
|
|
5
qt/aqt/data/web/js/vendor/BUILD.bazel
vendored
Normal file
5
qt/aqt/data/web/js/vendor/BUILD.bazel
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
filegroup(
|
||||||
|
name = "vendor",
|
||||||
|
srcs = glob(["**"]) + ["//qt/aqt/data/web/js/vendor/mathjax"],
|
||||||
|
visibility = ["//qt:__subpackages__"],
|
||||||
|
)
|
2
qt/aqt/data/web/js/vendor/mathjax/.gitignore
vendored
2
qt/aqt/data/web/js/vendor/mathjax/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
*
|
|
||||||
!conf.js
|
|
6
qt/aqt/data/web/js/vendor/mathjax/BUILD.bazel
vendored
Normal file
6
qt/aqt/data/web/js/vendor/mathjax/BUILD.bazel
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
load("//ts:mathjax.bzl", "copy_mathjax")
|
||||||
|
|
||||||
|
copy_mathjax(
|
||||||
|
name = "mathjax",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -114,7 +114,7 @@ class Previewer(QDialog):
|
||||||
jsinc = [
|
jsinc = [
|
||||||
"js/vendor/jquery.js",
|
"js/vendor/jquery.js",
|
||||||
"js/vendor/browsersel.js",
|
"js/vendor/browsersel.js",
|
||||||
"js/vendor/mathjax/conf.js",
|
"js/mathjax.js",
|
||||||
"js/vendor/mathjax/tex-chtml.js",
|
"js/vendor/mathjax/tex-chtml.js",
|
||||||
"js/reviewer.js",
|
"js/reviewer.js",
|
||||||
]
|
]
|
||||||
|
|
|
@ -155,7 +155,7 @@ class Reviewer:
|
||||||
js=[
|
js=[
|
||||||
"js/vendor/jquery.js",
|
"js/vendor/jquery.js",
|
||||||
"js/vendor/browsersel.js",
|
"js/vendor/browsersel.js",
|
||||||
"js/vendor/mathjax/conf.js",
|
"js/mathjax.js",
|
||||||
"js/vendor/mathjax/tex-chtml.js",
|
"js/vendor/mathjax/tex-chtml.js",
|
||||||
"js/reviewer.js",
|
"js/reviewer.js",
|
||||||
],
|
],
|
||||||
|
|
|
@ -13,19 +13,3 @@ exports_files([
|
||||||
".eslintrc.js",
|
".eslintrc.js",
|
||||||
"licenses.json",
|
"licenses.json",
|
||||||
])
|
])
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "mathjax",
|
|
||||||
srcs = glob(
|
|
||||||
include = glob([
|
|
||||||
'node_modules/mathjax/es5/tex-chtml.js',
|
|
||||||
'node_modules/mathjax/es5/input/tex/extensions/**/*',
|
|
||||||
'node_modules/mathjax/es5/output/chtml/fonts/woff-v2/**/*',
|
|
||||||
'node_modules/mathjax/es5/a11y/**/*',
|
|
||||||
'node_modules/mathjax/es5/sre/**/*',
|
|
||||||
]),
|
|
||||||
exclude = [
|
|
||||||
'node_modules/mathjax/es5/sre/mathmaps/mathmaps_ie.js',
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
70
ts/mathjax.bzl
Normal file
70
ts/mathjax.bzl
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
"Rule to copy mathjax subset from node_modules to vendor folder."
|
||||||
|
|
||||||
|
_exclude = [
|
||||||
|
"mathmaps_ie.js",
|
||||||
|
]
|
||||||
|
|
||||||
|
_include = [
|
||||||
|
"es5/tex-chtml.js",
|
||||||
|
"es5/input/tex/extensions",
|
||||||
|
"es5/output/chtml/fonts/woff-v2",
|
||||||
|
"es5/a11y",
|
||||||
|
"es5/sre",
|
||||||
|
]
|
||||||
|
|
||||||
|
_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():
|
||||||
|
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)
|
||||||
|
|
||||||
|
copy_mathjax = rule(
|
||||||
|
implementation = _copy_mathjax_impl,
|
||||||
|
attrs = {
|
||||||
|
"mathjax": attr.label(default = "@npm//mathjax:mathjax__files"),
|
||||||
|
},
|
||||||
|
)
|
Loading…
Reference in a new issue