1
+ /*
2
+
3
+ When making changes to this file, consider: https://virtru.atlassian.net/browse/DSPX-1577
4
+
5
+ */
1
6
import * as fs from 'fs' ;
2
7
import * as path from 'path' ;
3
8
import * as yaml from 'js-yaml' ;
@@ -22,7 +27,7 @@ const specsProcessedDir = path.join(repoRoot, 'specs-processed');
22
27
const ADD_TIMESTAMP_TO_DESCRIPTION = false ;
23
28
24
29
// The location prefix of built OpenAPI documentation
25
- const OUTPUT_PREFIX = 'docs/ OpenAPI-clients' ;
30
+ const OUTPUT_PREFIX = path . join ( repoRoot , 'docs' , ' OpenAPI-clients') ;
26
31
27
32
// The index page for OpenAPI documentation, to support bookmarking & sharing the URL
28
33
const OPENAPI_INDEX_PAGE = `${ OUTPUT_PREFIX } /index.md` ;
@@ -158,21 +163,21 @@ async function copySamplesToProcessedSpecs() {
158
163
159
164
console . log ( '🔄 Ensuring sample files exist in "specs-processed" directory...' ) ;
160
165
161
- const processedDir = path . resolve ( __dirname , 'specs- processed' ) ;
162
- fs . mkdirSync ( processedDir , { recursive : true } ) ;
163
-
166
+ // Use canonical processed and source directories
167
+ fs . mkdirSync ( specsProcessedDir , { recursive : true } ) ;
168
+
164
169
// Handle petstore specifically - it has a downloadUrl
165
- const petstorePath = path . resolve ( __dirname , 'specs-processed/ petstore.yaml' ) ;
166
- const petstoreSourcePath = path . resolve ( __dirname , 'specs/ petstore.yaml' ) ;
167
-
170
+ const petstorePath = path . join ( specsProcessedDir , 'petstore.yaml' ) ;
171
+ const petstoreSourcePath = path . join ( specsDir , 'petstore.yaml' ) ;
172
+
168
173
// Always copy from source directory, overwriting if it exists
169
174
console . log ( `Copying petstore spec from ${ petstoreSourcePath } ` ) ;
170
175
fs . copyFileSync ( petstoreSourcePath , petstorePath ) ;
171
-
176
+
172
177
// Handle bookstore specifically
173
- const bookstorePath = path . resolve ( __dirname , 'specs-processed/ bookstore.yaml' ) ;
174
- const bookstoreSourcePath = path . resolve ( __dirname , 'specs/ bookstore.yaml' ) ;
175
-
178
+ const bookstorePath = path . join ( specsProcessedDir , 'bookstore.yaml' ) ;
179
+ const bookstoreSourcePath = path . join ( specsDir , 'bookstore.yaml' ) ;
180
+
176
181
// Always copy from source directory, overwriting if it exists
177
182
console . log ( `Copying bookstore spec from ${ bookstoreSourcePath } ` ) ;
178
183
fs . copyFileSync ( bookstoreSourcePath , bookstorePath ) ;
@@ -206,14 +211,14 @@ async function preprocessOpenApiSpecs() {
206
211
207
212
// Generate modified path if not specified
208
213
if ( ! spec . specPathModified ) {
209
- // Store processed files in a 'specs-processed' directory by default
210
- spec . specPathModified = path . join (
211
- parsedPath . dir . replace ( / ^ \. \/ s p e c s / , './specs-processed' ) ,
212
- parsedPath . base
213
- ) ;
214
+ // Extract the relative path from specsDir
215
+ const relativePath = path . relative ( specsDir , spec . specPath ) ;
216
+
217
+ // Store processed files in 'specs-processed' directory while preserving the original directory structure
218
+ spec . specPathModified = path . join ( specsProcessedDir , relativePath ) ;
214
219
}
215
220
216
- const targetPath = path . resolve ( __dirname , spec . specPathModified ) ;
221
+ const targetPath = path . resolve ( spec . specPathModified ) ;
217
222
218
223
console . log ( `Processing: ${ sourcePath } → ${ targetPath } ` ) ;
219
224
@@ -313,10 +318,6 @@ Expand each section in the navigation panel to access the OpenAPI documentation
313
318
console . log ( '✨ OpenAPI preprocessing complete' ) ;
314
319
} ;
315
320
316
- // Execute the preprocessing function
317
- preprocessOpenApiSpecs ( ) . catch ( error => {
318
- console . error ( 'Failed to preprocess OpenAPI specs:' , error ) ;
319
- process . exit ( 1 ) ;
320
- } ) ;
321
321
322
- export { openApiSpecs , openApiSpecsArray } ;
322
+ // Export the function and data without automatically executing it
323
+ export { openApiSpecs , openApiSpecsArray , preprocessOpenApiSpecs } ;
0 commit comments