Skip to content

Commit 1bd525e

Browse files
Merge pull request #745 from mdmehran-qureshi/master
Implement bulk LWC compilation feature
2 parents 0a19fbe + dec7913 commit 1bd525e

File tree

4 files changed

+118
-4
lines changed

4 files changed

+118
-4
lines changed

lib/datapacksjob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,7 @@ DataPacksJob.prototype.deployJob = async function(jobInfo) {
27702770
}
27712771

27722772
// Deploy LWC components
2773-
if(jobInfo.deployGeneratedLwc === true) {
2773+
if(jobInfo.deployGeneratedLwc === true || jobInfo.useBulkOmniScriptLwcCompile) {
27742774
if(!fs.existsSync(tempSfdxLwcFolder)) {
27752775
VlocityUtils.error('Can\'t find compiled LWC components path. Skipping...');
27762776
}else{

lib/datapacktypes/omniscript.js

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ OmniScript.prototype.onDeployFinish = async function (jobInfo) {
236236
}
237237
}
238238
jobInfo.resusableOSToCompile = {};
239+
239240
}
240241

241242
OmniScript.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 (/^ERROR: No MODULE named markup/.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+
433537
OmniScript.prototype.onActivateError = async function (dataPackData) {
434538
var onActivateErrorResult = {},
435539
defaultNS = '%vlocity_namespace%__';

lib/defaultjobsettings.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ loginTimeoutForLoginLWC: 300000
1919
puppeteerHeadless: true
2020
lookForParentLayoutsForlWCCards: true
2121
exportPacksMaxSize: 5
22+
useBulkOmniScriptLwcCompile: false
2223
useAllRelationships: false
2324
ignoreAllErrors: false
2425
addSourceKeys: false

lib/sfdx.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ const _orgDisplay = async (targetusername) => {
4141
}
4242

4343
const _sourceDeploy = async (targetusername,sourcePath) =>{
44-
if(isEmptyDir(sourcePath)) return {details: { componentSuccesses :[]}};
44+
VlocityUtils.verbose('Source deploy called with:', { targetusername, sourcePath });
45+
if(isEmptyDir(sourcePath)) {
46+
VlocityUtils.verbose('Source path is empty, returning early');
47+
return {details: { componentSuccesses :[]}};
48+
}
49+
VlocityUtils.verbose('Source path is not empty, proceeding with deployment');
4550
return _run(`sf project deploy start --source-dir "${sourcePath}" --target-org "${targetusername}"`);
4651
}
4752

@@ -60,12 +65,16 @@ const _orgLogin = async (authFilePath) =>{
6065

6166
function isEmptyDir(path) {
6267
try {
68+
VlocityUtils.verbose('Checking if directory is empty:', path);
6369
const directory = fs.opendirSync(path)
6470
const entry = directory.readSync()
6571
directory.closeSync()
6672

67-
return entry === null
73+
const isEmpty = entry === null;
74+
VlocityUtils.verbose('Directory empty check result:', isEmpty, 'First entry:', entry ? entry.name : 'null');
75+
return isEmpty
6876
} catch (error) {
77+
VlocityUtils.error('Error checking if directory is empty:', path, error);
6978
return false
7079
}
7180
}

0 commit comments

Comments
 (0)