Skip to content

Commit f34ab99

Browse files
committed
extracted yaml and jinja transpilation in separate functions
1 parent f84eab5 commit f34ab99

File tree

1 file changed

+54
-26
lines changed

1 file changed

+54
-26
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -517,33 +517,9 @@ export class DataSchemaCompiler {
517517
(file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml'))
518518
&& file.content.match(JINJA_SYNTAX)
519519
) {
520-
const transpiledFile = await this.yamlCompiler.compileYamlWithJinjaFile(
521-
file,
522-
errorsReport,
523-
this.standalone ? {} : this.cloneCompileContextWithGetterAlias(this.compileContext),
524-
this.pythonContext!
525-
);
526-
if (transpiledFile) {
527-
// We update the jinja/yaml file content to the transpiled js content
528-
// and raise related flag so it will go JS transpilation flow afterward
529-
// avoiding costly YAML/Python parsing again.
530-
file.content = transpiledFile.content;
531-
file.convertedToJs = true;
532-
}
533-
534-
return transpiledFile;
520+
return this.transpileJinjaFile(file, errorsReport, options);
535521
} else if (file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')) {
536-
const transpiledFile = this.yamlCompiler.transpileYamlFile(file, errorsReport);
537-
538-
if (transpiledFile) {
539-
// We update the yaml file content to the transpiled js content
540-
// and raise related flag so it will go JS transpilation flow afterward
541-
// avoiding costly YAML/Python parsing again.
542-
file.content = transpiledFile.content;
543-
file.convertedToJs = true;
544-
}
545-
546-
return transpiledFile;
522+
return this.transpileYamlFile(file, errorsReport, options);
547523
} else {
548524
return file;
549525
}
@@ -666,6 +642,58 @@ export class DataSchemaCompiler {
666642
return undefined;
667643
}
668644

645+
private async transpileYamlFile(
646+
file: FileContent,
647+
errorsReport: ErrorReporter,
648+
{ cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage }: TranspileOptions
649+
): Promise<(FileContent | undefined)> {
650+
// if (getEnv('transpilationNative')) {
651+
//
652+
// } else if (getEnv('transpilationWorkerThreads')) {
653+
//
654+
// } else {
655+
const transpiledFile = this.yamlCompiler.transpileYamlFile(file, errorsReport);
656+
657+
if (transpiledFile) {
658+
// We update the yaml file content to the transpiled js content
659+
// and raise related flag so it will go JS transpilation flow afterward
660+
// avoiding costly YAML/Python parsing again.
661+
file.content = transpiledFile.content;
662+
file.convertedToJs = true;
663+
}
664+
665+
return transpiledFile;
666+
// }
667+
}
668+
669+
private async transpileJinjaFile(
670+
file: FileContent,
671+
errorsReport: ErrorReporter,
672+
{ cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage }: TranspileOptions
673+
): Promise<(FileContent | undefined)> {
674+
// if (getEnv('transpilationNative')) {
675+
//
676+
// } else if (getEnv('transpilationWorkerThreads')) {
677+
//
678+
// } else {
679+
const transpiledFile = await this.yamlCompiler.compileYamlWithJinjaFile(
680+
file,
681+
errorsReport,
682+
this.standalone ? {} : this.cloneCompileContextWithGetterAlias(this.compileContext),
683+
this.pythonContext!
684+
);
685+
if (transpiledFile) {
686+
// We update the jinja/yaml file content to the transpiled js content
687+
// and raise related flag so it will go JS transpilation flow afterward
688+
// avoiding costly YAML/Python parsing again.
689+
file.content = transpiledFile.content;
690+
file.convertedToJs = true;
691+
}
692+
693+
return transpiledFile;
694+
// }
695+
}
696+
669697
public withQuery(query, fn) {
670698
const oldQuery = this.currentQuery;
671699
this.currentQuery = query;

0 commit comments

Comments
 (0)