Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 72 additions & 12 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apimatic/cli",
"description": "The official CLI for APIMatic.",
"version": "1.1.0-alpha.10",
"version": "1.1.0-alpha.13",
"author": "APIMatic",
"bin": {
"apimatic": "./bin/run.js"
Expand Down Expand Up @@ -44,7 +44,7 @@
"test": "tsx node_modules/mocha/bin/_mocha --forbid-only \"test/**/*.test.ts\" --timeout 99999"
},
"dependencies": {
"@apimatic/sdk": "^0.2.0-alpha.1",
"@apimatic/sdk": "^0.2.0-alpha.2",
"@clack/prompts": "1.0.0-alpha.1",
"@oclif/core": "^4.2.8",
"@oclif/plugin-autocomplete": "^3.2.24",
Expand All @@ -69,6 +69,7 @@
"treeify": "^1.1.0",
"tslib": "^2.8.1",
"unzipper": "^0.12.3",
"which": "^5.0.0",
"yaml": "^2.8.0"
},
"devDependencies": {
Expand All @@ -90,6 +91,7 @@
"@types/sinon": "^17.0.4",
"@types/treeify": "^1.0.3",
"@types/unzipper": "^0.10.4",
"@types/which": "^3.0.4",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"chai": "^4.5.0",
Expand Down
29 changes: 16 additions & 13 deletions src/actions/portal/recipe/new-recipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from "path";
import fs from "fs";
import fsExtra from "fs-extra";
import which from "which";
import { parse } from "yaml";
import { TreeObject } from "treeify";
import { tmpdir } from "os";
Expand Down Expand Up @@ -175,22 +176,24 @@ export class PortalRecipeAction {
stepName: string
): Promise<Result<string, string>> {
this.prompts.displayContentStepInfo();
this.prompts.startProgressIndicatorWithMessage("Waiting for you to close the text editor");
let editor = process.env.EDITOR;
let editorArgs: string[] = [];
const tempFilePath = path.join(tmpdir(), `recipe-markdown-content-${Date.now()}.md`);
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.`;
await fsExtra.writeFile(tempFilePath, template);

try {
const tempFilePath = path.join(tmpdir(), `recipe-markdown-content-${Date.now()}.md`);
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.`;

await fsExtra.writeFile(tempFilePath, template);

if (!editor) {
if (process.platform === "win32") {
await execa("cmd", ["/c", "start", "/wait", "notepad", tempFilePath], { stdio: "ignore" });
} else {
editor = "nano";
await execa(editor, [tempFilePath], { stdio: "ignore" });
} else if (process.platform === "darwin" || process.platform === "linux") {
editor = "vim";
try {
await execa(editor, [tempFilePath], { stdio: "inherit" });
}
catch (error) {
// User exiting vim can throw a non-zero exit code leading to exception, ignore it.
}
}
} else {
if (editor === "code" || editor.endsWith("code.cmd") || editor.endsWith("code.exe")) {
Expand All @@ -200,17 +203,17 @@ export class PortalRecipeAction {
await execa(editor, editorArgs, { stdio: "ignore" });
}

this.prompts.stopProgressIndicatorWithMessage("✅ Text editor closed.");
const fileContent = await fsExtra.readFile(tempFilePath, "utf-8");

await fsExtra.unlink(tempFilePath);

recipe.addContentStep(stepName, stepName, fileContent);

this.prompts.displayStepAddedSuccessfullyMessage();
return Result.success("Added content step successfully.");
} catch (error) {
return Result.failure(`Unable to add content step. Please try again later.`);
}
finally {
await fsExtra.unlink(tempFilePath);
}
}

private async promptUserAndAddEndpointStepToRecipe(
Expand Down
2 changes: 1 addition & 1 deletion src/application/portal/recipe/recipe-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class PortalRecipeGenerator {
recipesConfig.workflows = [];
}
const existingIndex = recipesConfig.workflows.findIndex(
(workflow: any) => workflow.name === recipeName
(workflow: any) => workflow.permalink === `page:recipes/${recipeFileName}`
);

const newWorkflow = {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/api/validate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fsExtra from "fs-extra";

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

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

const apiValidationController: ApiValidationExternalApIsController = new ApiValidationExternalApIsController(
const apiValidationController: ApiValidationExternalApisController = new ApiValidationExternalApisController(
client
);

Expand Down
6 changes: 3 additions & 3 deletions src/commands/portal/quickstart.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from "@oclif/core";
import { ApiValidationExternalApIsController, ApiValidationSummary, Client } from "@apimatic/sdk";
import { ApiValidationExternalApisController, ApiValidationSummary, Client } from "@apimatic/sdk";
import { SDKClient } from "../../client-utils/sdk-client.js";
import { PortalQuickstartPrompts } from "../../prompts/portal/quickstart.js";
import { PortalQuickstartController } from "../../controllers/portal/quickstart.js";
Expand Down Expand Up @@ -28,7 +28,7 @@ export default class PortalQuickstart extends Command {
prompts: PortalQuickstartPrompts,
controller: PortalQuickstartController,
specFile: SpecFile,
apiValidationController: ApiValidationExternalApIsController
apiValidationController: ApiValidationExternalApisController
): Promise<ApiValidationSummary> {
const apiValidationSummary = await controller.getSpecValidationSummary(prompts, specFile, apiValidationController);

Expand Down Expand Up @@ -99,7 +99,7 @@ export default class PortalQuickstart extends Command {
}

const client: Client = await SDKClient.getInstance().getClient(null, this.config.configDir);
const apiValidationController: ApiValidationExternalApIsController = new ApiValidationExternalApIsController(
const apiValidationController: ApiValidationExternalApisController = new ApiValidationExternalApisController(
client
);

Expand Down
4 changes: 2 additions & 2 deletions src/commands/sdk/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fsExtra from "fs-extra";

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/api/validate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fsExtra from "fs-extra";
import { ApiResponse, ApiValidationExternalApIsController, ApiValidationSummary, ContentType, FileWrapper } from "@apimatic/sdk";
import { ApiResponse, ApiValidationExternalApisController, ApiValidationSummary, ContentType, FileWrapper } from "@apimatic/sdk";
import { GetValidationParams } from "../../types/api/validate.js";
import { createTempDirectory, deleteFile, zipDirectory } from "../../utils/utils.js";

export const getValidationSummary = async (
{ file, url }: GetValidationParams,
apiValidationController: ApiValidationExternalApIsController
apiValidationController: ApiValidationExternalApisController
): Promise<ApiValidationSummary> => {
let validation: ApiResponse<ApiValidationSummary>;

Expand Down
Loading