@@ -23,41 +23,45 @@ export async function runBuildRefsCli() {
2323 async ( { log, flags } ) => {
2424 const outDirs = getOutputsDeep ( REF_CONFIG_PATHS ) ;
2525
26- if ( flags . clean ) {
26+ const cacheEnabled = process . env . BUILD_TS_REFS_CACHE_ENABLE === 'true' || ! ! flags . cache ;
27+ const doCapture = process . env . BUILD_TS_REFS_CACHE_CAPTURE === 'true' ;
28+ const doClean = ! ! flags . clean || doCapture ;
29+ const doInitCache = cacheEnabled && ! doClean ;
30+
31+ if ( doClean ) {
2732 log . info ( 'deleting' , outDirs . length , 'ts output directories' ) ;
2833 await concurrentMap ( 100 , outDirs , ( outDir ) => del ( outDir ) ) ;
2934 }
3035
3136 let outputCache ;
32- if ( flags . cache ) {
37+ if ( cacheEnabled ) {
3338 outputCache = await RefOutputCache . create ( {
3439 log,
3540 outDirs,
3641 repoRoot : REPO_ROOT ,
3742 workingDir : CACHE_WORKING_DIR ,
3843 upstreamUrl : 'https://github.com/elastic/kibana.git' ,
3944 } ) ;
45+ }
4046
47+ if ( outputCache && doInitCache ) {
4148 await outputCache . initCaches ( ) ;
4249 }
4350
4451 await buildAllTsRefs ( log ) ;
4552
46- if ( outputCache ) {
47- if ( process . env . BUILD_TS_REFS_CACHE_CAPTURE === 'true' ) {
48- await outputCache . captureCache ( Path . resolve ( REPO_ROOT , 'target/ts_refs_cache' ) ) ;
49- }
53+ if ( outputCache && doCapture ) {
54+ await outputCache . captureCache ( Path . resolve ( REPO_ROOT , 'target/ts_refs_cache' ) ) ;
55+ }
5056
57+ if ( outputCache ) {
5158 await outputCache . cleanup ( ) ;
5259 }
5360 } ,
5461 {
5562 description : 'Build TypeScript projects' ,
5663 flags : {
5764 boolean : [ 'clean' , 'cache' ] ,
58- default : {
59- cache : process . env . BUILD_TS_REFS_CACHE_ENABLE === 'true' ? true : false ,
60- } ,
6165 } ,
6266 log : {
6367 defaultLevel : 'debug' ,
0 commit comments