Skip to content

Commit 449b7e0

Browse files
committed
feat: add typescript sdk for compiler
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent 3043611 commit 449b7e0

14 files changed

Lines changed: 1236 additions & 463 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
*.swp
44
.DS_Store
55
vendor
6+
dist

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.gs.ts

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,47 @@ func main() {
9393

9494
This example initializes the compiler, creates a compiler instance, and then calls `CompilePackages` to translate the specified Go package into TypeScript files in the output directory.
9595

96+
### TypeScript API
97+
98+
You can also use GoScript programmatically within your Node.js projects.
99+
100+
**Installation:**
101+
102+
```bash
103+
npm install goscript
104+
# or
105+
yarn add goscript
106+
```
107+
108+
**Usage:**
109+
110+
```typescript
111+
import { compile } from 'goscript';
112+
import * as path from 'path';
113+
114+
async function runCompilation() {
115+
const exampleDir = path.resolve(__dirname, 'path/to/your/go/project'); // Adjust path accordingly
116+
const outputDir = path.join(exampleDir, 'ts_output');
117+
118+
try {
119+
await compile({
120+
pkg: '.', // Compile the package in the exampleDir
121+
dir: exampleDir,
122+
output: outputDir,
123+
// Optional: specify path to goscript CLI if not in PATH or using go run
124+
// goscriptPath: '/path/to/goscript/executable'
125+
});
126+
console.log(`Compilation successful! Output in ${outputDir}`);
127+
} catch (error) {
128+
console.error('Compilation failed:', error);
129+
}
130+
}
131+
132+
runCompilation();
133+
```
134+
135+
This example imports the `compile` function, configures it to compile a Go package located in `exampleDir`, and outputs the TypeScript files to `outputDir`.
136+
96137
## Roadmap
97138

98139
Check [the compliance tests](./compliance/COMPLIANCE.md) for implementation progress.

0 commit comments

Comments
 (0)