Skip to content

Commit

Permalink
feat(type-safe-api): remove wrapper scripts for websocket docs projec…
Browse files Browse the repository at this point in the history
…ts (#861)

Remove the wrappers around the asyncapi documentation generators and instead call them
directly with `npx`.

Remove the wrapper around generating the asyncapi spec and instead add it as a subcommand of the
type-safe-api script to make it much faster.
  • Loading branch information
cogwirrel authored Oct 17, 2024
1 parent a61c700 commit 174a093
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 357 deletions.
9 changes: 0 additions & 9 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions packages/pdk/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions packages/type-safe-api/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ const generateAsyncApiSpec = (openApiSpec: any): any => {
};
};

void (async () => {
export default async (argv: string[]) => {
const args = parse<Arguments>({
specPath: { type: String, alias: "s" },
outputPath: { type: String, alias: "o" },
});
}, { argv });

const openApiSpec = (await SwaggerParser.bundle(args.specPath)) as any;

Expand All @@ -138,4 +138,4 @@ void (async () => {
writeFile(args.outputPath, JSON.stringify(asyncApiSpec, null, 2), {
readonly: true,
});
})();
};
3 changes: 3 additions & 0 deletions packages/type-safe-api/scripts/type-safe-api/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parse } from "ts-command-line-args";
import generateMockData from "./custom/mock-data/generate-mock-data";
import parseOpenapiSpec from "./parser/parse-openapi-spec";
import generate from "./generators/generate-next";
import generateAsyncapiSpec from "./custom/generate-asyncapi-spec/generate-asyncapi-spec";
import * as path from "path";

interface SubCommandArgs {
Expand All @@ -21,6 +22,8 @@ void (async () => {
return await generateMockData(argv);
case "parse-openapi-spec":
return await parseOpenapiSpec(argv);
case "generate-asyncapi-spec":
return await generateAsyncapiSpec(argv);
case "generate":
return await generate(argv, path.resolve(__dirname));
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ export enum TypeSafeApiScript {
GENERATE = "type-safe-api.generate",
GENERATE_NEXT = "type-safe-api generate",
GENERATE_MOCK_DATA = "type-safe-api generate-mock-data",
GENERATE_HTML_REDOC_DOCS = "type-safe-api.generate-html-redoc-docs",
GENERATE_ASYNCAPI_HTML_DOCS = "type-safe-api.generate-asyncapi-html-docs",
GENERATE_ASYNCAPI_MARKDOWN_DOCS = "type-safe-api.generate-asyncapi-markdown-docs",
CLEAN_OPENAPI_GENERATED_CODE = "type-safe-api.clean-openapi-generated-code",
COPY_GRADLE_WRAPPER = "type-safe-api.copy-gradle-wrapper",
COPY_ASYNC_SMITHY_TRANSFORMER = "type-safe-api.copy-async-smithy-transformer",
GENERATE_ASYNCAPI_SPEC = "type-safe-api.generate-asyncapi-spec",
GENERATE_ASYNCAPI_SPEC = "type-safe-api generate-asyncapi-spec",
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ SPDX-License-Identifier: Apache-2.0 */
import { Project, ProjectOptions, Task } from "projen";
import { GeneratedAsyncApiHtmlDocumentationOptions } from "../../types";
import { TypeSafeApiCommandEnvironment } from "../components/type-safe-api-command-environment";
import {
buildTypeSafeApiExecCommand,
TypeSafeApiScript,
} from "../components/utils";

export interface GeneratedAsyncApiHtmlDocumentationProjectOptions
extends ProjectOptions,
Expand All @@ -26,11 +22,9 @@ export class GeneratedAsyncApiHtmlDocumentationProject extends Project {

this.generateTask = this.addTask("generate");
this.generateTask.exec(
buildTypeSafeApiExecCommand(
TypeSafeApiScript.GENERATE_ASYNCAPI_HTML_DOCS,
`--spec-path ${options.specPath} --output-path .`
)
`npx --yes @asyncapi/[email protected] generate fromTemplate "${options.specPath}" @asyncapi/[email protected] --param singleFile=true --param outFilename=index.html --force-write`
);

this.compileTask.spawn(this.generateTask);

if (!options.commitGeneratedCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ SPDX-License-Identifier: Apache-2.0 */
import { Project, ProjectOptions, Task } from "projen";
import { GeneratedAsyncApiMarkdownDocumentationOptions } from "../../types";
import { TypeSafeApiCommandEnvironment } from "../components/type-safe-api-command-environment";
import {
buildTypeSafeApiExecCommand,
TypeSafeApiScript,
} from "../components/utils";

export interface GeneratedAsyncApiMarkdownDocumentationProjectOptions
extends ProjectOptions,
Expand All @@ -26,10 +22,7 @@ export class GeneratedAsyncApiMarkdownDocumentationProject extends Project {

this.generateTask = this.addTask("generate");
this.generateTask.exec(
buildTypeSafeApiExecCommand(
TypeSafeApiScript.GENERATE_ASYNCAPI_MARKDOWN_DOCS,
`--spec-path ${options.specPath} --output-path .`
)
`npx --yes @asyncapi/[email protected] generate fromTemplate "${options.specPath}" @asyncapi/[email protected] --param outFilename=index.md --force-write`
);
this.compileTask.spawn(this.generateTask);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class TypeSafeWebSocketApiModelProject extends TypeSafeApiModelProjectBas
this.generateTask.exec(
buildTypeSafeApiExecCommand(
TypeSafeApiScript.GENERATE_ASYNCAPI_SPEC,
`--spec-path ${this.parsedSpecFile} --output-path ${this.asyncApiSpecFile}`
`--specPath ${this.parsedSpecFile} --outputPath ${this.asyncApiSpecFile}`
)
);

Expand Down
Loading

0 comments on commit 174a093

Please sign in to comment.