Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@
"@fern-fern/generator-exec-sdk": "^0.0.1167",
"chalk": "^5.3.0",
"decompress": "^4.2.1",
"js-yaml": "^4.1.0",
"prettier2": "npm:prettier@^2.7.1",
"tmp-promise": "^3.0.3"
},
"devDependencies": {
"@fern-api/configs": "workspace:*",
"@types/decompress": "^4.2.7",
"@types/js-yaml": "^4.0.5",
"@types/node": "18.15.3",
"@types/prettier2": "npm:@types/prettier@^2.7.3",
"depcheck": "^1.4.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ export async function writeFilesToDiskAndRunGenerator({
runner
});

await writeFernMetadata({
outputDirectory: absolutePathToTmpOutputDirectory,
generatorInvocation,
context
});

const taskHandler = new LocalTaskHandler({
context,
absolutePathToLocalOutput,
Expand Down Expand Up @@ -264,3 +270,41 @@ function getSourceConfig(workspace: FernWorkspace): SourceConfig {
function getDockerDestinationForSource(source: IdentifiableSource): string {
return `${DOCKER_SOURCES_DIRECTORY}/${source.id}`;
}

function getCliVersion(): string {
return process.env.CLI_VERSION ?? "unknown";
}

interface FernMetadata {
cliVersion: string;
generatorName: string;
generatorVersion: string;
generatorsYml?: {
config?: unknown;
};
}

async function writeFernMetadata({
outputDirectory,
generatorInvocation,
context
}: {
outputDirectory: AbsoluteFilePath;
generatorInvocation: generatorsYml.GeneratorInvocation;
context: TaskContext;
}): Promise<void> {
const cliVersion = getCliVersion();

const metadata: FernMetadata = {
cliVersion,
generatorName: generatorInvocation.name,
generatorVersion: generatorInvocation.version,
generatorsYml: {
config: generatorInvocation.config
}
};

const metadataPath = join(outputDirectory, ".fern.metadata.json");
await writeFile(metadataPath, JSON.stringify(metadata, null, 2));
context.logger.debug(`Wrote Fern metadata to: ${metadataPath}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import axios from "axios";
import chalk from "chalk";
import decompress from "decompress";
import { createWriteStream } from "fs";
import { mkdir, rm } from "fs/promises";
import { mkdir, rm, writeFile } from "fs/promises";
import path from "path";
import { pipeline } from "stream/promises";
import terminalLink from "terminal-link";
Expand Down Expand Up @@ -101,7 +101,8 @@ export class RemoteTaskHandler {
await downloadFilesForTask({
s3PreSignedReadUrl: finishedStatus.s3PreSignedReadUrlV2,
absolutePathToLocalOutput,
context: this.context
context: this.context,
generatorInvocation: this.generatorInvocation
});
}
}
Expand Down Expand Up @@ -152,18 +153,26 @@ export class RemoteTaskHandler {
async function downloadFilesForTask({
s3PreSignedReadUrl,
absolutePathToLocalOutput,
context
context,
generatorInvocation
}: {
s3PreSignedReadUrl: string;
absolutePathToLocalOutput: AbsoluteFilePath;
context: InteractiveTaskContext;
generatorInvocation: generatorsYml.GeneratorInvocation;
}) {
try {
await downloadZipForTask({
s3PreSignedReadUrl,
absolutePathToLocalOutput
});

await writeFernMetadata({
outputDirectory: absolutePathToLocalOutput,
generatorInvocation,
context
});

context.logger.info(chalk.green(`Downloaded to ${absolutePathToLocalOutput}`));
} catch (e) {
context.failAndThrow("Failed to download files", e);
Expand Down Expand Up @@ -209,3 +218,41 @@ function convertLogLevel(logLevel: FernFiddle.LogLevel): LogLevel {
return LogLevel.Info;
}
}

function getCliVersion(): string {
return process.env.CLI_VERSION ?? "unknown";
}

interface FernMetadata {
cliVersion: string;
generatorName: string;
generatorVersion: string;
generatorsYml?: {
config?: unknown;
};
}

async function writeFernMetadata({
outputDirectory,
generatorInvocation,
context
}: {
outputDirectory: AbsoluteFilePath;
generatorInvocation: generatorsYml.GeneratorInvocation;
context: InteractiveTaskContext;
}): Promise<void> {
const cliVersion = getCliVersion();

const metadata: FernMetadata = {
cliVersion,
generatorName: generatorInvocation.name,
generatorVersion: generatorInvocation.version,
generatorsYml: {
config: generatorInvocation.config
}
};

const metadataPath = join(outputDirectory, RelativeFilePath.of(".fern.metadata.json"));
await writeFile(metadataPath, JSON.stringify(metadata, null, 2));
context.logger.debug(`Wrote Fern metadata to: ${metadataPath}`);
}
80 changes: 7 additions & 73 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading