@@ -36,21 +36,27 @@ export class CubeSchemaConverter {
3636
3737 public constructor ( protected fileRepository : any , protected converters : CubeConverterInterface [ ] ) { }
3838
39- protected async prepare ( ) : Promise < void > {
39+ /**
40+ * Parse Schema files from the repository and create a mapping of cube names to schema files.
41+ * If optional `cubeName` parameter is passed - only file with asked cube is parsed and stored.
42+ * @param cubeName
43+ * @protected
44+ */
45+ protected async prepare ( cubeName ?: string ) : Promise < void > {
4046 this . dataSchemaFiles = await this . fileRepository . dataSchemaFiles ( ) ;
4147
4248 this . dataSchemaFiles . forEach ( ( schemaFile ) => {
4349 if ( schemaFile . fileName . endsWith ( '.js' ) ) {
44- this . transformJS ( schemaFile ) ;
50+ this . transformJS ( schemaFile , cubeName ) ;
4551 } else if ( ( schemaFile . fileName . endsWith ( '.yml' ) || schemaFile . fileName . endsWith ( '.yaml' ) ) && ! schemaFile . content . match ( JINJA_SYNTAX ) ) {
4652 // Jinja-templated data models are not supported in Rollup Designer yet, so we're ignoring them,
4753 // and if user has chosen the cube from such file - it won't be found during generation.
48- this . transformYaml ( schemaFile ) ;
54+ this . transformYaml ( schemaFile , cubeName ) ;
4955 }
5056 } ) ;
5157 }
5258
53- protected transformYaml ( schemaFile : SchemaFile ) {
59+ protected transformYaml ( schemaFile : SchemaFile , filterCubeName ?: string ) {
5460 if ( ! schemaFile . content . trim ( ) ) {
5561 return ;
5662 }
@@ -84,18 +90,22 @@ export class CubeSchemaConverter {
8490
8591 const cubeName = ( cubeNamePair ?. value as YAML . Scalar ) . value ;
8692
87- if ( cubeName && typeof cubeName === 'string' ) {
93+ if ( cubeName && typeof cubeName === 'string' && ( ! filterCubeName || cubeName === filterCubeName ) ) {
8894 this . parsedFiles [ cubeName ] = {
8995 fileName : schemaFile . fileName ,
9096 yaml : yamlDoc ,
9197 cubeDefinition : cubeNode ,
9298 } ;
99+
100+ if ( cubeName === filterCubeName ) {
101+ return ;
102+ }
93103 }
94104 }
95105 }
96106 }
97107
98- protected transformJS ( schemaFile : SchemaFile ) {
108+ protected transformJS ( schemaFile : SchemaFile , filterCubeName ?: string ) {
99109 const ast = this . parseJS ( schemaFile ) ;
100110
101111 traverse ( ast , {
@@ -117,7 +127,7 @@ export class CubeSchemaConverter {
117127 throw new Error ( `Error parsing ${ schemaFile . fileName } ` ) ;
118128 }
119129
120- if ( t . isObjectExpression ( args [ 1 ] ?. node ) && ast != null ) {
130+ if ( t . isObjectExpression ( args [ 1 ] ?. node ) && ast != null && ( ! filterCubeName || cubeName === filterCubeName ) ) {
121131 this . parsedFiles [ cubeName ] = {
122132 fileName : schemaFile . fileName ,
123133 ast,
@@ -150,8 +160,8 @@ export class CubeSchemaConverter {
150160 }
151161 }
152162
153- public async generate ( ) {
154- await this . prepare ( ) ;
163+ public async generate ( cubeName ?: string ) {
164+ await this . prepare ( cubeName ) ;
155165
156166 this . converters . forEach ( ( converter ) => {
157167 converter . convert ( this . parsedFiles ) ;
0 commit comments