You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
# -*- coding: utf-8 -*-
|
|
"""扫描 assets 下 TypeScript 与《开发规范》常见偏离项(统计用,非门禁)。"""
|
|
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ASSETS = ROOT / "assets"
|
|
SKIP_DIRS = {"node_modules", "library", "temp", "build"}
|
|
|
|
|
|
def iter_ts_files():
|
|
for path in ASSETS.rglob("*.ts"):
|
|
if any(part in SKIP_DIRS for part in path.parts):
|
|
continue
|
|
yield path
|
|
|
|
|
|
def main():
|
|
set_map_files = []
|
|
export_fn_files = []
|
|
for path in iter_ts_files():
|
|
text = path.read_text(encoding="utf-8", errors="ignore")
|
|
rel = path.relative_to(ROOT)
|
|
if re.search(r"\bnew\s+Set\b|\bnew\s+Map\b", text):
|
|
set_map_files.append(str(rel))
|
|
if re.search(r"^export\s+function\s+", text, re.MULTILINE):
|
|
export_fn_files.append(str(rel))
|
|
|
|
print("=== 规范偏离统计(assets/*.ts)===")
|
|
print(f"Set/Map 使用文件数: {len(set_map_files)}")
|
|
print(f"export function 文件数: {len(export_fn_files)}")
|
|
if "--list" in sys.argv:
|
|
print("\n-- Set/Map --")
|
|
for p in set_map_files[:50]:
|
|
print(p)
|
|
if len(set_map_files) > 50:
|
|
print(f"... 另有 {len(set_map_files) - 50} 个")
|
|
print("\n-- export function --")
|
|
for p in export_fn_files[:50]:
|
|
print(p)
|
|
if len(export_fn_files) > 50:
|
|
print(f"... 另有 {len(export_fn_files) - 50} 个")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|