package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "jasmine_node_test", "ng_module", "ng_rollup_bundle", "ts_library")
load("//tools/http-server:http_server.bzl", "http_server")
load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")

ng_module(
    name = "todo",
    srcs = ["index.ts"],
    tags = [
        "ivy-only",
        "no-ivy-jit",
    ],
    deps = [
        "//packages/common",
        "//packages/core",
        "//packages/core/test/bundling/util:reflect_metadata",
        "//packages/platform-browser",
        "//packages/platform-browser-dynamic",
    ],
)

ng_rollup_bundle(
    name = "bundle",
    # TODO(alexeagle): This is inconsistent.
    # We try to teach users to always have their workspace at the start of a
    # path, to disambiguate from other workspaces.
    # Here, the rule implementation is looking in an execroot where the layout
    # has an "external" directory for external dependencies.
    # This should probably start with "angular/" and let the rule deal with it.
    entry_point = "packages/core/test/bundling/todo_r2/index.js",
    tags = [
        "ivy-only",
        "no-ivy-jit",
    ],
    deps = [
        ":todo",
        "//packages/common",
        "//packages/core",
        "//packages/core/test/bundling/util:reflect_metadata",
        "//packages/platform-browser",
        "//packages/platform-browser-dynamic",
    ],
)

ts_library(
    name = "test_lib",
    testonly = True,
    srcs = glob(["*_spec.ts"]),
    tags = [
        "ivy-only",
        "no-ivy-jit",
    ],
    deps = [
        "//packages:types",
        "//packages/core",
        "//packages/core/testing",
        "//packages/platform-browser",
        "//packages/platform-browser-dynamic",
        "//packages/private/testing",
    ],
)

jasmine_node_test(
    name = "test",
    data = [
        ":bundle",
        ":bundle.js",
        ":bundle.min.js",
        ":bundle.min_debug.js",
    ],
    tags = [
        "ivy-only",
        "no-ivy-jit",
    ],
    deps = [":test_lib"],
)

js_expected_symbol_test(
    name = "symbol_test",
    src = ":bundle.min_debug.js",
    golden = ":bundle.golden_symbols.json",
    tags = [
        "ivy-aot",
        "ivy-only",
        "no-ivy-jit",
    ],
)

genrule(
    name = "tslib",
    srcs = [
        "@ngdeps//node_modules/tslib:tslib.js",
    ],
    outs = [
        "tslib.js",
    ],
    cmd = "cp $< $@",
    tags = [
        "ivy-only",
        "no-ivy-jit",
    ],
)

ts_devserver(
    name = "devserver",
    entry_module = "angular/packages/core/test/bundling/todo_r2/index",
    serving_path = "/bundle.min.js",
    static_files = [
        "index.html",
        ":tslib",
        "todo.css",
        "base.css",
    ],
    tags = [
        "ivy-only",
        "no-ivy-jit",
    ],
    deps = [":todo"],
)

http_server(
    name = "prodserver",
    data = [
        "base.css",
        "index.html",
        "todo.css",
        ":bundle.min.js.br",
        ":bundle.min_debug.js",
    ],
    tags = [
        "ivy-only",
        "no-ivy-jit",
    ],
)
