|
| 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") |
1 | 6 |
|
2 | 7 | def _static_site_embedder_impl(ctx): |
3 | 8 | #tree = ctx.actions.declare_directory(ctx.attr.name + ".artifacts") |
@@ -32,3 +37,52 @@ site build and embedding or publishing. |
32 | 37 | "embedder": "embedder.go", |
33 | 38 | }, |
34 | 39 | ) |
| 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