Skip to content

Commit 806000a

Browse files
committed
build: use openapi-typescript provided function to convert AST to string
1 parent c5cfcaa commit 806000a

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"openapi-typescript": "^7.0.0-next.0",
3232
"prettier": "^3.0.0",
3333
"semantic-release": "^22.0.0",
34-
"semantic-release-plugin-update-version-in-files": "^1.1.0",
35-
"typescript": "^5.2.2"
34+
"semantic-release-plugin-update-version-in-files": "^1.1.0"
3635
},
3736
"engines": {
3837
"node": ">=16"

scripts/generate-types.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { readdir, mkdir, rm, writeFile, copyFile } from "node:fs/promises";
22
import { basename } from "node:path";
33

44
import * as prettier from "prettier";
5-
import openapiTS from "openapi-typescript";
6-
import { pathToFileURL } from "node:url"
7-
import ts from "typescript";
5+
import openapiTS, { astToString } from "openapi-typescript";
6+
import { pathToFileURL } from "node:url";
87

98
/* (!process.env.OCTOKIT_OPENAPI_VERSION) {
109
throw new Error("OCTOKIT_OPENAPI_VERSION is not set");
@@ -86,21 +85,14 @@ type Repository = components["schemas"]["full-repository"]
8685

8786
await copyFile("LICENSE", `packages/${packageName}/LICENSE`);
8887

89-
const generated = await openapiTS(pathToFileURL(`packages/openapi-webhooks/generated/${name}.json`));
90-
const sourceFile = ts.createSourceFile(
91-
'placeholder.ts',
92-
'',
93-
ts.ScriptTarget.ESNext,
94-
true,
95-
ts.ScriptKind.TS
96-
)
97-
const printer = ts.createPrinter()
98-
99-
const outputFile = printer.printList(ts.ListFormat.MultiLine, generated, sourceFile)
10088
await writeFile(
10189
`packages/${packageName}/types.d.ts`,
10290
await prettier.format(
103-
outputFile,
91+
astToString(
92+
await openapiTS(
93+
pathToFileURL(`packages/openapi-webhooks/generated/${name}.json`),
94+
),
95+
),
10496
{
10597
parser: "typescript",
10698
},

0 commit comments

Comments
 (0)