-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
26 changed files
with
409 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
4 changes: 4 additions & 0 deletions
4
packages/cli/config-management/generators-configuration-v2/.depcheckrc.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,4 @@ | ||
{ | ||
"ignores": ["@types/jest", "@types/node", "@babel/core", "@babel/preset-env", "@babel/preset-typescript"], | ||
"ignore-patterns": ["lib"] | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cli/config-management/generators-configuration-v2/.mrlint.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,4 @@ | ||
{ | ||
"type": "library", | ||
"private": false | ||
} |
1 change: 1 addition & 0 deletions
1
packages/cli/config-management/generators-configuration-v2/.prettierrc.cjs
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"); |
1 change: 1 addition & 0 deletions
1
packages/cli/config-management/generators-configuration-v2/babel.config.cjs
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("../../../../babel.config.json"); |
1 change: 1 addition & 0 deletions
1
packages/cli/config-management/generators-configuration-v2/jest.config.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 @@ | ||
export { default } from "../../../../shared/jest.config.shared"; |
49 changes: 49 additions & 0 deletions
49
packages/cli/config-management/generators-configuration-v2/package.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,49 @@ | ||
{ | ||
"name": "@fern-api/generators-configuration-v2", | ||
"version": "0.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fern-api/fern.git", | ||
"directory": "packages/cli/config-management/generators-configuration-v2" | ||
}, | ||
"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": "yarn compile && jest --passWithNoTests", | ||
"lint:eslint": "eslint --max-warnings 0 . --ignore-path=../../../../.eslintignore", | ||
"lint:eslint:fix": "eslint --max-warnings 0 . --ignore-path=../../../../.eslintignore --fix", | ||
"format": "prettier --write --ignore-unknown --ignore-path ../../../../shared/.prettierignore \"**\"", | ||
"format:check": "prettier --check --ignore-unknown --ignore-path ../../../../shared/.prettierignore \"**\"", | ||
"depcheck": "depcheck" | ||
}, | ||
"dependencies": { | ||
"@fern-api/config-management-commons": "workspace:*", | ||
"@fern-api/core-utils": "workspace:*", | ||
"@fern-api/project-configuration": "workspace:*", | ||
"js-yaml": "^4.1.0", | ||
"lodash-es": "^4.17.21", | ||
"zod": "^3.14.3" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.18.10", | ||
"@babel/preset-env": "^7.18.10", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@types/jest": "^28.1.7", | ||
"@types/js-yaml": "^4.0.5", | ||
"@types/lodash-es": "^4.17.6", | ||
"@types/node": "^18.7.7", | ||
"depcheck": "^1.4.3", | ||
"eslint": "^8.22.0", | ||
"jest": "^28.1.3", | ||
"prettier": "^2.7.1", | ||
"typescript": "4.6.4" | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/cli/config-management/generators-configuration-v2/src/GeneratorsConfiguration.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,45 @@ | ||
import { AbsoluteFilePath } from "@fern-api/core-utils"; | ||
import { GeneratorsConfigurationSchema } from "./schemas/GeneratorsConfigurationSchema"; | ||
|
||
export interface GeneratorsConfiguration { | ||
absolutePathToConfiguration: AbsoluteFilePath; | ||
rawConfiguration: GeneratorsConfigurationSchema; | ||
draft: DraftGeneratorInvocation[]; | ||
release: ReleaseGeneratorInvocation[]; | ||
} | ||
|
||
export interface DraftGeneratorInvocation { | ||
absolutePathToLocalOutput: AbsoluteFilePath | undefined; | ||
} | ||
|
||
export interface ReleaseGeneratorInvocation { | ||
outputs: GeneratorOutputs; | ||
} | ||
|
||
export interface BaseGeneratorInvocation { | ||
name: string; | ||
version: string; | ||
config: unknown; | ||
} | ||
|
||
export interface GeneratorOutputs { | ||
npm: NpmGeneratorOutput | undefined; | ||
maven: MavenGeneratorOutput | undefined; | ||
github: GithubGeneratorOutput | undefined; | ||
} | ||
|
||
export interface NpmGeneratorOutput { | ||
packageName: string; | ||
token: string; | ||
} | ||
|
||
export interface MavenGeneratorOutput { | ||
coordinate: string; | ||
username: string; | ||
password: string; | ||
} | ||
|
||
export interface GithubGeneratorOutput { | ||
repository: string; | ||
token: string; | ||
} |
17 changes: 17 additions & 0 deletions
17
...config-management/generators-configuration-v2/src/__test__/substituteEnvVariables.test.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,17 @@ | ||
import yaml from "js-yaml"; | ||
import { substituteEnvVariables } from "../substituteEnvVariables"; | ||
|
||
describe("substituteEnvVariables", () => { | ||
it("basic", () => { | ||
process.env.ENV_VAR = "test"; | ||
const rawYaml = ` | ||
foo: bar | ||
baz: | ||
qux: | ||
thud: \${ENV_VAR} | ||
plugh: \${ENV_VAR}`; | ||
const parsedYaml = yaml.load(rawYaml); | ||
const substitutedYaml = substituteEnvVariables(parsedYaml); | ||
expect(substitutedYaml).toEqual({ foo: "bar", baz: { qux: { thud: "test" } }, plugh: "test" }); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
...s/cli/config-management/generators-configuration-v2/src/convertGeneratorsConfiguration.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,67 @@ | ||
import { AbsoluteFilePath, dirname, resolve } from "@fern-api/core-utils"; | ||
import { GeneratorsConfiguration } from "./GeneratorsConfiguration"; | ||
import { GeneratorsConfigurationSchema } from "./schemas/GeneratorsConfigurationSchema"; | ||
|
||
export function convertGeneratorsConfiguration({ | ||
absolutePathToGeneratorsConfiguration, | ||
rawGeneratorsConfiguration, | ||
}: { | ||
absolutePathToGeneratorsConfiguration: AbsoluteFilePath; | ||
rawGeneratorsConfiguration: GeneratorsConfigurationSchema; | ||
}): GeneratorsConfiguration { | ||
return { | ||
absolutePathToConfiguration: absolutePathToGeneratorsConfiguration, | ||
rawConfiguration: rawGeneratorsConfiguration, | ||
draft: | ||
rawGeneratorsConfiguration.draft != null | ||
? rawGeneratorsConfiguration.draft.map((draftInvocation) => { | ||
return { | ||
name: draftInvocation.name, | ||
version: draftInvocation.version, | ||
absolutePathToLocalOutput: | ||
draftInvocation["local-output"] != null | ||
? resolve( | ||
dirname(absolutePathToGeneratorsConfiguration), | ||
draftInvocation["local-output"] | ||
) | ||
: undefined, | ||
config: draftInvocation.config, | ||
}; | ||
}) | ||
: [], | ||
release: | ||
rawGeneratorsConfiguration.release != null | ||
? rawGeneratorsConfiguration.release.map((draftInvocation) => { | ||
return { | ||
name: draftInvocation.name, | ||
version: draftInvocation.version, | ||
outputs: { | ||
npm: | ||
draftInvocation.outputs.npm != null | ||
? { | ||
packageName: draftInvocation.outputs.npm["package-name"], | ||
token: draftInvocation.outputs.npm.token, | ||
} | ||
: undefined, | ||
maven: | ||
draftInvocation.outputs.maven != null | ||
? { | ||
coordinate: draftInvocation.outputs.maven.coordinate, | ||
username: draftInvocation.outputs.maven.username, | ||
password: draftInvocation.outputs.maven.password, | ||
} | ||
: undefined, | ||
github: | ||
draftInvocation.outputs.github != null | ||
? { | ||
repository: draftInvocation.outputs.github.repository, | ||
token: draftInvocation.outputs.github.token, | ||
} | ||
: undefined, | ||
}, | ||
config: draftInvocation.config, | ||
}; | ||
}) | ||
: [], | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/cli/config-management/generators-configuration-v2/src/index.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,11 @@ | ||
export { | ||
type DraftGeneratorInvocation, | ||
type GeneratorOutputs, | ||
type GeneratorsConfiguration, | ||
type GithubGeneratorOutput, | ||
type MavenGeneratorOutput, | ||
type NpmGeneratorOutput, | ||
type ReleaseGeneratorInvocation, | ||
} from "./GeneratorsConfiguration"; | ||
export { loadGeneratorsConfiguration, loadRawGeneratorsConfiguration } from "./loadGeneratorsConfiguration"; | ||
export { type GeneratorsConfigurationSchema } from "./schemas/GeneratorsConfigurationSchema"; |
39 changes: 39 additions & 0 deletions
39
...ages/cli/config-management/generators-configuration-v2/src/loadGeneratorsConfiguration.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,39 @@ | ||
import { validateSchema } from "@fern-api/config-management-commons"; | ||
import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/core-utils"; | ||
import { GENERATORS_CONFIGURATION_FILENAME } from "@fern-api/project-configuration"; | ||
import { readFile } from "fs/promises"; | ||
import yaml from "js-yaml"; | ||
import { convertGeneratorsConfiguration } from "./convertGeneratorsConfiguration"; | ||
import { GeneratorsConfiguration } from "./GeneratorsConfiguration"; | ||
import { GeneratorsConfigurationSchema } from "./schemas/GeneratorsConfigurationSchema"; | ||
import { substituteEnvVariables } from "./substituteEnvVariables"; | ||
|
||
export async function loadRawGeneratorsConfiguration({ | ||
absolutePathToWorkspace, | ||
}: { | ||
absolutePathToWorkspace: AbsoluteFilePath; | ||
}): Promise<GeneratorsConfigurationSchema> { | ||
const contentsStr = await readFile(getPathToGeneratorsConfiguration({ absolutePathToWorkspace })); | ||
const contentsParsed = substituteEnvVariables(yaml.load(contentsStr.toString())); | ||
return await validateSchema(GeneratorsConfigurationSchema, contentsParsed); | ||
} | ||
|
||
export async function loadGeneratorsConfiguration({ | ||
absolutePathToWorkspace, | ||
}: { | ||
absolutePathToWorkspace: AbsoluteFilePath; | ||
}): Promise<GeneratorsConfiguration> { | ||
const rawGeneratorsConfiguration = await loadRawGeneratorsConfiguration({ absolutePathToWorkspace }); | ||
return convertGeneratorsConfiguration({ | ||
absolutePathToGeneratorsConfiguration: getPathToGeneratorsConfiguration({ absolutePathToWorkspace }), | ||
rawGeneratorsConfiguration, | ||
}); | ||
} | ||
|
||
function getPathToGeneratorsConfiguration({ | ||
absolutePathToWorkspace, | ||
}: { | ||
absolutePathToWorkspace: AbsoluteFilePath; | ||
}): AbsoluteFilePath { | ||
return join(absolutePathToWorkspace, RelativeFilePath.of(GENERATORS_CONFIGURATION_FILENAME)); | ||
} |
9 changes: 9 additions & 0 deletions
9
...onfig-management/generators-configuration-v2/src/schemas/BaseGeneratorInvocationSchema.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,9 @@ | ||
import { z } from "zod"; | ||
|
||
export const BaseGeneratorInvocationSchema = z.strictObject({ | ||
name: z.string(), | ||
version: z.string(), | ||
config: z.unknown(), | ||
}); | ||
|
||
export type BaseGeneratorInvocationSchema = z.infer<typeof BaseGeneratorInvocationSchema>; |
9 changes: 9 additions & 0 deletions
9
...nfig-management/generators-configuration-v2/src/schemas/DraftGeneratorInvocationSchema.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,9 @@ | ||
import { FilePath } from "@fern-api/core-utils"; | ||
import { z } from "zod"; | ||
import { BaseGeneratorInvocationSchema } from "./BaseGeneratorInvocationSchema"; | ||
|
||
export const DraftGeneratorInvocationSchema = BaseGeneratorInvocationSchema.extend({ | ||
"local-output": z.optional(z.string().transform(FilePath.of)), | ||
}); | ||
|
||
export type DraftGeneratorInvocationSchema = z.infer<typeof DraftGeneratorInvocationSchema>; |
12 changes: 12 additions & 0 deletions
12
...s/cli/config-management/generators-configuration-v2/src/schemas/GeneratorOutputsSchema.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,12 @@ | ||
import { z } from "zod"; | ||
import { GithubRepositoryOutputSchema } from "./GithubRepositoryOutputSchema"; | ||
import { MavenRegistryOutputSchema } from "./MavenRegistryOutputSchema"; | ||
import { NpmRegistryOutputSchema } from "./NpmRegistryOutputSchema"; | ||
|
||
export const GeneratorOutputsSchema = z.strictObject({ | ||
npm: z.optional(NpmRegistryOutputSchema), | ||
maven: z.optional(MavenRegistryOutputSchema), | ||
github: z.optional(GithubRepositoryOutputSchema), | ||
}); | ||
|
||
export type GeneratorOutputsSchema = z.infer<typeof GeneratorOutputsSchema>; |
10 changes: 10 additions & 0 deletions
10
...onfig-management/generators-configuration-v2/src/schemas/GeneratorsConfigurationSchema.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,10 @@ | ||
import { z } from "zod"; | ||
import { DraftGeneratorInvocationSchema } from "./DraftGeneratorInvocationSchema"; | ||
import { ReleaseGeneratorInvocationSchema } from "./ReleaseGeneratorInvocationSchema"; | ||
|
||
export const GeneratorsConfigurationSchema = z.strictObject({ | ||
draft: z.optional(z.array(DraftGeneratorInvocationSchema)), | ||
release: z.optional(z.array(ReleaseGeneratorInvocationSchema)), | ||
}); | ||
|
||
export type GeneratorsConfigurationSchema = z.infer<typeof GeneratorsConfigurationSchema>; |
8 changes: 8 additions & 0 deletions
8
...config-management/generators-configuration-v2/src/schemas/GithubRepositoryOutputSchema.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,8 @@ | ||
import { z } from "zod"; | ||
|
||
export const GithubRepositoryOutputSchema = z.strictObject({ | ||
repository: z.string(), | ||
token: z.string(), | ||
}); | ||
|
||
export type GithubRepositoryOutputSchema = z.infer<typeof GithubRepositoryOutputSchema>; |
9 changes: 9 additions & 0 deletions
9
...li/config-management/generators-configuration-v2/src/schemas/MavenRegistryOutputSchema.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,9 @@ | ||
import { z } from "zod"; | ||
|
||
export const MavenRegistryOutputSchema = z.strictObject({ | ||
coordinate: z.string(), | ||
username: z.string(), | ||
password: z.string(), | ||
}); | ||
|
||
export type MavenRegistryOutputSchema = z.infer<typeof MavenRegistryOutputSchema>; |
8 changes: 8 additions & 0 deletions
8
.../cli/config-management/generators-configuration-v2/src/schemas/NpmRegistryOutputSchema.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,8 @@ | ||
import { z } from "zod"; | ||
|
||
export const NpmRegistryOutputSchema = z.strictObject({ | ||
"package-name": z.string(), | ||
token: z.string(), | ||
}); | ||
|
||
export type NpmRegistryOutputSchema = z.infer<typeof NpmRegistryOutputSchema>; |
Oops, something went wrong.