hyperweb-io / hyperweb-io/ts-codegen

Sample Project Generation

Offen
#70 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
126
Forks
31
Ø Merge
19 Min.
Gemergte PRs (30 T.)
2

Beschreibung

CosmWasm projects usually have a setup including a contracts and packages folder: [cw-plus](https://github.com/CosmWasm/cw-plus) and [dao dao](https://github.com/DA0-DA0/dao-contracts) as a couple examples.
I think ts-codegen should have a sample project generation file in the docs to make using this tool easier.

**codegen.ts**
```
import codegen, { ContractFile } from "@cosmwasm/ts-codegen";
import { glob } from "glob";

glob("../@(contracts|packages)/*/schema", (err, matches) => {
if (err) console.log(err);

let contracts: ContractFile[] = [];

matches.forEach((x) => {
contracts.push({
name: x.split("/")[2],
dir: x,
});
});

codegen({
contracts,
outPath: "./generated",

options: {
bundle: {
bundleFile: "index.ts",
scope: "contracts",
},
types: {
enabled: true,
},
client: {
enabled: true,
},
},
}).then(() => {
console.log("✨ all done!");
});
});
```

I used glob, because this is how ts-codegen's utils.readSchemas interprets paths. If a valid path is not given from windows, then ts-codegen will not generate anything.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.