mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-10 00:40:30 +08:00
787fa1ca6e
Former-commit-id: 07fc4002b57215485805fcc9eaa6d869f6e22af1
37 lines
847 B
Bash
Executable File
37 lines
847 B
Bash
Executable File
#!/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 个文件已格式化"
|