Skip to content

Commit

Permalink
Migrate to AWS-SDK V3 syntax (#4810)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturi authored Dec 4, 2023
1 parent 58869e6 commit a116db5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions bin/upload-to-cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const path = require('node:path')
const { pipeline, finished } = require('node:stream/promises')
const { readFile } = require('node:fs/promises')
const { S3 } = require('@aws-sdk/client-s3');
const { S3Client, ListObjectsV2Command, PutObjectCommand } = require('@aws-sdk/client-s3');

const packlist = require('npm-packlist')
const tar = require('tar')
Expand Down Expand Up @@ -109,7 +109,7 @@ async function main (packageName, version) {
// where we force push a local build
if (version?.startsWith('-')) version = undefined // eslint-disable-line no-param-reassign

const s3 = new S3({
const s3Client = new S3Client({
credentials: {
accessKeyId: process.env.EDGLY_KEY,
secretAccessKey: process.env.EDGLY_SECRET,
Expand Down Expand Up @@ -144,11 +144,12 @@ async function main (packageName, version) {

const outputPath = path.posix.join(dirName, `v${version}`)

const { Contents: existing } = await s3.listObjects({
const { Contents: existing } = await s3Client.send(new ListObjectsV2Command({
Bucket: AWS_BUCKET,
Prefix: outputPath,
})
if (existing.length > 0) {
}))

if (existing?.length > 0) {
if (process.argv.includes('--force')) {
console.warn(`WARN Release files for ${dirName} v${version} already exist, overwriting...`)
} else {
Expand All @@ -174,16 +175,16 @@ async function main (packageName, version) {
for (const [filename, buffer] of files.entries()) {
const key = path.posix.join(outputPath, filename)
console.log(`pushing s3://${AWS_BUCKET}/${key}`)
await s3.putObject({
await s3Client.send(new PutObjectCommand({
Bucket: AWS_BUCKET,
Key: key,
ContentType: mime.lookup(filename),
Body: buffer,
})
}))
}
}

main(...process.argv.slice(2)).catch((err) => {
console.error(err.stack)
console.error(err)
process.exit(1)
})

0 comments on commit a116db5

Please sign in to comment.