Skip to content

Commit c734c33

Browse files
committed
build: fold update-known-events into generate-types script
1 parent 23b2d8e commit c734c33

File tree

6 files changed

+119
-122
lines changed

6 files changed

+119
-122
lines changed

README.md

Lines changed: 59 additions & 51 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@
3636
"proxyquire": "^2.0.0",
3737
"semantic-release": "^17.0.0",
3838
"simple-mock": "^0.8.0",
39-
"table-builder": "^2.1.1",
4039
"ts-jest": "^26.2.0",
4140
"ts-node": "^9.1.1",
4241
"typescript": "^4.0.2"
4342
},
4443
"scripts": {
4544
"build": "pika build",
4645
"coverage": "jest --coverage && open coverage/lcov-report/index.html",
47-
"update-known-events": "node scripts/update-known-events.js",
4846
"lint": "prettier --check 'src/**/*.{ts,json}' 'scripts/**/*' 'test/**/*' README.md package.json",
4947
"lint:fix": "prettier --write 'src/**/*.{ts,json}' 'scripts/**/*' 'test/**/*' README.md package.json",
5048
"pretest": "npm run -s lint",

scripts/generate-file.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/generate-types.ts

100644100755
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,64 @@ const generateTypeScriptFile = (name: string, contents: string[]) => {
113113
);
114114
};
115115

116+
const asCode = (str: string): string => `\`${str}\``;
117+
const asLink = (event: string): string => {
118+
const link = `https://developer.github.com/v3/activity/events/types/#${event.replace(
119+
/[^a-z]/g,
120+
""
121+
)}event`;
122+
123+
return `[${asCode(event)}](${link})`;
124+
};
125+
126+
const updateReadme = (properties: string[]) => {
127+
const headers = "| Event | Actions |";
128+
129+
const events = properties
130+
.filter((property) => property !== "*" && property !== "error")
131+
.reduce<Record<string, string[]>>((events, property) => {
132+
console.log(property);
133+
const [event, action] = property.split(".");
134+
135+
events[event] ||= [];
136+
137+
if (action) {
138+
events[event].push(action);
139+
}
140+
141+
return events;
142+
}, {});
143+
144+
const rows = Object.entries(events).map(
145+
([event, actions]) =>
146+
`| ${asLink(event)} | ${actions.map(asCode).join("<br>")} |`
147+
);
148+
149+
const table = format([headers, "| --- | --- |", ...rows].join("\n"), {
150+
parser: "markdown",
151+
});
152+
153+
const readme = fs.readFileSync("README.md", "utf-8");
154+
155+
const TableStartString =
156+
"<!-- autogenerated via scripts/generate-types.ts -->";
157+
const TableEndString =
158+
"<!-- /autogenerated via scripts/generate-types.ts -->";
159+
const tableStartIndex = readme.indexOf(TableStartString);
160+
const tableEndIndex = readme.indexOf(TableEndString);
161+
162+
assert.ok(tableStartIndex !== -1, "cannot find start of table");
163+
assert.ok(tableEndIndex !== -1, "cannot find end of table");
164+
165+
fs.writeFileSync(
166+
"README.md",
167+
`${readme.slice(
168+
0,
169+
tableStartIndex + TableStartString.length
170+
)}\n\n${table}\n${readme.slice(tableEndIndex)}`
171+
);
172+
};
173+
116174
const run = () => {
117175
const [imports, properties] = getImportsAndProperties();
118176

@@ -140,6 +198,8 @@ const run = () => {
140198
...properties.map(([key]) => `"${key}",`),
141199
"];",
142200
]);
201+
202+
updateReadme(properties.map(([key]) => key));
143203
};
144204

145205
run();

scripts/update-known-events.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)