-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
272 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"ignores": [ | ||
"@types/jest", | ||
"globals", | ||
"@types/node", | ||
"@fern-fern/ir-sdk" | ||
], | ||
"ignore-patterns": [ | ||
"lib" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("../../../.prettierrc.json"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "@fern-api/typescript-codegen", | ||
"version": "0.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fern-api/fern.git" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"type": "module", | ||
"source": "src/index.ts", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"clean": "rm -rf ./lib && tsc --build --clean", | ||
"compile": "tsc --build", | ||
"test": "vitest --run --passWithNoTests", | ||
"test:update": "vitest --run --passWithNoTests -u", | ||
"lint:eslint": "eslint --max-warnings 0 . --ignore-path=../../../.eslintignore", | ||
"lint:eslint:fix": "yarn lint:eslint --fix", | ||
"format": "prettier --write --ignore-unknown --ignore-path ../../../shared/.prettierignore \"**\"", | ||
"format:check": "prettier --check --ignore-unknown --ignore-path ../../../shared/.prettierignore \"**\"", | ||
"organize-imports": "organize-imports-cli tsconfig.json", | ||
"depcheck": "depcheck" | ||
}, | ||
"devDependencies": { | ||
"@fern-api/fs-utils": "workspace:*", | ||
"@fern-api/core-utils": "workspace:*", | ||
"@fern-api/generator-commons": "workspace:*", | ||
"@fern-fern/ir-sdk": "53.8.0", | ||
"zod": "^3.22.3", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^18.7.18", | ||
"depcheck": "^1.4.6", | ||
"eslint": "^8.56.0", | ||
"organize-imports-cli": "^0.10.0", | ||
"prettier": "^2.7.1", | ||
"typescript": "4.6.4", | ||
"vitest": "^2.0.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CodeBlock as CommonCodeBlock } from "@fern-api/generator-commons"; | ||
import { AstNode, Writer } from "../typescript"; | ||
|
||
export declare namespace CodeBlock { | ||
/* Write arbitrary code */ | ||
type Args = CommonCodeBlock.Arg<Writer>; | ||
} | ||
|
||
export class CodeBlock extends AstNode { | ||
private args: CodeBlock.Args; | ||
|
||
public constructor(args: CodeBlock.Args) { | ||
super(); | ||
this.args = args; | ||
} | ||
|
||
public write(writer: Writer): void { | ||
const commonCodeBlock = new CommonCodeBlock(this.args); | ||
return commonCodeBlock.write(writer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { assertNever } from "@fern-api/core-utils"; | ||
import { AstNode } from "./core/AstNode"; | ||
import { Writer } from "./core/Writer"; | ||
|
||
type InternalType = String_; | ||
|
||
interface String_ { | ||
type: "string"; | ||
} | ||
|
||
/* A C# parameter to a method */ | ||
export class Type extends AstNode { | ||
private constructor(public readonly internalType: InternalType) { | ||
super(); | ||
} | ||
|
||
public write(writer: Writer): void { | ||
switch (this.internalType.type) { | ||
case "string": | ||
writer.write("string"); | ||
break; | ||
default: | ||
assertNever(this.internalType.type); | ||
} | ||
} | ||
|
||
/* Static factory methods for creating a Type */ | ||
public static string(): Type { | ||
return new this({ | ||
type: "string" | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { CodeBlock } from "./CodeBlock"; | ||
import { AstNode, Writer } from "./core"; | ||
|
||
export declare namespace Variable { | ||
interface Args { | ||
/* Whether to export */ | ||
export?: boolean; | ||
/* Whether to label as const */ | ||
const?: boolean; | ||
/* The name of the variable */ | ||
name: string; | ||
/* The initializer for the variable */ | ||
initializer: CodeBlock; | ||
} | ||
} | ||
|
||
export class Variable extends AstNode { | ||
public constructor(private readonly args: Variable.Args) { | ||
super(); | ||
} | ||
|
||
public write(writer: Writer): void { | ||
if (this.args.export) { | ||
writer.write("export "); | ||
} | ||
if (this.args.const) { | ||
writer.write("const "); | ||
} | ||
writer.write(`${this.args.name} = `); | ||
writer.writeNodeStatement(this.args.initializer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { AbstractAstNode } from "@fern-api/generator-commons"; | ||
|
||
export abstract class AstNode extends AbstractAstNode {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AbstractWriter } from "@fern-api/generator-commons"; | ||
|
||
export class Writer extends AbstractWriter { | ||
public toString(): string { | ||
return this.buffer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { AstNode } from "./AstNode"; | ||
export { Writer } from "./Writer"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./core"; | ||
export { CodeBlock } from "./CodeBlock"; | ||
export { Type } from "./Type"; | ||
export { Variable } from "./Variable"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * as ts from "./typescript"; | ||
export * from "./ast/core"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as AST from "./ast"; | ||
|
||
export function codeblock(arg: AST.CodeBlock.Args): AST.CodeBlock { | ||
return new AST.CodeBlock(arg); | ||
} | ||
|
||
export function variable(arg: AST.Variable.Args): AST.Variable { | ||
return new AST.Variable(arg); | ||
} | ||
|
||
export * from "./ast"; | ||
export { Type as Types } from "./ast"; | ||
export * from "./ast/core"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../../shared/tsconfig.shared.json", | ||
"compilerOptions": { "composite": true, "outDir": "lib", "rootDir": "src" }, | ||
"include": ["./src/**/*"], | ||
"references": [ | ||
{ "path": "../../../packages/commons/core-utils" }, | ||
{ "path": "../../../packages/commons/fs-utils" }, | ||
{ "path": "../../../packages/commons/logging-execa" }, | ||
{ "path": "../../commons" } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "../../../shared/vitest.config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
generators/typescript/sdk/generator/src/version/VersionFileGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { IntermediateRepresentation } from "@fern-fern/ir-sdk/api"; | ||
import { Directory } from "ts-morph"; | ||
import { Writer, ts } from "@fern-api/typescript-codegen"; | ||
|
||
export declare namespace VersionFileGenerator { | ||
interface Args { | ||
ir: IntermediateRepresentation; | ||
rootDirectory: Directory; | ||
} | ||
} | ||
|
||
export class VersionFileGenerator { | ||
private ir: IntermediateRepresentation; | ||
private rootDirectory: Directory; | ||
|
||
constructor({ ir, rootDirectory }: VersionFileGenerator.Args) { | ||
this.ir = ir; | ||
this.rootDirectory = rootDirectory; | ||
} | ||
|
||
public generate(): void { | ||
const writer = new Writer(); | ||
writer.writeNodeStatement( | ||
ts.variable({ | ||
const: true, | ||
export: true, | ||
initializer: ts.codeblock(`"${this.ir.sdkConfig.platformHeaders.sdkVersion}"`), | ||
name: "SdkVersion" | ||
}) | ||
); | ||
this.rootDirectory.createSourceFile("version.ts", writer.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.