load("@io_bazel_rules_docker//container:container.bzl", "container_push")
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm//nuxt:index.bzl", "nuxt")
load("//rules/nodejs:common.bzl", "js_library")

deps = [
    "@npm//@nuxtjs/axios",
    "@npm//bootstrap",
    "@npm//bootstrap-vue",
    "@npm//core-js",
    "@npm//dateformat",
    "@npm//pug",
    "@npm//pug-plain-loader",
    "@npm//sass",
    "@npm//sass-loader",
    "@npm//vue",
]

js_library(
    name = "nuxt-srcs",
    srcs = ["nuxt.config.js"] + glob([
        "assets/**",
        "components/**/*.vue",
        "layouts/*.vue",
        "middleware/*.js",
        "pages/**/*.vue",
        "plugins/*.js",
        "static/*",
        "store/*.js",
    ]),
    data = [
        "//nexus/cognitron/web/client",
    ],
)

nuxt(
    name = "web_dev",
    args = [
        "-c",
        "nexus/cognitron/web/nuxt.config.js",
    ],
    data = [":nuxt-srcs"] + deps,
)

nuxt(
    name = ".nuxt",
    args = [
        "build",
        "--standalone",
        "-c",
        "nexus/cognitron/web/nuxt.config.js",
        "--buildDir=$(@D)",
    ],
    data = [":nuxt-srcs"] + deps,
    output_dir = True,
)

nodejs_image(
    name = "image",
    base = "//images/production:base-nodejs-image",
    data = glob(["static/*"]) + [
        "nuxt.config.js",
        ":.nuxt",
        "@npm//@nuxtjs/axios",
        "@npm//bootstrap-vue",
        "@npm//nuxt",
    ],
    entry_point = "@npm//:node_modules/nuxt/bin/nuxt.js",
    templated_args = [
        "start",
        "-c",
        "nexus/cognitron/web/nuxt.config.js",
    ],
)


container_push(
    name = "push-public-latest",
    format = "Docker",
    image = ":image",
    registry = "registry.hub.docker.com",
    repository = "thesuperpirate/cognitron-web",
    tag = "latest",
)

container_push(
    name = "push-public-testing",
    format = "Docker",
    image = ":image",
    registry = "registry.hub.docker.com",
    repository = "thesuperpirate/cognitron-web",
    tag = "testing",
)
