From cdc17b01268291d764f7eb12af8a1210ea5af914 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Fri, 10 May 2024 20:44:11 -0700 Subject: [PATCH] feat: add ibazel and prettier fmt (#3) --- README.md | 9 ++++++- scaffold.yaml | 28 +++++++++++--------- {{ .ProjectSnake }}/.bazelrc | 8 ++++++ {{ .ProjectSnake }}/.gitignore | 4 +++ {{ .ProjectSnake }}/README.bazel.md | 2 +- {{ .ProjectSnake }}/tools/format/BUILD.bazel | 17 +++++++++++- {{ .ProjectSnake }}/tools/ibazel | 1 + {{ .ProjectSnake }}/tools/tools.lock.json | 27 ++++++++++++++++++- 8 files changed, 79 insertions(+), 17 deletions(-) create mode 120000 {{ .ProjectSnake }}/tools/ibazel diff --git a/README.md b/README.md index 82b2d2c..4451f87 100644 --- a/README.md +++ b/README.md @@ -1 +1,8 @@ -# Scaffold for basic Aspect Build workspace +# Scaffold for basic Aspect Workflows project + +Create a new project from scratch on macos: + +```shell +% brew install scaffold +% scaffold new https://github.com/alexeagle/aspect-workflows-template.git +``` diff --git a/scaffold.yaml b/scaffold.yaml index ddea6de..77bad32 100644 --- a/scaffold.yaml +++ b/scaffold.yaml @@ -1,27 +1,26 @@ messages: pre: | - # Welcome to Aspect + # Welcome to Aspect, the multi-language monorepo dev platform Generate boilerplate code for a new Bazel project using Aspect CLI and Aspect Workflows. post: | - # Get Started + # Next Steps - 1. Read the developer guide in {{ .ProjectSnake }}/README.bazel.md - 2. Try out some commands, such as: - - ```sh - cd {{ .ProjectSnake }} + 1. `cd {{ .ProjectSnake }}`, or open that folder in your editor. + 2. Read the developer guide in `/README.bazel.md`. + 3. Try out some commands, such as: {{- if .Scaffold.lint }} - aspect run format + - Format: `aspect run format` + - Lint: `aspect lint ...` {{- end }} - aspect test ... - ``` + - Run all tests: `aspect test ...` + - Watch mode: `./tools/ibazel run //my:devserver` + + 4. Add source code and run `aspect configure` to create + additional `BUILD.bazel` files. questions: - - name: lint - prompt: - confirm: "Setup format and linting?" - name: langs prompt: multi: true @@ -29,6 +28,9 @@ questions: options: - JavaScript & TypeScript - Python + - name: lint + prompt: + confirm: "Setup format and linting?" features: - value: "{{ .Scaffold.lint }}" diff --git a/{{ .ProjectSnake }}/.bazelrc b/{{ .ProjectSnake }}/.bazelrc index 6c11a76..758bc64 100644 --- a/{{ .ProjectSnake }}/.bazelrc +++ b/{{ .ProjectSnake }}/.bazelrc @@ -8,6 +8,14 @@ import %workspace%/.aspect/bazelrc/performance.bazelrc ### YOUR PROJECT SPECIFIC OPTIONS GO HERE ### +{{ if eq .Computed.javascript "true" }} +# for speed, passes an argument `--skipLibCheck` to *every* spawn of tsc +common --@aspect_rules_ts//ts:skipLibCheck=always +# use `tsc` for transpiling, even though it's slow. +# TODO(alex): change to SWC by default +common --@aspect_rules_ts//ts:default_to_tsc_transpiler +{{ end }} + # Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`. # This file should appear in `.gitignore` so that settings are not shared with team members. This # should be last statement in this config so the user configuration is able to overwrite flags from diff --git a/{{ .ProjectSnake }}/.gitignore b/{{ .ProjectSnake }}/.gitignore index 9b053b0..372668c 100644 --- a/{{ .ProjectSnake }}/.gitignore +++ b/{{ .ProjectSnake }}/.gitignore @@ -11,3 +11,7 @@ MODULE.bazel.lock # Symlinks created by Bazel into the output tree /bazel-* + +{{ if eq .Computed.javascript "true" }} +node_modules/ +{{ end }} diff --git a/{{ .ProjectSnake }}/README.bazel.md b/{{ .ProjectSnake }}/README.bazel.md index 2c9d7bc..16695ac 100644 --- a/{{ .ProjectSnake }}/README.bazel.md +++ b/{{ .ProjectSnake }}/README.bazel.md @@ -19,7 +19,7 @@ For developers to be able to run a CLI tool without needing manual installation: See https://blog.aspect.build/run-tools-installed-by-bazel for details. -{{- if eq .Computed.javascript "true" }} +{{ if eq .Computed.javascript "true" }} ## Working with npm packages To install a `node_modules` tree locally for the editor or other tooling outside of Bazel: diff --git a/{{ .ProjectSnake }}/tools/format/BUILD.bazel b/{{ .ProjectSnake }}/tools/format/BUILD.bazel index 1592913..9070f6e 100644 --- a/{{ .ProjectSnake }}/tools/format/BUILD.bazel +++ b/{{ .ProjectSnake }}/tools/format/BUILD.bazel @@ -5,7 +5,22 @@ we don't want to trigger eager fetches of these for builds that don't want to ru """ load("@aspect_rules_lint//format:defs.bzl", "format_multirun") +{{ if eq .Computed.javascript "true" }} +load("@npm//:prettier/package_json.bzl", prettier = "bin") +{{ end }} package(default_visibility = ["//:__subpackages__"]) -format_multirun(name = "format") +{{ if eq .Computed.javascript "true" }} +prettier.prettier_binary( + name = "prettier", + env = {"BAZEL_BINDIR": "."}, +) +{{ end }} + +format_multirun( + name = "format", +{{ if eq .Computed.javascript "true" }} + javascript = ":prettier", +{{ end }} +) diff --git a/{{ .ProjectSnake }}/tools/ibazel b/{{ .ProjectSnake }}/tools/ibazel new file mode 120000 index 0000000..d27d0fe --- /dev/null +++ b/{{ .ProjectSnake }}/tools/ibazel @@ -0,0 +1 @@ +_multitool_run_under_cwd.sh \ No newline at end of file diff --git a/{{ .ProjectSnake }}/tools/tools.lock.json b/{{ .ProjectSnake }}/tools/tools.lock.json index 12c1723..48e0527 100644 --- a/{{ .ProjectSnake }}/tools/tools.lock.json +++ b/{{ .ProjectSnake }}/tools/tools.lock.json @@ -1,3 +1,28 @@ { - "$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json" + "$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json", + "ibazel": { + "binaries": [ + { + "kind": "file", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.25.2/ibazel_darwin_arm64", + "os": "macos", + "cpu": "arm64", + "sha256": "e4d5e04a2a0e4dda21350ffe26623469a85ab8786570aea962b058a954dcd3f1" + }, + { + "kind": "file", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.25.2/ibazel_linux_amd64", + "os": "linux", + "cpu": "x86_64", + "sha256": "1377caf887a7a239106ad6408fca1e14dfb239b3072b3abddbb660ff994b62aa" + }, + { + "kind": "file", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.25.2/ibazel_linux_arm64", + "os": "linux", + "cpu": "arm64", + "sha256": "3c15af15ffe77f7c4ed799a6a7c539541922a4811b8b9f4fbac044060ef89b64" + } + ] + } }