Skip to content

Commit

Permalink
feat(code-gen/experimental): generate type docs strings as JSDoc blocks
Browse files Browse the repository at this point in the history
This improves usage of tags like `@deprecated` on fields on `@link` tags to link to routes and other types.
  • Loading branch information
dirkdev98 committed May 5, 2023
1 parent 53f03cd commit a94ee51
Show file tree
Hide file tree
Showing 13 changed files with 492 additions and 187 deletions.
6 changes: 5 additions & 1 deletion packages/code-gen/src/experimental/api-client/react-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
fileContextRemoveLinePrefix,
fileContextSetIndent,
} from "../file/context.js";
import { fileFormatInlineComment } from "../file/format.js";
import { fileFormatInlineComment } from "../file/docs.js";
import { fileWrite, fileWriteInline } from "../file/write.js";
import { referenceUtilsGetProperty } from "../processors/reference-utils.js";
import { structureResolveReference } from "../processors/structure.js";
Expand Down Expand Up @@ -497,6 +497,7 @@ export function reactQueryGenerateFunction(
${parameterListWithExtraction({
prefix: "opts",
withRequestConfig: true,
defaultToNull: false,
})}
);
}, options);`,
Expand Down Expand Up @@ -550,6 +551,7 @@ ${hookName}.queryKey = (
${parameterListWithExtraction({
prefix: "opts",
withRequestConfig: true,
defaultToNull: false,
})}
));
}
Expand All @@ -572,6 +574,7 @@ ${hookName}.queryKey = (
${parameterListWithExtraction({
prefix: "opts",
withRequestConfig: true,
defaultToNull: false,
})}
));
}
Expand Down Expand Up @@ -675,6 +678,7 @@ ${hookName}.setQueryData = (
${parameterListWithExtraction({
prefix: "variables",
withRequestConfig: true,
defaultToNull: false,
})}
), options);
`,
Expand Down
2 changes: 1 addition & 1 deletion packages/code-gen/src/experimental/crud/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
fileContextRemoveLinePrefix,
fileContextSetIndent,
} from "../file/context.js";
import { fileFormatInlineComment } from "../file/format.js";
import { fileFormatInlineComment } from "../file/docs.js";
import { fileWrite } from "../file/write.js";
import {
crudInformationGetHasCustomReadableType,
Expand Down
2 changes: 1 addition & 1 deletion packages/code-gen/src/experimental/database/js-postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
fileContextRemoveLinePrefix,
fileContextSetIndent,
} from "../file/context.js";
import { fileFormatInlineComment } from "../file/format.js";
import { fileFormatInlineComment } from "../file/docs.js";
import { fileWrite, fileWriteInline } from "../file/write.js";
import { modelKeyGetPrimary } from "../processors/model-keys.js";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/code-gen/src/experimental/database/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
fileContextCreateGeneric,
fileContextSetIndent,
} from "../file/context.js";
import { fileFormatInlineComment } from "../file/format.js";
import { fileFormatInlineComment } from "../file/docs.js";
import { fileWrite, fileWriteInline } from "../file/write.js";
import {
modelKeyGetPrimary,
Expand Down
2 changes: 1 addition & 1 deletion packages/code-gen/src/experimental/file/context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppError } from "@compas/stdlib";
import { fileFormatInlineComment } from "./format.js";
import { fileFormatInlineComment } from "./docs.js";
import {
fileImportsAddPlaceholder,
fileImportsStringifyImports,
Expand Down
24 changes: 24 additions & 0 deletions packages/code-gen/src/experimental/file/docs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Format the provided contents as an inline comment for the specific file.
*
* @param {import("./context").GenerateFile} file
* @param {string} contents
* @returns {string}
*/
export function fileFormatInlineComment(
file: import("./context").GenerateFile,
contents: string,
): string;
/**
* Format the provided contents as a doc block comment. Compatible with things like JSDoc
* blocks.
*
* @param {import("./context").GenerateFile} file
* @param {string} contents
* @returns {void}
*/
export function fileWriteDocBlock(
file: import("./context").GenerateFile,
contents: string,
): void;
//# sourceMappingURL=docs.d.ts.map
36 changes: 36 additions & 0 deletions packages/code-gen/src/experimental/file/docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
fileContextAddLinePrefix,
fileContextRemoveLinePrefix,
} from "./context.js";
import { fileWrite } from "./write.js";

/**
* Format the provided contents as an inline comment for the specific file.
*
* @param {import("./context").GenerateFile} file
* @param {string} contents
* @returns {string}
*/
export function fileFormatInlineComment(file, contents) {
return `${file.inlineCommentPrefix}${contents.replace(
/\n/g,
`\n${file.inlineCommentPrefix}`,
)}`;
}

/**
* Format the provided contents as a doc block comment. Compatible with things like JSDoc
* blocks.
*
* @param {import("./context").GenerateFile} file
* @param {string} contents
* @returns {void}
*/
export function fileWriteDocBlock(file, contents) {
fileWrite(file, `/**`);
fileContextAddLinePrefix(file, " * ");
fileWrite(file, contents);

fileContextRemoveLinePrefix(file, 3);
fileWrite(file, " */");
}
16 changes: 0 additions & 16 deletions packages/code-gen/src/experimental/file/format.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/code-gen/src/experimental/file/format.js

This file was deleted.

Loading

0 comments on commit a94ee51

Please sign in to comment.