Skip to content

Commit bda0609

Browse files
authored
Merge pull request #148 from kindlyops/excessive-rebuilds
2 parents 6b546a0 + cf9dca1 commit bda0609

File tree

4 files changed

+65
-31
lines changed

4 files changed

+65
-31
lines changed

cmd/lighting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func init() {
130130
"off": "/press/bank/20/14",
131131
"ftb": "/press/bank/20/4",
132132
"dsk": "/press/bank/20/5",
133-
"keylighton": "/press/bank/20/2",
134-
"keylightoff": "/press/bank/20/3",
133+
"keylighton": "/press/bank/20/18",
134+
"keylightoff": "/press/bank/20/19",
135135
})
136136

137137
rootCmd.AddCommand(lightingBridgeCmd)

embeddy/BUILD.bazel

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2-
load("@npm//next:index.bzl", "next")
3-
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
4-
load("//:glue.bzl", "static_site_embedder")
2+
3+
load("//:glue.bzl", "embed_nextjs")
54

65
filegroup(
76
name = "source_files",
@@ -20,33 +19,9 @@ filegroup(
2019
],
2120
)
2221

23-
copy_to_bin(
24-
name = "copy_source_files",
25-
srcs = [":source_files"],
26-
)
27-
28-
next(
29-
name = "next_build",
30-
outs = [".next"],
31-
args = ["build $(RULEDIR)"],
32-
data = [":copy_source_files"], # + NPM_DEPENDENCIES,
33-
tags = ["no-sandbox"],
34-
)
35-
36-
next(
37-
name = "next_export",
38-
outs = ["dist"],
39-
args = [
40-
"export $(RULEDIR)",
41-
"-o $(@)",
42-
],
43-
data = [":next_build"],
44-
visibility = ["//visibility:public"],
45-
)
46-
47-
static_site_embedder(
22+
embed_nextjs(
4823
name = "embedder",
49-
srcs = [":dist"],
24+
srcs = [":source_files"],
5025
)
5126

5227
# keep

embeddy/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export default function Home() {
3737

3838
sendRequest("/api/light/off");
3939
};
40+
const sendBRB = (event) => {
41+
event.preventDefault();
42+
43+
sendRequest("/api/switcher/brb");
44+
};
4045
const sendFTB = (event) => {
4146
event.preventDefault();
4247

glue.bzl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Bazel macro for building an embedded NextJS app into a go library.
3+
"""
4+
load("@npm//next:index.bzl", "next")
5+
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
16

27
def _static_site_embedder_impl(ctx):
38
#tree = ctx.actions.declare_directory(ctx.attr.name + ".artifacts")
@@ -32,3 +37,52 @@ site build and embedding or publishing.
3237
"embedder": "embedder.go",
3338
},
3439
)
40+
41+
def embed_nextjs(name, srcs = [], visibility=None, **kwargs):
42+
"""
43+
Embeds a static site into a go library.
44+
45+
This is useful for collecting together the generated files from a static
46+
site build and embedding or publishing.
47+
48+
Args:
49+
name: Name of the embedder.
50+
srcs: List of files to embed.
51+
visibility: Visibility of the embedder.
52+
**kwargs: Additional arguments to pass to the embedder rule.
53+
54+
Returns:
55+
A label pointing to the embedder.
56+
"""
57+
copy_to_bin(
58+
name = "copy_source_files",
59+
srcs = srcs,
60+
visibility = ["//visibility:private"],
61+
)
62+
63+
next(
64+
name = "next_build",
65+
outs = [".next/build-manifest.json"],
66+
args = ["build $(RULEDIR)"],
67+
data = [":copy_source_files"], # + NPM_DEPENDENCIES,
68+
# tags = ["no-sandbox"],
69+
visibility = ["//visibility:private"],
70+
)
71+
72+
next(
73+
name = "next_export",
74+
outs = ["dist"],
75+
args = [
76+
"export $(RULEDIR)",
77+
"-o $(@)",
78+
],
79+
data = [":next_build"],
80+
visibility = ["//visibility:private"],
81+
)
82+
83+
return static_site_embedder(
84+
name = name,
85+
srcs = [":dist"],
86+
visibility = visibility,
87+
**kwargs
88+
)

0 commit comments

Comments
 (0)