/** * Batch auto_knowledge — generate complete COMPONENT_PROPERTIES from d.ts * Output: knowledge JSON files + combined TS snippet for knowledge-handler.ts */ const path = require('path'); const fs = require('fs'); const mod = require(path.resolve(__dirname, '../dist/tools/cocos/utils/component-knowledge')); const ALL_COMPONENTS = [ 'cc.Label', 'cc.Sprite', 'cc.Button', 'cc.Widget', 'cc.Layout', 'cc.UITransform', 'cc.RichText', 'cc.ScrollView', 'cc.Toggle', 'cc.ToggleContainer', 'cc.ProgressBar', 'cc.Slider', 'cc.PageView', 'cc.Mask', 'cc.Graphics', 'cc.UIOpacity', 'cc.SafeArea', 'cc.BlockInputEvents', 'cc.LabelOutline', 'cc.LabelShadow', 'cc.PageViewIndicator', 'cc.EditBox', 'cc.AudioSource', 'cc.VideoPlayer', 'cc.WebView', 'cc.ParticleSystem2D', 'cc.ParticleSystem', 'cc.Camera', 'cc.Canvas', 'cc.Animation', 'cc.SkeletalAnimation', 'cc.MeshRenderer', 'cc.SkinnedMeshRenderer', 'cc.DirectionalLight', 'cc.PointLight', 'cc.SpotLight', 'cc.SphereLight', 'cc.RigidBody2D', 'cc.BoxCollider2D', 'cc.CircleCollider2D', 'cc.PolygonCollider2D', 'cc.RigidBody', 'cc.BoxCollider', 'cc.SphereCollider', 'cc.CapsuleCollider', 'cc.MeshCollider', 'cc.MotionStreak', 'cc.Billboard', 'cc.Line', 'cc.TiledMap', 'cc.TiledLayer', 'cc.HingeJoint2D', 'cc.DistanceJoint2D', 'cc.SpringJoint2D', 'cc.FixedJoint2D', 'cc.WheelJoint2D', 'cc.SliderJoint2D', 'cc.RelativeJoint2D', 'cc.MouseJoint2D', 'cc.HingeConstraint', 'cc.FixedConstraint', 'cc.PointToPointConstraint', 'cc.Terrain', 'cc.LODGroup', 'cc.ReflectionProbe', 'sp.Skeleton', 'dragonBones.ArmatureDisplay', ]; const snippets = []; let saved = 0, failed = 0; for (const comp of ALL_COMPONENTS) { const className = mod.componentTypeToClassName(comp); const dtsInfo = mod.parseDtsClass(className, { recursive: true }); if (!dtsInfo) { console.log(` ❌ ${comp}: not found in d.ts`); failed++; continue; } const classified = mod.classifyProperties(dtsInfo, null); const knowledge = mod.buildRecommendedKnowledge(comp, dtsInfo, classified); // Save knowledge file mod.saveKnowledgeFile(comp, knowledge); // Generate TS snippet const snippet = mod.generateTsSnippet(comp, knowledge); snippets.push(snippet); const propCount = Object.keys(knowledge.properties).length; console.log(` ✅ ${comp}: ${propCount} props`); saved++; } // Write combined snippets to file const outputPath = path.resolve(__dirname, '../dev-knowledge/COMPONENT_PROPERTIES_GENERATED.ts'); const outputDir = path.dirname(outputPath); if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true }); const header = `/** * AUTO-GENERATED by batch-auto-knowledge.js * Date: ${new Date().toISOString()} * Components: ${saved} * * Paste this into COMPONENT_PROPERTIES in knowledge-handler.ts */ const COMPONENT_PROPERTIES: Record = {\n`; const footer = `\n};\n`; fs.writeFileSync(outputPath, header + snippets.join('\n') + footer, 'utf-8'); console.log(`\n Saved: ${saved} | Failed: ${failed}`); console.log(` Knowledge files: dev-knowledge/components/`); console.log(` TS output: ${outputPath}`);