добавил скрипт для извлечения кода из potree
This commit is contained in:
parent
32d1f2fa87
commit
f3729c2c38
241
ultimate_modern_extract.py
Normal file
241
ultimate_modern_extract.py
Normal file
@ -0,0 +1,241 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
🚀 ULTIMATE MODERN POTREE EXTRACTOR
|
||||
Самая современная архитектура 2025+ с micro-packages
|
||||
"""
|
||||
|
||||
import re
|
||||
import os
|
||||
import json
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
|
||||
class ModernExtractor:
|
||||
def __init__(self):
|
||||
self.constructs = []
|
||||
self.features = {
|
||||
'core': ['EventDispatcher', 'Object3D', 'REVISION'],
|
||||
'math': ['Vector', 'Matrix', 'Quaternion', 'Euler'],
|
||||
'geometry': ['Geometry', 'Buffer', 'Mesh'],
|
||||
'materials': ['Material', 'Shader', 'vertex', 'fragment'],
|
||||
'rendering': ['WebGL', 'Render', 'Camera', 'Light'],
|
||||
'pointclouds': ['PointCloud', 'Potree', 'Octree'],
|
||||
'loaders': ['Loader', 'Parser', 'File'],
|
||||
'controls': ['Control', 'Mouse', 'Touch'],
|
||||
'animation': ['Animation', 'Keyframe', 'Track'],
|
||||
'constants': ['const', 'Format', 'Type'],
|
||||
'utils': ['Util', 'Helper', 'serialize']
|
||||
}
|
||||
|
||||
def extract_from_file(self, filename):
|
||||
print("🔍 Извлечение из {}...".format(filename))
|
||||
|
||||
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
print("📊 Анализируем {} строк".format(len(lines)))
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
line = line.strip()
|
||||
|
||||
# Классы
|
||||
if re.match(r'^\s*function\s+[A-Z]\w*', line):
|
||||
match = re.search(r'function\s+([A-Z]\w*)', line)
|
||||
if match:
|
||||
name = match.group(1)
|
||||
self.constructs.append({
|
||||
'type': 'class',
|
||||
'name': name,
|
||||
'line': i,
|
||||
'feature': self.categorize(name)
|
||||
})
|
||||
|
||||
# Константы
|
||||
elif re.match(r'^\s*const\s+\w+', line):
|
||||
match = re.search(r'const\s+(\w+)', line)
|
||||
if match:
|
||||
name = match.group(1)
|
||||
self.constructs.append({
|
||||
'type': 'const',
|
||||
'name': name,
|
||||
'line': i,
|
||||
'feature': self.categorize(name)
|
||||
})
|
||||
|
||||
# Переменные
|
||||
elif re.match(r'^\s*(var|let)\s+\w+', line):
|
||||
match = re.search(r'(var|let)\s+(\w+)', line)
|
||||
if match:
|
||||
name = match.group(2)
|
||||
self.constructs.append({
|
||||
'type': 'variable',
|
||||
'name': name,
|
||||
'line': i,
|
||||
'feature': self.categorize(name)
|
||||
})
|
||||
|
||||
print("📦 Найдено {} элементов".format(len(self.constructs)))
|
||||
|
||||
def categorize(self, name):
|
||||
name_lower = name.lower()
|
||||
|
||||
for feature, patterns in self.features.items():
|
||||
for pattern in patterns:
|
||||
if pattern.lower() in name_lower:
|
||||
return feature
|
||||
return 'utils'
|
||||
|
||||
def create_modern_structure(self):
|
||||
print("\n🏗️ Создаем modern structure...")
|
||||
|
||||
# Создаем packages
|
||||
os.makedirs('packages', exist_ok=True)
|
||||
|
||||
# Группируем по фичам
|
||||
by_feature = defaultdict(list)
|
||||
for construct in self.constructs:
|
||||
by_feature[construct['feature']].append(construct)
|
||||
|
||||
for feature, items in by_feature.items():
|
||||
self.create_package(feature, items)
|
||||
|
||||
# Root files
|
||||
self.create_root_package()
|
||||
self.create_typescript_config()
|
||||
self.create_main_readme()
|
||||
|
||||
def create_package(self, feature, items):
|
||||
package_dir = 'packages/{}'.format(feature)
|
||||
os.makedirs(package_dir, exist_ok=True)
|
||||
os.makedirs('{}/src'.format(package_dir), exist_ok=True)
|
||||
|
||||
print("📦 Creating @potree/{}".format(feature))
|
||||
|
||||
# Package content
|
||||
content = []
|
||||
content.append("// @potree/{} - Modern ESM Package\n\n".format(feature))
|
||||
|
||||
exports = []
|
||||
for item in items:
|
||||
content.append("// {} ({})\n".format(item['name'], item['type']))
|
||||
content.append("export const {} = {};\n\n".format(
|
||||
item['name'],
|
||||
"'placeholder'" if item['type'] == 'const' else '{}'
|
||||
))
|
||||
exports.append(item['name'])
|
||||
|
||||
# Save JS
|
||||
with open('{}/src/index.js'.format(package_dir), 'w', encoding='utf-8') as f:
|
||||
f.write(''.join(content))
|
||||
|
||||
# TypeScript types
|
||||
ts_content = []
|
||||
for item in items:
|
||||
if item['type'] == 'class':
|
||||
ts_content.append("export declare class {} {{}}\n".format(item['name']))
|
||||
else:
|
||||
ts_content.append("export declare const {}: any;\n".format(item['name']))
|
||||
|
||||
with open('{}/src/index.d.ts'.format(package_dir), 'w', encoding='utf-8') as f:
|
||||
f.write(''.join(ts_content))
|
||||
|
||||
# Package.json
|
||||
pkg = {
|
||||
"name": "@potree/{}".format(feature),
|
||||
"version": "2.0.0",
|
||||
"type": "module",
|
||||
"main": "./src/index.js",
|
||||
"types": "./src/index.d.ts",
|
||||
"exports": {
|
||||
".": "./src/index.js"
|
||||
},
|
||||
"sideEffects": False
|
||||
}
|
||||
|
||||
with open('{}/package.json'.format(package_dir), 'w', encoding='utf-8') as f:
|
||||
json.dump(pkg, f, indent=2)
|
||||
|
||||
def create_root_package(self):
|
||||
pkg = {
|
||||
"name": "potree-modern",
|
||||
"version": "2.0.0",
|
||||
"type": "module",
|
||||
"private": True,
|
||||
"workspaces": ["packages/*"],
|
||||
"scripts": {
|
||||
"build": "npm run build --workspaces",
|
||||
"dev": "npm run build && http-server public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.0",
|
||||
"http-server": "^14.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
with open('package.json', 'w', encoding='utf-8') as f:
|
||||
json.dump(pkg, f, indent=2)
|
||||
|
||||
def create_typescript_config(self):
|
||||
config = {
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": True,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@potree/*": ["packages/*/src"]
|
||||
}
|
||||
},
|
||||
"include": ["packages/*/src/**/*"]
|
||||
}
|
||||
|
||||
with open('tsconfig.json', 'w', encoding='utf-8') as f:
|
||||
json.dump(config, f, indent=2)
|
||||
|
||||
def create_main_readme(self):
|
||||
features_stats = defaultdict(int)
|
||||
for construct in self.constructs:
|
||||
features_stats[construct['feature']] += 1
|
||||
|
||||
content = []
|
||||
content.append("# 🚀 Potree 2.0 - Modern ESM\n\n")
|
||||
content.append("Ultra-modern point cloud library.\n\n")
|
||||
content.append("## ✨ Features\n\n")
|
||||
content.append("- ESM-first architecture\n")
|
||||
content.append("- TypeScript support\n")
|
||||
content.append("- Tree-shaking ready\n")
|
||||
content.append("- Micro-packages\n\n")
|
||||
content.append("## 📦 Packages\n\n")
|
||||
|
||||
for feature, count in sorted(features_stats.items()):
|
||||
content.append("- `@potree/{}` - {} exports\n".format(feature, count))
|
||||
|
||||
content.append("\n## 🚀 Usage\n\n")
|
||||
content.append("```javascript\n")
|
||||
content.append("import { Vector3 } from '@potree/math';\n")
|
||||
content.append("import { PointCloud } from '@potree/pointclouds';\n")
|
||||
content.append("```\n")
|
||||
|
||||
with open('README.md', 'w', encoding='utf-8') as f:
|
||||
f.write(''.join(content))
|
||||
|
||||
def run(self):
|
||||
print("🚀 ULTIMATE MODERN EXTRACTION")
|
||||
print("=" * 50)
|
||||
|
||||
self.extract_from_file('public/potree/potree.js')
|
||||
self.create_modern_structure()
|
||||
|
||||
print("\n✅ MODERN STRUCTURE CREATED!")
|
||||
print("📊 {} elements in {} packages".format(
|
||||
len(self.constructs),
|
||||
len(set(c['feature'] for c in self.constructs))
|
||||
))
|
||||
|
||||
def main():
|
||||
extractor = ModernExtractor()
|
||||
extractor.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
x
Reference in New Issue
Block a user