Skip to content

Commit 5eecf75

Browse files
authored
feat: adds user-agent and various other improvements for serve, quickstart and recipe commands (#110)
1 parent 590060d commit 5eecf75

File tree

13 files changed

+133
-56
lines changed

13 files changed

+133
-56
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@apimatic/cli",
33
"description": "The official CLI for APIMatic.",
4-
"version": "1.1.0-alpha.10",
4+
"version": "1.1.0-alpha.13",
55
"author": "APIMatic",
66
"bin": {
77
"apimatic": "./bin/run.js"
@@ -44,7 +44,7 @@
4444
"test": "tsx node_modules/mocha/bin/_mocha --forbid-only \"test/**/*.test.ts\" --timeout 99999"
4545
},
4646
"dependencies": {
47-
"@apimatic/sdk": "^0.2.0-alpha.1",
47+
"@apimatic/sdk": "^0.2.0-alpha.2",
4848
"@clack/prompts": "1.0.0-alpha.1",
4949
"@oclif/core": "^4.2.8",
5050
"@oclif/plugin-autocomplete": "^3.2.24",
@@ -69,6 +69,7 @@
6969
"treeify": "^1.1.0",
7070
"tslib": "^2.8.1",
7171
"unzipper": "^0.12.3",
72+
"which": "^5.0.0",
7273
"yaml": "^2.8.0"
7374
},
7475
"devDependencies": {
@@ -90,6 +91,7 @@
9091
"@types/sinon": "^17.0.4",
9192
"@types/treeify": "^1.0.3",
9293
"@types/unzipper": "^0.10.4",
94+
"@types/which": "^3.0.4",
9395
"@typescript-eslint/eslint-plugin": "^8.0.0",
9496
"@typescript-eslint/parser": "^8.0.0",
9597
"chai": "^4.5.0",

src/actions/portal/recipe/new-recipe.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path";
22
import fs from "fs";
33
import fsExtra from "fs-extra";
4+
import which from "which";
45
import { parse } from "yaml";
56
import { TreeObject } from "treeify";
67
import { tmpdir } from "os";
@@ -175,22 +176,24 @@ export class PortalRecipeAction {
175176
stepName: string
176177
): Promise<Result<string, string>> {
177178
this.prompts.displayContentStepInfo();
178-
this.prompts.startProgressIndicatorWithMessage("Waiting for you to close the text editor");
179179
let editor = process.env.EDITOR;
180180
let editorArgs: string[] = [];
181+
const tempFilePath = path.join(tmpdir(), `recipe-markdown-content-${Date.now()}.md`);
182+
const template = `# The Heading Goes Here\n\nThis is placeholder text for your API Recipe content step. Feel free to edit this. Save your changes and then close the file once you're done.`;
183+
await fsExtra.writeFile(tempFilePath, template);
181184

182185
try {
183-
const tempFilePath = path.join(tmpdir(), `recipe-markdown-content-${Date.now()}.md`);
184-
const template = `# The Heading Goes Here\n\nThis is placeholder text for your API Recipe content step. Feel free to edit this. Save your changes and then close the file once you're done.`;
185-
186-
await fsExtra.writeFile(tempFilePath, template);
187-
188186
if (!editor) {
189187
if (process.platform === "win32") {
190188
await execa("cmd", ["/c", "start", "/wait", "notepad", tempFilePath], { stdio: "ignore" });
191-
} else {
192-
editor = "nano";
193-
await execa(editor, [tempFilePath], { stdio: "ignore" });
189+
} else if (process.platform === "darwin" || process.platform === "linux") {
190+
editor = "vim";
191+
try {
192+
await execa(editor, [tempFilePath], { stdio: "inherit" });
193+
}
194+
catch (error) {
195+
// User exiting vim can throw a non-zero exit code leading to exception, ignore it.
196+
}
194197
}
195198
} else {
196199
if (editor === "code" || editor.endsWith("code.cmd") || editor.endsWith("code.exe")) {
@@ -200,17 +203,17 @@ export class PortalRecipeAction {
200203
await execa(editor, editorArgs, { stdio: "ignore" });
201204
}
202205

203-
this.prompts.stopProgressIndicatorWithMessage("✅ Text editor closed.");
204206
const fileContent = await fsExtra.readFile(tempFilePath, "utf-8");
205-
206-
await fsExtra.unlink(tempFilePath);
207-
208207
recipe.addContentStep(stepName, stepName, fileContent);
208+
209209
this.prompts.displayStepAddedSuccessfullyMessage();
210210
return Result.success("Added content step successfully.");
211211
} catch (error) {
212212
return Result.failure(`Unable to add content step. Please try again later.`);
213213
}
214+
finally {
215+
await fsExtra.unlink(tempFilePath);
216+
}
214217
}
215218

216219
private async promptUserAndAddEndpointStepToRecipe(

src/application/portal/recipe/recipe-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class PortalRecipeGenerator {
8080
recipesConfig.workflows = [];
8181
}
8282
const existingIndex = recipesConfig.workflows.findIndex(
83-
(workflow: any) => workflow.name === recipeName
83+
(workflow: any) => workflow.permalink === `page:recipes/${recipeFileName}`
8484
);
8585

8686
const newWorkflow = {

src/commands/api/validate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fsExtra from "fs-extra";
22

33
import { ux, Flags, Command } from "@oclif/core";
4-
import { ApiError, ApiValidationExternalApIsController, ApiValidationSummary, Client } from "@apimatic/sdk";
4+
import { ApiError, ApiValidationExternalApisController, ApiValidationSummary, Client } from "@apimatic/sdk";
55

66
import { AuthenticationError, loggers } from "../../types/utils.js";
77
import { SDKClient } from "../../client-utils/sdk-client.js";
@@ -42,7 +42,7 @@ Specification file provided is valid
4242
const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
4343
const client: Client = await SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
4444

45-
const apiValidationController: ApiValidationExternalApIsController = new ApiValidationExternalApIsController(
45+
const apiValidationController: ApiValidationExternalApisController = new ApiValidationExternalApisController(
4646
client
4747
);
4848

src/commands/portal/quickstart.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command } from "@oclif/core";
2-
import { ApiValidationExternalApIsController, ApiValidationSummary, Client } from "@apimatic/sdk";
2+
import { ApiValidationExternalApisController, ApiValidationSummary, Client } from "@apimatic/sdk";
33
import { SDKClient } from "../../client-utils/sdk-client.js";
44
import { PortalQuickstartPrompts } from "../../prompts/portal/quickstart.js";
55
import { PortalQuickstartController } from "../../controllers/portal/quickstart.js";
@@ -28,7 +28,7 @@ export default class PortalQuickstart extends Command {
2828
prompts: PortalQuickstartPrompts,
2929
controller: PortalQuickstartController,
3030
specFile: SpecFile,
31-
apiValidationController: ApiValidationExternalApIsController
31+
apiValidationController: ApiValidationExternalApisController
3232
): Promise<ApiValidationSummary> {
3333
const apiValidationSummary = await controller.getSpecValidationSummary(prompts, specFile, apiValidationController);
3434

@@ -99,7 +99,7 @@ export default class PortalQuickstart extends Command {
9999
}
100100

101101
const client: Client = await SDKClient.getInstance().getClient(null, this.config.configDir);
102-
const apiValidationController: ApiValidationExternalApIsController = new ApiValidationExternalApIsController(
102+
const apiValidationController: ApiValidationExternalApisController = new ApiValidationExternalApisController(
103103
client
104104
);
105105

src/commands/sdk/generate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fsExtra from "fs-extra";
33

44
import { Command, Flags } from "@oclif/core";
55
import { SDKClient } from "../../client-utils/sdk-client.js";
6-
import { ApiError, Client, CodeGenerationExternalApIsController } from "@apimatic/sdk";
6+
import { ApiError, Client, CodeGenerationExternalApisController } from "@apimatic/sdk";
77

88
import { replaceHTML, isJSONParsable, getFileNameFromPath } from "../../utils/utils.js";
99
import { getSDKGenerationId, downloadGeneratedSDK } from "../../controllers/sdk/generate.js";
@@ -83,7 +83,7 @@ Success! Your SDK is located at swagger_sdk_csharp
8383

8484
const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
8585
const client: Client = await SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
86-
const sdkGenerationController: CodeGenerationExternalApIsController = new CodeGenerationExternalApIsController(
86+
const sdkGenerationController: CodeGenerationExternalApisController = new CodeGenerationExternalApisController(
8787
client
8888
);
8989

src/controllers/api/validate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fsExtra from "fs-extra";
2-
import { ApiResponse, ApiValidationExternalApIsController, ApiValidationSummary, ContentType, FileWrapper } from "@apimatic/sdk";
2+
import { ApiResponse, ApiValidationExternalApisController, ApiValidationSummary, ContentType, FileWrapper } from "@apimatic/sdk";
33
import { GetValidationParams } from "../../types/api/validate.js";
44
import { createTempDirectory, deleteFile, zipDirectory } from "../../utils/utils.js";
55

66
export const getValidationSummary = async (
77
{ file, url }: GetValidationParams,
8-
apiValidationController: ApiValidationExternalApIsController
8+
apiValidationController: ApiValidationExternalApisController
99
): Promise<ApiValidationSummary> => {
1010
let validation: ApiResponse<ApiValidationSummary>;
1111

0 commit comments

Comments
 (0)