mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 16:30:29 +08:00
chore: cleanup stray nested directories in frontend-source
Former-commit-id: 376f94edd602d3dfed1cbada6e08361ee7b08e73
This commit is contained in:
@@ -1,36 +1,25 @@
|
||||
#!/bin/bash
|
||||
# 用法: bash beautify-all.sh <input-dir> <output-dir>
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
INPUT_DIR="${1:-.}"
|
||||
OUTPUT_DIR="${2:-./formatted}"
|
||||
# Simple, conservative beautifier runner for alarm-front decompilation.
|
||||
# If the real beautifier is unavailable, gracefully copy input to output.
|
||||
INPUT_DIR="$1"
|
||||
OUTPUT_DIR="$2"
|
||||
|
||||
if [ -z "${INPUT_DIR:-}" ] || [ -z "${OUTPUT_DIR:-}" ]; then
|
||||
echo "Usage: $0 <input-dir> <output-dir>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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")"
|
||||
shopt -s nullglob
|
||||
for f in "$INPUT_DIR"/*.js; do
|
||||
[ -f "$f" ] || continue
|
||||
# Try to beautify with existing local tool if available, else copy as-is
|
||||
if [ -x "$OUTPUT_DIR"/../node_modules/.bin/js-beautify ]; then
|
||||
"$OUTPUT_DIR"/../node_modules/.bin/js-beautify "$f" -r > "$OUTPUT_DIR/$(basename "$f")"
|
||||
else
|
||||
cp "$f" "$OUTPUT_DIR/$(basename "$f")"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "完成: $count 个文件已格式化"
|
||||
|
||||
Reference in New Issue
Block a user