@cosmwasm/ts-codegen 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/builder/builder.d.ts +1 -1
- package/esm/generators/create-helpers.js +2 -26
- package/esm/plugins/provider-bundle.js +1 -1
- package/esm/plugins/provider.js +1 -1
- package/esm/utils/header.js +2 -1
- package/esm/utils/package.js +26 -0
- package/generators/create-helpers.js +3 -27
- package/package.json +6 -4
- package/plugins/provider-bundle.js +1 -1
- package/plugins/provider.js +1 -1
- package/utils/header.js +5 -7
- package/utils/package.d.ts +1 -0
- package/utils/package.js +30 -0
package/README.md
CHANGED
@@ -98,7 +98,7 @@ codegen({
|
|
98
98
|
messageBuilder: {
|
99
99
|
enabled: false
|
100
100
|
},
|
101
|
-
|
101
|
+
useContractHooks: {
|
102
102
|
enabled: false
|
103
103
|
}
|
104
104
|
}
|
@@ -195,7 +195,7 @@ Generate raw message jsons for use in your application with the `message-builder
|
|
195
195
|
|
196
196
|
| option | description |
|
197
197
|
| -------------------------------- | --------------------------------------- |
|
198
|
-
| `
|
198
|
+
| `useContractHooks.enabled` | enable the `useContracts` plugin |
|
199
199
|
|
200
200
|
#### Use Contracts Provider Usage
|
201
201
|
|
package/builder/builder.d.ts
CHANGED
@@ -22,7 +22,7 @@ export type TSBuilderOptions = {
|
|
22
22
|
* Default: true
|
23
23
|
*/
|
24
24
|
useShorthandCtor?: boolean;
|
25
|
-
|
25
|
+
useContractHooks?: UseContractsOptions;
|
26
26
|
} & RenderOptions;
|
27
27
|
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'message-builder' | 'plugin';
|
28
28
|
export interface BuilderFile {
|
@@ -1,32 +1,8 @@
|
|
1
1
|
import { join, dirname, basename, extname } from "path";
|
2
|
-
import { readFileSync, existsSync } from "fs";
|
3
2
|
import { sync as mkdirp } from "mkdirp";
|
4
3
|
import { writeContentToFile } from "../utils/files";
|
4
|
+
import { readAndParsePackageJson } from "../utils/package";
|
5
5
|
import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, } from "../helpers";
|
6
|
-
// need to search due to the dist/ folder and src/, etc.
|
7
|
-
function findPackageJson(currentDir) {
|
8
|
-
const filePath = join(currentDir, 'package.json');
|
9
|
-
// Check if package.json exists in the current directory
|
10
|
-
if (existsSync(filePath)) {
|
11
|
-
return filePath;
|
12
|
-
}
|
13
|
-
// Get the parent directory
|
14
|
-
const parentDir = dirname(currentDir);
|
15
|
-
// If reached the root directory, package.json is not found
|
16
|
-
if (parentDir === currentDir) {
|
17
|
-
throw new Error('package.json not found in any parent directory');
|
18
|
-
}
|
19
|
-
// Recursively look in the parent directory
|
20
|
-
return findPackageJson(parentDir);
|
21
|
-
}
|
22
|
-
function readAndParsePackageJson() {
|
23
|
-
// Start searching from the current directory
|
24
|
-
const pkgPath = findPackageJson(__dirname);
|
25
|
-
// Read and parse the package.json
|
26
|
-
const str = readFileSync(pkgPath, 'utf8');
|
27
|
-
const pkg = JSON.parse(str);
|
28
|
-
return pkg;
|
29
|
-
}
|
30
6
|
const pkg = readAndParsePackageJson();
|
31
7
|
const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
|
32
8
|
const header = `/**
|
@@ -49,7 +25,7 @@ const write = (outPath, file, content, varname) => {
|
|
49
25
|
};
|
50
26
|
export const createHelpers = (input, builderContext) => {
|
51
27
|
const files = [];
|
52
|
-
if (input.options?.
|
28
|
+
if (input.options?.useContractHooks?.enabled &&
|
53
29
|
Object.keys(builderContext.providers)?.length) {
|
54
30
|
const useShorthandCtor = input.options?.useShorthandCtor;
|
55
31
|
files.push(write(input.outPath, "contractContextBase.ts", useShorthandCtor
|
@@ -18,7 +18,7 @@ export class ContractsProviderBundlePlugin extends BuilderPluginBase {
|
|
18
18
|
return new RenderContext(contract, options, this.builder.builderContext);
|
19
19
|
}
|
20
20
|
async doRender(name, context) {
|
21
|
-
if (!this.option?.
|
21
|
+
if (!this.option?.useContractHooks?.enabled) {
|
22
22
|
return;
|
23
23
|
}
|
24
24
|
const providerInfos = context.getProviderInfos();
|
package/esm/plugins/provider.js
CHANGED
@@ -17,7 +17,7 @@ export class ContractsContextProviderPlugin extends BuilderPluginBase {
|
|
17
17
|
return new RenderContext(contract, options, this.builder.builderContext);
|
18
18
|
}
|
19
19
|
async doRender(name, context) {
|
20
|
-
if (!this.option?.
|
20
|
+
if (!this.option?.useContractHooks?.enabled) {
|
21
21
|
return;
|
22
22
|
}
|
23
23
|
const providerInfo = context.getProviderInfos()[name];
|
package/esm/utils/header.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import { readAndParsePackageJson } from "./package";
|
2
|
+
const pkg = readAndParsePackageJson();
|
2
3
|
const version = process.env.NODE_ENV === 'test' ? 'latest' : pkg.version;
|
3
4
|
export const header = `/**
|
4
5
|
* This file was automatically generated by ${pkg.name}@${version}.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { join, dirname } from "path";
|
2
|
+
import { readFileSync, existsSync } from "fs";
|
3
|
+
// need to search due to the dist/ folder and src/, etc.
|
4
|
+
function findPackageJson(currentDir) {
|
5
|
+
const filePath = join(currentDir, 'package.json');
|
6
|
+
// Check if package.json exists in the current directory
|
7
|
+
if (existsSync(filePath)) {
|
8
|
+
return filePath;
|
9
|
+
}
|
10
|
+
// Get the parent directory
|
11
|
+
const parentDir = dirname(currentDir);
|
12
|
+
// If reached the root directory, package.json is not found
|
13
|
+
if (parentDir === currentDir) {
|
14
|
+
throw new Error('package.json not found in any parent directory');
|
15
|
+
}
|
16
|
+
// Recursively look in the parent directory
|
17
|
+
return findPackageJson(parentDir);
|
18
|
+
}
|
19
|
+
export function readAndParsePackageJson() {
|
20
|
+
// Start searching from the current directory
|
21
|
+
const pkgPath = findPackageJson(__dirname);
|
22
|
+
// Read and parse the package.json
|
23
|
+
const str = readFileSync(pkgPath, 'utf8');
|
24
|
+
const pkg = JSON.parse(str);
|
25
|
+
return pkg;
|
26
|
+
}
|
@@ -2,35 +2,11 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.createHelpers = void 0;
|
4
4
|
const path_1 = require("path");
|
5
|
-
const fs_1 = require("fs");
|
6
5
|
const mkdirp_1 = require("mkdirp");
|
7
6
|
const files_1 = require("../utils/files");
|
7
|
+
const package_1 = require("../utils/package");
|
8
8
|
const helpers_1 = require("../helpers");
|
9
|
-
|
10
|
-
function findPackageJson(currentDir) {
|
11
|
-
const filePath = (0, path_1.join)(currentDir, 'package.json');
|
12
|
-
// Check if package.json exists in the current directory
|
13
|
-
if ((0, fs_1.existsSync)(filePath)) {
|
14
|
-
return filePath;
|
15
|
-
}
|
16
|
-
// Get the parent directory
|
17
|
-
const parentDir = (0, path_1.dirname)(currentDir);
|
18
|
-
// If reached the root directory, package.json is not found
|
19
|
-
if (parentDir === currentDir) {
|
20
|
-
throw new Error('package.json not found in any parent directory');
|
21
|
-
}
|
22
|
-
// Recursively look in the parent directory
|
23
|
-
return findPackageJson(parentDir);
|
24
|
-
}
|
25
|
-
function readAndParsePackageJson() {
|
26
|
-
// Start searching from the current directory
|
27
|
-
const pkgPath = findPackageJson(__dirname);
|
28
|
-
// Read and parse the package.json
|
29
|
-
const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
|
30
|
-
const pkg = JSON.parse(str);
|
31
|
-
return pkg;
|
32
|
-
}
|
33
|
-
const pkg = readAndParsePackageJson();
|
9
|
+
const pkg = (0, package_1.readAndParsePackageJson)();
|
34
10
|
const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
|
35
11
|
const header = `/**
|
36
12
|
* This file and any referenced files were automatically generated by ${pkg.name}@${version}
|
@@ -52,7 +28,7 @@ const write = (outPath, file, content, varname) => {
|
|
52
28
|
};
|
53
29
|
const createHelpers = (input, builderContext) => {
|
54
30
|
const files = [];
|
55
|
-
if (input.options?.
|
31
|
+
if (input.options?.useContractHooks?.enabled &&
|
56
32
|
Object.keys(builderContext.providers)?.length) {
|
57
33
|
const useShorthandCtor = input.options?.useShorthandCtor;
|
58
34
|
files.push(write(input.outPath, "contractContextBase.ts", useShorthandCtor
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cosmwasm/ts-codegen",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.0",
|
4
4
|
"description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
6
6
|
"homepage": "https://github.com/cosmwasm/ts-codegen",
|
@@ -38,7 +38,9 @@
|
|
38
38
|
"ast-stringify": "0.1.0"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@babel/
|
41
|
+
"@babel/generator": "7.24.4",
|
42
|
+
"@babel/traverse": "7.24.1",
|
43
|
+
"@babel/types": "7.24.0",
|
42
44
|
"@cosmology/ts-codegen-types": "^1.1.0",
|
43
45
|
"@pyramation/json-schema-to-typescript": " 11.0.4",
|
44
46
|
"@types/rimraf": "3.0.2",
|
@@ -55,7 +57,7 @@
|
|
55
57
|
"parse-package-name": "1.0.0",
|
56
58
|
"rimraf": "3.0.2",
|
57
59
|
"shelljs": "0.8.5",
|
58
|
-
"wasm-ast-types": "^1.
|
60
|
+
"wasm-ast-types": "^1.2.0"
|
59
61
|
},
|
60
62
|
"keywords": [
|
61
63
|
"cosmwasm",
|
@@ -63,5 +65,5 @@
|
|
63
65
|
"smart contracts",
|
64
66
|
"codegen"
|
65
67
|
],
|
66
|
-
"gitHead": "
|
68
|
+
"gitHead": "8765a19d3cc72296ac528f9ec12f215e6017e34e"
|
67
69
|
}
|
@@ -44,7 +44,7 @@ class ContractsProviderBundlePlugin extends plugin_base_1.BuilderPluginBase {
|
|
44
44
|
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
45
45
|
}
|
46
46
|
async doRender(name, context) {
|
47
|
-
if (!this.option?.
|
47
|
+
if (!this.option?.useContractHooks?.enabled) {
|
48
48
|
return;
|
49
49
|
}
|
50
50
|
const providerInfos = context.getProviderInfos();
|
package/plugins/provider.js
CHANGED
@@ -45,7 +45,7 @@ class ContractsContextProviderPlugin extends plugin_base_1.BuilderPluginBase {
|
|
45
45
|
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
46
46
|
}
|
47
47
|
async doRender(name, context) {
|
48
|
-
if (!this.option?.
|
48
|
+
if (!this.option?.useContractHooks?.enabled) {
|
49
49
|
return;
|
50
50
|
}
|
51
51
|
const providerInfo = context.getProviderInfos()[name];
|
package/utils/header.js
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.header = void 0;
|
7
|
-
const
|
8
|
-
const
|
4
|
+
const package_1 = require("./package");
|
5
|
+
const pkg = (0, package_1.readAndParsePackageJson)();
|
6
|
+
const version = process.env.NODE_ENV === 'test' ? 'latest' : pkg.version;
|
9
7
|
exports.header = `/**
|
10
|
-
* This file was automatically generated by ${
|
8
|
+
* This file was automatically generated by ${pkg.name}@${version}.
|
11
9
|
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
12
|
-
* and run the ${
|
10
|
+
* and run the ${pkg.name} generate command to regenerate this file.
|
13
11
|
*/
|
14
12
|
\n`;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function readAndParsePackageJson(): any;
|
package/utils/package.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.readAndParsePackageJson = void 0;
|
4
|
+
const path_1 = require("path");
|
5
|
+
const fs_1 = require("fs");
|
6
|
+
// need to search due to the dist/ folder and src/, etc.
|
7
|
+
function findPackageJson(currentDir) {
|
8
|
+
const filePath = (0, path_1.join)(currentDir, 'package.json');
|
9
|
+
// Check if package.json exists in the current directory
|
10
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
11
|
+
return filePath;
|
12
|
+
}
|
13
|
+
// Get the parent directory
|
14
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
15
|
+
// If reached the root directory, package.json is not found
|
16
|
+
if (parentDir === currentDir) {
|
17
|
+
throw new Error('package.json not found in any parent directory');
|
18
|
+
}
|
19
|
+
// Recursively look in the parent directory
|
20
|
+
return findPackageJson(parentDir);
|
21
|
+
}
|
22
|
+
function readAndParsePackageJson() {
|
23
|
+
// Start searching from the current directory
|
24
|
+
const pkgPath = findPackageJson(__dirname);
|
25
|
+
// Read and parse the package.json
|
26
|
+
const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
|
27
|
+
const pkg = JSON.parse(str);
|
28
|
+
return pkg;
|
29
|
+
}
|
30
|
+
exports.readAndParsePackageJson = readAndParsePackageJson;
|