Skip to content

Commit 7f81cb1

Browse files
committed
update script to add app_events jsdocs to discourse code
1 parent 9a1b94d commit 7f81cb1

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

scripts/add_app_events_docs_to_discourse.mjs

+25-16
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,43 @@ function updateFileWithAppEventDocs(filePath, appEventsDetails) {
1414
appEventsDetails.forEach((details) => {
1515
const { lineNumber } = details;
1616
// lines is 0-indexed while lineNumber refers to file line number which is 1-indexed
17-
const startPos = lineNumber - 1;
18-
const indentation = lines[startPos].length - lines[startPos].trimStart().length;
17+
const startPos = lineNumber - 1;
18+
const indentation =
19+
lines[startPos].length - lines[startPos].trimStart().length;
1920
const docString = createDocumentation(details, indentation); // TODO: this should be a separate script
2021
lines.splice(startPos, 0, docString);
2122
});
2223

23-
fs.writeFileSync(filePath, lines.join('\n'), 'utf8');
24+
fs.writeFileSync(filePath, lines.join("\n"), "utf8");
2425
}
2526

26-
function createDocumentation(details, indentation=0) {
27-
const { eventId, args, comments } = details;
28-
if (!eventId && !comments && args.length === 0) { return null; }
27+
function createDocumentation(details, indentation = 0) {
28+
const { eventId, args, description } = details;
29+
if (!eventId && !description && args.length === 0) {
30+
return null;
31+
}
2932

3033
const createArgDoc = (arg) => {
3134
const argTemplate = (argName, argType, argDesc) => {
3235
const templatedDesc = argDesc ? ` - ${argDesc}` : "";
3336
return ` * @arg {${argType}} ${argName}${templatedDesc}`;
3437
};
3538

36-
if (arg.argType === 'object') {
39+
if (arg.argType === "object") {
3740
const objectArgName = `objectArg${arg.argPosition}`;
3841
const initialObjDoc = ` * @arg {object} ${objectArgName}`;
3942
return [
4043
initialObjDoc,
4144
...arg.argValue
42-
.map((nestedArg) => argTemplate(`${objectArgName}.${nestedArg.key}`, nestedArg.valueType, nestedArg.description))
43-
.map((part) => `${' '.repeat(indentation)}${part}`)
44-
].join('\n');
45+
.map((nestedArg) =>
46+
argTemplate(
47+
`${objectArgName}.${nestedArg.key}`,
48+
nestedArg.valueType,
49+
nestedArg.description
50+
)
51+
)
52+
.map((part) => `${" ".repeat(indentation)}${part}`),
53+
].join("\n");
4554
}
4655

4756
return argTemplate(arg.argValue, arg.argType, arg.description);
@@ -50,19 +59,20 @@ function createDocumentation(details, indentation=0) {
5059
const argsStrings = args
5160
.sort((a, b) => a.argPosition - b.argPosition)
5261
.map((arg) => createArgDoc(arg));
62+
const descString = description ? ` * ${description}\n *` : ` *`;
5363

5464
return [
5565
`/**`,
5666
` * ${eventId} appEvent`,
57-
` *`,
67+
descString,
5868
` * @event ${eventId}`,
5969
...argsStrings,
60-
` */`
61-
].map((part) => `${' '.repeat(indentation)}${part}`)
62-
.join('\n');
70+
` */`,
71+
]
72+
.map((part) => `${" ".repeat(indentation)}${part}`)
73+
.join("\n");
6374
}
6475

65-
6676
(async () => {
6777
if (process.argv.length != 2) {
6878
console.log(
@@ -71,7 +81,6 @@ function createDocumentation(details, indentation=0) {
7181
process.exit(1);
7282
}
7383

74-
7584
const appEventsDetailsFilePath = path.join(
7685
".",
7786
"lib",

0 commit comments

Comments
 (0)