load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//ts:typescript.bzl", "typescript")
load("//ts:copy.bzl", "copy_files_into_group")
load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test")

js_library(
    name = "pycmd",
    srcs = ["pycmd.d.ts"],
    visibility = ["//qt/aqt/data/web/js:__subpackages__"],
)

typescript(
    name = "aqt",
    srcs = glob(
        ["*.ts"],
        exclude = ["*.d.ts"],
    ),
    deps = [
        "pycmd",
        "@npm//@types/jquery",
        "@npm//@types/jqueryui",
    ],
)

copy_files_into_group(
    name = "editor",
    srcs = [
        "browser_editor.js",
        "reviewer_editor.js",
        "note_creator.js",
    ],
    package = "//ts/editor",
)

copy_files_into_group(
    name = "reviewer",
    srcs = [
        "reviewer.js",
    ],
    package = "//ts/reviewer",
)

filegroup(
    name = "js",
    srcs = [
        "aqt",
        "mathjax.js",
        "reviewer",
        "editor",
        "//qt/aqt/data/web/js/vendor",
    ],
    visibility = ["//qt:__subpackages__"],
)

prettier_test(
    name = "format_check",
    srcs = glob([
        "*.ts",
        "*.js",
    ]),
)

# source files need fixing first
eslint_test(
    name = "eslint",
    srcs = glob(["*.ts"]),
)

exports_files([
    "mathjax.js",
    "tsconfig.json",
])
