Skip to content

Commit

Permalink
Merge pull request #34 from golemcloud/ts-cleanups-jco-update
Browse files Browse the repository at this point in the history
Typescript: update jco and cleanup npm scripts
  • Loading branch information
vigoo authored Jun 20, 2024
2 parents 677d1fb + c013bdc commit 570ca51
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 32 deletions.
14 changes: 6 additions & 8 deletions examples/ts/INSTRUCTIONS
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
Compile the TypeScript project with npm:
```bash
npm install
npm run build
npm run componentize
```
The `out/component_name.wasm` file is ready to be uploaded to Golem Cloud!

To do stub generation run the following command:
```bash
npm run stub
```

This will generate the typescript declaration files in `src/interfaces`

All npm run commands:
- stub: generates TypeScript mappings from the wit files
- build: compiles and bundles the TypeScript sources
- componentize: runs stub and build, then creates the wasm file for the component
- clean: "rm -rf out src/interfaces src/main.d.ts"
2 changes: 1 addition & 1 deletion examples/ts/ts-actor-minimal/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
out/
src/interfaces/
src/generated/
src/main.d.ts
src/main.js
2 changes: 1 addition & 1 deletion examples/ts/ts-actor-minimal/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"exclude": [
"node_modules",
"out",
"src/interfaces",
"src/generated",
"src/main.d.ts",
"src/main.js"
]
Expand Down
12 changes: 5 additions & 7 deletions examples/ts/ts-actor-minimal/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"scripts": {
"stub": "jco transpile wit --name main --no-namespaced-exports --stub --out-dir src && rm -rf src/main.js",
"buildTs": "rollup --config",
"checkTs": "tsc",
"buildWasm": "jco componentize -w wit -o out/component_name.wasm out/main.js",
"build": "npm run stub && npm run checkTs && npm run buildTs && npm run buildWasm",
"stub": "jco stubgen wit -o src/generated",
"build": "rollup --config",
"componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js",
"clean": "rm -rf out src/interfaces src/main.d.ts"
},
"devDependencies": {
"@golemcloud/componentize-js": "0.8.3-golem.3",
"@golemcloud/golem-ts": "0.1.0",
"@golemcloud/jco": "1.2.4-golem.3",
"@golemcloud/jco": "1.2.4-golem.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"rollup-plugin-typescript2": "^0.36.0",
"@types/node": "^20.14.2",
"rollup": "^4.18.0",
"tslib": "^2.6.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/ts/ts-actor-minimal/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typescript from "@rollup/plugin-typescript";
import typescript from "rollup-plugin-typescript2";
import resolve from "@rollup/plugin-node-resolve";

export default {
Expand Down
4 changes: 2 additions & 2 deletions examples/ts/ts-actor-minimal/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PackNameApi } from './interfaces/pack-name-api.js';
import { Api } from './generated/component-name.js';

let state = BigInt(0);

export const api: typeof PackNameApi = {
export const api: Api = {
add(value: bigint) {
console.log(`Adding ${value} to the counter`);
state += value;
Expand Down
2 changes: 1 addition & 1 deletion examples/ts/ts-fetch-example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
out/
src/interfaces/
src/generated/
src/main.d.ts
src/main.js
2 changes: 1 addition & 1 deletion examples/ts/ts-fetch-example/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"exclude": [
"node_modules",
"out",
"src/interfaces",
"src/generated",
"src/main.d.ts",
"src/main.js"
]
Expand Down
12 changes: 5 additions & 7 deletions examples/ts/ts-fetch-example/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"scripts": {
"stub": "jco transpile wit --name main --no-namespaced-exports --stub --out-dir src && rm -rf src/main.js",
"buildTs": "rollup --config",
"checkTs": "tsc",
"buildWasm": "jco componentize -w wit -o out/component_name.wasm out/main.js",
"build": "npm run stub && npm run checkTs && npm run buildTs && npm run buildWasm",
"stub": "jco stubgen wit -o src/generated",
"build": "rollup --config",
"componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js",
"clean": "rm -rf out src/interfaces src/main.d.ts"
},
"devDependencies": {
"@golemcloud/componentize-js": "0.8.3-golem.3",
"@golemcloud/golem-ts": "0.1.0",
"@golemcloud/jco": "1.2.4-golem.3",
"@golemcloud/jco": "1.2.4-golem.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"rollup-plugin-typescript2": "^0.36.0",
"@types/node": "^20.14.2",
"rollup": "^4.18.0",
"tslib": "^2.6.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/ts/ts-fetch-example/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typescript from "@rollup/plugin-typescript";
import typescript from "rollup-plugin-typescript2";
import resolve from "@rollup/plugin-node-resolve";

export default {
Expand Down
4 changes: 2 additions & 2 deletions examples/ts/ts-fetch-example/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {asyncToSyncAsResult} from "@golemcloud/golem-ts";
import { PackNameApi } from './interfaces/pack-name-api';
import { Api } from './generated/component-name';

let result: any

export const api: typeof PackNameApi = {
export const api: Api = {
getLastResult(): string {
return JSON.stringify(result);
},
Expand Down

0 comments on commit 570ca51

Please sign in to comment.