Skip to content

Commit 55a5e72

Browse files
authored
Centralize use of __dirname (#1321)
Simplifies the model and ensure abs path data is scoped to only where we read and write files, removing those from template building functions.
1 parent d70ac04 commit 55a5e72

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

tools/gen-agenda.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,29 @@ if (month < 1 || month > 12) {
3737
process.exit(1);
3838
}
3939

40+
// Repository root assuming this script is in a subdirectory.
41+
const repoRoot = path.resolve(__dirname, "../");
42+
43+
// Get JoiningAMeeting contents
44+
const howToJoin = fs
45+
.readFileSync(path.join(repoRoot, "JoiningAMeeting.md"), "utf8")
46+
.split("\n## How to join\n\n")[1];
47+
4048
// For all three meetings in a month, fill and write the template
4149
for (num = 0; num < 3; num++) {
4250
const meeting = getMeeting(year, month, num);
4351
const contents = fillMeetingTemplate(meeting);
4452

45-
// Create missing directories recursively
46-
fs.mkdirSync(path.dirname(meeting.filePath), { recursive: true });
47-
48-
// Write file
49-
fs.writeFileSync(meeting.filePath, contents);
50-
51-
console.log(`Wrote file: ${meeting.repoPath}`);
53+
// Create missing directories recursively and write file.
54+
const absPath = path.join(repoRoot, meeting.filePath);
55+
fs.mkdirSync(path.dirname(absPath), { recursive: true });
56+
fs.writeFileSync(absPath, contents);
57+
console.log(`Wrote file: ${meeting.filePath}`);
5258
}
5359

5460
// --------------------------------------------------------------------------
5561

5662
function fillMeetingTemplate(meeting) {
57-
// Get JoiningAMeeting contents
58-
const howToJoin = fs
59-
.readFileSync(path.resolve(__dirname, "../JoiningAMeeting.md"), "utf8")
60-
.split("\n## How to join\n\n")[1];
61-
6263
const prior1Meeting = getPriorMeeting(meeting);
6364
const prior2Meeting = getPriorMeeting(prior1Meeting);
6465

@@ -206,10 +207,8 @@ function getMeeting(year, month, num) {
206207
});
207208

208209
const fileName = ["wg-primary", "wg-secondary-apac", "wg-secondary-eu"][num];
209-
const repoPath = `agendas/${year}/${month2D}-${monthShort}/${day2D}-${fileName}.md`;
210-
211-
const filePath = path.resolve(__dirname, "../", repoPath);
212-
const url = `https://github.com/graphql/graphql-wg/blob/main/${repoPath}`;
210+
const filePath = `agendas/${year}/${month2D}-${monthShort}/${day2D}-${fileName}.md`;
211+
const url = `https://github.com/graphql/graphql-wg/blob/main/${filePath}`;
213212

214213
return {
215214
num,
@@ -220,7 +219,6 @@ function getMeeting(year, month, num) {
220219
monthName,
221220
dateTimeRange,
222221
timeLink,
223-
repoPath,
224222
filePath,
225223
url,
226224
};

0 commit comments

Comments
 (0)