@@ -236,6 +236,7 @@ OmniScript.prototype.onDeployFinish = async function (jobInfo) {
236236 }
237237 }
238238 jobInfo . resusableOSToCompile = { } ;
239+
239240}
240241
241242OmniScript . prototype . compileOmniScriptLwc = async function ( jobInfo , omniScriptId , omniScriptKey ) {
@@ -297,6 +298,7 @@ OmniScript.prototype.compileOSLWC = async function (jobInfo, omniScriptId, omniS
297298 const _compileOSLWC = async ( jobInfo , omniScriptId , omniScriptKey ) => {
298299 const promiseJob = new Promise ( async ( res , rej ) => {
299300 try {
301+
300302 let puppeteerOptions = await utilityservice . prototype . getPuppeteerOptions ( jobInfo ) ;
301303
302304 VlocityUtils . verbose ( 'Deployed OmniScript ID' , omniScriptKey + ' (' + omniScriptId + ')' ) ;
@@ -334,7 +336,9 @@ OmniScript.prototype.compileOSLWC = async function (jobInfo, omniScriptId, omniS
334336 page . goto ( loginURl , { timeout : loginTimeout } )
335337 ] ) ;
336338
337- var omniScriptDisignerpageLink = siteUrl + '/apex/' + package + 'OmniLwcCompile?id=' + omniScriptId + '&activate=true' ; //0jNTC0000000VGk2AM
339+ // Add bulk parameter if enabled
340+ var bulkParam = jobInfo . useBulkOmniScriptLwcCompile ? '&deploybulk=true' : '' ;
341+ var omniScriptDisignerpageLink = siteUrl + '/apex/' + package + 'OmniLwcCompile?id=' + omniScriptId + '&activate=true' + bulkParam ;
338342 var omniScriptLogId = omniScriptKey + ' (' + omniScriptId + ')' ;
339343
340344 VlocityUtils . report ( 'Starting OmniScript LWC Activation' , omniScriptLogId ) ;
@@ -363,6 +367,12 @@ OmniScript.prototype.compileOSLWC = async function (jobInfo, omniScriptId, omniS
363367 VlocityUtils . report ( 'Elapsed Time' , jobInfo . elapsedTime ) ;
364368 if ( currentStatus === 'DONE' ) {
365369 VlocityUtils . success ( 'LWC Activated' , omniScriptLogId ) ;
370+
371+ // Extract session storage data if in bulk mode
372+ if ( jobInfo . useBulkOmniScriptLwcCompile ) {
373+ await this . extractSessionStorageData ( page , omniScriptKey , jobInfo ) ;
374+ }
375+
366376 break ;
367377 } else if ( / ^ E R R O R : N o M O D U L E n a m e d m a r k u p / . test ( currentStatus ) ) {
368378 var missingLWCTrimedError = currentStatus . substring ( 'ERROR: ' . length , currentStatus . indexOf ( ' found :' ) ) ;
@@ -430,6 +440,100 @@ OmniScript.prototype.compileOSLWC = async function (jobInfo, omniScriptId, omniS
430440
431441}
432442
443+ OmniScript . prototype . extractSessionStorageData = async function ( page , omniScriptKey , jobInfo ) {
444+ try {
445+ VlocityUtils . report ( 'Extracting session storage data for bulk deployment' , omniScriptKey ) ;
446+
447+ // Get bulkAllResources from session storage
448+ const bulkData = await page . evaluate ( ( ) => {
449+ const bulkAllResources = sessionStorage . getItem ( 'bulkAllResources' ) ;
450+ if ( bulkAllResources ) {
451+ try {
452+ return JSON . parse ( bulkAllResources ) ;
453+ } catch ( parseError ) {
454+ return null ;
455+ }
456+ }
457+ return null ;
458+ } ) ;
459+
460+ if ( ! bulkData || ( typeof bulkData === 'object' && Object . keys ( bulkData ) . length === 0 ) ) {
461+ VlocityUtils . warn ( 'No bulkAllResources data found in session storage' , omniScriptKey ) ;
462+ return ;
463+ }
464+
465+ const tempSfdxLwcFolder = path . join ( jobInfo . tempFolder || './vlocity-temp' , 'tempDeployLWC' , 'salesforce_sfdx' ) ;
466+ const lwcFolderPath = path . join ( tempSfdxLwcFolder , 'lwc' ) ;
467+
468+ // Ensure the directory structure exists
469+ await fs . ensureDir ( lwcFolderPath ) ;
470+
471+ VlocityUtils . verbose ( 'Writing files to temp LWC folder:' , lwcFolderPath ) ;
472+
473+ // Process files in parallel for better performance
474+ const processFile = async ( relativePath , content ) => {
475+ try {
476+ VlocityUtils . verbose ( `Processing bulk item: ${ relativePath } ` , omniScriptKey ) ;
477+
478+ // Handle special case for package.xml (no component folder)
479+ if ( relativePath === 'package.xml' || relativePath === 'bulkCompiledCount' ) {
480+ return ;
481+ } else {
482+ // Preserve the exact path structure from session storage
483+ const fullPath = path . join ( tempSfdxLwcFolder , relativePath ) ;
484+
485+ // Ensure the directory structure exists
486+ await fs . ensureDir ( path . dirname ( fullPath ) ) ;
487+
488+ // Write the file to the exact path
489+ await fs . writeFile ( fullPath , content ) ;
490+
491+ VlocityUtils . verbose ( `Extracted file: ${ relativePath } ` , omniScriptKey ) ;
492+ }
493+ } catch ( error ) {
494+ VlocityUtils . warn ( `Failed to process bulk item ${ relativePath } ` , omniScriptKey , error ) ;
495+ throw error ; // Re-throw to be caught by Promise.allSettled
496+ }
497+ } ;
498+
499+ // Process all files in parallel with proper error handling
500+ const filePromises = Object . entries ( bulkData ) . map ( ( [ key , value ] ) =>
501+ processFile ( key , value ) . catch ( error => ( {
502+ key,
503+ error,
504+ success : false
505+ } ) )
506+ ) ;
507+
508+ const results = await Promise . allSettled ( filePromises ) ;
509+
510+ // Log results
511+ let successCount = 0 ;
512+ let failureCount = 0 ;
513+
514+ results . forEach ( ( result , index ) => {
515+ if ( result . status === 'fulfilled' ) {
516+ if ( result . value && result . value . success === false ) {
517+ failureCount ++ ;
518+ VlocityUtils . error ( `Failed to process file: ${ result . value . key } ` , omniScriptKey , result . value . error ) ;
519+ } else {
520+ successCount ++ ;
521+ }
522+ } else {
523+ failureCount ++ ;
524+ VlocityUtils . error ( `Failed to process file at index ${ index } ` , omniScriptKey , result . reason ) ;
525+ }
526+ } ) ;
527+
528+ VlocityUtils . report ( `File processing completed: ${ successCount } successful, ${ failureCount } failed` , omniScriptKey ) ;
529+
530+ VlocityUtils . success ( 'Session storage data extracted successfully' , omniScriptKey ) ;
531+
532+ } catch ( error ) {
533+ VlocityUtils . error ( 'Failed to extract session storage data' , omniScriptKey , error ) ;
534+ }
535+ }
536+
433537OmniScript . prototype . onActivateError = async function ( dataPackData ) {
434538 var onActivateErrorResult = { } ,
435539 defaultNS = '%vlocity_namespace%__' ;
0 commit comments