@@ -42,10 +42,17 @@ export interface ZipMetadata {
4242}
4343
4444export interface GenerateZipOptions {
45- includeGitDiffHeader ?: boolean
45+ includeGitDiff ?: boolean
4646 silent ?: boolean
4747}
4848
49+ export interface ZipProjectOptions {
50+ projectPath ?: string
51+ includeGitDiff ?: boolean
52+ metadataDir ?: string
53+ includeNonWorkspaceFiles ?: boolean
54+ }
55+
4956export const ZipConstants = {
5057 newlineRegex : / \r ? \n / ,
5158 gitignoreFilename : '.gitignore' ,
@@ -180,31 +187,23 @@ export class ZipUtil {
180187 await processDirectory ( metadataDir )
181188 }
182189
183- protected async zipProject ( useCase : FeatureUseCase , projectPath ?: string , metadataDir ?: string ) {
190+ protected async zipProject (
191+ workspaceFolders : CurrentWsFolders ,
192+ excludePatterns : string [ ] ,
193+ options ?: ZipProjectOptions
194+ ) {
184195 const zip = new ZipStream ( )
185- let projectPaths = [ ]
186- if ( useCase === FeatureUseCase . TEST_GENERATION && projectPath ) {
187- projectPaths . push ( projectPath )
188- } else {
189- projectPaths = getWorkspacePaths ( )
190- }
191- if ( useCase === FeatureUseCase . CODE_SCAN ) {
196+ const projectPaths = options ?. projectPath ? [ options ?. projectPath ] : getWorkspacePaths ( )
197+ if ( options ?. includeGitDiff ) {
192198 await this . processCombinedGitDiff ( zip , projectPaths , '' )
193199 }
194200 const languageCount = new Map < CodewhispererLanguage , number > ( )
195201
196- await this . processSourceFiles (
197- zip ,
198- languageCount ,
199- projectPaths ,
200- this . getWorkspaceFolders ( useCase ) ,
201- this . getExcludePatterns ( useCase ) ,
202- useCase === FeatureUseCase . TEST_GENERATION
203- )
204- if ( metadataDir ) {
205- await this . processMetadataDir ( zip , metadataDir )
202+ await this . processSourceFiles ( zip , languageCount , projectPaths , workspaceFolders , excludePatterns )
203+ if ( options ?. metadataDir ) {
204+ await this . processMetadataDir ( zip , options ?. metadataDir )
206205 }
207- if ( useCase !== FeatureUseCase . TEST_GENERATION ) {
206+ if ( options ?. includeNonWorkspaceFiles ) {
208207 this . processOtherFiles ( zip , languageCount )
209208 }
210209
@@ -364,9 +363,14 @@ export class ZipUtil {
364363 ) : Promise < ZipMetadata > {
365364 try {
366365 const zipDirPath = this . getZipDirPath ( )
367- const zipFilePath = await ( zipType === 'file'
368- ? this . zipFile ( uri , options ?. includeGitDiffHeader )
369- : this . zipProject ( FeatureUseCase . CODE_SCAN ) )
366+ const zipFilePath =
367+ zipType === 'file'
368+ ? await this . zipFile ( uri , options ?. includeGitDiff )
369+ : await this . zipProject (
370+ this . getWorkspaceFolders ( FeatureUseCase . CODE_SCAN ) ,
371+ this . getExcludePatterns ( FeatureUseCase . CODE_SCAN ) ,
372+ { includeGitDiff : options ?. includeGitDiff , includeNonWorkspaceFiles : true }
373+ )
370374
371375 if ( ! options ?. silent ) {
372376 getLogger ( ) . debug ( `Picked source files: [${ [ ...this . _pickedSourceFiles ] . join ( ', ' ) } ]` )
@@ -413,7 +417,14 @@ export class ZipUtil {
413417 }
414418 }
415419
416- const zipFilePath : string = await this . zipProject ( FeatureUseCase . TEST_GENERATION , projectPath , metadataDir )
420+ const zipFilePath : string = await this . zipProject (
421+ this . getWorkspaceFolders ( FeatureUseCase . TEST_GENERATION ) ,
422+ this . getExcludePatterns ( FeatureUseCase . TEST_GENERATION ) ,
423+ {
424+ metadataDir,
425+ projectPath,
426+ }
427+ )
417428 const zipFileSize = ( await fs . stat ( zipFilePath ) ) . size
418429 return {
419430 rootDir : zipDirPath ,
0 commit comments