Skip to content
Merged
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $ npm install -g @apimatic/cli
$ apimatic COMMAND
running command...
$ apimatic (--version)
@apimatic/cli/1.1.0-alpha.16 win32-x64 node-v20.18.3
@apimatic/cli/1.1.0-alpha.19 win32-x64 node-v20.18.3
$ apimatic --help [COMMAND]
USAGE
$ apimatic COMMAND
Expand Down Expand Up @@ -210,7 +210,7 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/main/s

## `apimatic portal:copilot`

Adds the API Copilot configuration in APIMATIC-BUILD.json
Configure API Copilot for your API Documentation portal

```
USAGE
Expand Down Expand Up @@ -316,12 +316,10 @@ Generate and deploy a Docs as Code portal with hot reload.

```
USAGE
$ apimatic portal:serve [-p <value>] [-i <value>] [-d <value>] [-o] [--no-reload] [-i <value>] [-k <value>]
$ apimatic portal:serve [-p <value>] [-i <value>] [-d <value>] [-o] [--no-reload] [-k <value>]

FLAGS
-d, --destination=<value> [default: <input>/portal] path where the portal will be generated.
-i, --ignore=<value> Comma-separated list of file and directory paths to exclude from portal generation and hot
reload.
-i, --input=<value> [default: ./] path to the parent directory containing the 'src' directory, which includes
API specifications and configuration files.
-k, --auth-key=<value> override current authentication state with an authentication key.
Expand Down
37 changes: 14 additions & 23 deletions package-lock.json

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

