11import { InternalError } from '../utils/errors' ;
2+ import { ConfigBlockType } from './language-definition' ;
23import { ConfigLoader } from './loader' ;
3- import { LoadedProject } from './loader/entities/project' ;
44import { FileParser } from './parser' ;
5- import { ConfigBlockType , ParsedModule , ParsedProject } from './parser/entities' ;
5+ import { ParsedModule , ParsedProject } from './parser/entities' ;
6+ import { ProjectConfig } from './parser/entities/project' ;
67import { JsonFileParser } from './parser/json/file-parser' ;
78
89
@@ -12,30 +13,30 @@ export class ConfigCompiler {
1213 'json' : new JsonFileParser ( ) ,
1314 }
1415
15- static async compileProject ( directory : string ) : Promise < ParsedProject > {
16- const loadedProject = await ConfigCompiler . load ( directory ) ;
17- return ConfigCompiler . parse ( loadedProject ) ;
18- }
19-
20- private static load ( directory : string ) : Promise < LoadedProject > {
21- return new ConfigLoader ( ) . loadProject ( directory ) ;
22- }
16+ static async parseProject ( directory : string ) : Promise < ParsedProject > {
17+ const loadedProject = await ( new ConfigLoader ( ) . loadProject ( directory ) ) ;
2318
24- private static async parse ( loadedProject : LoadedProject ) : Promise < ParsedProject > {
25- const configBlocks = await Promise . all ( loadedProject . coreModule . files . map ( ( file ) => {
19+ const configBlocksResult = await Promise . all ( loadedProject . coreModule . files . map ( ( file ) => {
2620 const parser = ConfigCompiler . supportedParsers [ file . fileType ] ;
2721 if ( ! parser ) {
2822 throw new InternalError ( `Unsupported file format loaded into parser: ${ file . fileName } ` ) ;
2923 }
3024
3125 return parser . parse ( file ) ;
3226 } ) ) ;
27+ const configBlocks = configBlocksResult . flat ( 1 ) ;
28+
29+ const parsedProjectConfigs = configBlocks . filter ( ( u ) => u . configType === ConfigBlockType . PROJECT ) ;
30+ if ( parsedProjectConfigs . length !== 1 ) {
31+ throw new Error ( 'One one project config can be specified' ) ;
32+ }
3333
34+ const projectConfig = parsedProjectConfigs [ 0 ] as ProjectConfig ;
3435 return new ParsedProject ( {
3536 coreModule : new ParsedModule ( {
3637 configBlocks : configBlocks . flat ( 1 ) ,
3738 } ) ,
38- projectConfig : configBlocks . flat ( 1 ) . find ( ( u ) => u . configType === ConfigBlockType . PROJECT ) ! ,
39+ projectConfig,
3940 } )
4041 }
4142}
0 commit comments