Skip to content

Commit 49b403c

Browse files
authored
fix: quickstart fails for zipped specs (#107)
1 parent 8f1d265 commit 49b403c

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/controllers/portal/quickstart.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import filetype from "file-type";
55
import fs from "fs";
66
import fsExtra from "fs-extra";
7+
import { readdir } from "fs/promises";
78
import { getAuthInfo } from "../../client-utils/auth-manager.js";
89
import { ApiError, ApiValidationExternalApIsController, ApiValidationSummary } from "@apimatic/sdk";
910
import { LoginCredentials, SpecFile } from "../../types/portal/quickstart.js";
@@ -114,19 +115,18 @@ export class PortalQuickstartController {
114115
} else {
115116
specPath = path.normalize(specPath);
116117
const fileType = await filetype.fromFile(specPath);
118+
filePath = tempSpecDir;
117119

118120
if (fileType?.ext === "zip") {
119-
filePath = tempSpecDir;
120121
await unzipFile(fs.createReadStream(specPath), tempSpecDir);
121122
} else {
122123
const destinationPath = path.join(tempSpecDir, path.basename(specPath));
123-
filePath = destinationPath;
124124
await fsExtra.copy(specPath, destinationPath);
125125
}
126126
}
127127
}
128128

129-
return { filePath, url: this.specUrl };
129+
return { localPath: filePath, url: this.specUrl };
130130
}
131131

132132
async getSpecValidationSummary(
@@ -135,7 +135,7 @@ export class PortalQuickstartController {
135135
apiValidationController: ApiValidationExternalApIsController
136136
): Promise<ApiValidationSummary> {
137137
const validationFlags: GetValidationParams = {
138-
file: specFile.filePath,
138+
file: specFile.localPath,
139139
url: specFile.url
140140
};
141141

@@ -248,9 +248,16 @@ export class PortalQuickstartController {
248248
await clearDirectory(path.join(targetFolder, ".git"));
249249
await clearDirectory(path.join(targetFolder, ".github"));
250250

251-
if (specFile.filePath && validationSummary.success) {
252-
await deleteFile(path.join(targetFolder, "spec", "Apimatic-Calculator.json"));
253-
fsExtra.copy(specFile.filePath, path.join(targetFolder, "spec", path.basename(specFile.filePath)));
251+
if (specFile.localPath && validationSummary.success) {
252+
const specFolder = path.join(targetFolder, "spec");
253+
await deleteFile(path.join(specFolder, "Apimatic-Calculator.json"));
254+
255+
const files = await readdir(specFile.localPath);
256+
for (const file of files) {
257+
const srcPath = path.join(specFile.localPath, file);
258+
const destPath = path.join(specFolder, file);
259+
await fsExtra.copy(srcPath, destPath);
260+
}
254261
}
255262

256263
const buildFilePath = path.join(targetFolder, "APIMATIC-BUILD.json");

src/controllers/portal/serve.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ export const generatePortal = async (
111111
generateZipFile: false
112112
};
113113

114-
await downloadDocsPortal(generatePortalParams, configDir);
114+
const generatedDocsResult = await downloadDocsPortal(generatePortalParams, configDir);
115+
if (generatedDocsResult.isFailed()) {
116+
throw new Error(generatedDocsResult.error);
117+
}
115118
};
116119

117120
async function handleFileChange(

src/types/portal/quickstart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type LoginCredentials = {
44
}
55

66
export type SpecFile = {
7-
filePath: string;
7+
localPath: string;
88
url: string;
99
}
1010

0 commit comments

Comments
 (0)