@@ -12,7 +12,7 @@ import { copyMpkFiles, getMpkPaths } from "./monorepo";
1212import { createModuleMpkInDocker } from "./mpk" ;
1313import { ModuleInfo , PackageInfo , WidgetInfo } from "./package-info" ;
1414import { addFilesToPackageXml , PackageType } from "./package-xml" ;
15- import { cp , ensureFileExists , exec , mkdir , popd , pushd , rm , unzip , zip , chmod } from "./shell" ;
15+ import { cp , ensureFileExists , exec , mkdir , popd , pushd , rm , unzip , zip , chmod , find } from "./shell" ;
1616import chalk from "chalk" ;
1717
1818type Step < Info , Config > = ( params : { info : Info ; config : Config } ) => Promise < void > ;
@@ -194,6 +194,57 @@ export async function addWidgetsToMpk({ config }: ModuleStepParams): Promise<voi
194194 rm ( "-rf" , target ) ;
195195}
196196
197+ export async function addREADMEOSSToMpk ( { config, info } : ModuleStepParams ) : Promise < void > {
198+ logStep ( "Add READMEOSS to mpk" ) ;
199+
200+ // Check that READMEOSS file exists in package root and find it by name pattern
201+ const packageRoot = config . paths . package ;
202+ const widgetName = info . mxpackage . name ;
203+ const version = info . version . format ( ) ;
204+
205+ // We'll search for files matching the name and version, ignoring timestamp
206+ const readmeossPattern = `*${ widgetName } __${ version } __READMEOSS_*.html` ;
207+
208+ console . info ( `Looking for READMEOSS file matching pattern: ${ readmeossPattern } ` ) ;
209+
210+ // Find files matching the pattern in package root
211+ const matchingFiles = find ( packageRoot ) . filter ( file => {
212+ const fileName = parse ( file ) . base ;
213+ // Check if filename contains the widget name, version, and READMEOSS
214+ return fileName . includes ( `${ widgetName } __${ version } __READMEOSS_` ) && fileName . endsWith ( ".html" ) ;
215+ } ) ;
216+
217+ if ( matchingFiles . length === 0 ) {
218+ console . warn (
219+ `⚠️ READMEOSS file not found for ${ widgetName } version ${ version } . Expected pattern: ${ readmeossPattern } `
220+ ) ;
221+ console . warn ( ` Skipping READMEOSS addition to mpk.` ) ;
222+ return ;
223+ }
224+
225+ const readmeossFile = matchingFiles [ 0 ] ;
226+ console . info ( `Found READMEOSS file: ${ parse ( readmeossFile ) . base } ` ) ;
227+
228+ const mpk = config . output . files . modulePackage ;
229+ const widgets = await getMpkPaths ( config . dependencies ) ;
230+ const mpkEntry = parse ( mpk ) ;
231+ const target = join ( mpkEntry . dir , "tmp" ) ;
232+
233+ rm ( "-rf" , target ) ;
234+
235+ console . info ( "Unzip module mpk" ) ;
236+ await unzip ( mpk , target ) ;
237+ chmod ( "-R" , "a+rw" , target ) ;
238+
239+ console . info ( `Add READMEOSS file to ${ mpkEntry . base } ` ) ;
240+ // Copy the READMEOSS file to the target directory
241+ cp ( readmeossFile , target ) ;
242+
243+ console . info ( "Create module zip archive" ) ;
244+ await zip ( target , mpk ) ;
245+ rm ( "-rf" , target ) ;
246+ }
247+
197248export async function moveModuleToDist ( { info, config } : ModuleStepParams ) : Promise < void > {
198249 logStep ( "Move module to dist" ) ;
199250
0 commit comments