@@ -10,14 +10,13 @@ import { TocEndpoint, TocGroup, TocModel } from "../../../types/toc/toc.js";
1010import { PortalService } from "../../../infrastructure/services/portal-service.js" ;
1111import { DirectoryPath } from "../../../types/file/directoryPath.js" ;
1212
13- const DEFAULT_TOC_FILENAME = "toc.yml" ;
14- const APIMATIC_BUILD_FILENAME = "APIMATIC-BUILD.json" ;
15-
1613export class PortalNewTocAction {
1714 private readonly prompts : PortalNewTocPrompts ;
1815 private readonly sdlParser : SdlParser ;
1916 private readonly tocGenerator : TocStructureGenerator ;
2017 private readonly contentParser : TocContentParser ;
18+ private readonly DEFAULT_TOC_FILENAME : string = "toc.yml" as const ;
19+ private readonly APIMATIC_BUILD_FILENAME : string = "APIMATIC-BUILD.json" as const ;
2120
2221 constructor ( ) {
2322 this . prompts = new PortalNewTocPrompts ( ) ;
@@ -26,7 +25,7 @@ export class PortalNewTocAction {
2625 this . contentParser = new TocContentParser ( ) ;
2726 }
2827
29- async createToc (
28+ public async createToc (
3029 buildDirectory : DirectoryPath ,
3130 configDir : string ,
3231 tocDirectory ?: DirectoryPath ,
@@ -36,7 +35,7 @@ export class PortalNewTocAction {
3635 ) : Promise < Result < string , string > > {
3736 try {
3837 const tocDir = await this . getDestinationPath ( buildDirectory , tocDirectory ) ;
39- const tocPath = path . join ( tocDir , DEFAULT_TOC_FILENAME ) ;
38+ const tocPath = path . join ( tocDir , this . DEFAULT_TOC_FILENAME ) ;
4039 const tocCheckResult = await this . handleExistingToc ( tocPath , force ) ;
4140 if ( ! tocCheckResult . isSuccess ( ) ) {
4241 return tocCheckResult ;
@@ -64,7 +63,7 @@ export class PortalNewTocAction {
6463 this . prompts . displayOutroMessage ( tocPath ) ;
6564 return Result . success ( tocPath ) ;
6665 } catch ( error ) {
67- this . prompts . logError ( getMessageInRedColor ( `${ error } ` ) ) ;
66+ this . prompts . logError ( getMessageInRedColor ( `${ ( error as Error ) . message } ` ) ) ;
6867 return Result . failure ( `❌ An unexpected error occurred while generating the TOC file.` ) ;
6968 }
7069 }
@@ -143,7 +142,7 @@ export class PortalNewTocAction {
143142 }
144143
145144 private async getContentFolderPath ( buildDirectory : DirectoryPath ) : Promise < string > {
146- const buildFilePath = path . join ( buildDirectory . toString ( ) , APIMATIC_BUILD_FILENAME ) ;
145+ const buildFilePath = path . join ( buildDirectory . toString ( ) , this . APIMATIC_BUILD_FILENAME ) ;
147146 const defaultContentFolder = path . join ( buildDirectory . toString ( ) , "content" ) ;
148147
149148 if ( ! ( await fsExtra . pathExists ( buildFilePath ) ) ) {
@@ -163,7 +162,7 @@ export class PortalNewTocAction {
163162 }
164163
165164 private async getSpecFolderPath ( buildDirectory : DirectoryPath ) : Promise < string > {
166- const buildFilePath = path . join ( buildDirectory . toString ( ) , APIMATIC_BUILD_FILENAME ) ;
165+ const buildFilePath = path . join ( buildDirectory . toString ( ) , this . APIMATIC_BUILD_FILENAME ) ;
167166 const defaultSpecFolder = path . join ( buildDirectory . toString ( ) , "spec" ) ;
168167
169168 if ( ! ( await fsExtra . pathExists ( buildFilePath ) ) ) {
0 commit comments