1- import fs from 'fs/promises' ;
2-
31import { ast , Program } from '@ton-community/tlb-parser' ;
42
53import { TLBCode , TLBType } from './ast' ;
@@ -19,14 +17,6 @@ export function getTLBCodeByAST(tree: Program, input: string) {
1917 return tlbCode ;
2018}
2119
22- export async function getTLBCode ( inputPath : string ) {
23- const input = await fs . readFile ( inputPath , 'utf-8' ) ;
24-
25- const tree = ast ( input ) ;
26-
27- return getTLBCodeByAST ( tree , input ) ;
28- }
29-
3020export function generateCodeByAST ( tree : Program , input : string , getGenerator : ( tlbCode : TLBCode ) => CodeGenerator ) {
3121 let tlbCode = getTLBCodeByAST ( tree , input ) ;
3222 let codeGenerator : CodeGenerator = getGenerator ( tlbCode ) ;
@@ -72,7 +62,7 @@ export function generateCodeByAST(tree: Program, input: string, getGenerator: (t
7262 return generatedCode ;
7363}
7464
75- function getGenerator ( resultLanguage : string ) {
65+ export function getGenerator ( resultLanguage : string ) {
7666 return ( tlbCode : TLBCode ) => {
7767 if ( resultLanguage == 'typescript' ) {
7868 return new TypescriptGenerator ( tlbCode ) ;
@@ -86,21 +76,3 @@ export async function generateCodeFromData(input: string, resultLanguage: string
8676 const tree = ast ( input ) ;
8777 return generateCodeByAST ( tree , input , getGenerator ( resultLanguage ) ) ;
8878}
89-
90- export async function generateCodeWithGenerator (
91- inputPath : string ,
92- outputPath : string ,
93- getGenerator : ( tlbCode : TLBCode ) => CodeGenerator ,
94- ) {
95- const input = await fs . readFile ( inputPath , 'utf-8' ) ;
96-
97- const tree = ast ( input ) ;
98-
99- await fs . writeFile ( outputPath , generateCodeByAST ( tree , input , getGenerator ) , { } ) ;
100- // eslint-disable-next-line no-console
101- console . log ( `Generated code is saved to ${ outputPath } ` ) ;
102- }
103-
104- export async function generateCode ( inputPath : string , outputPath : string , resultLanguage : string ) {
105- return generateCodeWithGenerator ( inputPath , outputPath , getGenerator ( resultLanguage ) ) ;
106- }
0 commit comments