@@ -12,7 +12,7 @@ import { copyMpkFiles, getMpkPaths } from "./monorepo";
12
12
import { createModuleMpkInDocker } from "./mpk" ;
13
13
import { ModuleInfo , PackageInfo , WidgetInfo } from "./package-info" ;
14
14
import { 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" ;
16
16
import chalk from "chalk" ;
17
17
18
18
type Step < Info , Config > = ( params : { info : Info ; config : Config } ) => Promise < void > ;
@@ -194,6 +194,57 @@ export async function addWidgetsToMpk({ config }: ModuleStepParams): Promise<voi
194
194
rm ( "-rf" , target ) ;
195
195
}
196
196
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
+
197
248
export async function moveModuleToDist ( { info, config } : ModuleStepParams ) : Promise < void > {
198
249
logStep ( "Move module to dist" ) ;
199
250
0 commit comments