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
21 changes: 14 additions & 7 deletions src/controllers/portal/quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from "path";
import filetype from "file-type";
import fs from "fs";
import fsExtra from "fs-extra";
import { readdir } from "fs/promises";
import { getAuthInfo } from "../../client-utils/auth-manager.js";
import { ApiError, ApiValidationExternalApIsController, ApiValidationSummary } from "@apimatic/sdk";
import { LoginCredentials, SpecFile } from "../../types/portal/quickstart.js";
Expand Down Expand Up @@ -114,19 +115,18 @@ export class PortalQuickstartController {
} else {
specPath = path.normalize(specPath);
const fileType = await filetype.fromFile(specPath);
filePath = tempSpecDir;

if (fileType?.ext === "zip") {
filePath = tempSpecDir;
await unzipFile(fs.createReadStream(specPath), tempSpecDir);
} else {
const destinationPath = path.join(tempSpecDir, path.basename(specPath));
filePath = destinationPath;
await fsExtra.copy(specPath, destinationPath);
}
}
}

return { filePath, url: this.specUrl };
return { localPath: filePath, url: this.specUrl };
}

async getSpecValidationSummary(
Expand All @@ -135,7 +135,7 @@ export class PortalQuickstartController {
apiValidationController: ApiValidationExternalApIsController
): Promise<ApiValidationSummary> {
const validationFlags: GetValidationParams = {
file: specFile.filePath,
file: specFile.localPath,
url: specFile.url
};

Expand Down Expand Up @@ -248,9 +248,16 @@ export class PortalQuickstartController {
await clearDirectory(path.join(targetFolder, ".git"));
await clearDirectory(path.join(targetFolder, ".github"));

if (specFile.filePath && validationSummary.success) {
await deleteFile(path.join(targetFolder, "spec", "Apimatic-Calculator.json"));
fsExtra.copy(specFile.filePath, path.join(targetFolder, "spec", path.basename(specFile.filePath)));
if (specFile.localPath && validationSummary.success) {
const specFolder = path.join(targetFolder, "spec");
await deleteFile(path.join(specFolder, "Apimatic-Calculator.json"));

const files = await readdir(specFile.localPath);
for (const file of files) {
const srcPath = path.join(specFile.localPath, file);
const destPath = path.join(specFolder, file);
await fsExtra.copy(srcPath, destPath);
}
}

const buildFilePath = path.join(targetFolder, "APIMATIC-BUILD.json");
Expand Down
5 changes: 4 additions & 1 deletion src/controllers/portal/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export const generatePortal = async (
generateZipFile: false
};

await downloadDocsPortal(generatePortalParams, configDir);
const generatedDocsResult = await downloadDocsPortal(generatePortalParams, configDir);
if (generatedDocsResult.isFailed()) {
throw new Error(generatedDocsResult.error);
}
};

async function handleFileChange(
Expand Down
2 changes: 1 addition & 1 deletion src/types/portal/quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type LoginCredentials = {
}

export type SpecFile = {
filePath: string;
localPath: string;
url: string;
}

Expand Down