Skip to content

Commit 6ac818b

Browse files
authored
Merge pull request #57 from TrueCarry/feat/web-compatibility
Feat/web compatibility
2 parents 7bd8983 + 4943e52 commit 6ac818b

5 files changed

Lines changed: 38 additions & 39 deletions

File tree

generate_tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22

3-
import { generateCode } from './src/main';
3+
import { generateCode } from './src/node';
44

55
function genCodeForTest(name: string) {
66
const fixturesDir = path.resolve(__dirname, 'test');

index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
export {
2-
generateCode,
3-
getTLBCode,
4-
getTLBCodeByAST,
5-
generateCodeByAST,
6-
generateCodeWithGenerator,
7-
generateCodeFromData,
8-
} from './src/main';
1+
export { getTLBCodeByAST, generateCodeByAST, generateCodeFromData } from './src/main';
2+
export { generateCode, getTLBCode, generateCodeWithGenerator } from './src/node';
93
export * from './src/ast';
104
export { isBigInt as isBigIntForJson, isBigIntExpr as isBigIntExprForJson } from './src/generators/typescript/utils';
115
export type { CodeGenerator } from './src/generators/generator';

main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import meow from 'meow';
33

4-
import { generateCode } from './src/main';
4+
import { generateCode } from './src/node';
55

66
const cli = meow(
77
`

src/main.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fs from 'fs/promises';
2-
31
import { ast, Program } from '@ton-community/tlb-parser';
42

53
import { 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-
3020
export 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-
}

src/node.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import fs from 'fs/promises';
2+
3+
import { ast } from '@ton-community/tlb-parser';
4+
5+
import { TLBCode } from './ast';
6+
import { CodeGenerator } from './generators/generator';
7+
import { generateCodeByAST, getGenerator, getTLBCodeByAST } from './main';
8+
9+
export async function getTLBCode(inputPath: string) {
10+
const input = await fs.readFile(inputPath, 'utf-8');
11+
12+
const tree = ast(input);
13+
14+
return getTLBCodeByAST(tree, input);
15+
}
16+
17+
export async function generateCodeWithGenerator(
18+
inputPath: string,
19+
outputPath: string,
20+
getGenerator: (tlbCode: TLBCode) => CodeGenerator,
21+
) {
22+
const input = await fs.readFile(inputPath, 'utf-8');
23+
24+
const tree = ast(input);
25+
26+
await fs.writeFile(outputPath, generateCodeByAST(tree, input, getGenerator), {});
27+
// eslint-disable-next-line no-console
28+
console.log(`Generated code is saved to ${outputPath}`);
29+
}
30+
31+
export async function generateCode(inputPath: string, outputPath: string, resultLanguage: string) {
32+
return generateCodeWithGenerator(inputPath, outputPath, getGenerator(resultLanguage));
33+
}

0 commit comments

Comments
 (0)