pantry/scripts/index-packages.ts
Jacob Heider 72b9fa85bd
simplify index-packages (#153)
* simplify index-packages

* Fix import map location

* sqs modules needs permission :x

---------

Co-authored-by: Max Howell <mxcl@me.com>
2023-02-02 16:51:19 -05:00

43 lines
1.1 KiB
TypeScript
Executable file

#!/usr/bin/env -S tea -E
/*---
args:
- deno
- run
- --allow-read
- --allow-env
- --allow-net
- --allow-sys
---*/
import { usePantry } from "hooks"
import * as ARGV from "./utils/args.ts"
import { SQSClient, SendMessageCommand } from "npm:@aws-sdk/client-sqs@^3"
import { panic } from "utils"
const sqsClient = new SQSClient({ region: Deno.env.get("AWS_REGION") ?? panic("No region specified") })
const pantry = usePantry()
const pkgs = await ARGV.toArray(ARGV.pkgs())
for(const pkg of pkgs) {
try {
const yml = await pantry.getYAML(pkg).parse()
const project = pkg.project
const taskMessage = {
project,
github: yml?.versions?.github || "",
// TODO: add other useable data here eventually
}
const res = await sqsClient.send(new SendMessageCommand({
MessageGroupId: 'project',
MessageDeduplicationId: project,
MessageBody: JSON.stringify(taskMessage),
QueueUrl: Deno.env.get("SQS_GENERATE_PACKAGE_DETAILS_URL")!,
}))
console.log(`SQS task for pkg:${project} messageId:${res.MessageId}`)
} catch (error) {
console.error(error);
}
}