mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
21 lines
579 B
JavaScript
21 lines
579 B
JavaScript
import _ from 'lodash'
|
|
|
|
export default (s3Response, prefix, service, stage) => {
|
|
if (s3Response.Contents.length) {
|
|
const regex = new RegExp(`${prefix}/${service}/${stage}/(.+-.+-.+-.+)/(.+)`)
|
|
const s3Objects = s3Response.Contents.filter((s3Object) =>
|
|
s3Object.Key.match(regex),
|
|
)
|
|
const names = s3Objects.map((s3Object) => {
|
|
const match = s3Object.Key.match(regex)
|
|
return {
|
|
directory: match[1],
|
|
file: match[2],
|
|
}
|
|
})
|
|
const grouped = _.groupBy(names, 'directory')
|
|
return Object.values(grouped)
|
|
}
|
|
return []
|
|
}
|