mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-09-17 10:17:09 +03:00
set up elm format diffs for the library and component-catalog
This commit is contained in:
parent
b8a1d3163d
commit
a044547808
7
BUCK
7
BUCK
@ -1,5 +1,5 @@
|
|||||||
# A list of available rules and their signatures can be found here: https://buck2.build/docs/api/rules/
|
# A list of available rules and their signatures can be found here: https://buck2.build/docs/api/rules/
|
||||||
load("@prelude-nri//:elm.bzl", "elm_docs")
|
load("@prelude-nri//:elm.bzl", "elm_docs", "elm_format_diffs")
|
||||||
load("@prelude-nri//:node.bzl", "node_modules", "npm_bin", "npm_script_test")
|
load("@prelude-nri//:node.bzl", "node_modules", "npm_bin", "npm_script_test")
|
||||||
|
|
||||||
elm_docs(
|
elm_docs(
|
||||||
@ -44,3 +44,8 @@ npm_script_test(
|
|||||||
"script/puppeteer-tests.js": "script/puppeteer-tests.js",
|
"script/puppeteer-tests.js": "script/puppeteer-tests.js",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
elm_format_diffs(
|
||||||
|
name = "elm_format_diffs",
|
||||||
|
srcs = glob(["src/**/*.elm"]),
|
||||||
|
)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
load("@prelude-nri//:elm.bzl", "elm_app")
|
load("@prelude-nri//:elm.bzl", "elm_app", "elm_format_diffs")
|
||||||
|
|
||||||
elm_app(
|
elm_app(
|
||||||
name = "app",
|
name = "app",
|
||||||
@ -26,3 +26,8 @@ filegroup(
|
|||||||
"//:puppeteer",
|
"//:puppeteer",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
elm_format_diffs(
|
||||||
|
name = "elm_format_diffs",
|
||||||
|
srcs = glob(["src/**/*.elm"]),
|
||||||
|
)
|
||||||
|
@ -111,3 +111,44 @@ elm_app = rule(
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _elm_format_diffs_impl(ctx: "context"):
|
||||||
|
suggested_changes = []
|
||||||
|
|
||||||
|
for src in ctx.attrs.srcs:
|
||||||
|
suggestion = ctx.actions.declare_output("__suggested_changes__", src.short_path)
|
||||||
|
ctx.actions.run(
|
||||||
|
[
|
||||||
|
"bash",
|
||||||
|
"-xo", "pipefail",
|
||||||
|
"-c",
|
||||||
|
"""
|
||||||
|
$1 --stdin < $2 | diff -u $2 - > $3
|
||||||
|
if test "$?" -eq 1; then
|
||||||
|
# we're fine with files being different; we'll catch that in
|
||||||
|
# the BXL script.
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
""",
|
||||||
|
"--",
|
||||||
|
ctx.attrs._elm_toolchain.get(ElmToolchainInfo).elm_format,
|
||||||
|
src,
|
||||||
|
suggestion.as_output(),
|
||||||
|
],
|
||||||
|
category = "elm_format_diffs",
|
||||||
|
identifier = src.short_path,
|
||||||
|
)
|
||||||
|
suggested_changes.append(suggestion)
|
||||||
|
|
||||||
|
return [DefaultInfo(default_outputs = suggested_changes)]
|
||||||
|
|
||||||
|
elm_format_diffs = rule(
|
||||||
|
impl = _elm_format_diffs_impl,
|
||||||
|
attrs = {
|
||||||
|
"srcs": attrs.list(attrs.source()),
|
||||||
|
"_elm_toolchain": attrs.toolchain_dep(
|
||||||
|
default="toolchains//:elm",
|
||||||
|
providers = [ElmToolchainInfo],
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
@ -26,3 +26,33 @@ genrule(
|
|||||||
executable = True,
|
executable = True,
|
||||||
visibility = ["PUBLIC"],
|
visibility = ["PUBLIC"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ELM_FORMAT_URL = select({
|
||||||
|
"config//os:linux": "https://github.com/avh4/elm-format/releases/download/0.8.7/elm-format-0.8.7-linux-x64.tgz",
|
||||||
|
"config//os:macos": select({
|
||||||
|
"config//cpu:arm64": "https://github.com/avh4/elm-format/releases/download/0.8.7/elm-format-0.8.7-mac-arm64.tgz",
|
||||||
|
"config//cpu:x86_64": "https://github.com/avh4/elm-format/releases/download/0.8.7/elm-format-0.8.7-mac-x64.tgz",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
ELM_FORMAT_SHA256 = select({
|
||||||
|
"config//os:linux": "44344c7b6f838dc5d9495dfe4253280a698c2251ee8cfa29b6d1a032b6efb13b",
|
||||||
|
"config//os:macos": select({
|
||||||
|
"config//cpu:arm64": "d8f898be599fa767d3b6607256e273dd4f62ea7abc41369a068e903159787098",
|
||||||
|
"config//cpu:x86_64": "064102cd471550beb43ff7eb3dd6ac7c2a1946cf038dbde389873384f62cbdc4",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "elm_format_archive",
|
||||||
|
urls = [ELM_FORMAT_URL],
|
||||||
|
sha256 = ELM_FORMAT_SHA256,
|
||||||
|
)
|
||||||
|
|
||||||
|
genrule(
|
||||||
|
name = "elm_format_binary",
|
||||||
|
out = "elm-format",
|
||||||
|
cmd = "cp $(location :elm_format_archive)/elm-format $OUT",
|
||||||
|
executable = True,
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user