|
| 1 | +/* |
| 2 | + * Copyright 2025 Collate. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +const fs = require('fs'); |
| 15 | +const path = require('path'); |
| 16 | +const { execSync } = require('child_process'); |
| 17 | +const { generateDomainMarkdown, generateIndexMarkdown } = require('./markdown.js'); |
| 18 | +const { loadTestsFromPlaywright } = require('./playwright-loader.js'); |
| 19 | + |
| 20 | +// Constants |
| 21 | +// Script is in: openmetadata-ui/src/main/resources/ui/playwright/doc-generator/ |
| 22 | +const PLAYWRIGHT_DIR = path.resolve(__dirname, '../e2e'); |
| 23 | +const OUTPUT_DIR = path.resolve(__dirname, '../docs'); |
| 24 | + |
| 25 | +const DOMAIN_MAPPING = { |
| 26 | + // Overrides (Must be at the top to take precedence over generic keys like 'Pipeline') |
| 27 | + 'TestSuitePipeline': { domain: 'Observability', name: 'Data Quality' }, |
| 28 | + 'TestSuiteMultiPipeline': { domain: 'Observability', name: 'Data Quality' }, |
| 29 | + 'ObservabilityAlerts': { domain: 'Observability', name: 'Alerts & Notifications' }, |
| 30 | + 'NotificationAlerts': { domain: 'Observability', name: 'Alerts & Notifications' }, |
| 31 | + 'DataQualityAndProfiler': { domain: 'Observability', name: 'Profiler' }, |
| 32 | + 'ProfilerConfigurationPage': { domain: 'Observability', name: 'Profiler' }, |
| 33 | + 'TestCases': { domain: 'Observability', name: 'Data Quality' }, |
| 34 | + 'TestCase': { domain: 'Observability', name: 'Data Quality' }, // Matches TestCaseVersionPage, AddTestCaseNewFlow |
| 35 | + 'IncidentManager': { domain: 'Observability', name: 'Incident Manager' }, |
| 36 | + |
| 37 | + // Governance |
| 38 | + 'Automator': { domain: 'Governance', name: 'Automator' }, |
| 39 | + 'Glossary': { domain: 'Governance', name: 'Glossary' }, |
| 40 | + 'Tag': { domain: 'Governance', name: 'Tags' }, |
| 41 | + 'Classification': { domain: 'Governance', name: 'Tags' }, // Alias |
| 42 | + 'Workflow': { domain: 'Governance', name: 'Workflows' }, |
| 43 | + 'Metric': { domain: 'Governance', name: 'Metrics' }, |
| 44 | + 'KnowledgeCenter': { domain: 'Governance', name: 'Knowledge Center' }, |
| 45 | + 'CustomProperty': { domain: 'Governance', name: 'Custom Properties' }, |
| 46 | + 'Customproperties': { domain: 'Governance', name: 'Custom Properties' }, // Fix for casing |
| 47 | + 'Domain': { domain: 'Governance', name: 'Domains & Data Products' }, |
| 48 | + 'DataProduct': { domain: 'Governance', name: 'Domains & Data Products' }, // Alias |
| 49 | + 'DataContract': { domain: 'Governance', name: 'Data Contracts' }, |
| 50 | + |
| 51 | + // Platform |
| 52 | + 'RBAC': { domain: 'Platform', name: 'RBAC' }, |
| 53 | + 'Role': { domain: 'Platform', name: 'RBAC' }, |
| 54 | + 'Policy': { domain: 'Platform', name: 'RBAC' }, |
| 55 | + 'Policies': { domain: 'Platform', name: 'RBAC' }, |
| 56 | + 'SSO': { domain: 'Platform', name: 'SSO' }, |
| 57 | + 'User': { domain: 'Platform', name: 'Users & Teams' }, |
| 58 | + 'Team': { domain: 'Platform', name: 'Users & Teams' }, |
| 59 | + 'Persona': { domain: 'Platform', name: 'Personas & Customizations' }, |
| 60 | + 'Customization': { domain: 'Platform', name: 'Personas & Customizations' }, |
| 61 | + 'Customize': { domain: 'Platform', name: 'Personas & Customizations' }, |
| 62 | + 'Theme': { domain: 'Platform', name: 'Personas & Customizations' }, |
| 63 | + 'AppMarketplace': { domain: 'Platform', name: 'App Marketplace' }, |
| 64 | + 'Application': { domain: 'Platform', name: 'App Marketplace' }, |
| 65 | + 'Settings': { domain: 'Platform', name: 'Settings' }, |
| 66 | + 'Cron': { domain: 'Platform', name: 'Settings' }, |
| 67 | + 'Lineage': { domain: 'Platform', name: 'Lineage (UI)' }, // Default UI Lineage |
| 68 | + 'Impact': { domain: 'Platform', name: 'Lineage (UI)' }, |
| 69 | + 'Entity': { domain: 'Platform', name: 'Entities' }, |
| 70 | + 'Bulk': { domain: 'Platform', name: 'Entities' }, |
| 71 | + 'Navbar': { domain: 'Platform', name: 'Navigation' }, |
| 72 | + 'Navigation': { domain: 'Platform', name: 'Navigation' }, |
| 73 | + 'PageSize': { domain: 'Platform', name: 'Navigation' }, |
| 74 | + 'Pagination': { domain: 'Platform', name: 'Navigation' }, |
| 75 | + 'Login': { domain: 'Platform', name: 'Authentication' }, |
| 76 | + 'Auth': { domain: 'Platform', name: 'Authentication' }, |
| 77 | + 'Tour': { domain: 'Platform', name: 'Onboarding' }, |
| 78 | + |
| 79 | + // Discovery |
| 80 | + 'Search': { domain: 'Discovery', name: 'Search' }, |
| 81 | + 'DataInsight': { domain: 'Discovery', name: 'Data Insights' }, |
| 82 | + 'Feed': { domain: 'Discovery', name: 'Feed' }, |
| 83 | + 'Conversation': { domain: 'Discovery', name: 'Feed' }, |
| 84 | + 'Chat': { domain: 'Discovery', name: 'Feed' }, |
| 85 | + 'DataAsset': { domain: 'Discovery', name: 'Data Assets' }, // Generic bucket |
| 86 | + 'Table': { domain: 'Discovery', name: 'Data Assets' }, |
| 87 | + 'Topic': { domain: 'Discovery', name: 'Data Assets' }, |
| 88 | + 'Dashboard': { domain: 'Discovery', name: 'Data Assets' }, |
| 89 | + 'Pipeline': { domain: 'Discovery', name: 'Data Assets' }, |
| 90 | + 'Container': { domain: 'Discovery', name: 'Data Assets' }, |
| 91 | + 'Database': { domain: 'Discovery', name: 'Data Assets' }, |
| 92 | + 'Schema': { domain: 'Discovery', name: 'Data Assets' }, |
| 93 | + 'Explore': { domain: 'Discovery', name: 'Explore' }, |
| 94 | + 'MyData': { domain: 'Discovery', name: 'My Data' }, |
| 95 | + 'Curated': { domain: 'Discovery', name: 'Curated Assets' }, |
| 96 | + 'Home': { domain: 'Discovery', name: 'Home Page' }, |
| 97 | + 'Landing': { domain: 'Discovery', name: 'Home Page' }, |
| 98 | + 'RecentlyViewed': { domain: 'Discovery', name: 'Home Page' }, |
| 99 | + 'Following': { domain: 'Discovery', name: 'Home Page' }, |
| 100 | + |
| 101 | + // Observability |
| 102 | + 'Quality': { domain: 'Observability', name: 'Data Quality' }, |
| 103 | + 'Dim': { domain: 'Observability', name: 'Data Quality' }, // Dimensionality |
| 104 | + 'TestSuite': { domain: 'Observability', name: 'Data Quality' }, |
| 105 | + 'TestCase': { domain: 'Observability', name: 'Data Quality' }, |
| 106 | + 'Profiler': { domain: 'Observability', name: 'Profiler' }, |
| 107 | + 'RCA': { domain: 'Observability', name: 'Root Cause Analysis' }, |
| 108 | + 'Incident': { domain: 'Observability', name: 'Incident Manager' }, |
| 109 | + 'Alert': { domain: 'Observability', name: 'Alerts & Notifications' }, |
| 110 | + 'Notification': { domain: 'Observability', name: 'Alerts & Notifications' }, |
| 111 | + |
| 112 | + // Integration |
| 113 | + 'Connector': { domain: 'Integration', name: 'Connectors' }, |
| 114 | + 'Service': { domain: 'Integration', name: 'Connectors' }, |
| 115 | + 'Ingestion': { domain: 'Integration', name: 'Connectors' }, |
| 116 | + 'Query': { domain: 'Integration', name: 'Connectors' }, // QueryEntity |
| 117 | +}; |
| 118 | + |
| 119 | +function getComponentInfo(fileName) { |
| 120 | + for (const [key, def] of Object.entries(DOMAIN_MAPPING)) { |
| 121 | + if (fileName.includes(key)) return def; |
| 122 | + } |
| 123 | + return { domain: 'Platform', name: 'Other' }; |
| 124 | +} |
| 125 | + |
| 126 | +function main() { |
| 127 | + console.log(`🚀 Starting Documentation Generation (Node.js)`); |
| 128 | + console.log(` Input: ${PLAYWRIGHT_DIR}`); |
| 129 | + console.log(` Output: ${OUTPUT_DIR}`); |
| 130 | + |
| 131 | + if (!fs.existsSync(PLAYWRIGHT_DIR)) { |
| 132 | + console.error(`❌ Playwright directory not found!`); |
| 133 | + process.exit(1); |
| 134 | + } |
| 135 | + |
| 136 | + // 1. Find and Parse Files using Native Playwright Loader |
| 137 | + console.log(`📝 asking Playwright to list tests...`); |
| 138 | + const parsedFiles = loadTestsFromPlaywright(PLAYWRIGHT_DIR); |
| 139 | + console.log(` Received ${parsedFiles.length} file suites from Playwright.`); |
| 140 | + |
| 141 | + // 2. Group by Domain + Component |
| 142 | + const groupings = new Map(); |
| 143 | + |
| 144 | + parsedFiles.forEach(file => { |
| 145 | + const { domain, name } = getComponentInfo(file.fileName); |
| 146 | + const key = `${domain}:${name}`; |
| 147 | + |
| 148 | + if (!groupings.has(key)) { |
| 149 | + groupings.set(key, { domain, name, files: [] }); |
| 150 | + } |
| 151 | + groupings.get(key).files.push(file); |
| 152 | + }); |
| 153 | + |
| 154 | + // 3. Convert to Component Objects |
| 155 | + const components = Array.from(groupings.values()).map(g => ({ |
| 156 | + name: g.name, |
| 157 | + domain: g.domain, |
| 158 | + slug: g.name.toLowerCase().replace(/[^a-z0-9]+/g, '-'), |
| 159 | + files: g.files, |
| 160 | + totalTests: g.files.reduce((s, f) => s + f.totalTests, 0), |
| 161 | + totalSteps: g.files.reduce((s, f) => s + f.totalSteps, 0), |
| 162 | + totalScenarios: g.files.reduce((s, f) => s + f.totalScenarios, 0), |
| 163 | + })); |
| 164 | + |
| 165 | + // 4. Generate Content |
| 166 | + console.log(`⚙️ Generating Markdown for ${components.length} components...`); |
| 167 | + |
| 168 | + // Clean output directory |
| 169 | + if (fs.existsSync(OUTPUT_DIR)) { |
| 170 | + fs.rmSync(OUTPUT_DIR, { recursive: true, force: true }); |
| 171 | + } |
| 172 | + fs.mkdirSync(OUTPUT_DIR, { recursive: true }); |
| 173 | + |
| 174 | + // Stats |
| 175 | + const stats = { |
| 176 | + components: components.length, |
| 177 | + files: parsedFiles.length, |
| 178 | + tests: components.reduce((s,c) => s + c.totalTests, 0), |
| 179 | + steps: components.reduce((s,c) => s + c.totalSteps, 0) |
| 180 | + }; |
| 181 | + |
| 182 | + // Group Components by Domain for Generation |
| 183 | + const componentsByDomain = {}; |
| 184 | + components.forEach(c => { |
| 185 | + if (!componentsByDomain[c.domain]) componentsByDomain[c.domain] = []; |
| 186 | + componentsByDomain[c.domain].push(c); |
| 187 | + }); |
| 188 | + |
| 189 | + // Generate Consolidated Domain Pages |
| 190 | + Object.entries(componentsByDomain).forEach(([domain, comps]) => { |
| 191 | + const content = generateDomainMarkdown(domain, comps); |
| 192 | + fs.writeFileSync(path.join(OUTPUT_DIR, `${domain}.md`), content); |
| 193 | + console.log(` ✓ ${domain}.md`); |
| 194 | + }); |
| 195 | + |
| 196 | + // Generate Main Index (README.md) |
| 197 | + fs.writeFileSync(path.join(OUTPUT_DIR, 'README.md'), generateIndexMarkdown(components, stats)); |
| 198 | + console.log(` ✓ README.md`); |
| 199 | + |
| 200 | + // 5. Stage files in Git |
| 201 | + try { |
| 202 | + console.log(`\n📦 Staging generated docs...`); |
| 203 | + execSync('git add .', { cwd: OUTPUT_DIR, stdio: 'inherit' }); |
| 204 | + console.log(` ✓ git add completed for ${OUTPUT_DIR}`); |
| 205 | + } catch (error) { |
| 206 | + console.error(` ⚠️ Warning: Failed to stage files with git.`); |
| 207 | + console.error(error.message); |
| 208 | + } |
| 209 | + |
| 210 | + console.log(`\n✅ Success! Documentation generated in:`); |
| 211 | + console.log(` ${OUTPUT_DIR}`); |
| 212 | +} |
| 213 | + |
| 214 | +main(); |
0 commit comments