@@ -17,13 +17,9 @@ import { LauncherService } from '../../infrastructure/launcher-service.js';
1717import { ZipService } from '../../infrastructure/zip-service.js' ;
1818import { FileName } from '../../types/file/fileName.js' ;
1919import { FeaturesToRemove , ValidationService } from '../../infrastructure/services/validation-service.js' ;
20-
21- const defaultSpecUrl = new UrlPath (
22- `https://raw.githubusercontent.com/apimatic/sample-docs-as-code-portal/refs/heads/master/src/spec/openapi.json`
23- ) ;
24- const metadataFileUrl = new UrlPath (
25- `https://raw.githubusercontent.com/apimatic/sample-docs-as-code-portal/refs/heads/master/src/spec/APIMATIC-META.json`
26- ) ;
20+ import { BuildContext } from '../../types/build-context.js' ;
21+ import { TempContext } from '../../types/temp-context.js' ;
22+ import { getLanguagesConfig } from '../../types/build/build.js' ;
2723
2824export class SdkQuickstartAction {
2925 private readonly prompts = new SdkQuickstartPrompts ( ) ;
@@ -32,6 +28,13 @@ export class SdkQuickstartAction {
3228 private readonly launcherService = new LauncherService ( ) ;
3329 private readonly zipService = new ZipService ( ) ;
3430 private readonly validationService = new ValidationService ( this . configDir ) ;
31+ private readonly buildFileUrl = new UrlPath (
32+ `https://github.com/apimatic/sample-docs-as-code-portal/archive/refs/heads/master.zip`
33+ ) ;
34+ private readonly defaultSpecUrl = new UrlPath (
35+ `https://raw.githubusercontent.com/apimatic/sample-docs-as-code-portal/refs/heads/master/src/spec/openapi.json`
36+ ) ;
37+ private readonly repositoryFolderName = 'sample-docs-as-code-portal-master/src' as const ;
3538
3639 constructor ( private readonly configDir : DirectoryPath , private readonly commandMetadata : CommandMetadata ) { }
3740
@@ -50,7 +53,7 @@ export class SdkQuickstartAction {
5053
5154 let specPath : FilePath | undefined ;
5255 while ( ! specPath ) {
53- const inputPath = await this . prompts . specPathPrompt ( defaultSpecUrl ) ;
56+ const inputPath = await this . prompts . specPathPrompt ( this . defaultSpecUrl ) ;
5457 if ( ! inputPath ) {
5558 this . prompts . noSpecSpecified ( ) ;
5659 return ActionResult . cancelled ( ) ;
@@ -89,7 +92,7 @@ export class SdkQuickstartAction {
8992 return ActionResult . cancelled ( ) ;
9093 }
9194 const downloadFileResult = await this . prompts . downloadSpecFile (
92- this . fileDownloadService . downloadFile ( defaultSpecUrl )
95+ this . fileDownloadService . downloadFile ( this . defaultSpecUrl )
9396 ) ;
9497 if ( downloadFileResult . isErr ( ) ) {
9598 this . prompts . serviceError ( downloadFileResult . error ) ;
@@ -152,35 +155,39 @@ export class SdkQuickstartAction {
152155 break ;
153156 }
154157
155- // Setup source directory with the spec folder
156- const apimaticMetaFile = await this . prompts . downloadMetadataFile (
157- this . fileDownloadService . downloadFile ( metadataFileUrl )
158+ // Setup source directory with the build structure
159+ const masterBuildFile = await this . prompts . downloadBuildDirectory (
160+ this . fileDownloadService . downloadFile ( this . buildFileUrl )
158161 ) ;
159- if ( apimaticMetaFile . isErr ( ) ) {
160- this . prompts . serviceError ( apimaticMetaFile . error ) ;
162+ if ( masterBuildFile . isErr ( ) ) {
163+ this . prompts . serviceError ( masterBuildFile . error ) ;
161164 return ActionResult . failed ( ) ;
162165 }
163- const tempSpecDirectory = tempDirectory . join ( 'spec' ) ;
164- await this . fileService . createDirectoryIfNotExists ( tempSpecDirectory ) ;
165- const metadataFilePath = new FilePath ( tempSpecDirectory , apimaticMetaFile . value . filename ) ;
166- await this . fileService . writeFile ( metadataFilePath , apimaticMetaFile . value . stream ) ;
167-
168- if ( await this . fileService . isZipFile ( specPath ) ) {
169- await this . zipService . unArchive ( specPath , tempSpecDirectory ) ;
170- } else {
171- await this . fileService . copyToDir ( specPath , tempSpecDirectory ) ;
172- }
166+ const tempContext = new TempContext ( tempDirectory ) ;
167+ const masterBuildFilePath = await tempContext . save ( masterBuildFile . value . stream ) ;
168+ await this . zipService . unArchive ( masterBuildFilePath , tempDirectory ) ;
169+ const extractedFolder = tempDirectory . join ( this . repositoryFolderName ) ;
170+
171+ const tempBuildContext = new BuildContext ( extractedFolder ) ;
172+ await tempBuildContext . deleteWorkflowDir ( ) ;
173+
174+ const buildFile = await tempBuildContext . getBuildFileContents ( ) ;
175+ buildFile . generatePortal ! . languageConfig = getLanguagesConfig ( [ language ] ) ;
176+ await tempBuildContext . updateBuildFileContents ( buildFile ) ;
173177
174178 const sourceDirectory = inputDirectory . join ( 'src' ) ;
179+ await this . fileService . copyDirectoryContents ( extractedFolder , sourceDirectory ) ;
180+
175181 const specDirectory = sourceDirectory . join ( 'spec' ) ;
176- await this . fileService . copyDirectoryContents ( tempSpecDirectory , specDirectory ) ;
182+ const specContext = new SpecContext ( specDirectory ) ;
183+ await specContext . replaceDefaultSpec ( specPath ) ;
177184
178- const srcDirectoryStructure = await this . fileService . getDirectory ( sourceDirectory ) ;
179- this . prompts . printDirectoryStructure ( inputDirectory , srcDirectoryStructure ) ;
185+ const buildDirectoryStructure = await this . fileService . getDirectory ( sourceDirectory ) ;
186+ this . prompts . printDirectoryStructure ( inputDirectory , buildDirectoryStructure ) ;
180187
181188 const sdkDirectory = inputDirectory . join ( 'sdk' ) ;
182189 const sdkGenerateAction = new GenerateAction ( this . configDir , this . commandMetadata ) ;
183- const result = await sdkGenerateAction . execute ( specDirectory , sdkDirectory , language as Language , true , false ) ;
190+ const result = await sdkGenerateAction . execute ( sourceDirectory , sdkDirectory , language as Language , true , false ) ;
184191 if ( result . isFailed ( ) ) {
185192 return ActionResult . failed ( ) ;
186193 }
0 commit comments