mirror of
https://github.com/ivabus/pantry
synced 2025-06-08 08:20:32 +03:00
quick-matrix format for ls-aws-s3.ts
This commit is contained in:
parent
ee504738cf
commit
fcc3c404a1
1 changed files with 43 additions and 9 deletions
|
@ -10,9 +10,13 @@ args:
|
|||
---*/
|
||||
|
||||
import { S3 } from "s3"
|
||||
import SemVer, * as semver from "semver"
|
||||
import { format }from "deno/datetime/mod.ts"
|
||||
|
||||
const sortByModified = Deno.args.includes("-m")
|
||||
const reverse = Deno.args.includes("-r")
|
||||
const fullMatrix = Deno.args.includes("-x")
|
||||
|
||||
|
||||
const s3 = new S3({
|
||||
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
|
||||
|
@ -30,18 +34,48 @@ for await(const obj of bucket.listAllObjects({ batchSize: 200 })) {
|
|||
output.push({ key: key!, lastModified: lastModified! })
|
||||
}
|
||||
|
||||
output.sort((a, b) => {
|
||||
switch (sortByModified) {
|
||||
case true: return a.lastModified.valueOf() - b.lastModified.valueOf()
|
||||
case false: return a.key < b.key ? -1 : 1
|
||||
}
|
||||
})
|
||||
if (fullMatrix) {
|
||||
produceMatrix(output)
|
||||
} else {
|
||||
output.sort((a, b) => {
|
||||
switch (sortByModified) {
|
||||
case true: return a.lastModified.valueOf() - b.lastModified.valueOf()
|
||||
case false: return a.key < b.key ? -1 : 1
|
||||
}
|
||||
})
|
||||
|
||||
if (reverse) { output.reverse() }
|
||||
|
||||
console.table(output)
|
||||
if (reverse) { output.reverse() }
|
||||
console.table(output)
|
||||
}
|
||||
|
||||
interface FileInfo {
|
||||
key: string
|
||||
lastModified: Date
|
||||
}
|
||||
|
||||
function produceMatrix(objects: FileInfo[]): void {
|
||||
const matrix = new Map()
|
||||
for (const { key, lastModified } of objects) {
|
||||
const [_, project, _platform, _arch, _v] = key.match(new RegExp("(.*)/(darwin|linux)/(aarch64|x86-64)/v(.*)\.tar\.(x|g)z"))!
|
||||
const flavor = `${_platform}/${_arch}`
|
||||
const version = semver.parse(_v)
|
||||
if (!version) continue
|
||||
const stats = matrix.get(project) || { project }
|
||||
|
||||
if (version.gt(stats[flavor]?.[0] || new SemVer([0,0,0]))) {
|
||||
stats[flavor] = [version, format(lastModified, "yyyy-MM-dd HH:mm")]
|
||||
}
|
||||
|
||||
matrix.set(project, stats)
|
||||
}
|
||||
|
||||
const output = [...matrix.values()].map(o => ({
|
||||
project: o.project,
|
||||
'darwin/aarch64': `${o['darwin/aarch64']?.join(": ")}`,
|
||||
'darwin/x86-64': `${o['darwin/x86-64']?.join(": ")}`,
|
||||
'linux/aarch64': `${o['linux/aarch64']?.join(": ")}`,
|
||||
'linux/x86-64': `${o['linux/x86-64']?.join(": ")}`
|
||||
}))
|
||||
output.sort((a, b) => a.project < b.project ? -1: 1)
|
||||
console.table(output)
|
||||
}
|
Loading…
Reference in a new issue