diff --git a/scripts/generateDetailedPages.js b/scripts/generateDetailedPages.js index d819295786..40e70cab9f 100644 --- a/scripts/generateDetailedPages.js +++ b/scripts/generateDetailedPages.js @@ -8,10 +8,8 @@ const execAsync = util.promisify(exec); const rootDir = path.dirname(__dirname); const pkgDir = rootDir + "/en/package" const templatesDir = rootDir + "/templates" -const versionsDir = rootDir + "/vcpkg/versions" const destDir = path.dirname(__dirname); const commitFilePath = path.join(__dirname, 'commit.txt'); -const vcpkgDir = path.join(__dirname, '../vcpkg'); async function readJsonFile(filePath) { const fileData = await fs.readFile(filePath, 'utf8'); @@ -35,7 +33,7 @@ async function getCommitHash(commitFilePath) { async function generateGithubFileUrls(packageInfo, commitHash, vcpkgDir) { const portDirPath = path.join(vcpkgDir, 'ports', packageInfo.Name); const fileNames = await fs.readdir(portDirPath); - + fileNames.sort(); const effectiveCommitHash = commitHash || 'master'; const githubBaseUrl = `https://github.com/microsoft/vcpkg/blob/${effectiveCommitHash}/ports/${packageInfo.Name}/`; @@ -48,10 +46,10 @@ async function generateGithubFileUrls(packageInfo, commitHash, vcpkgDir) { } -async function getPackageVersions(pkgName) { +async function getPackageVersions(pkgName, vcpkgDir) { const pkgFolder = pkgName.charAt(0) + '-'; const pkgJsonFile = path.join('/', pkgName + '.json'); - const versionFile = path.join(versionsDir, pkgFolder, pkgJsonFile); + const versionFile = path.join(vcpkgDir, 'versions', pkgFolder, pkgJsonFile); const rawData = await fs.readFile(versionFile); const versionsInfo = JSON.parse(rawData); @@ -101,7 +99,7 @@ function transform_dep(dep) { } } -async function renderAllTemplates() { +async function renderAllTemplates(vcpkgDir) { const commitHash = await getCommitHash(commitFilePath); // Load all templates and data once at the beginning. @@ -152,7 +150,7 @@ async function renderAllTemplates() { const renderData = { ...sharedData, package: packageInfo, - packageVersions: await getPackageVersions(packageInfo.Name), + packageVersions: await getPackageVersions(packageInfo.Name, vcpkgDir), dependencies: packageInfo.dependenciesList, features: packageInfo.FeaturesContent }; @@ -163,9 +161,15 @@ async function renderAllTemplates() { } } -async function main() { +async function main(vcpkgDir) { await fs.mkdir(pkgDir, { recursive: true }); - await renderAllTemplates(); + await renderAllTemplates(vcpkgDir); +} + +if (process.argv.length < 3) { + console.log("Usage: node generateDetailedPages.js "); + process.exit(1); } -main(); +const vcpkgDir = process.argv[2]; +main(vcpkgDir); diff --git a/scripts/generatePackages.js b/scripts/generatePackages.js index ea22cb4f7c..0ed7578cfb 100644 --- a/scripts/generatePackages.js +++ b/scripts/generatePackages.js @@ -52,27 +52,41 @@ async function readManifest(manifestFile) { return out; } -async function getFileCommitInfo(repoPath, filePath) { - try { - // Ensure the file path is relative to the repository root - const relativeFilePath = path.relative(repoPath, filePath); - const { stdout } = await execAsync(`git -C ${repoPath} log -1 --format='%H %cd' --date=format:%Y-%m-%d -- ${relativeFilePath}`); - - const [commitHash, ...dateParts] = stdout.trim().split(' '); - const lastModifiedDate = dateParts.join(' '); +function toPosixPath(p) { + return p.split(path.sep).join('/'); +} - return{ - commitHash, - lastModifiedDate - }; +async function getPortsCommitInfo(repoPath) { + try { + const { stdout } = await execAsync( + `git -C ${repoPath} log --format=%H%x09%cd --date=format:%Y-%m-%d --name-only -- ports/*/vcpkg.json`, + { maxBuffer: 64 * 1024 * 1024 } + ); + const commitInfoMap = new Map(); + let currentCommit = null; + for (const line of stdout.split('\n')) { + if (!line.trim()) continue; + const commitMatch = line.match(/^([0-9a-f]{40})\t(.+)$/); + if (commitMatch) { + currentCommit = { commitHash: commitMatch[1], lastModifiedDate: commitMatch[2] }; + continue; + } + if (currentCommit) { + const normalizedPath = toPosixPath(line.trim()); + if (!commitInfoMap.has(normalizedPath)) { + commitInfoMap.set(normalizedPath, currentCommit); + } + } + } + return commitInfoMap; } catch (error) { - console.error(`Error getting last modified date for ${repoPath}: ${error}`); - return null; + console.error(`Error getting commit info for ports: ${error}`); + return new Map(); } } -async function readPorts(vcpkgDir) { +async function readPorts(vcpkgDir, commitInfoMap) { const portsDir = path.join(vcpkgDir, 'ports'); let dirents = await fs.readdir(portsDir, { encoding: 'utf-8', withFileTypes: true }); @@ -84,7 +98,8 @@ async function readPorts(vcpkgDir) { console.log('Failed to read ' + manifestFile); continue; } - const commitInfo = await getFileCommitInfo(vcpkgDir, manifestFile); + const relativeManifestPath = toPosixPath(path.relative(vcpkgDir, manifestFile)); + const commitInfo = commitInfoMap.get(relativeManifestPath); if (commitInfo){ temp['LastModified'] = commitInfo.lastModifiedDate; @@ -126,7 +141,8 @@ async function main(vcpkgDir, destDir) { const starsFile = path.join(destDir, 'stars.json'); const outputFile = path.join(destDir, 'output.json'); - let portsData = await readPorts(vcpkgDir); + const commitInfoMap = await getPortsCommitInfo(vcpkgDir); + let portsData = await readPorts(vcpkgDir, commitInfoMap); let githubData = await readStars(starsFile); mergeDataSources(portsData, githubData); let mergedData = Object.values(portsData); @@ -146,4 +162,4 @@ if (process.argv.length < 3) { } const vcpkgDir = process.argv[2]; const destDir = path.dirname(__dirname); -main(vcpkgDir, destDir); \ No newline at end of file +main(vcpkgDir, destDir); diff --git a/scripts/rebuild.sh b/scripts/rebuild.sh index 63474f9a6a..301fcba19d 100755 --- a/scripts/rebuild.sh +++ b/scripts/rebuild.sh @@ -16,6 +16,5 @@ rm -rf ../en node generateDocs.js node generateGitHubStars.js ../vcpkg $1 node generatePackages.js ../vcpkg -node generateDetailedPages.js +node generateDetailedPages.js ../vcpkg node validateLinks.js -