load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") load("@aspect_rules_js//js:defs.bzl", "js_run_devserver") load("@aspect_rules_ts//ts:defs.bzl", "ts_config") load("@npm//:defs.bzl", "npm_link_all_packages") load("@npm//:react-scripts/package_json.bzl", cra_bin = "bin") load("@rules_pkg//:pkg.bzl", "pkg_tar") load("//pkg/edge/api/graphiql:copy_build.bzl", "copy_build") package(default_visibility = ["//visibility:public"]) npm_link_all_packages(name = "node_modules") copy_to_bin( name = "copy_env", srcs = [ ".env", ], ) CRA_DEPS = [ "//pkg/edge/api/graphiql/src", "//pkg/edge/api/graphiql/public", "//pkg/edge/api/graphiql:package.json", "graphiql_tsconfig", "//:tsconfig", ":node_modules/react-scripts", ":node_modules/react", ":node_modules/react-dom", ":node_modules/graphql", ":node_modules/graphiql", ":node_modules/@graphiql/plugin-explorer", ":node_modules/lodash", ":node_modules/typescript", ":node_modules/@types", ] DEV_DEPS = CRA_DEPS + ["copy_env"] cra_bin.react_scripts( # Note: If you want to change the name make sure you update BUILD_PATH below accordingly # https://create-react-app.dev/docs/advanced-configuration/ name = "build", srcs = CRA_DEPS, args = ["build"], chdir = package_name(), env = { "BUILD_PATH": "./build", }, out_dirs = ["build"], ) pkg_tar( name = "tar", srcs = [":build"], package_dir = "graphiql", strip_prefix = ".", # can you believe that this maintains the folder structure and doesnt flatten it? visibility = ["//visibility:public"], ) js_run_devserver( name = "start", args = ["start"], chdir = package_name(), command = "node_modules/.bin/react-scripts", data = DEV_DEPS, tags = [ # This tag instructs ibazel to pipe into stdin a event describing actions. # ibazel send EOF to stdin by default and `react-scripts start` will stop when getting EOF in stdin. # So use this to prevent EOF. "ibazel_notify_changes", ], ) ts_config( name = "graphiql_tsconfig", src = "//pkg/edge/api/graphiql:tsconfig.json", visibility = ["//visibility:public"], ) copy_build( name = "copy_bundle", out_path = "hack/graphiql/react", src_path = ":build", )