# Copyright Google Inc. All Rights Reserved.
#
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file at https://angular.io/license

load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("//tools:ts_json_schema.bzl", "ts_json_schema")
load("//tools:defaults.bzl", "ts_library")

# @external_begin
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
# @external_end

licenses(["notice"])  # MIT

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

ts_library(
    name = "angular-cli",
    srcs = glob(
        include = ["**/*.ts"],
        exclude = [
            "**/*_spec.ts",
            # NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
            "node_modules/**",
        ],
    ) + [
        # @external_begin
        # These files are generated from the JSON schema
        "//packages/angular/cli:lib/config/schema.ts",
        "//packages/angular/cli:commands/analytics.ts",
        "//packages/angular/cli:commands/add.ts",
        "//packages/angular/cli:commands/build.ts",
        "//packages/angular/cli:commands/deploy.ts",
        "//packages/angular/cli:commands/config.ts",
        "//packages/angular/cli:commands/doc.ts",
        "//packages/angular/cli:commands/e2e.ts",
        "//packages/angular/cli:commands/easter-egg.ts",
        "//packages/angular/cli:commands/generate.ts",
        "//packages/angular/cli:commands/help.ts",
        "//packages/angular/cli:commands/lint.ts",
        "//packages/angular/cli:commands/new.ts",
        "//packages/angular/cli:commands/serve.ts",
        "//packages/angular/cli:commands/test.ts",
        "//packages/angular/cli:commands/update.ts",
        "//packages/angular/cli:commands/version.ts",
        "//packages/angular/cli:commands/run.ts",
        "//packages/angular/cli:commands/extract-i18n.ts",
        # @external_end
    ],
    data = glob(
        include = [
            "bin/**/*",
            "**/*.json",
            "**/*.md",
        ],
        exclude = [
            # NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
            "node_modules/**",
        ],
    ),
    module_name = "@angular/cli",
    # strict_checks = False,
    deps = [
        "//packages/angular_devkit/architect",
        "//packages/angular_devkit/architect/node",
        "//packages/angular_devkit/core",
        "//packages/angular_devkit/core/node",
        "//packages/angular_devkit/schematics",
        "//packages/angular_devkit/schematics/tools",
        "@npm//@types/debug",
        "@npm//@types/inquirer",
        "@npm//@types/node",
        "@npm//@types/resolve",
        "@npm//@types/rimraf",
        "@npm//@types/semver",
        "@npm//@types/universal-analytics",
        "@npm//@types/uuid",
        "@npm//ansi-colors",
    ],
)

ts_json_schema(
    name = "cli_schema",
    src = "lib/config/schema.json",
)

ts_json_schema(
    name = "analytics_schema",
    src = "commands/analytics.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "add_schema",
    src = "commands/add.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "build_schema",
    src = "commands/build.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "deploy_schema",
    src = "commands/deploy.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "config_schema",
    src = "commands/config.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "doc_schema",
    src = "commands/doc.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "e2e_schema",
    src = "commands/e2e.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "easter_egg_schema",
    src = "commands/easter-egg.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "generate_schema",
    src = "commands/generate.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "help_schema",
    src = "commands/help.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "lint_schema",
    src = "commands/lint.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "new_schema",
    src = "commands/new.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "run_schema",
    src = "commands/run.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "serve_schema",
    src = "commands/serve.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "test_schema",
    src = "commands/test.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "update_schema",
    src = "commands/update.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "version_schema",
    src = "commands/version.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_json_schema(
    name = "extract-i18n_schema",
    src = "commands/extract-i18n.json",
    data = [
        "commands/definitions.json",
    ],
)

ts_library(
    name = "angular-cli_test_lib",
    testonly = True,
    srcs = glob(
        include = ["**/*_spec.ts"],
        exclude = [
            # NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
            "node_modules/**",
        ],
    ),
    # strict_checks = False,
    deps = [
        ":angular-cli",
        "//packages/angular_devkit/core",
    ],
)

jasmine_node_test(
    name = "angular-cli_test",
    srcs = [":angular-cli_test_lib"],
)

# @external_begin
pkg_npm(
    name = "npm_package",
    deps = [
        ":angular-cli",
    ],
)

pkg_tar(
    name = "npm_package_archive",
    srcs = [":npm_package"],
    extension = "tar.gz",
    strip_prefix = "./npm_package",
    tags = ["manual"],
)
# @external_end
