import { Dgeni } from 'dgeni' ; import { ReadTypeScriptModules } from 'dgeni-packages/typescript/processors/readTypeScriptModules' ; import { TsParser } from 'dgeni-packages/typescript/services/TsParser' ; import { readFileSync } from 'fs' ; import { join , relative } from 'path' ; import { apiDocsPackage } from './docs-package' ; import { EntryPointGrouper } from './processors/entry-point-grouper' ; /**
 * Determines the command line arguments for the current Bazel action. Since this action can
 * have a large set of input files, Bazel may write the arguments into a parameter file.
 * This function is responsible for handling normal argument passing or Bazel parameter files.
 * Read more here: https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file
 */ function getBazelActionArguments ( ) { const args = process . argv . slice ( 2 ) ; if ( args [ 0 ] . startsWith ( '--param-file=' ) ) { return readFileSync ( args [ 0 ] . split ( '=' ) [ 1 ] , 'utf8' ) . trim ( ) . split ( '\n' ) ; } return args ; } if ( require . main === module ) { const [ bazelLabelPackagePath , outputDirPath , ... entryPointArgs ] = getBazelActionArguments ( ) ; const execRootPath = process . cwd ( ) ; const packagePath = join ( execRootPath , bazelLabelPackagePath ) ; apiDocsPackage . config ( function ( readTypeScriptModules , tsParser , entryPointGrouper , templateFinder , writeFilesProcessor , readFilesProcessor ) { readFilesProcessor . basePath = execRootPath ; readTypeScriptModules . basePath = packagePath ; tsParser . options . paths = { } ; for ( let i = 0 ; i + 1 < entryPointArgs . length ; i += 2 ) { const packageName = entryPointArgs [ i ] ; const entryPoints = entryPointArgs [ i + 1 ] . split ( ',' ) ; entryPoints . forEach ( ( entryPointName ) => { const entryPointPath = `${ packageName }/${ entryPointName }` ; const entryPointIndexPath = `${ entryPointPath }/index.ts` ; entryPointGrouper . entryPoints . push ( entryPointPath ) ; tsParser . options . paths ! [ `@sbb-esta/${ entryPointPath }` ] = [ entryPointIndexPath ] ; readTypeScriptModules . sourceFiles . push ( entryPointIndexPath ) ; } ) ; } tsParser . options . baseUrl = packagePath ; tsParser . options . paths ! [ '*' ] = [ relative ( packagePath , 'external/npm/node_modules/*' ) ] ; templateFinder . templateFolders = [ join ( execRootPath , 'tools/dgeni/templates/' ) ] ; writeFilesProcessor . outputFolder = outputDirPath ; } ) ; new Dgeni ( [ apiDocsPackage ] ) . generate ( ) . catch ( ( e ) => { console . error ( e ) ; process . exit ( 1 ) ; } ) ; }