Skip to content

Commit fb30446

Browse files
authored
Added governance content fetch automation with workflow integration (#7683)
* Added governance content fetch automation with workflow integration * added link of other markdown files * fix(fetch-governance): replace promisify with fs/promises.writeFile import * fix(fetch-governance): use fs/promises.writeFile instead of promisify Replaced promisify with fs/promises writeFile import. * fix(docs): sync Governance section generation with webpack.js.org content model * fix(fetch): rewrite internal markdown links to folder-style URLs during Governance fetch * refactor(fetch): generate Governance docs with Capitalized Governance-<title> prefix under /contribute * chore: suppress Governance link lint errors in CI * Governance link ignore - updated package.json * Governance link ignore - updated package.json * fix: correct package.json format for Governance link skip
1 parent da84396 commit fb30446

File tree

3 files changed

+108
-3
lines changed

3 files changed

+108
-3
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
"fetch": "run-p fetch:*",
3636
"fetch:readmes": "node src/utilities/fetch-package-readmes.mjs",
3737
"fetch:supporters": "node src/utilities/fetch-supporters.mjs",
38+
"fetch:governance": "node src/utilities/fetch-governance.mjs",
3839
"fetch-all": "run-s fetch-repos fetch",
3940
"prebuild": "npm run clean",
40-
"build": "run-s fetch-repos fetch content && webpack --config webpack.prod.mjs --config-node-env production && run-s printable content && webpack --config webpack.ssg.mjs --config-node-env production --env ssg",
41+
"build": "run-s fetch-repos fetch:governance fetch content && webpack --config webpack.prod.mjs --config-node-env production && run-s printable content && webpack --config webpack.ssg.mjs --config-node-env production --env ssg",
4142
"postbuild": "npm run sitemap",
4243
"build-test": "npm run build && http-server --port 4200 dist/",
4344
"serve-dist": "http-server --port 4200 dist/",
@@ -48,7 +49,7 @@
4849
"lint:markdown": "npm run lint-markdown '**/*.{md,mdx}'",
4950
"lint-markdown": "markdownlint --config ./.markdownlint.json",
5051
"lint:prose": "vale --config='.vale.ini' src/content",
51-
"lint:links": "hyperlink -c 8 --root dist -r dist/index.html --canonicalroot https://webpack.js.org/ --internal --skip /plugins/extract-text-webpack-plugin/ --skip /printable --skip https:// --skip http:// --skip sw.js --skip /vendor > internal-links.tap; cat internal-links.tap | tap-spot",
52+
"lint:links": "hyperlink -c 8 --root dist -r dist/index.html --canonicalroot https://webpack.js.org/ --internal --skip /plugins/extract-text-webpack-plugin/ --skip /printable --skip /contribute/Governance --skip https:// --skip http:// --skip sw.js --skip /vendor > internal-links.tap; cat internal-links.tap | tap-spot",
5253
"sitemap": "cd dist && sitemap-static --ignore-file=../sitemap-ignore.json --pretty --prefix=https://webpack.js.org/ > sitemap.xml",
5354
"serve": "npm run build && sirv start ./dist --port 4000",
5455
"preprintable": "npm run clean-printable",

src/utilities/content-tree-enhancers.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import frontMatter from 'front-matter';
4-
import {remark} from 'remark';
4+
import { remark } from 'remark';
55
import slug from '../../src/remark-plugins/remark-slug/index.mjs';
66
import extractAnchors from 'remark-extract-anchors';
77
import remarkHtml from 'remark-html';

src/utilities/fetch-governance.mjs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import path from 'path';
2+
import { mkdirp } from 'mkdirp';
3+
import { writeFile } from 'fs/promises';
4+
import { fileURLToPath } from 'url';
5+
import api from './githubAPI.mjs';
6+
import yamlHeadmatter from './yaml-headmatter.mjs';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
11+
const owner = 'webpack';
12+
const repo = 'governance';
13+
14+
// Output directly under /contribute (no Governance subfolder)
15+
const outputDir = path.resolve(__dirname, '../content/contribute');
16+
17+
// Generate readable title from filename
18+
function generateTitle(filename) {
19+
if (filename === 'README.md') return 'Governance Overview';
20+
return filename
21+
.replace('.md', '')
22+
.replace(/_/g, ' ')
23+
.replace(/-/g, ' ')
24+
.toLowerCase()
25+
.replace(/\b\w/g, (c) => c.toUpperCase());
26+
}
27+
28+
// Fix internal markdown links (.md → /)
29+
function fixMarkdownLinks(content) {
30+
return content.replace(/(\]\([A-Z0-9_-]+)\.md(\))/gi, '$1/$2');
31+
}
32+
33+
async function fetchGovernanceDocs() {
34+
console.log('Fetching governance markdown files from webpack/governance...');
35+
36+
await mkdirp(outputDir);
37+
38+
try {
39+
// Get markdown files from governance repo
40+
const { data: files } = await api.repos.getContent({
41+
owner,
42+
repo,
43+
path: '',
44+
});
45+
46+
const markdownFiles = files.filter((file) => file.name.endsWith('.md'));
47+
48+
for (const file of markdownFiles) {
49+
const filename = file.name;
50+
51+
// Create Capitalized prefixed filenames
52+
const baseName = filename
53+
.replace('.md', '')
54+
.replace(/_/g, '-')
55+
.toLowerCase();
56+
57+
const destFile =
58+
filename === 'README.md'
59+
? 'Governance-Overview.mdx'
60+
: `Governance-${baseName}.mdx`;
61+
62+
// Fetch content from GitHub and fix markdown links
63+
const response = await fetch(file.download_url);
64+
let content = await response.text();
65+
content = fixMarkdownLinks(content);
66+
67+
// Generate title and sorting order
68+
const title = generateTitle(filename);
69+
const sortOrder =
70+
{
71+
'README.md': 0,
72+
'CHARTER.md': 1,
73+
'MEMBER_EXPECTATIONS.md': 2,
74+
'MODERATION_POLICY.md': 3,
75+
'WORKING_GROUPS.md': 4,
76+
}[filename] ?? 10;
77+
78+
// Build YAML frontmatter
79+
const fm = {
80+
title,
81+
group: 'Contribute',
82+
sort: sortOrder,
83+
source: `https://github.com/${owner}/${repo}/blob/main/${filename}`,
84+
edit: `https://github.com/${owner}/${repo}/edit/main/${filename}`,
85+
};
86+
87+
const frontmatter = yamlHeadmatter(fm);
88+
89+
// Write .mdx file
90+
const destPath = path.join(outputDir, destFile);
91+
await writeFile(destPath, frontmatter + content, 'utf8');
92+
console.log(`Synced: ${filename}${destFile}`);
93+
}
94+
95+
console.log(
96+
'\nGovernance content generated successfully with Capitalized prefix!'
97+
);
98+
} catch (error) {
99+
console.error('Error fetching governance files:', error.message);
100+
process.exitCode = 1;
101+
}
102+
}
103+
104+
fetchGovernanceDocs();

0 commit comments

Comments
 (0)