Skip to content

Commit abd9ef2

Browse files
committed
Added governance content fetch automation with workflow integration
1 parent b48ccc6 commit abd9ef2

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
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
"prebuild": "npm run clean",
39-
"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",
40+
"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",
4041
"postbuild": "npm run sitemap",
4142
"build-test": "npm run build && http-server --port 4200 dist/",
4243
"serve-dist": "http-server --port 4200 dist/",

src/utilities/fetch-governance.mjs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { mkdirp } from 'mkdirp';
4+
import { promisify } from 'util';
5+
import { fileURLToPath } from 'url';
6+
import api from './githubAPI.mjs';
7+
import yamlHeadmatter from './yaml-headmatter.mjs';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = path.dirname(__filename);
11+
12+
const writeFile = promisify(fs.writeFile);
13+
14+
const owner = 'webpack';
15+
const repo = 'governance';
16+
17+
// Local output directory inside webpack.js.org
18+
const outputDir = path.resolve(__dirname, '../content/contribute/governance');
19+
20+
// Map source files to destination filenames
21+
const fileMap = {
22+
'README.md': 'index.mdx',
23+
'CHARTER.md': 'charter.mdx',
24+
'MEMBER_EXPECTATIONS.md': 'member-expectations.mdx',
25+
'MODERATION_POLICY.md': 'moderation-policy.mdx',
26+
'WORKING_GROUPS.md': 'working-groups.mdx',
27+
};
28+
29+
// Generate frontmatter titles automatically
30+
function generateTitle(filename) {
31+
if (filename === 'README.md') return 'Governance Overview';
32+
return filename
33+
.replace('.md', '')
34+
.replace(/_/g, ' ')
35+
.replace(/-/g, ' ')
36+
.toLowerCase()
37+
.replace(/\b\w/g, (c) => c.toUpperCase());
38+
}
39+
40+
async function fetchGovernanceDocs() {
41+
console.log(
42+
'📦 Fetching governance markdown files from webpack/governance...\n'
43+
);
44+
45+
await mkdirp(outputDir);
46+
47+
try {
48+
// Get list of files in the governance repo
49+
const { data: files } = await api.repos.getContent({
50+
owner,
51+
repo,
52+
path: '',
53+
});
54+
55+
// Filter markdown files
56+
const markdownFiles = files.filter((file) => file.name.endsWith('.md'));
57+
58+
for (const file of markdownFiles) {
59+
const filename = file.name;
60+
const destFile = fileMap[filename];
61+
62+
if (!destFile) {
63+
console.log(`Skipping ${filename} — not mapped`);
64+
continue;
65+
}
66+
67+
const rawUrl = file.download_url;
68+
const response = await fetch(rawUrl);
69+
const content = await response.text();
70+
71+
// Add YAML frontmatter
72+
const title = generateTitle(filename);
73+
const frontmatter = yamlHeadmatter({
74+
title,
75+
source: `https://github.com/${owner}/${repo}/blob/main/${filename}`,
76+
edit: `https://github.com/${owner}/${repo}/edit/main/${filename}`,
77+
});
78+
79+
const finalContent = frontmatter + content;
80+
81+
const destPath = path.join(outputDir, destFile);
82+
await writeFile(destPath, finalContent, 'utf8');
83+
84+
console.log(
85+
`Synced: ${filename}${path.relative(process.cwd(), destPath)}`
86+
);
87+
}
88+
89+
console.log('\n Governance content successfully synced!');
90+
} catch (error) {
91+
console.error('Error fetching governance files:', error.message);
92+
process.exitCode = 1;
93+
}
94+
}
95+
96+
fetchGovernanceDocs();

0 commit comments

Comments
 (0)