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