Skip to content

Commit

Permalink
Add exports for NPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Jan 16, 2024
1 parent 1c76154 commit aff9e4b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { generateCode } from "./src/main";
export { generateCode, generateCodeByAST, generateCodeWithGenerator } from "./src/main";
export { CodeGenerator } from "./src/generators/generator";
export { TypescriptGenerator } from "./src/generators/typescript/generator";
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@polyprogrammist_test/tlbgen",
"version": "1.0.2",
"version": "1.0.13",
"description": "",
"main": "index.js",
"main": "build/index.js",
"scripts": {
"test": "jest",
"build": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ast } from '@igorivaniuk/tlb-parser'
import fs from 'fs'


export function generate(tree: Program, input: string, getGenerator: (tlbCode: TLBCode) => CodeGenerator) {
export function generateCodeByAST(tree: Program, input: string, getGenerator: (tlbCode: TLBCode) => CodeGenerator) {
let oldTlbCode: TLBCodeBuild = { types: new Map<string, TLBTypeBuild>() };

let splittedInput = input.split("\n");
Expand Down Expand Up @@ -63,19 +63,24 @@ export function generate(tree: Program, input: string, getGenerator: (tlbCode: T
return generatedCode;
}

export function generateCode(inputPath: string, outputPath: string, resultLanguage: string) {
export function generateCodeWithGenerator(inputPath: string, outputPath: string, getGenerator: (tlbCode: TLBCode) => CodeGenerator) {
const input = fs.readFileSync(
inputPath,
'utf-8',
)

const tree = ast(input)

fs.writeFile(outputPath, generate(tree, input, (tlbCode: TLBCode) => {
fs.writeFile(outputPath, generateCodeByAST(tree, input, getGenerator), () => { });
}

export function generateCode(inputPath: string, outputPath: string, resultLanguage: string) {
let getGenerator = (tlbCode: TLBCode) => {
if (resultLanguage == 'typescript') {
return new TypescriptGenerator(tlbCode)
} else {
throw new Error(`Result language ${resultLanguage} is not supported`)
}
}), () => { });
}
generateCodeWithGenerator(inputPath, outputPath, getGenerator);
}

0 comments on commit aff9e4b

Please sign in to comment.