@@ -13,6 +13,8 @@ import {
1313} from "@fern-typescript/commons" ;
1414import { GeneratorContext } from "@fern-typescript/contexts" ;
1515import { SdkGenerator } from "@fern-typescript/sdk-generator" ;
16+ import { copyFile } from "fs/promises" ;
17+ import path from "path" ;
1618
1719import { SdkCustomConfig } from "./custom-config/SdkCustomConfig" ;
1820import { SdkCustomConfigSchema } from "./custom-config/schema/SdkCustomConfigSchema" ;
@@ -251,6 +253,7 @@ export class SdkGeneratorCli extends AbstractGeneratorCli<SdkCustomConfig> {
251253 pathToSrc : persistedTypescriptProject . getSrcDirectory ( )
252254 } ) ;
253255 await writeTemplateFiles ( rootDirectory , this . getTemplateVariables ( customConfig ) ) ;
256+ await this . writeLicenseFile ( config , rootDirectory , generatorContext . logger ) ;
254257 await this . postProcess ( persistedTypescriptProject , customConfig ) ;
255258
256259 return persistedTypescriptProject ;
@@ -265,6 +268,45 @@ export class SdkGeneratorCli extends AbstractGeneratorCli<SdkCustomConfig> {
265268 } ;
266269 }
267270
271+ private async writeLicenseFile (
272+ config : FernGeneratorExec . GeneratorConfig ,
273+ rootDirectory : AbsoluteFilePath ,
274+ logger : Logger
275+ ) : Promise < void > {
276+ if ( config . license ?. type === "custom" ) {
277+ // For custom licenses, we need to get the license content from the source file
278+ // The CLI should have read the license file content and made it available
279+ // For now, we'll read the license file from the original location
280+
281+ try {
282+ // The license file path is relative to the fern config directory
283+ // We need to construct the full path to read the license content
284+ const licenseFileName = config . license . filename ?? "LICENSE" ;
285+ const licenseFilePath = path . join ( rootDirectory , licenseFileName ) ;
286+
287+ await this . copyLicenseFile ( licenseFilePath ) ;
288+ logger . debug ( `Successfully wrote LICENSE file to ${ licenseFilePath } ` ) ;
289+ } catch ( error ) {
290+ // If we can't read the license file, we'll skip writing it
291+ // This maintains backwards compatibility
292+ logger . warn ( `Failed to write LICENSE file: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
293+ }
294+ }
295+ }
296+
297+ private async copyLicenseFile ( destinationPath : string ) : Promise < void > {
298+ // In Docker execution environment, the license file is mounted at /tmp/LICENSE
299+ const dockerLicensePath = "/tmp/LICENSE" ;
300+
301+ try {
302+ await copyFile ( dockerLicensePath , destinationPath ) ;
303+ } catch ( error ) {
304+ throw new Error (
305+ `Could not copy license file from ${ dockerLicensePath } : ${ error instanceof Error ? error . message : String ( error ) } `
306+ ) ;
307+ }
308+ }
309+
268310 private async postProcess (
269311 persistedTypescriptProject : PersistedTypescriptProject ,
270312 _customConfig : SdkCustomConfig
0 commit comments