mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
feat: add batch beautifier script
Former-commit-id: 07fc4002b57215485805fcc9eaa6d869f6e22af1
This commit is contained in:
Executable
+36
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 用法: bash beautify-all.sh <input-dir> <output-dir>
|
||||||
|
|
||||||
|
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 个文件已格式化"
|
||||||
Reference in New Issue
Block a user