Skip to content

Commit

Permalink
chore(cli): Add browser compatible base generator (#5288)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Nov 26, 2024
1 parent 1ca6030 commit fa4aa6e
Show file tree
Hide file tree
Showing 185 changed files with 367 additions and 240 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@fern-api/generator-commons",
"name": "@fern-api/base-generator",
"version": "0.0.0",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern.git",
"directory": "generators/commons"
"directory": "generators/base"
},
"private": true,
"files": [
Expand All @@ -28,12 +28,12 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-api/browser-compatible-base-generator": "workspace:*",
"@fern-api/core-utils": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/logger": "workspace:*",
"@fern-api/logging-execa": "workspace:*",
"@fern-fern/generator-cli-sdk": "0.0.17",
"@fern-fern/generator-exec-sdk": "^0.0.898",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
"tmp-promise": "^3.0.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Logger } from "@fern-api/logger";
import { AbstractGeneratorContext } from "./AbstractGeneratorContext";
import { AbstractGeneratorContext, FernGeneratorExec } from "@fern-api/browser-compatible-base-generator";
import { GeneratorAgentClient } from "./GeneratorAgentClient";
import { FernGeneratorCli } from "@fern-fern/generator-cli-sdk";
import { readFile } from "fs/promises";
import yaml from "js-yaml";
import path from "path";
import { ReferenceConfigBuilder } from "./reference";
import { FernGeneratorExec } from "@fern-fern/generator-exec-sdk";

const DOCKER_FEATURES_CONFIG_PATH = "/assets/features.yml";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable no-console */
import { assertNever } from "@fern-api/core-utils";
import * as GeneratorExecParsing from "@fern-fern/generator-exec-sdk/serialization";
import { readFile } from "fs/promises";
import { AbstractGeneratorContext } from "./AbstractGeneratorContext";
import { FernGeneratorExec, GeneratorNotificationService } from "./GeneratorNotificationService";
import {
AbstractGeneratorContext,
FernGeneratorExec,
GeneratorExecParsing,
GeneratorNotificationService
} from "@fern-api/browser-compatible-base-generator";

export abstract class AbstractGeneratorCli<
CustomConfig,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createWriteStream } from "fs";
import { mkdir, readdir } from "fs/promises";
import { pipeline } from "stream";
import { promisify } from "util";
import { AbstractGeneratorContext } from "./AbstractGeneratorContext";
import { AbstractGeneratorContext } from "@fern-api/browser-compatible-base-generator";

const LOCAL_FILE_SCHEME = "file:///";
const PROTOBUF_ZIP_FILENAME = "proto.zip";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbsoluteFilePath, getDirectoryContents, getDirectoryContentsForSnapshot } from "@fern-api/fs-utils";
import path from "path";
import { AbstractGeneratorContext } from "../AbstractGeneratorContext";
import { AbstractGeneratorContext } from "@fern-api/browser-compatible-base-generator";
import { SourceFetcher } from "../SourceFetcher";

const AWS_BUCKET_NAME = "fdr-api-definition-source-test";
Expand Down
6 changes: 6 additions & 0 deletions generators/base/src/browserCompatibleExports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Export everything from @fern-api/browser-compatible-base-generator
// so that generators can simply consume @fern-api/base-generator.
//
// Packages that require browser compatibility should import directly
// from @fern-api/browser-compatible-base-generator.
export * from "@fern-api/browser-compatible-base-generator";
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
export * from "./AbstractGeneratorAgent";
export * from "./AbstractGeneratorCli";
export * from "./AbstractGeneratorContext";
export * from "./GeneratorNotificationService";
export * from "./browserCompatibleExports";
export * from "./SourceFetcher";
export * from "./ast";
export * from "./project";
export * from "./readme";
export * from "./reference";
export * from "./utils";
export * from "./dynamic-snippets";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractGeneratorContext } from "../AbstractGeneratorContext";
import { AbstractGeneratorContext } from "@fern-api/browser-compatible-base-generator";
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { File } from "./File";

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FernGeneratorExec } from "../GeneratorNotificationService";
import { FernGeneratorExec } from "@fern-api/browser-compatible-base-generator";
import { camelCase } from "lodash-es";

export abstract class AbstractReadmeSnippetBuilder {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions generators/base/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { parseGeneratorConfig } from "./parseGeneratorConfig";
export { parseIR } from "./parseIR";
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FernGeneratorExec } from "@fern-fern/generator-exec-sdk";
import * as GeneratorExecParsing from "@fern-fern/generator-exec-sdk/serialization";
import { FernGeneratorExec, GeneratorExecParsing } from "@fern-api/browser-compatible-base-generator";
import { readFile } from "fs/promises";

