@@ -16,6 +16,8 @@ import { MigrationResult, RelatedObjectsMigrate } from '../interfaces';
1616import { sfProject } from '../../utils/sfcli/project/sfProject' ;
1717import { fileutil , File } from '../../utils/file/fileutil' ;
1818import { Logger } from '../../utils/logger' ;
19+ import { ApexAssessmentInfo } from '../../utils' ;
20+ import { FileDiffUtil } from '../../utils/lwcparser/fileutils/FileDiffUtil' ;
1921import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration' ;
2022
2123const APEXCLASS = 'Apexclass' ;
@@ -50,23 +52,36 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
5052 sfProject . deploy ( APEXCLASS , targetOrg . getUsername ( ) ) ;
5153 shell . cd ( pwd ) ;
5254 }
53- public processApexFiles ( dir : string ) : File [ ] {
55+
56+ public assess ( ) : ApexAssessmentInfo [ ] {
57+ const pwd = shell . pwd ( ) ;
58+ shell . cd ( this . projectPath ) ;
59+ const targetOrg : Org = this . org ;
60+ sfProject . retrieve ( APEXCLASS , targetOrg . getUsername ( ) ) ;
61+ const apexAssessmentInfos = this . processApexFiles ( this . projectPath ) ;
62+ shell . cd ( pwd ) ;
63+ return apexAssessmentInfos ;
64+ }
65+ public processApexFiles ( dir : string ) : ApexAssessmentInfo [ ] {
5466 dir += APEX_CLASS_PATH ;
5567 let files : File [ ] = [ ] ;
5668 files = fileutil . readFilesSync ( dir ) ;
69+ const fileAssessmentInfo : ApexAssessmentInfo [ ] = [ ] ;
5770 for ( const file of files ) {
5871 if ( file . ext !== '.cls' ) continue ;
5972 try {
60- this . processApexFile ( file ) ;
73+ const apexAssementInfo = this . processApexFile ( file ) ;
74+ if ( apexAssementInfo && apexAssementInfo . diff && apexAssementInfo . diff . length === 0 ) continue ;
75+ fileAssessmentInfo . push ( apexAssementInfo ) ;
6176 } catch ( err ) {
6277 Logger . logger . error ( `Error processing ${ file . name } ` ) ;
6378 Logger . logger . error ( err ) ;
6479 }
6580 }
66- return files ;
81+ return fileAssessmentInfo ;
6782 }
6883
69- public processApexFile ( file : File ) : void {
84+ public processApexFile ( file : File ) : ApexAssessmentInfo {
7085 const fileContent = fs . readFileSync ( file . location , 'utf8' ) ;
7186 const interfaces : InterfaceImplements [ ] = [ ] ;
7287 interfaces . push ( this . vlocityOpenInterface , this . vlocityOpenInterface2 , this . callableInterface ) ;
@@ -95,11 +110,26 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
95110 updateMessages . push ( 'File has been updated to allow calls to Omnistudio components' ) ;
96111 tokenUpdates . push ( ...tokeUpdatesForMethodCalls ) ;
97112 }
113+ let difference = '' ;
98114 if ( tokenUpdates && tokenUpdates . length > 0 ) {
115+ const updatedContent = parser . rewrite ( tokenUpdates ) ;
99116 fs . writeFileSync ( file . location , parser . rewrite ( tokenUpdates ) ) ;
117+ difference = new FileDiffUtil ( ) . getFileDiff ( file . name , fileContent , updatedContent ) ;
118+ }
119+ if ( updateMessages . length === 0 ) {
120+ Logger . logger . info (
121+ `File ${ file . name } does not have any omnistudio calls or remote calls. No changes will be applied.`
122+ ) ;
100123 }
101124 const warningMessage : string [ ] = this . processNonReplacableMethodCalls ( file , parser ) ;
102125 Logger . logger . warn ( warningMessage ) ;
126+ return {
127+ name : file . name ,
128+ warnings : warningMessage ,
129+ infos : updateMessages ,
130+ path : file . location ,
131+ diff : difference ,
132+ } ;
103133 }
104134
105135 private processApexFileForRemotecalls ( file : File , parser : ApexASTParser ) : TokenUpdater [ ] {
0 commit comments