@@ -13,7 +13,13 @@ export const BuildParam = defineExtension({
1313 paramsSchema : ( ) => {
1414 return z . object ( {
1515 paramName : z . string ( ) ,
16- value : z . string ( )
16+ value : z . union ( [
17+ z . string ( ) ,
18+ z . record ( z . any ( ) ) ,
19+ z . array ( z . any ( ) ) ,
20+ z . number ( ) ,
21+ z . boolean ( )
22+ ] )
1723 } ) ;
1824 } ,
1925 async build ( params , ctx ) {
@@ -27,6 +33,9 @@ export const BuildParam = defineExtension({
2733
2834 const { paramName, value } = params ;
2935
36+ // Serialize value to a TypeScript literal.
37+ const valueStr = JSON . stringify ( value , null , 4 ) ;
38+
3039 // Generate a unique class name based on the paramName.
3140 const hash = crypto . createHash ( "sha256" ) . update ( paramName ) . digest ( "hex" ) ;
3241 const className = `BuildParam_${ hash . slice ( - 10 ) } ` ;
@@ -43,12 +52,17 @@ export const BuildParam = defineExtension({
4352 // File exists, just ensure it's imported in extensions.ts
4453 } else {
4554 // Create the BuildParam implementation file.
46- const fileContent = `import { BuildParam } from "@ webiny/api-core/exports/api/buildParam ";
55+ const fileContent = `import { BuildParam } from "webiny/api/buildParams ";
4756
48- export class ${ className } implements BuildParam.Interface {
57+ class ${ className } implements BuildParam.Interface {
4958 key = "${ paramName } ";
50- value = " ${ value } " ;
59+ value = ${ valueStr } ;
5160}
61+
62+ export default BuildParam.createImplementation({
63+ implementation: ${ className } ,
64+ dependencies: []
65+ });
5266` ;
5367 fs . writeFileSync ( filePath , fileContent , "utf8" ) ;
5468 }
@@ -83,9 +97,9 @@ export class ${className} implements BuildParam.Interface {
8397 index = last . getChildIndex ( ) + 1 ;
8498 }
8599
86- // Add import for the BuildParam class .
100+ // Add import for the BuildParam implementation .
87101 source . insertImportDeclaration ( index , {
88- namedImports : [ className ] ,
102+ defaultImport : className ,
89103 moduleSpecifier : importPath
90104 } ) ;
91105
0 commit comments