Skip to content

Commit

Permalink
Merge pull request #148 from kindlyops/excessive-rebuilds
Browse files Browse the repository at this point in the history
  • Loading branch information
statik committed Mar 1, 2022
2 parents 6b546a0 + cf9dca1 commit bda0609
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cmd/lighting.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func init() {
"off": "/press/bank/20/14",
"ftb": "/press/bank/20/4",
"dsk": "/press/bank/20/5",
"keylighton": "/press/bank/20/2",
"keylightoff": "/press/bank/20/3",
"keylighton": "/press/bank/20/18",
"keylightoff": "/press/bank/20/19",
})

rootCmd.AddCommand(lightingBridgeCmd)
Expand Down
33 changes: 4 additions & 29 deletions embeddy/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@npm//next:index.bzl", "next")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("//:glue.bzl", "static_site_embedder")

load("//:glue.bzl", "embed_nextjs")

filegroup(
name = "source_files",
Expand All @@ -20,33 +19,9 @@ filegroup(
],
)

copy_to_bin(
name = "copy_source_files",
srcs = [":source_files"],
)

next(
name = "next_build",
outs = [".next"],
args = ["build $(RULEDIR)"],
data = [":copy_source_files"], # + NPM_DEPENDENCIES,
tags = ["no-sandbox"],
)

next(
name = "next_export",
outs = ["dist"],
args = [
"export $(RULEDIR)",
"-o $(@)",
],
data = [":next_build"],
visibility = ["//visibility:public"],
)

static_site_embedder(
embed_nextjs(
name = "embedder",
srcs = [":dist"],
srcs = [":source_files"],
)

# keep
Expand Down
5 changes: 5 additions & 0 deletions embeddy/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export default function Home() {

sendRequest("/api/light/off");
};
const sendBRB = (event) => {
event.preventDefault();

sendRequest("/api/switcher/brb");
};
const sendFTB = (event) => {
event.preventDefault();

Expand Down
54 changes: 54 additions & 0 deletions glue.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
Bazel macro for building an embedded NextJS app into a go library.
"""
load("@npm//next:index.bzl", "next")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")

def _static_site_embedder_impl(ctx):
#tree = ctx.actions.declare_directory(ctx.attr.name + ".artifacts")
Expand Down Expand Up @@ -32,3 +37,52 @@ site build and embedding or publishing.
"embedder": "embedder.go",
},
)

def embed_nextjs(name, srcs = [], visibility=None, **kwargs):
"""
Embeds a static site into a go library.
This is useful for collecting together the generated files from a static
site build and embedding or publishing.
Args:
name: Name of the embedder.
srcs: List of files to embed.
visibility: Visibility of the embedder.
**kwargs: Additional arguments to pass to the embedder rule.
Returns:
A label pointing to the embedder.
"""
copy_to_bin(
name = "copy_source_files",
srcs = srcs,
visibility = ["//visibility:private"],
)

next(
name = "next_build",
outs = [".next/build-manifest.json"],
args = ["build $(RULEDIR)"],
data = [":copy_source_files"], # + NPM_DEPENDENCIES,
# tags = ["no-sandbox"],
visibility = ["//visibility:private"],
)

next(
name = "next_export",
outs = ["dist"],
args = [
"export $(RULEDIR)",
"-o $(@)",
],
data = [":next_build"],
visibility = ["//visibility:private"],
)

return static_site_embedder(
name = name,
srcs = [":dist"],
visibility = visibility,
**kwargs
)

0 comments on commit bda0609

Please sign in to comment.