Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): added winglibs to docs with required automation #972

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/update-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
run: npx tsx scripts/updateDocs.ts
env:
GITHUB_TOKEN: ${{ secrets.WING_GITHUB_TOKEN }}
- name: Update winglibs
run: npx tsx scripts/winglibDocs.ts
env:
GITHUB_TOKEN: ${{ secrets.WING_GITHUB_TOKEN }}
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v5
Expand Down
170 changes: 170 additions & 0 deletions scripts/winglibDocs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { request } from "@octokit/request";
import fs from "node:fs/promises";
import tar from "tar";
import { glob } from "glob";
import { join, dirname } from 'node:path';
import { readFileSync } from 'fs';

const authorization = `token ${process.env.GITHUB_TOKEN}`;

const WINGLIB_DIR = join(process.cwd(), 'versioned_docs', 'version-latest', '04-winglibs', '05-winglibs');
const categoryFile = `label: winglibs
collapsible: true
collapsed: true
link:
type: generated-index
title: Wing Libs (winglibs)
`;

type WingLibPackage = {
name: string;
description: string;
version: string;
author?: {
name: string;
email: string;
};
repository?: {
type: string;
url: string;
directory: string;
};
license?: string;
wing?: {
platforms?: string[];
docs?: {
title: string;
summary: string;
demoURL?: string;
};
};
};

const buildUrlsForPlatforms = (platforms: string[]) => {
return platforms.map(platform => {
switch (platform) {
case 'sim':
return `[${platform}](/docs/platforms/sim)`;
case 'tf-aws':
return `[${platform}](/docs/platforms/AWS/tf-aws)`;
case 'awscdk':
return `[${platform}](/docs/platforms/AWS/awscdk)`;
case 'tf-gcp':
return `[${platform}](/docs/platforms/google-cloud/tf-gcp)`;
case 'tf-azure':
return `[${platform}](/docs/platforms/microsoft-azure/tf-azure)`;
case '*':
return `[*](/docs/platforms/platforms)`;
default:
return platform
}
}).join(', ');
}

(async () => {

console.log("Getting latest winglibs...");
const tarball = await request('GET /repos/winglang/winglibs/tarball/main', {
headers: {
authorization
},
});

await fs.mkdir("winglibs", { recursive: true });
await fs.writeFile("winglibs.tgz", Buffer.from(tarball.data));

console.log("Extracting winglibs...");
await tar.extract({
file: "winglibs.tgz",
cwd: "winglibs",
});


const files = glob.sync("winglibs/**/**/README.md");

let filteredWingLibs = files.map(file => {
return {
winglib: file.split('/')[2],
readme: file,
path: dirname(file)
}
// filter out the project README file
}).filter(file => !file.winglib.includes('README.md'))

// hydrate with Package JSON file
const winglibs = filteredWingLibs.map(lib => {
const packageJson = JSON.parse(readFileSync(join(lib.path, 'package.json'), { encoding: 'utf-8' })) as WingLibPackage;
return {
...lib,
packageJson,
title: packageJson.wing?.docs?.title || lib.winglib,
version: packageJson.version,
description: packageJson.wing?.docs?.summary || packageJson.description,
platforms: packageJson.wing?.platforms || [],
demoURL: packageJson.wing?.docs?.demoURL || ''
}
});

// Write files to WINGLIB_DIR
await fs.rm(WINGLIB_DIR, { force: true, recursive: true });
await fs.mkdir(WINGLIB_DIR, { recursive: true });

// Write required docusuarus file for category
await fs.writeFile(join(WINGLIB_DIR, '_category_.yml'), categoryFile);

let table = `---
title: List of winglibs
id: all-winglibs
sidebar_label: List of winglibs
description: Table of all Wing libraries
keywords: [winglib, Wing library]
---

| Library | Package name | Version | Description | Supported Wing platforms |
| -------- | ------- | ------- | ------- | ------- |`;


// Create the table.
// @ts-ignore
for (const { title, version, description, platforms, demoURL, packageJson, winglib } of winglibs) {
table += `\n| [${title}](/docs/winglibs/winglibs/${winglib}) | [${packageJson.name}](/docs/winglibs/winglibs/${winglib}) | v${version} | ${description} ${demoURL ? `([Example](${demoURL}))` : ''} | ${buildUrlsForPlatforms(platforms)} |`;
}

// contributing to winglibs
table += `\n\n## Contributing to winglibs

Want to contribute your own winglib to this list? Check out the [contributing guide](https://github.com/winglang/winglibs?tab=readme-ov-file#how-do-i-add-a-new-library) for more information.

`

await fs.writeFile(join(WINGLIB_DIR, '../04-toc.md'), table);


for (const { winglib, readme, packageJson, title } of winglibs) {

const content = await fs.readFile(readme, { encoding: 'utf-8' });
// remove any markdown images from the content (for now)
const contentWithoutImages = content.replace(/!\[.*\]\(.*\)/g, '');
console.log(join(WINGLIB_DIR, `${winglib}.md`))

const file = `---
title: ${title}
id: ${winglib}
sidebar_label: ${title}
description: ${packageJson.wing?.docs?.summary || packageJson.description}
keywords: [winglib, Wing library]
---
${contentWithoutImages}
`

await fs.writeFile(join(WINGLIB_DIR, `${winglib}.md`), file);
}

console.log("Cleaning up...");
await fs.rm("winglibs.tgz");
await fs.rm("winglibs", {
force: true,
recursive: true,
});
})();

