@@ -3,10 +3,11 @@ import fsp from 'fs/promises';
33import yaml from 'js-yaml' ;
44
55import { Cache } from '../cache.ts' ;
6- import { exists , run , toAbsolutePath } from '../common.ts' ;
6+ import { exists , GENERATORS , run , toAbsolutePath } from '../common.ts' ;
77import { createSpinner } from '../spinners.ts' ;
88import type { Spec } from '../types.ts' ;
99
10+ import { getSnippetFile } from '../config.ts' ;
1011import { bundleSpecsForClient , bundleSpecsForDoc , lintCommon } from './format.ts' ;
1112import type { BaseBuildSpecsOptions } from './types.ts' ;
1213
@@ -73,51 +74,64 @@ async function buildSpec({
7374 // In case of lite we use a the `search` spec as a base because only its bundled form exists.
7475 const specBase = isLiteSpec ? 'search' : spec ;
7576 const logSuffix = `${ outputFormat } ${ docs ? 'doc spec' : 'spec' } ` ;
76- const basePath = docs ? 'docs/' : 'specs/' ;
77- const deps = isLiteSpec ? [ 'search' , 'recommend' ] : [ spec ] ;
77+ const basePath = docs ? 'docs' : 'specs' ;
78+ const deps = isLiteSpec ? [ 'specs/search' , 'specs/recommend' ] : [ `specs/${ spec } ` ] ;
79+ const generatedFile = `${ basePath } /bundled/${ spec } .${ outputFormat } ` ;
80+
81+ const generatedFiles = [ generatedFile ] ;
82+ if ( docs && outputFormat === 'yml' ) {
83+ for ( const gen of Object . values ( GENERATORS ) ) {
84+ if ( gen . client === spec ) {
85+ deps . push ( getSnippetFile ( gen ) ) ;
86+ }
87+ }
88+
89+ generatedFiles . push ( `docs/bundled/${ spec } -snippets.json` ) ;
90+ }
91+
7892 const cache = new Cache ( {
79- folder : toAbsolutePath ( 'specs/ ' ) ,
80- generatedFiles : [ `bundled/ ${ spec } .yml` ] ,
81- filesToCache : [ ...deps , 'common' ] ,
82- cacheFile : toAbsolutePath ( `specs/dist/${ spec } .cache` ) ,
93+ folder : toAbsolutePath ( '. ' ) ,
94+ generatedFiles,
95+ dependencies : [ ...deps , 'specs/ common' ] ,
96+ cacheFile : toAbsolutePath ( `specs/dist/${ spec } - ${ basePath } - ${ outputFormat } .cache` ) ,
8397 } ) ;
8498
8599 const spinner = createSpinner ( `starting '${ spec } ' ${ logSuffix } ` ) ;
86100
87101 if ( useCache ) {
88- spinner . text = `checking cache for '${ specBase } '` ;
102+ spinner . text = `checking cache for '${ specBase } ' ${ logSuffix } ` ;
89103
90- if ( await cache . isValid ( ) ) {
91- spinner . succeed ( `job skipped, cache found for '${ specBase } '` ) ;
104+ if ( await cache . hit ( ) ) {
105+ spinner . succeed ( `job skipped, cache found for '${ specBase } ' ${ logSuffix } ` ) ;
92106 return ;
93107 }
94108
95- spinner . text = `cache not found for '${ specBase } '` ;
109+ spinner . text = `cache not found for '${ specBase } ' ${ logSuffix } ` ;
96110 }
97111
98112 // First linting the base
99113 spinner . text = `linting '${ spec } ' ${ logSuffix } ` ;
100114 await run ( `yarn specs:fix specs/${ specBase } ` ) ;
101115
102116 // Then bundle the file
103- const bundledPath = toAbsolutePath ( ` ${ basePath } /bundled/ ${ spec } . ${ outputFormat } ` ) ;
117+ const bundledPath = toAbsolutePath ( generatedFile ) ;
104118 await run ( `yarn redocly bundle specs/${ specBase } /spec.yml -o ${ bundledPath } --ext ${ outputFormat } ` ) ;
105119
106120 if ( ! ( await exists ( bundledPath ) ) ) {
107121 throw new Error ( `Bundled file not found ${ bundledPath } .` ) ;
108122 }
109123
110124 // Add the correct tags to be able to generate the proper client
111- if ( ! isLiteSpec ) {
112- docs ? await bundleSpecsForDoc ( bundledPath , spec ) : await bundleSpecsForClient ( bundledPath , spec ) ;
113- } else {
125+ if ( isLiteSpec ) {
114126 await buildLiteSpec ( {
115127 spec,
116128 bundledPath : toAbsolutePath ( bundledPath ) ,
117129 outputFormat,
118130 docs,
119131 useCache,
120132 } ) ;
133+ } else if ( outputFormat === 'yml' ) {
134+ docs ? await bundleSpecsForDoc ( bundledPath , spec ) : await bundleSpecsForClient ( bundledPath , spec ) ;
121135 }
122136
123137 spinner . text = `validating '${ spec } ' ${ logSuffix } ` ;
0 commit comments