mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2026-03-09 13:30:20 +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
|
let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
# Use the same esp-idf-full as previously in .envrc
|
|
||||||
esp-idf = esp-dev.packages.${system}.esp-idf-full;
|
esp-idf = esp-dev.packages.${system}.esp-idf-full;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
@ -24,10 +23,11 @@
|
||||||
esp-idf
|
esp-idf
|
||||||
pkgs.python3
|
pkgs.python3
|
||||||
pkgs.python3Packages.invoke
|
pkgs.python3Packages.invoke
|
||||||
|
|
||||||
# Formatting tools
|
# Formatting tools
|
||||||
pkgs.clang-tools
|
pkgs.clang-tools
|
||||||
pkgs.nodePackages.prettier
|
pkgs.nodePackages.prettier
|
||||||
# pkgs.nodePackages.svgo
|
pkgs.nodePackages.svgo
|
||||||
pkgs.black
|
pkgs.black
|
||||||
pkgs.nixfmt
|
pkgs.nixfmt
|
||||||
];
|
];
|
||||||
|
|
|
||||||
42
tasks.py
42
tasks.py
|
|
@ -83,37 +83,59 @@ def format(c):
|
||||||
result = c.run(
|
result = c.run(
|
||||||
"find main components -name '*.c' -o -name '*.h' | xargs clang-format -i",
|
"find main components -name '*.c' -o -name '*.h' | xargs clang-format -i",
|
||||||
warn=True,
|
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")
|
missing_tools.append("clang-format")
|
||||||
|
|
||||||
print("Formatting Python files...")
|
print("Formatting Python files...")
|
||||||
result = c.run("black tasks.py", warn=True)
|
result = c.run("black tasks.py", 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 black", warn=True, hide=True)
|
||||||
|
if not check.ok:
|
||||||
missing_tools.append("black")
|
missing_tools.append("black")
|
||||||
|
|
||||||
print("Formatting Nix files...")
|
print("Formatting Nix files...")
|
||||||
result = c.run("nixfmt flake.nix", warn=True)
|
result = c.run("nixfmt flake.nix", 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 nixfmt", warn=True, hide=True)
|
||||||
|
if not check.ok:
|
||||||
missing_tools.append("nixfmt")
|
missing_tools.append("nixfmt")
|
||||||
|
|
||||||
print("Formatting SVG files...")
|
print("Formatting SVG files...")
|
||||||
result = c.run(
|
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,
|
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")
|
missing_tools.append("svgo")
|
||||||
|
|
||||||
print("Formatting other files...")
|
print("Formatting other files...")
|
||||||
result = c.run("prettier --write '**/*.{js,json,yaml,yml,md,html,css}'", warn=True)
|
result = c.run(
|
||||||
if result and not result.ok:
|
"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")
|
missing_tools.append("prettier")
|
||||||
|
|
||||||
if missing_tools:
|
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("Please install them or reload the nix-shell.")
|
||||||
|
print("=" * 60 + "\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("✅ All files formatted successfully!")
|
||||||
|
print("=" * 60 + "\n")
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue