import { pipeline } from 'stream' ; import { promisify } from 'util' ; import vfs from 'vinyl-fs' ; import { transformFileWithBabel , transformFileStream } from '@kbn/dev-utils' ; import { BuildContext } from '../build_context' ; const asyncPipeline = promisify ( pipeline ) ; export async function writeServerFiles ( { log , config , plugin , sourceDir , buildDir , kibanaVersion , } ) { log . info ( 'copying server source into the build and converting with babel' ) ; await asyncPipeline ( vfs . src ( [ 'kibana.json' , ... ( plugin . manifest . server ? config . serverSourcePatterns || [ 'yarn.lock' , 'tsconfig.json' , 'package.json' , 'index.{js,ts}' , '{lib,server,common,translations}/**/*' , ] : [ ] ) , ] , { cwd : sourceDir , base : sourceDir , buffer : true , ignore : [ '**/*.d.ts' , '**/public/**' , '**/__tests__/**' , '**/*.{test,test.mocks,mock,mocks}.*' , ] , allowEmpty : true , } ) , transformFileStream ( ( file ) => { if ( file . relative !== 'kibana.json' ) { return ; } const json = file . contents . toString ( 'utf8' ) ; const manifest = JSON . parse ( json ) ; file . contents = Buffer . from ( JSON . stringify ( { ... manifest , kibanaVersion , } , null , 2 ) ) ; } ) , transformFileStream ( async ( file ) => { if ( file . path . includes ( 'node_modules' ) ) { return ; } if ( [ '.js' , '.ts' , '.tsx' ] . includes ( file . extname ) ) { await transformFileWithBabel ( file ) ; } } ) , vfs . dest ( buildDir ) ) ; }