Skip to content

Commit 83008ea

Browse files
committed
feat: add isReviewApp to UploadAssetsToS3 to determine correct s3 bucket
1 parent 5a31325 commit 83008ea

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

plugins/upload-assets-to-s3/src/tasks/upload-assets-to-s3.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@ export const UploadAssetsToS3Schema = z
6363
export { UploadAssetsToS3Schema as schema }
6464

6565
export default class UploadAssetsToS3 extends Task<{ task: typeof UploadAssetsToS3Schema }> {
66-
async uploadFile(file: string, s3: S3Client): Promise<void> {
66+
async uploadFile(file: string, s3: S3Client, isReviewApp): Promise<void> {
6767
const type = getFileType(file)
6868
const encoding = getFileEncoding(file)
6969
const filepath = path.join(this.options.directory, file)
7070
const body = fs.createReadStream(filepath)
7171
const key = path.posix.join(this.options.destination, file)
7272

73-
const bucketByEnv =
74-
process.env.NODE_ENV === 'branch' ? this.options.reviewBucket : this.options.prodBucket
73+
const bucketByEnv = isReviewApp ? this.options.reviewBucket : this.options.prodBucket
7574
let currentBucket = ''
7675

7776
try {
@@ -98,7 +97,7 @@ export default class UploadAssetsToS3 extends Task<{ task: typeof UploadAssetsTo
9897
}
9998
}
10099

101-
async run({ cwd }: TaskRunContext): Promise<void> {
100+
async run({ cwd, command }: TaskRunContext): Promise<void> {
102101
// Wrap extensions in braces if there are multiple
103102
const extensions = this.options.extensions.includes(',')
104103
? `{${this.options.extensions}}`
@@ -136,8 +135,9 @@ export default class UploadAssetsToS3 extends Task<{ task: typeof UploadAssetsTo
136135
secretAccessKey
137136
}
138137
})
138+
const isReviewApp = process.env.NODE_ENV === 'branch' || command === 'deploy:review'
139139

140-
await Promise.all(files.map((file) => this.uploadFile(file, s3)))
140+
await Promise.all(files.map((file) => this.uploadFile(file, s3, isReviewApp)))
141141
}
142142
}
143143

0 commit comments

Comments
 (0)