@@ -16,6 +16,8 @@ import { FileDownloadService } from "../../infrastructure/services/file-download
1616import { getLanguagesConfig } from "../../types/build/build.js" ;
1717import { FilePath } from "../../types/file/filePath.js" ;
1818import { SpecContext } from "../../types/spec-context.js" ;
19+ import { FeaturesToRemove , ValidationService } from "../../infrastructure/services/validation-service.js" ;
20+ import { FileName } from "../../types/file/fileName.js" ;
1921
2022const defaultPort : number = 3000 as const ;
2123
@@ -26,19 +28,25 @@ export class PortalQuickstartAction {
2628 private readonly configDir : DirectoryPath ;
2729 private readonly commandMetadata : CommandMetadata ;
2830 private readonly fileDownloadService = new FileDownloadService ( ) ;
29- private readonly buildFileUrl = new UrlPath ( `https://github.com/apimatic/sample-docs-as-code-portal/archive/refs/heads/master.zip` ) ;
30- private readonly defaultSpecUrl = new UrlPath ( `https://raw.githubusercontent.com/apimatic/sample-docs-as-code-portal/refs/heads/master/src/spec/openapi.json` ) ;
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+ ) ;
3137 private readonly repositoryFolderName = "sample-docs-as-code-portal-master/src" as const ;
38+ private readonly validationService : ValidationService ;
3239
3340 constructor ( configDir : DirectoryPath , commandMetadata : CommandMetadata ) {
3441 this . configDir = configDir ;
3542 this . commandMetadata = commandMetadata ;
43+ this . validationService = new ValidationService ( this . configDir ) ;
3644 }
3745
3846 public readonly execute = async ( ) : Promise < ActionResult > => {
3947 const storedAuth = await getAuthInfo ( this . configDir . toString ( ) ) ;
4048 if ( ! storedAuth ?. authKey ) {
41- const loginResult = await new LoginAction ( this . configDir , this . commandMetadata ) . execute ( ) ;
49+ const loginResult = await new LoginAction ( this . configDir , this . commandMetadata ) . execute ( ) ;
4250 if ( loginResult . isFailed ( ) ) {
4351 return ActionResult . failed ( ) ;
4452 }
@@ -98,6 +106,24 @@ export class PortalQuickstartAction {
98106 }
99107 }
100108
109+ const unallowed = validationResult . getValue ( ) ;
110+ if ( unallowed && ( unallowed . Features ?. length > 0 || unallowed . EndpointCount > unallowed . EndpointLimit ) ) {
111+ const config : FeaturesToRemove = {
112+ features : unallowed . Features . filter ( ( name ) => ! ! name ) ,
113+ endpointsToKeep : unallowed . EndpointLimit
114+ } ;
115+
116+ const stripUnallowedFeaturesResult = await this . validationService . stripUnallowedFeatures ( specPath , config ) ;
117+ if ( stripUnallowedFeaturesResult . isErr ( ) ) {
118+ this . prompts . splitSpecDetected ( unallowed ) ;
119+ return ActionResult . failed ( ) ;
120+ } else {
121+ this . prompts . stripUnallowedFeaturesStep ( unallowed ) ;
122+ const specContext = new SpecContext ( tempDirectory ) ;
123+ specPath = await specContext . save ( stripUnallowedFeaturesResult . value , new FileName ( "pruned-spec.zip" ) ) ;
124+ }
125+ }
126+
101127 // Step 3/4
102128 this . prompts . selectLanguagesStep ( ) ;
103129 const languages = await this . prompts . selectLanguagesPrompt ( ) ;
@@ -163,9 +189,11 @@ export class PortalQuickstartAction {
163189 const result = await portalServeAction . execute ( sourceDirectory , portalDirectory , defaultPort , true , false , ( ) => {
164190 this . prompts . nextSteps ( ) ;
165191 } ) ;
192+
166193 if ( result . isFailed ( ) ) {
167194 return ActionResult . failed ( ) ;
168195 }
196+
169197 return ActionResult . success ( ) ;
170198 } ) ;
171199 } ;
0 commit comments