- Notifications
You must be signed in to change notification settings - Fork26
A code generation framework inspired by JavaScript front-end frameworks
License
alloy-framework/alloy
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Alloy is a framework for code generation that borrows concepts from JavaScriptfront-end frameworks like React and Solid to provide highly ergonomic andproductive source code generation. Use JSX syntax or string templates to definesource files and the language elements within them. Alloy helps handle a lot ofthe hard bits like building source text from strings, linking declarations andimporting necessary dependencies, applying naming conventions, formatting, andgenerating syntax for a number of languages.
import*asayfrom"@alloy-js/core";import*astsfrom"@alloy-js/typescript";consthelloWorldRef=ay.refkey();constres=ay.render(<ay.Output><ay.SourceFilepath="readme.md"filetype="markdown"> This is a sample output project.</ay.SourceFile><ts.SourceFilepath="test1.ts"><ts.VarDeclarationexportname="foo"refkey={helloWorldRef}> "Hello world"</ts.VarDeclaration></ts.SourceFile><ts.SourceFilepath="test2.ts"><ts.VarDeclarationname="v">{helloWorldRef}</ts.VarDeclaration> console.log(v);</ts.SourceFile></ay.Output>,);console.log(res[2].contents);// import { foo } from "./test2.ts";//// const v = foo;
Or, if you prefer, you can use string templates:
import{refkey,render,code}from"@alloy-js/core";import*asayfrom"@alloy-js/core/stc";import*astsfrom"@alloy-js/typescript/stc";consthelloWorldRef=refkey();constres=render(ay.Output().children(ay.SourceFile({path:"readme.md",filetype:"markdown"}).code` This is a sample output project. `,ts.SourceFile({path:"test1.ts"}).children(ts.VarDeclaration({export:true,name:"foo",refkey:helloWorldRef}).code` "Hello world" `,),ts.SourceFile({path:"test2.ts"}).code`${ts.VarDeclaration({name:"v"}).children(helloWorldRef)} console.log(v); `,),);console.log(res[2].contents);// import { foo } from "./test2.ts";//// const v = foo;
This project is in pre-beta. Expect everything to change. Feedback is especiallyappreciated. The docs are not great but are being worked on.
- pnpm
- node 20+
Use this template to get started.
Alternatively, you can find the latest packages on GitHub by clicking the green checkbox next to the latest commit and clicking "details" next to Continuous Releases. Alloy will be published to NPM in the coming weeks.
Clone the repo, then:
> pnpm install> pnpm build
- C#: @alloy-js/csharp
- Java: @alloy-js/java
- TypeScript: @alloy-js/typescript
More are coming soon.
About
A code generation framework inspired by JavaScript front-end frameworks
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.