11import assert from "node:assert" ;
22import fs from "node:fs" ;
33import * as Path from "node:path" ;
4+ import { fileURLToPath } from "node:url" ;
45import {
56 camelCase ,
67 capitalCase ,
@@ -139,21 +140,26 @@ const deriveResourceName = (id: Identifier): string => {
139140 return pascalCase ( id . name ) ;
140141} ;
141142
143+ const resolvePyAssets = ( fn : string ) => {
144+ const __dirname = Path . dirname ( fileURLToPath ( import . meta. url ) ) ;
145+ if ( __filename . endsWith ( "dist/index.js" ) ) {
146+ return Path . resolve ( __dirname , ".." , "assets" , "api" , "writer-generator" , "python" , fn ) ;
147+ } else {
148+ return Path . resolve ( __dirname , "../../.." , "assets" , "api" , "writer-generator" , "python" , fn ) ;
149+ }
150+ } ;
151+
142152type TypeSchemaPackageGroups = {
143153 groupedResources : Record < string , RegularTypeSchema [ ] > ;
144154 groupedComplexTypes : Record < string , RegularTypeSchema [ ] > ;
145155} ;
146156
147157export class Python extends Writer < PythonGeneratorOptions > {
148- private readonly staticDir : string | undefined ;
149158 private readonly nameFormatFunction : ( name : string ) => string ;
150159 private tsIndex : TypeSchemaIndex | undefined ;
151160
152161 constructor ( options : PythonGeneratorOptions ) {
153- super ( {
154- ...options ,
155- } ) ;
156- this . staticDir = options . staticDir || undefined ;
162+ super ( options ) ;
157163 this . nameFormatFunction = this . getFieldFormatFunction ( options . fieldFormat ) ;
158164 }
159165
@@ -169,7 +175,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
169175
170176 private generateRootPackages ( groups : TypeSchemaPackageGroups ) : void {
171177 this . generateRootInitFile ( groups ) ;
172- this . copyStaticFiles ( ) ;
178+ fs . cpSync ( resolvePyAssets ( "requirements.txt" ) , Path . resolve ( this . opts . outputDir , "requirements.txt" ) ) ;
173179 }
174180
175181 private generateSDKPackages ( groups : TypeSchemaPackageGroups ) : void {
@@ -628,8 +634,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
628634 }
629635
630636 private includeResourceFamilyValidator ( ) : void {
631- const path = "src/api/writer-generator/python/resource_family_validator.py" ;
632- const content = fs . readFileSync ( path , "utf-8" ) ;
637+ const content = fs . readFileSync ( resolvePyAssets ( "resource_family_validator.py" ) , "utf-8" ) ;
633638 this . line ( content ) ;
634639 }
635640
@@ -683,11 +688,6 @@ export class Python extends Writer<PythonGeneratorOptions> {
683688 return this . pyFhirPackage ( identifier ) ;
684689 }
685690
686- copyStaticFiles ( ) : void {
687- if ( ! this . staticDir ) return ;
688- fs . cpSync ( Path . resolve ( this . staticDir ) , this . opts . outputDir , { recursive : true } ) ;
689- }
690-
691691 getFieldFormatFunction ( format : StringFormatKey ) : ( name : string ) => string {
692692 if ( ! AVAILABLE_STRING_FORMATS [ format ] ) {
693693 this . logger ( ) ?. warn ( `Unknown field format '${ format } '. Defaulting to SnakeCase.` ) ;
0 commit comments