46 changes: 46 additions & 0 deletions versioned_docs/version-latest/04-winglibs/04-toc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: List of winglibs
id: all-winglibs
sidebar_label: List of winglibs
description: Table of all Wing libraries
keywords: [winglib, Wing library]
---

| Library | Package name | Version | Description | Supported Wing platforms |
| -------- | ------- | ------- | ------- | ------- |
| [Amazon Bedrock](/docs/winglibs/winglibs/bedrock) | [@winglibs/bedrock](/docs/winglibs/winglibs/bedrock) | v0.0.9 | A Wing library for Amazon Bedrock | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [AWS Budget](/docs/winglibs/winglibs/budget) | [@winglibs/budget](/docs/winglibs/winglibs/budget) | v0.1.5 | A Wing library for working with [AWS Budgets] | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Cloud checks](/docs/winglibs/winglibs/checks) | [@winglibs/checks](/docs/winglibs/winglibs/checks) | v0.0.16 | A self-validation mechanism for cloud applications | [*](/docs/platforms/platforms) |
| [cloudv2](/docs/winglibs/winglibs/cloudv2) | [@winglibs/cloudv2](/docs/winglibs/winglibs/cloudv2) | v0.0.2 | Standard cloud library for Wing | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon Cognito](/docs/winglibs/winglibs/cognito) | [@winglibs/cognito](/docs/winglibs/winglibs/cognito) | v0.0.14 | A wing library to work with Amazon Cognito | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Containers](/docs/winglibs/winglibs/containers) | [@winglibs/containers](/docs/winglibs/winglibs/containers) | v0.1.5 | Deploy containers with Wing | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon DynamoDB](/docs/winglibs/winglibs/dynamodb) | [@winglibs/dynamodb](/docs/winglibs/winglibs/dynamodb) | v0.2.1 | A Wing library for Amazon DynamoDB | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon EventBridge](/docs/winglibs/winglibs/eventbridge) | [@winglibs/eventbridge](/docs/winglibs/winglibs/eventbridge) | v0.1.6 | A Wing library for working with Amazon EventBridge | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws), [awscdk](/docs/platforms/AWS/awscdk) |
| [FIFO Queue](/docs/winglibs/winglibs/fifoqueue) | [@winglibs/fifoqueue](/docs/winglibs/winglibs/fifoqueue) | v0.0.10 | A wing library to work with FIFO (first-in first-out) Queues | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [GitHub](/docs/winglibs/winglibs/github) | [@winglibs/github](/docs/winglibs/winglibs/github) | v0.0.14 | A wing library to work with GitHub Probot | [*](/docs/platforms/platforms) |
| [JWT authentication](/docs/winglibs/winglibs/jwt) | [@winglibs/jwt](/docs/winglibs/winglibs/jwt) | v0.0.7 | Wing library for JWT authentication | [*](/docs/platforms/platforms) |
| [Kubernetes (k8s)](/docs/winglibs/winglibs/k8s) | [@winglibs/k8s](/docs/winglibs/winglibs/k8s) | v0.0.8 | Wing for Kubernetes | k8s |
| [Lock](/docs/winglibs/winglibs/lock) | [@winglibs/lock](/docs/winglibs/winglibs/lock) | v0.0.6 | Wing library for cloud lock | [*](/docs/platforms/platforms) |
| [Message Fanout](/docs/winglibs/winglibs/messagefanout) | [@winglibs/messagefanout](/docs/winglibs/winglibs/messagefanout) | v0.0.7 | Wing library to fan out messages | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Momento](/docs/winglibs/winglibs/momento) | [@winglibs/momento](/docs/winglibs/winglibs/momento) | v0.0.4 | Wing library for [momento](https://www.gomomento.com/) | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws), [tf-gcp](/docs/platforms/google-cloud/tf-gcp), [tf-azure](/docs/platforms/microsoft-azure/tf-azure) |
| [ngrok](/docs/winglibs/winglibs/ngrok) | [@winglibs/ngrok](/docs/winglibs/winglibs/ngrok) | v0.0.9 | Wing library for [ngrok](https://ngrok.com/). Create local tunnels to Wing endpoints. | [*](/docs/platforms/platforms) |
| [OpenAI](/docs/winglibs/winglibs/openai) | [@winglibs/openai](/docs/winglibs/winglibs/openai) | v0.0.7 | Wing library for [OpenAI](https://openai.com/) | [*](/docs/platforms/platforms) |
| [Postgres](/docs/winglibs/winglibs/postgres) | [@winglibs/postgres](/docs/winglibs/winglibs/postgres) | v0.1.11 | Wing library for [Postgres](https://www.postgresql.org/) | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Python](/docs/winglibs/winglibs/python) | [@winglibs/python](/docs/winglibs/winglibs/python) | v0.1.4 | A Wing library for running [Python](https://www.python.org/) code in [inflight](https://www.winglang.io/docs/concepts/inflights#inflight-code). | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [React](/docs/winglibs/winglibs/react) | [@winglibs/react](/docs/winglibs/winglibs/react) | v0.1.4 | A Wing library for [React](https://react.dev/) | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Redis](/docs/winglibs/winglibs/redis) | [@winglibs/redis](/docs/winglibs/winglibs/redis) | v0.0.11 | A Wing library for [Redis](https://redis.io/) ([Example](https://www.winglang.io/docs/examples/redis)) | [sim](/docs/platforms/sim) |
| [Amazon SageMaker](/docs/winglibs/winglibs/sagemaker) | [@winglibs/sagemaker](/docs/winglibs/winglibs/sagemaker) | v0.0.8 | The library enables owners of a trained sagemaker model, to access its Endpoints from a winglang [inflight](https://www.winglang.io/docs/concepts/inflights#inflight-code) code. | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon SES](/docs/winglibs/winglibs/ses) | [@winglibs/ses](/docs/winglibs/winglibs/ses) | v0.0.6 | Wing library for interacting with Amazon SES. | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Wing simulator utils](/docs/winglibs/winglibs/simtools) | [@winglibs/simtools](/docs/winglibs/winglibs/simtools) | v0.0.4 | '[Wing simulator](https://www.winglang.io/docs/platforms/sim) utility library' | [sim](/docs/platforms/sim) |
| [Slack](/docs/winglibs/winglibs/slack) | [@winglibs/slack](/docs/winglibs/winglibs/slack) | v0.1.3 | A Wing library for working with [Slack](https://slack.com/) | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon SNS](/docs/winglibs/winglibs/sns) | [@winglibs/sns](/docs/winglibs/winglibs/sns) | v0.1.5 | A Wing library for working with [Amazon SNS](https://aws.amazon.com/sns/) | [tf-aws](/docs/platforms/AWS/tf-aws), [awscdk](/docs/platforms/AWS/awscdk), [sim](/docs/platforms/sim) |
| [Terraform utilities](/docs/winglibs/winglibs/tf) | [@winglibs/tf](/docs/winglibs/winglibs/tf) | v0.0.7 | Terraform utilities library for Wing | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [tsoa](/docs/winglibs/winglibs/tsoa) | [@winglibs/tsoa](/docs/winglibs/winglibs/tsoa) | v0.1.13 | A Wing library for working with [TSOA](https://tsoa-community.github.io/docs/) - An OpenAPI-compliant Web APIs using TypeScript. | [sim](/docs/platforms/sim) |
| [Vite](/docs/winglibs/winglibs/vite) | [@winglibs/vite](/docs/winglibs/winglibs/vite) | v0.2.3 | A Wing library to deploy [Vite applications](https://vitejs.dev/) to the cloud. | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [WebSocket](/docs/winglibs/winglibs/websockets) | [@winglibs/websockets](/docs/winglibs/winglibs/websockets) | v0.3.10 | A Wing library that enables you to create WebSockets using Wing. | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws), [awscdk](/docs/platforms/AWS/awscdk) |

## Contributing to winglibs

Want to contribute your own winglib to this list? Check out the [contributing guide](https://github.com/winglang/winglibs?tab=readme-ov-file#how-do-i-add-a-new-library) for more information.


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
label: winglibs
collapsible: true
collapsed: true
link:
type: generated-index
title: Wing Libs (winglibs)
66 changes: 66 additions & 0 deletions versioned_docs/version-latest/04-winglibs/05-winglibs/bedrock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Amazon Bedrock
id: bedrock
sidebar_label: Amazon Bedrock
description: A Wing library for Amazon Bedrock
keywords: [winglib, Wing library]
---
# bedrock

A Wing library for working with [Amazon Bedrock](https://aws.amazon.com/bedrock/).

## Prerequisites

* [winglang](https://winglang.io).
* [Model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) to Amazon bedrock

## Installation

```sh
npm i @winglibs/bedrock
```

## Usage

```js
bring bedrock;

pub class JokeMaker {
claud: bedrock.Model;

new() {
this.claud = new bedrock.Model("anthropic.claude-v2") as "claude";
}

pub inflight makeJoke(topic: str): str {
let res = this.claud.invoke({
prompt: "\n\nHuman: Tell me a joke about {topic}\n\nAssistant:",
max_tokens_to_sample: 300,
temperature: 0.5,
top_k: 250,
top_p: 1,
stop_sequences: [
"\n\nHuman:"
],
anthropic_version: "bedrock-2023-05-31"
});

return res["completion"].asStr();
}
}
```

## Development & Testing

When running in simulator using `wing run`, request are sent to Amazon Bedrock.
When running tests using `wing test` or by running tests from within Wing Console, requests are
handled by the mocked service.

## Maintainers

[@eladb](https://github.com/eladb), [@ekeren](https://github.com/ekeren)

## License

This library is licensed under the [MIT License](./LICENSE).

50 changes: 50 additions & 0 deletions versioned_docs/version-latest/04-winglibs/05-winglibs/budget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: AWS Budget
id: budget
sidebar_label: AWS Budget
description: A Wing library for working with [AWS Budgets]
keywords: [winglib, Wing library]
---
# budget

A Wing library for working with [AWS Budgets](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html)

## Prerequisites

* [winglang](https://winglang.io).

## Installation

```sh
npm i @winglibs/budget
```

## Usage

**⚠️ The budget refers to the entire account and not just for the current project!**

Add your budget alert to the code:

```js
bring budget;

new budget.Alert(
name: "Test",
amount: 10,
emailAddresses: ["[email protected]"],
);
```

*Note: ​The budget amount is in USD.*

You get an alert when your monthly payment goes over your budget.

## TODO

- [ ] Set a budget alert only for resources with certain tags.
- [ ] Allow to perform automatic actions when the budget runs out.

## License

This library is licensed under the [MIT License](./LICENSE).

Loading