kunkun/packages/schema/scripts/upload-schema-to-s3.ts
Huakun Shen ed87fc6c12
App Setup (#2)
* chore: add vendor submodules

* feat: add packages for db,ci,schema,api,jarvis cmds

* feat: add tauri-jarvis-plugin

* feat: implement extension commands list

* fix(desktop): import path errors after packages refactor

* chore: add self signed cert

* fix: prevent prerender for desktop

* fix(desktop): desktop sveltekit static build, use csr for dynamic route

* feat: add error handling page and components

* refactor: component lib

* refactor: move more types, functions and components out of desktop

* refactor(ui): more refactor

* refactor(ui): move store components to @kksh/ui

* ci: add CI for build & test

* refactor: rename @kksh/extensions to @kksh/extension

* ci: add 2 more ci

* ci: fix

* fix: CI env var

* chore: add changeset

* feat: implement extension store item detail view

* feat: implement extension store install, uninstall, upgrade

* format

* revert: upgradable logic, the new one doesn't work yet

* refactor: make @kksh/ui dependent only on @kksh/api

Reason: @kksh/ui may be published later for building website, all its dependency packages must be also published. To avoid trouble it should be standalone, depend only on packages already published

* refactor: cleanup

* fixed: some typescript error

* chore: got typedoc working on @kksh/api

* ci: disable manifest schema upload CI on push
2024-11-03 13:54:44 -05:00

66 lines
1.8 KiB
TypeScript

import {
GetObjectCommand,
ListBucketsCommand,
PutObjectCommand,
S3Client
} from "@aws-sdk/client-s3"
import { toJSONSchema } from "@gcornut/valibot-json-schema"
import { ExtPackageJson } from "@kksh/api/models"
import { parse, string } from "valibot"
import { getJsonSchema } from "../src"
const s3Client = new S3Client({
endpoint: parse(string(), process.env.S3_ENDPOINT),
region: "auto",
credentials: {
accessKeyId: parse(string(), process.env.S3_ACCESS_KEY_ID),
secretAccessKey: parse(string(), process.env.S3_SECRET_ACCESS_KEY)
}
})
/* -------------------------------------------------------------------------- */
/* Get Schema */
/* -------------------------------------------------------------------------- */
// const { Body } = await s3Client.send(
// new GetObjectCommand({
// Bucket: "jarvis-extensions",
// Key: "schema.json",
// }),
// );
// const data = await Body?.transformToByteArray();
// if (data) {
// fs.writeFileSync("schema.json", data);
// }
/* -------------------------------------------------------------------------- */
/* Upload Schema to S3 */
/* -------------------------------------------------------------------------- */
const schemaStr = getJsonSchema(ExtPackageJson)
await s3Client.send(
new PutObjectCommand({
Bucket: "jarvis-extensions",
Key: "nightly.schema.json",
Body: schemaStr,
ContentType: "application/json"
})
)
s3Client
.send(
new PutObjectCommand({
Bucket: "jarvis-extensions",
Key: "schema.json",
Body: schemaStr,
ContentType: "application/json"
})
)
.then(() => {
console.log("Schema uploaded to S3")
})
.catch((err) => {
console.error("Failed to upload schema.json")
console.error(err)
process.exit(1)
})