@@ -3,38 +3,32 @@ import { basename, join } from "path";
33import { globSync } from "glob" ;
44import { exec } from "child_process" ;
55
6+ type OssReadMeValidationCriteria = {
7+ package : string ;
8+ version : string ;
9+ } ;
10+
611export async function getOssFiles (
712 folderPath : string ,
8- isOssReadmeRequired : boolean
13+ validationCriteria ?: OssReadMeValidationCriteria
914) : Promise < Array < { src : string ; dest : string } > > {
1015 if ( ! folderPath || typeof folderPath !== "string" ) {
1116 throw new TypeError ( `Invalid folderPath: ${ folderPath } ` ) ;
1217 }
1318
14- const licenseFile = join ( folderPath , `License.txt` ) ;
19+ const license = join ( folderPath , `License.txt` ) ;
1520 try {
16- await access ( licenseFile ) ;
21+ await access ( license ) ;
1722 } catch {
18- throw new Error ( `License file not found at expected location: ${ licenseFile } ` ) ;
23+ throw new Error ( `License file not found at expected location: ${ license } ` ) ;
1924 }
2025
21- const readmeossPattern = "*__*__READMEOSS_*.html" ;
22- const readmeossFiles = globSync ( readmeossPattern , { cwd : folderPath , absolute : true , ignore : "**/.*/**" } ) ;
23-
24- if ( isOssReadmeRequired && readmeossFiles . length === 0 ) {
25- throw new Error ( `No OSS README file found in ${ folderPath } matching ${ readmeossPattern } ` ) ;
26+ const readmePattern = "*__*__READMEOSS_*.html" ;
27+ const readme = globSync ( readmePattern , { cwd : folderPath , absolute : true , ignore : "**/.*/**" } ) [ 0 ] ;
28+ if ( validationCriteria ) {
29+ validateOssReadme ( readme , validationCriteria ) ;
2630 }
27-
28- if ( readmeossFiles . length === 0 ) {
29- return [ { src : licenseFile , dest : basename ( licenseFile ) } ] ;
30- }
31-
32- const ossReadmeFile = readmeossFiles [ 0 ] ;
33-
34- return [
35- { src : licenseFile , dest : basename ( licenseFile ) } ,
36- { src : ossReadmeFile , dest : basename ( ossReadmeFile ) }
37- ] ;
31+ return [ { src : license , dest : basename ( license ) } , ...( readme ? [ { src : readme , dest : basename ( readme ) } ] : [ ] ) ] ;
3832}
3933
4034type FilePathPair = { src : string ; dest : string } ;
@@ -61,7 +55,7 @@ export function unzip(src: string, dest: string): Promise<string> {
6155 return execShellCommand ( `unzip "${ src } " -d "${ dest } "` ) ;
6256}
6357
64- function execShellCommand ( cmd : string , workingDirectory = process . cwd ( ) ) : Promise < string > {
58+ export function execShellCommand ( cmd : string , workingDirectory = process . cwd ( ) ) : Promise < string > {
6559 return new Promise ( ( resolve , reject ) => {
6660 exec ( cmd , { cwd : workingDirectory } , ( error , stdout , stderr ) => {
6761 if ( error ) {
@@ -76,3 +70,45 @@ function execShellCommand(cmd: string, workingDirectory = process.cwd()): Promis
7670 } ) ;
7771 } ) ;
7872}
73+
74+ export function validateOssReadme ( ossReadme : string , validationCriteria : OssReadMeValidationCriteria ) : void {
75+ if ( ! ossReadme || typeof ossReadme !== "string" ) {
76+ throw new TypeError ( `Invalid OSS README path/name: ${ ossReadme } ` ) ;
77+ }
78+ if ( ! validationCriteria . version || typeof validationCriteria . version !== "string" ) {
79+ throw new TypeError ( `Invalid version: ${ validationCriteria . version } ` ) ;
80+ }
81+ if ( ! validationCriteria . package || typeof validationCriteria . package !== "string" ) {
82+ throw new TypeError ( `Invalid package name: ${ validationCriteria . package } ` ) ;
83+ }
84+
85+ const fileName = basename ( ossReadme ) ;
86+ const expectedPackage = validationCriteria . package . trim ( ) ;
87+ const expectedVersion = validationCriteria . version . trim ( ) ;
88+
89+ // File name pattern: SiemensMendix<PACKAGE>__<VERSION>__READMEOSS_*.html
90+ // Example: SiemensMendixNanoflowCommons__6.3.1__READMEOSS_2026-02-10__04-28-37.html
91+ const parsed = fileName . match ( / ^ S i e m e n s M e n d i x ( .+ ?) _ _ ( .+ ?) _ _ R E A D M E O S S _ ( .+ ) \. h t m l $ / ) ;
92+
93+ if ( ! parsed ) {
94+ throw new Error (
95+ `OSS README validation failed: '${ fileName } ' does not match expected pattern ` +
96+ `'SiemensMendix<PACKAGE>__<VERSION>__READMEOSS_*.html'.`
97+ ) ;
98+ }
99+
100+ const foundPackage = parsed [ 1 ] ;
101+ const foundVersion = parsed [ 2 ] ;
102+
103+ if ( foundPackage !== expectedPackage ) {
104+ throw new Error (
105+ `OSS README validation failed: expected package '${ expectedPackage } ' but found '${ foundPackage } ' in '${ fileName } '.`
106+ ) ;
107+ }
108+
109+ if ( foundVersion !== expectedVersion ) {
110+ throw new Error (
111+ `OSS README validation failed: expected version '${ expectedVersion } ' but found '${ foundVersion } ' in '${ fileName } '.`
112+ ) ;
113+ }
114+ }
0 commit comments