Skip to content

Commit cf62df3

Browse files
committed
add templates for redis
Signed-off-by: karthik2804 <[email protected]>
1 parent 6cc3474 commit cf62df3

File tree

19 files changed

+276
-0
lines changed

19 files changed

+276
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
target
4+
.spin/
5+
dist.js
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 1,
3+
"project": {
4+
"worlds": [
5+
"spin-redis"
6+
]
7+
},
8+
"packages": {}
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "{{project-name | kebab_case}}",
3+
"version": "1.0.0",
4+
"description": "{{project-description}}",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm",
8+
"test": "echo \"Error: no test specified\" && exit 1",
9+
"postinstall": "knitwit"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC",
14+
"devDependencies": {
15+
"mkdirp": "^3.0.1",
16+
"webpack": "^5.74.0",
17+
"webpack-cli": "^4.10.0",
18+
"@fermyon/knitwit": "https://github.com/fermyon/knitwit"
19+
},
20+
"dependencies": {
21+
"@fermyon/spin-sdk": "^2.0.0"
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
name = "{{project-name | kebab_case}}"
5+
version = "0.1.0"
6+
authors = ["{{authors}}"]
7+
description = "{{project-description}}"
8+
9+
[application.trigger.redis]
10+
address = "{{redis-address}}"
11+
12+
[[trigger.redis]]
13+
channel = "{{redis-channel}}"
14+
component = "{{project-name | kebab_case}}"
15+
16+
[component.{{project-name | kebab_case}}]
17+
source = "target/{{project-name | kebab_case}}.wasm"
18+
exclude_files = ["**/node_modules"]
19+
[component.{{project-name | kebab_case}}.build]
20+
command = "npm run build"
21+
watch = ["src/**/*.ts", "package.json"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { RedisHandler } from "@fermyon/spin-sdk";
2+
3+
const decoder = new TextDecoder();
4+
5+
export class MyRedisHandler extends RedisHandler {
6+
async handleMessage(msg) {
7+
console.log("Received message:", decoder.decode(msg));
8+
}
9+
}
10+
11+
export const inboundRedis = new MyRedisHandler();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require('path');
2+
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack")
3+
4+
module.exports = {
5+
entry: './src/index.js',
6+
experiments: {
7+
outputModule: true,
8+
},
9+
output: {
10+
path: path.resolve(__dirname, './'),
11+
filename: 'dist.js',
12+
module: true,
13+
library: {
14+
type: "module",
15+
}
16+
},
17+
plugins: [
18+
new SpinSdkPlugin()
19+
],
20+
optimization: {
21+
minimize: false
22+
},
23+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[application.trigger.redis]
2+
address = "{{redis-address}}"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[[trigger.redis]]
2+
channel = "{{redis-channel}}"
3+
component = "{{project-name | kebab_case}}"
4+
5+
[component.{{project-name | kebab_case}}]
6+
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm"
7+
allowed_outbound_hosts = []
8+
[component.{{project-name | kebab_case}}.build]
9+
command = "npm run build"
10+
workdir = "{{ output-path }}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
manifest_version = "1"
2+
id = "redis-js"
3+
description = "Redis message handler using JavaScript"
4+
tags = ["redis", "js"]
5+
6+
[add_component]
7+
skip_files = ["spin.toml"]
8+
[add_component.snippets]
9+
component = "component.txt"
10+
application_trigger = "application-trigger.txt"
11+
[add_component.conditions.address_exists]
12+
condition = { manifest_entry_exists = "application.trigger.redis" }
13+
skip_parameters = ["redis-address"]
14+
skip_snippets = ["application_trigger"]
15+
16+
[parameters]
17+
project-description = { type = "string", prompt = "Description", default = "" }
18+
redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" }
19+
redis-channel = { type = "string", prompt = "Redis channel" }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
target
4+
.spin/
5+
dist.js

0 commit comments

Comments
 (0)