10 changes: 4 additions & 6 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.16",
"version": "1.1.0-alpha.19",
"author": "APIMatic",
"bin": {
"apimatic": "./bin/run.js"
Expand Down Expand Up @@ -50,7 +50,6 @@
"@oclif/plugin-autocomplete": "^3.2.24",
"@oclif/plugin-help": "^6.2.26",
"@oclif/plugin-not-found": "^3.2.44",
"adm-zip": "^0.5.14",
"archiver": "^7.0.1",
"async-mutex": "^0.5.0",
"axios": "^1.8.1",
Expand Down Expand Up @@ -80,14 +79,13 @@
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"@oclif/test": "^4.1.13",
"@types/adm-zip": "^0.5.5",
"@types/archiver": "^5.1.1",
"@types/base-64": "^1.0.0",
"@types/chai": "^4.3.20",
"@types/connect-livereload": "^0.5.1",
"@types/express": "^4.17.13",
"@types/connect-livereload": "^0.5.32",
"@types/express": "^4.17.23",
"@types/fs-extra": "^9.0.13",
"@types/livereload": "^0.9.2",
"@types/livereload": "^0.9.5",
"@types/mocha": "^5.2.7",
"@types/mock-fs": "^4.13.4",
"@types/node": "^20.17.50",
Expand Down
8 changes: 2 additions & 6 deletions src/actions/portal/recipe/new-recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class PortalRecipeAction {
let editorArgs: string[] = [];
const tempFilePath = path.join(tmpdir(), `recipe-markdown-content-${Date.now()}.txt`);
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, 'utf-8');
await fsExtra.writeFile(tempFilePath, template, "utf-8");

try {
if (!editor) {
Expand Down Expand Up @@ -301,11 +301,7 @@ export class PortalRecipeAction {
"Extracting endpoint groups and endpoints from the API specification."
);

const endpointGroupsResult = await this.sdlParser.getEndpointGroupsFromSdl(
specFolderPath,
contentFolderPath,
configDir
);
const endpointGroupsResult = await this.sdlParser.getEndpointGroupsFromSdl(specFolderPath, configDir);

if (endpointGroupsResult.isFailed()) {
this.prompts.stopProgressIndicatorWithMessage("Unable to extract endpoints from your API specification.");
Expand Down
22 changes: 2 additions & 20 deletions src/actions/portal/serve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from "path";
import { PortalServePrompts } from "../../prompts/portal/serve.js";
import { ServeFlags, ServePaths } from "../../types/portal/serve.js";
import { ServeHandler } from "../../application/portal/serve/serve-handler.js";
Expand All @@ -11,8 +10,6 @@ export class PortalServeAction {
protected readonly prompts: PortalServePrompts;
protected readonly serveHandler: ServeHandler;
protected readonly docsPortalService: PortalService;
private readonly GENERATED_PORTAL_ARTIFACTS_ZIP_FILENAME = ".generated_portal.zip";
private readonly GENERATED_BUILD_INPUT_ZIP_FILENAME = ".portal_source.zip";

public constructor(prompts: PortalServePrompts, serveHandler: ServeHandler, docsPortalService: PortalService) {
this.prompts = prompts;
Expand All @@ -30,15 +27,10 @@ export class PortalServeAction {
zipPortal: boolean
) => Promise<ActionResult>
): Promise<Result<string, string>> {
const ignoredPaths = [
...flags.ignore.split(",").map((path) => path.trim()),
...this.getGeneratedFilesPaths(paths.sourceDirectoryPath, paths.destinationDirectoryPath)
];

const result = await generatePortal(
new DirectoryPath(paths.sourceDirectoryPath),
new DirectoryPath(paths.destinationDirectoryPath),
true,
false,
false
);

Expand All @@ -49,7 +41,7 @@ export class PortalServeAction {
return Result.failure(setupServerResult.error!);
}

const startServerResult = await this.serveHandler.startServer(paths, flags, ignoredPaths, generatePortal);
const startServerResult = await this.serveHandler.startServer(paths, flags, generatePortal);
if (startServerResult.isFailed()) {
return Result.failure(startServerResult.error!);
}
Expand All @@ -59,14 +51,4 @@ export class PortalServeAction {
async (message) => Result.failure(message)
);
}

private getGeneratedFilesPaths(sourceDirectoryPath: string, generatedPortalArtifactsDirectoryPath: string): string[] {
const generatedBuildInputZipPath = path.join(sourceDirectoryPath, this.GENERATED_BUILD_INPUT_ZIP_FILENAME);
const generatedPortalArtifactsZipFilePath = path.join(
sourceDirectoryPath,
this.GENERATED_PORTAL_ARTIFACTS_ZIP_FILENAME
);

return [generatedBuildInputZipPath, generatedPortalArtifactsZipFilePath, generatedPortalArtifactsDirectoryPath];
}
}
2 changes: 1 addition & 1 deletion src/actions/portal/toc/new-toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class PortalNewTocAction {
return { endpointGroups: new Map(), models: [] };
}

const sdlResult = await this.sdlParser.getTocComponentsFromSdl(specFolderPath, buildDirectory, configDir);
const sdlResult = await this.sdlParser.getTocComponentsFromSdl(specFolderPath, configDir);

if (!sdlResult.isSuccess()) {
this.prompts.stopProgressIndicatorWithMessage(`⚠️ ${sdlResult.error!}`);
Expand Down
9 changes: 1 addition & 8 deletions src/application/portal/serve/portal-watcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from "path";
import chokidar from "chokidar";
import crypto from "crypto";
import console from "console";
Expand All @@ -17,22 +16,16 @@ export class PortalWatcher {

public async watchAndRegeneratePortalOnChange(
paths: ServePaths,
ignoredPaths: string[],
generatePortal: (
buildDirectory: DirectoryPath,
portalDirectory: DirectoryPath,
force: boolean,
zipPortal: boolean
) => Promise<ActionResult>
) {
// Convert ignoredPaths to absolute paths for consistent comparison
const absoluteIgnoredPaths = [...ignoredPaths.filter((ignoredPath) => ignoredPath.trim() !== "")].map(
(ignoredPath) => path.resolve(paths.sourceDirectoryPath, ignoredPath)
);

//Regex matches any hidden files and folders.
const watcher = chokidar.watch(paths.sourceDirectoryPath, {
ignored: [...absoluteIgnoredPaths, /(^|[/\\])\..+/],
ignored: [/(^|[/\\])\..+/],
ignoreInitial: true,
persistent: true,
awaitWriteFinish: true,
Expand Down
3 changes: 1 addition & 2 deletions src/application/portal/serve/serve-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class ServeHandler {
public async startServer(
paths: ServePaths,
flags: ServeFlags,
ignoredPaths: string[],
generatePortal: (
buildDirectory: DirectoryPath,
portalDirectory: DirectoryPath,
Expand All @@ -56,7 +55,7 @@ export class ServeHandler {
}

if (!flags["no-reload"]) {
await this.portalWatcher.watchAndRegeneratePortalOnChange(paths, ignoredPaths, generatePortal);
await this.portalWatcher.watchAndRegeneratePortalOnChange(paths, generatePortal);
}

if (process.platform !== "darwin") {
Expand Down
Loading