export async function parseGeneratorConfig(pathToConfig: string): Promise<FernGeneratorExec.GeneratorConfig> {
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions generators/base/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": "../../shared/tsconfig.shared.json",
"compilerOptions": {
"composite": true,
"outDir": "lib",
"rootDir": "src"
},
"include": [
"./src/**/*"
],
"references": [
{
"path": "../browser-compatible-base"
},
{
"path": "../../packages/cli/logger"
},
{
"path": "../../packages/commons/core-utils"
},
{
"path": "../../packages/commons/fs-utils"
},
{
"path": "../../packages/commons/logging-execa"
}
]
}
File renamed without changes.
10 changes: 10 additions & 0 deletions generators/browser-compatible-base/.depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ignores": [
"@types/jest",
"globals",
"@types/node"
],
"ignore-patterns": [
"lib"
]
}
1 change: 1 addition & 0 deletions generators/browser-compatible-base/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../.prettierrc.json");
42 changes: 42 additions & 0 deletions generators/browser-compatible-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@fern-api/browser-compatible-base-generator",
"version": "0.0.0",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern.git",
"directory": "generators/browser-compatible-base"
},
"private": true,
"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 --passWithNoTests --run",
"test:update": "vitest --passWithNoTests --run -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"
},
"dependencies": {
"@fern-api/logger": "workspace:*",
"@fern-fern/generator-exec-sdk": "^0.0.898"
},
"devDependencies": {
"depcheck": "^1.4.6",
"eslint": "^8.56.0",
"vitest": "^2.1.4",
"organize-imports-cli": "^0.10.0",
"prettier": "^2.7.1",
"typescript": "4.6.4"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions generators/browser-compatible-base/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./AbstractGeneratorContext";
export * from "./GeneratorNotificationService";
export * from "./ast";
export * from "./utils";
export * from "./dynamic-snippets";
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export { getBasename } from "./getBasename";
export { getPackageName } from "./getPackageName";
export { getSdkVersion } from "./getSdkVersion";
export { parseGeneratorConfig } from "./parseGeneratorConfig";
export { parseIR } from "./parseIR";
19 changes: 19 additions & 0 deletions generators/browser-compatible-base/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../shared/tsconfig.shared.json",
"compilerOptions": {
"composite": true,
"outDir": "lib",
"rootDir": "src"
},
"include": [
"./src/**/*"
],
"references": [
{
"path": "../../packages/cli/logger"
},
{
"path": "../../packages/commons/core-utils"
},
]
}
1 change: 1 addition & 0 deletions generators/browser-compatible-base/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "../../shared/vitest.config";
11 changes: 0 additions & 11 deletions generators/commons/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion generators/csharp/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generator-commons": "workspace:*",
"@fern-api/base-generator": "workspace:*",
"@fern-api/logging-execa": "workspace:*",
"@fern-fern/ir-sdk": "^53.18.0",
"lodash-es": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/FileGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { AbstractCsharpGeneratorContext } from "./cli";
import { BaseCsharpCustomConfigSchema } from "./custom-config";
import { File } from "@fern-api/generator-commons";
import { File } from "@fern-api/base-generator";

export abstract class FileGenerator<
GeneratedFile extends File,
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/ast/ClassInstantiation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arguments, hasNamedArgument, isNamedArgument } from "@fern-api/generator-commons";
import { Arguments, hasNamedArgument, isNamedArgument } from "@fern-api/base-generator";
import { ClassReference } from "./ClassReference";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/ast/CodeBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeBlock as CommonCodeBlock } from "@fern-api/generator-commons";
import { CodeBlock as CommonCodeBlock } from "@fern-api/base-generator";
import { AstNode, Writer } from "../csharp";

