Skip to content

Commit

Permalink
example for typescript sdk (#41)
Browse files Browse the repository at this point in the history
* example for typescript using ts4w

https://www.npmjs.com/package/ts4w

* add test - it's failign though

* dependnecies

* Apply suggestions from code review

Co-authored-by: Mark McCulloh <[email protected]>

* obsolete

* relative files have to reference statically, with an absolute path

* Update to most recent version

* Add simple readme

* Adapt gh workflow to ts

---------

Co-authored-by: Mark McCulloh <[email protected]>
  • Loading branch information
skorfmann and MarkMcCulloh authored Feb 27, 2024
1 parent c812994 commit 2c1b7bd
Show file tree
Hide file tree
Showing 6 changed files with 5,556 additions and 2 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/wing-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ jobs:
mkdir -p ~/.wing
echo '{}' > ~/.wing/secrets.json
- name: Execute wing test in matrix directory
run: cd ${{ matrix.example.directory }} && wing test --debug --platform sim main.w
run: |
cd ${{ matrix.example.directory }}
if [ -f "main.w" ]; then
wing test --debug --platform sim main.w
elif [ -f "main.ts" ]; then
wing test --debug --platform sim main.ts
else
echo "No main.w or main.ts found"
exit 1
fi
test-tf-aws:
needs: setup
Expand Down Expand Up @@ -135,7 +144,16 @@ jobs:
env:
TF_LOG: info
TF_LOG_PATH: ${{ runner.workspace }}/terraform.log
run: cd ${{ matrix.example.directory }} && wing test --debug --no-analytics --no-update-check --platform tf-aws main.w
run: |
cd ${{ matrix.example.directory }}
if [ -f "main.w" ]; then
wing test --debug --no-analytics --no-update-check --platform tf-aws main.w
elif [ -f "main.ts" ]; then
wing test --debug --no-analytics --no-update-check --platform tf-aws main.ts
else
echo "No main.w or main.ts found"
exit 1
fi
- name: Output Terraform log
if: failure()
run: cat ${{ runner.workspace }}/terraform.log
5 changes: 5 additions & 0 deletions examples/typescript/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Wing Typescript Example

This is based on the [Wing Typescript SDK](https://www.winglang.io/docs/typescript/) and demonstrates a simple function with testing.

The [my-ssr-framework.ts](./my-ssr-framework.ts) part could be easily swapped by something like [hono](https://hono.dev/) or [remix](https://remix.run/).
19 changes: 19 additions & 0 deletions examples/typescript/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { cloud, lift, main } from "@wingcloud/framework";
import { myServer } from "./my-ssr-framework";
import assert from "node:assert";

main((root, test) => {
let bucket = new cloud.Bucket(root, "Bucket");

bucket.addObject("hello", "Hello World from lifted Bucket!");

new cloud.Function(root, "hello", lift({bucket}).inflight(async ({bucket}) => {
const result = await myServer({bucket})
return result;
}));

test("testing it works", lift({bucket}).inflight(async ({bucket}) => {
const result = await myServer({bucket})
assert.equal(result , "Hello World from lifted Bucket!");
}))
})
7 changes: 7 additions & 0 deletions examples/typescript/my-ssr-framework.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { cloud } from "@wingcloud/framework";

export const myServer = async ({bucket}: { bucket: cloud.IBucketClient }) => {
const file = await bucket.get("hello");
console.log(file);
return file;
}
Loading

0 comments on commit 2c1b7bd

Please sign in to comment.