1
1
/* eslint-disable prettier/prettier */
2
2
/* eslint-disable @typescript-eslint/restrict-template-expressions */
3
3
import fs from 'fs' ;
4
+ import path from 'path' ;
4
5
import open from 'open' ;
6
+ import { Connection } from '@salesforce/core' ;
5
7
import {
6
8
ApexAssessmentInfo ,
7
9
AssessmentInfo ,
8
10
LWCAssessmentInfo ,
9
- OmniAssessmentInfo ,
10
11
FlexCardAssessmentInfo ,
11
12
nameLocation ,
12
13
} from '../interfaces' ;
13
- import { OSAssesmentReporter } from './OSAssessmentReporter' ;
14
+ import { OrgPreferences } from '../orgpreferences' ;
15
+ import { ReportHeaderFormat } from '../reportGenerator/reportInterfaces' ;
16
+ import { OmnistudioOrgDetails } from '../orgUtils' ;
17
+ import { OSAssessmentReporter } from './OSAssessmentReporter' ;
14
18
import { IPAssessmentReporter } from './IPAssessmentReporter' ;
15
19
import { DRAssessmentReporter } from './DRAssessmentReporter' ;
16
20
17
21
export class AssessmentReporter {
18
- public static async generate ( result : AssessmentInfo , instanceUrl : string ) : Promise < void > {
22
+ public static async generate (
23
+ result : AssessmentInfo ,
24
+ instanceUrl : string , connection : Connection ,
25
+ omnistudioOrgDetails : OmnistudioOrgDetails
26
+ ) : Promise < void > {
19
27
const basePath = process . cwd ( ) + '/assessment_reports' ;
20
28
fs . mkdirSync ( basePath , { recursive : true } ) ;
21
29
const omniscriptAssessmentFilePath = basePath + '/omniscript_assessment.html' ;
@@ -24,25 +32,28 @@ export class AssessmentReporter {
24
32
const dataMapperAssessmentFilePath = basePath + '/datamapper_assessment.html' ;
25
33
const apexAssessmentFilePath = basePath + '/apex_assessment.html' ;
26
34
const lwcAssessmentFilePath = basePath + '/lwc_assessment.html' ;
35
+ const rollbackFlagsReportPath = basePath + '/rollback_flags_report.html' ;
36
+ const orgDetails : ReportHeaderFormat [ ] = this . formattedOrgDetails ( omnistudioOrgDetails ) ;
27
37
28
38
this . createDocument (
29
39
omniscriptAssessmentFilePath ,
30
- this . generateOmniAssesment ( result . omniAssessmentInfo , instanceUrl )
40
+ OSAssessmentReporter . generateOSAssesment ( result . omniAssessmentInfo . osAssessmentInfos , instanceUrl , orgDetails )
31
41
) ;
32
42
this . createDocument (
33
43
flexcardAssessmentFilePath ,
34
44
this . generateCardAssesment ( result . flexCardAssessmentInfos , instanceUrl )
35
45
) ;
36
46
this . createDocument (
37
47
integrationProcedureAssessmentFilePath ,
38
- IPAssessmentReporter . generateIPAssesment ( result . omniAssessmentInfo . ipAssessmentInfos , instanceUrl )
48
+ IPAssessmentReporter . generateIPAssesment ( result . omniAssessmentInfo . ipAssessmentInfos , instanceUrl , orgDetails )
39
49
) ;
40
50
this . createDocument (
41
51
dataMapperAssessmentFilePath ,
42
52
DRAssessmentReporter . generateDRAssesment ( result . dataRaptorAssessmentInfos , instanceUrl )
43
53
) ;
44
54
this . createDocument ( apexAssessmentFilePath , this . generateApexAssesment ( result . apexAssessmentInfos ) ) ;
45
55
this . createDocument ( lwcAssessmentFilePath , this . generateLwcAssesment ( result . lwcAssessmentInfos ) ) ;
56
+
46
57
const nameUrls = [
47
58
{
48
59
name : 'omnscript assessment report' ,
@@ -69,7 +80,88 @@ export class AssessmentReporter {
69
80
location : 'lwc_assessment.html' ,
70
81
} ,
71
82
] ;
83
+
84
+ // Check rollback flags
85
+ const enabledFlags = await OrgPreferences . checkRollbackFlags ( connection ) ;
86
+ if ( enabledFlags . length > 0 ) {
87
+ this . createDocument ( rollbackFlagsReportPath , this . generateRollbackFlagsReport ( enabledFlags ) ) ;
88
+ nameUrls . push ( {
89
+ name : 'Rollback Flags Report' ,
90
+ location : 'rollback_flags_report.html' ,
91
+ } ) ;
92
+ }
93
+
94
+
72
95
await this . createMasterDocument ( nameUrls , basePath ) ;
96
+ this . pushAssestUtilites ( 'javascripts' , basePath ) ;
97
+ this . pushAssestUtilites ( 'styles' , basePath ) ;
98
+ }
99
+
100
+ private static formattedOrgDetails ( orgDetails : OmnistudioOrgDetails ) : ReportHeaderFormat [ ] {
101
+ return [
102
+ {
103
+ key : 'Org Name' ,
104
+ value : orgDetails . orgDetails . Name ,
105
+ } ,
106
+ {
107
+ key : 'Org Id' ,
108
+ value : orgDetails . orgDetails . Id ,
109
+ } ,
110
+ {
111
+ key : 'Package Name' ,
112
+ value : orgDetails . packageDetails [ 0 ] . namespace ,
113
+ } ,
114
+ {
115
+ key : 'Data Model' ,
116
+ value : orgDetails . dataModel ,
117
+ } ,
118
+ {
119
+ key : 'Assessment Date and Time' ,
120
+ value : new Date ( ) as unknown as string ,
121
+ } ,
122
+ ] ;
123
+ }
124
+
125
+ /**
126
+ * Copies `.js` and `.css` files from a source directory (based on `folderName`)
127
+ * to a specified destination directory.
128
+ *
129
+ * @param folderName - The subdirectory under `/src/` where source asset files are located (e.g., `'javascripts'`, `'styles'`).
130
+ * @param destDir - The absolute or relative path to the destination directory where the assets should be copied.
131
+ *
132
+ * @remarks
133
+ * - If the destination directory does not exist, the method logs a warning and exits.
134
+ * - Only `.js` and `.css` files are copied.
135
+ * - The source files remain in place after copying.
136
+ */
137
+ private static pushAssestUtilites ( folderName : string , destDir : string ) : void {
138
+ const sourceDir = path . join ( process . cwd ( ) , 'src' , folderName ) ;
139
+
140
+ if ( ! fs . existsSync ( destDir ) ) {
141
+ // Destination directory does not exist. Skipping file copy.
142
+ return ;
143
+ }
144
+
145
+ fs . readdir ( sourceDir , ( readDirErr , files ) => {
146
+ if ( readDirErr ) {
147
+ // Error reading source directory: readDirErr.message
148
+ return ;
149
+ }
150
+
151
+ files . forEach ( ( file ) => {
152
+ const ext = path . extname ( file ) ;
153
+ if ( ext === '.js' || ext === '.css' ) {
154
+ const srcPath = path . join ( sourceDir , file ) ;
155
+ const destPath = path . join ( destDir , file ) ;
156
+
157
+ fs . copyFile ( srcPath , destPath , ( copyErr ) => {
158
+ if ( copyErr ) {
159
+ // Failed to copy file: copyErr.message
160
+ }
161
+ } ) ;
162
+ }
163
+ } ) ;
164
+ } ) ;
73
165
}
74
166
75
167
private static async createMasterDocument ( reports : nameLocation [ ] , basePath : string ) : Promise < void > {
@@ -195,11 +287,6 @@ export class AssessmentReporter {
195
287
</div>` ;
196
288
return tableBody ;
197
289
}
198
- private static generateOmniAssesment ( omniAssessmentInfo : OmniAssessmentInfo , instanceUrl : string ) : string {
199
- let htmlBody = '' ;
200
- htmlBody += '<br />' + OSAssesmentReporter . generateOSAssesment ( omniAssessmentInfo . osAssessmentInfos , instanceUrl ) ;
201
- return htmlBody ;
202
- }
203
290
204
291
private static generateCardAssesment ( flexCardAssessmentInfos : FlexCardAssessmentInfo [ ] , instanceUrl : string ) : string {
205
292
let tableBody = '' ;
@@ -246,7 +333,6 @@ export class AssessmentReporter {
246
333
</head>
247
334
<body>
248
335
<div style="margin: 20px;">
249
- <div class="slds-text-heading_large">OmniStudio Migration Assessment </div>
250
336
${ resultsAsHtml }
251
337
</div>
252
338
</div>
@@ -311,4 +397,19 @@ export class AssessmentReporter {
311
397
</div>` ;
312
398
return tableBody ;
313
399
}
400
+
401
+ private static generateRollbackFlagsReport ( enabledFlags : string [ ] ) : string {
402
+ return `
403
+ <div class="slds-box slds-theme_warning" style="margin-bottom: 20px;">
404
+ <div class="slds-text-heading_medium slds-m-bottom_small">⚠️ Warning: Rollback Flags Enabled</div>
405
+ <p>The following rollback flags are currently enabled and will be disabled during migration:</p>
406
+ <ul class="slds-m-top_small">
407
+ ${ enabledFlags . map ( ( flag ) => `<li>${ flag } </li>` ) . join ( '' ) }
408
+ </ul>
409
+ <p class="slds-m-top_small">
410
+ <strong>Note:</strong> These flags will not be supported after migration. For assistance, please contact support.
411
+ </p>
412
+ </div>
413
+ ` ;
414
+ }
314
415
}
0 commit comments