export declare namespace CodeBlock {
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/ast/Dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertNever } from "@fern-api/core-utils";
import { UnnamedArgument } from "@fern-api/generator-commons";
import { UnnamedArgument } from "@fern-api/base-generator";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";
import { Type } from "./Type";
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/ast/Ternary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ternary as CommonTernary } from "@fern-api/generator-commons";
import { Ternary as CommonTernary } from "@fern-api/base-generator";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";

Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/ast/core/AstNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractAstNode } from "@fern-api/generator-commons";
import { AbstractAstNode } from "@fern-api/base-generator";
import { execSync } from "child_process";
import { BaseCsharpCustomConfigSchema } from "../../custom-config";
import { Writer } from "./Writer";
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/ast/core/Writer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractWriter } from "@fern-api/generator-commons";
import { AbstractWriter } from "@fern-api/base-generator";
import { ClassReference } from "..";
import { csharp } from "../..";
import { BaseCsharpCustomConfigSchema } from "../../custom-config";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { AbstractGeneratorCli, parseIR } from "@fern-api/generator-commons";
import { AbstractGeneratorCli, parseIR } from "@fern-api/base-generator";
import { IntermediateRepresentation } from "@fern-fern/ir-sdk/api";
import * as IrSerialization from "@fern-fern/ir-sdk/serialization";
import { readFile } from "fs/promises";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, RelativeFilePath } from "@fern-api/fs-utils";
import { AbstractGeneratorContext, FernGeneratorExec, GeneratorNotificationService } from "@fern-api/generator-commons";
import { AbstractGeneratorContext, FernGeneratorExec, GeneratorNotificationService } from "@fern-api/base-generator";
import {
FernFilepath,
HttpHeader,
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/project/CSharpFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FernFilepath } from "@fern-fern/ir-sdk/api";
import path from "path";
import { Class, Enum, Interface } from "../ast";
import { BaseCsharpCustomConfigSchema } from "../custom-config";
import { File } from "@fern-api/generator-commons";
import { File } from "@fern-api/base-generator";

export type Namespace = string;

Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/project/CsharpProject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/fs-utils";
import { SourceFetcher, File, AbstractProject, FernGeneratorExec } from "@fern-api/generator-commons";
import { SourceFetcher, File, AbstractProject, FernGeneratorExec } from "@fern-api/base-generator";
import { loggingExeca } from "@fern-api/logging-execa";
import { mkdir, readFile, writeFile } from "fs/promises";
import { template } from "lodash-es";
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/project/PrebuiltUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbsoluteFilePath, RelativeFilePath } from "@fern-api/fs-utils";
import { readFile } from "fs/promises";
import { Annotation, ClassReference } from "../ast";
import { File } from "@fern-api/generator-commons";
import { File } from "@fern-api/base-generator";

export class PrebuiltUtilities {
private utilitiesDirectory = RelativeFilePath.of("Utilities");
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
{ "path": "../../../packages/commons/core-utils" },
{ "path": "../../../packages/commons/fs-utils" },
{ "path": "../../../packages/commons/logging-execa" },
{ "path": "../../commons" }
{ "path": "../../base" }
]
}
2 changes: 1 addition & 1 deletion generators/csharp/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@fern-api/csharp-codegen": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generator-commons": "workspace:*",
"@fern-api/base-generator": "workspace:*",
"@fern-fern/ir-sdk": "^53.18.0",
"zod": "^3.22.3",
"@types/jest": "^29.5.12",
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/model/src/ModelGeneratorCli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractCsharpGeneratorCli, validateReadOnlyMemoryTypes } from "@fern-api/csharp-codegen";
import { FernGeneratorExec, GeneratorNotificationService } from "@fern-api/generator-commons";
import { FernGeneratorExec, GeneratorNotificationService } from "@fern-api/base-generator";
import { IntermediateRepresentation } from "@fern-fern/ir-sdk/api";
import { generateModels } from "./generateModels";
import { generateWellKnownProtobufFiles } from "./generateWellKnownProtobufFiles";
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/model/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"include": ["./src/**/*"],
"references": [
{ "path": "../../../packages/commons/fs-utils" },
{ "path": "../../commons" },
{ "path": "../../base" },
{ "path": "../codegen" }
]
}
2 changes: 1 addition & 1 deletion generators/csharp/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@fern-api/csharp-codegen": "workspace:*",
"@fern-api/fern-csharp-model": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generator-commons": "workspace:*",
"@fern-api/base-generator": "workspace:*",
"@fern-api/logger": "workspace:*",
"@fern-fern/generator-cli-sdk": "0.0.17",
"@fern-fern/generator-exec-sdk": "^0.0.898",
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/sdk/src/CsharpGeneratorAgent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractGeneratorAgent } from "@fern-api/generator-commons";
import { AbstractGeneratorAgent } from "@fern-api/base-generator";
import { Logger } from "@fern-api/logger";
import { FernGeneratorCli } from "@fern-fern/generator-cli-sdk";
import { FernGeneratorExec } from "@fern-fern/generator-exec-sdk";
Expand Down
Loading

0 comments on commit fa4aa6e

Please sign in to comment.