Changes
4 changed files (+107/-1)
-
-
@@ -1,5 +1,7 @@node_modules .env /esm /dist
-
-
-
@@ -1,2 +1,3 @@nodejs 20.6 bun 1.0 bun 1.0 awscli 2
-
-
-
@@ -7,6 +7,8 @@You need Bun v1, and Node.js v20 (optional). Node.js is required for publishing the package and running benchmark on V8. AWS CLI is also required for website deployment. This project has `.tool-versions` file. Use of a tool that supports reading `.tool-versions` is recommended.
-
@@ -111,3 +113,20 @@```sh npm publish ``` ### Deploy built website ```sh bun scripts/website/deploy.ts --s3-bucket "S3 bucket name" --cf-dist-id "CloudFront distribution ID" ``` In order to authenticate, you need configure below environment variables: - `AWS_ACCESS_KEY_ID` - `AWS_SECRET_ACCESS_KEY` - `AWS_DEFAULT_REGION` Each CLI options has corresponding environment variables. - `--s3-bucket` ... `S3_BUCKET` - `--cf-dist-id` ... `CF_DIST_ID`
-
-
-
@@ -0,0 +1,84 @@// This script deploys website/dist to a AWS S3 Bucket. // This script expects an environment to have non-empty variables // AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_DEFAULT_REGION. import * as commander from "commander"; interface DeployOptions { s3BucketName: string; cfDistributionID: string; } function deploy({ s3BucketName, cfDistributionID }: DeployOptions) { const sync = Bun.spawnSync( [ "aws", "s3", "sync", "--delete", new URL("../../website/dist", import.meta.url).pathname, `s3://${s3BucketName}`, ], { stdio: ["inherit", "inherit", "inherit"], }, ); if (!sync.success) { throw new Error("Failed to sync local contents to S3 bucket"); } const invalidation = Bun.spawnSync( [ "aws", "cloudfront", "create-invalidation", "--distribution-id", cfDistributionID, "--paths", "/*", ], { stdio: ["inherit", "inherit", "inherit"], }, ); if (!invalidation.success) { throw new Error("Failed to invalidate CloudFront cache"); } } if (import.meta.main) { interface CLIOptions { s3Bucket?: string; cfDistId?: string; } const program = commander.program .option("--s3-bucket", "S3 Bucket name to deploy ($S3_BUCKET_NAME)") .option( "--cf-dist-id", "CloudFront distribution ID of the website CDN ($CF_DIST_ID)", ) .action( ({ s3Bucket = Bun.env.S3_BUCKET, cfDistId = Bun.env.CF_DIST_ID, }: CLIOptions) => { if (!s3Bucket) { throw new Error("S3 Bucket name is required."); } if (!cfDistId) { throw new Error("CloudFront distribution ID is required."); } deploy({ s3BucketName: s3Bucket, cfDistributionID: cfDistId, }); }, ); await program.parseAsync(Bun.argv); }
-