From 787fa1ca6e9296fad35f666399904f5f2d81aba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=8D=E7=BC=96=E8=AF=91=E5=B7=A5=E4=BD=9C=E5=8C=BA?= Date: Wed, 29 Apr 2026 12:03:19 +0800 Subject: [PATCH] feat: add batch beautifier script Former-commit-id: 07fc4002b57215485805fcc9eaa6d869f6e22af1 --- frontend-source/scripts/beautify-all.sh | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 frontend-source/scripts/beautify-all.sh diff --git a/frontend-source/scripts/beautify-all.sh b/frontend-source/scripts/beautify-all.sh new file mode 100755 index 00000000..19e72750 --- /dev/null +++ b/frontend-source/scripts/beautify-all.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# 用法: bash beautify-all.sh + +INPUT_DIR="${1:-.}" +OUTPUT_DIR="${2:-./formatted}" + +mkdir -p "$OUTPUT_DIR" + +count=0 +for file in "$INPUT_DIR"/*.js; do + [ ! -f "$file" ] && continue + base=$(basename "$file") + output="$OUTPUT_DIR/${base%.js}.formatted.js" + + # 先用 js-beautify 还原缩进和换行 + npx js-beautify "$file" \ + --indent-size 2 \ + --brace-style collapse \ + --wrap-line-length 120 \ + > "$output.tmp" 2>/dev/null + + # 再用 prettier 统一风格 + npx prettier --write "$output.tmp" \ + --parser babel \ + --print-width 120 \ + --tab-width 2 \ + --single-quote true \ + --trailing-comma es5 \ + 2>/dev/null + + mv "$output.tmp" "$output" + count=$((count + 1)) + echo "格式化: $base → $(basename "$output")" +done + +echo "完成: $count 个文件已格式化"