mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2026-03-09 05:20:21 +00:00
refactor(format): enhance formatting tasks with tool existence checks and improved output
This commit is contained in:
parent
008c79852b
commit
6e695bd48c
2 changed files with 39 additions and 17 deletions
|
|
@ -15,7 +15,6 @@
|
|||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
# Use the same esp-idf-full as previously in .envrc
|
||||
esp-idf = esp-dev.packages.${system}.esp-idf-full;
|
||||
in
|
||||
{
|
||||
|
|
@ -24,10 +23,11 @@
|
|||
esp-idf
|
||||
pkgs.python3
|
||||
pkgs.python3Packages.invoke
|
||||
|
||||
# Formatting tools
|
||||
pkgs.clang-tools
|
||||
pkgs.nodePackages.prettier
|
||||
# pkgs.nodePackages.svgo
|
||||
pkgs.nodePackages.svgo
|
||||
pkgs.black
|
||||
pkgs.nixfmt
|
||||
];
|
||||
|
|
|
|||
42
tasks.py
42
tasks.py
|
|
@ -83,37 +83,59 @@ def format(c):
|
|||
result = c.run(
|
||||
"find main components -name '*.c' -o -name '*.h' | xargs clang-format -i",
|
||||
warn=True,
|
||||
hide=False,
|
||||
)
|
||||
if result and not result.ok:
|
||||
if result.exited == 127 or (not result.ok and result.exited != 0):
|
||||
# Check if tool exists
|
||||
check = c.run("command -v clang-format", warn=True, hide=True)
|
||||
if not check.ok:
|
||||
missing_tools.append("clang-format")
|
||||
|
||||
print("Formatting Python files...")
|
||||
result = c.run("black tasks.py", warn=True)
|
||||
if result and not result.ok:
|
||||
result = c.run("black tasks.py", warn=True, hide=False)
|
||||
if result.exited == 127 or (not result.ok and result.exited != 0):
|
||||
check = c.run("command -v black", warn=True, hide=True)
|
||||
if not check.ok:
|
||||
missing_tools.append("black")
|
||||
|
||||
print("Formatting Nix files...")
|
||||
result = c.run("nixfmt flake.nix", warn=True)
|
||||
if result and not result.ok:
|
||||
result = c.run("nixfmt flake.nix", warn=True, hide=False)
|
||||
if result.exited == 127 or (not result.ok and result.exited != 0):
|
||||
check = c.run("command -v nixfmt", warn=True, hide=True)
|
||||
if not check.ok:
|
||||
missing_tools.append("nixfmt")
|
||||
|
||||
print("Formatting SVG files...")
|
||||
result = c.run(
|
||||
"find . -name '*.svg' -not -path './build/*' -not -path './managed_components/*' | xargs svgo",
|
||||
"find . -name '*.svg' -not -path './build/*' -not -path './managed_components/*' | xargs -r svgo",
|
||||
warn=True,
|
||||
hide=False,
|
||||
)
|
||||
if result and not result.ok:
|
||||
if result.exited == 127 or (not result.ok and result.exited != 0):
|
||||
check = c.run("command -v svgo", warn=True, hide=True)
|
||||
if not check.ok:
|
||||
missing_tools.append("svgo")
|
||||
|
||||
print("Formatting other files...")
|
||||
result = c.run("prettier --write '**/*.{js,json,yaml,yml,md,html,css}'", warn=True)
|
||||
if result and not result.ok:
|
||||
result = c.run(
|
||||
"prettier --write '**/*.{js,json,yaml,yml,md,html,css}'", warn=True, hide=False
|
||||
)
|
||||
if result.exited == 127 or (not result.ok and result.exited != 0):
|
||||
check = c.run("command -v prettier", warn=True, hide=True)
|
||||
if not check.ok:
|
||||
missing_tools.append("prettier")
|
||||
|
||||
if missing_tools:
|
||||
print(f"\n❌ ERROR: Missing formatting tools: {', '.join(missing_tools)}")
|
||||
print("\n" + "=" * 60)
|
||||
print(f"❌ ERROR: Missing formatting tools: {', '.join(missing_tools)}")
|
||||
print("=" * 60)
|
||||
print("Please install them or reload the nix-shell.")
|
||||
print("=" * 60 + "\n")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("\n" + "=" * 60)
|
||||
print("✅ All files formatted successfully!")
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
|
||||
@task
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue