Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions scripts/generateDetailedPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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}/`;

Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
};
Expand All @@ -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 <vcpkg-root>");
process.exit(1);
}

main();
const vcpkgDir = process.argv[2];
main(vcpkgDir);
52 changes: 34 additions & 18 deletions scripts/generatePackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -146,4 +162,4 @@ if (process.argv.length < 3) {
}
const vcpkgDir = process.argv[2];
const destDir = path.dirname(__dirname);
main(vcpkgDir, destDir);
main(vcpkgDir, destDir);
3 changes: 1 addition & 2 deletions scripts/rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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