@dedot/codegen 0.0.1-alpha.23 → 0.0.1-alpha.24
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/cjs/index.js +6 -3
- package/cjs/packageInfo.js +1 -1
- package/index.js +7 -4
- package/package.json +7 -7
- package/packageInfo.js +1 -1
package/cjs/index.js
CHANGED
|
@@ -27,18 +27,21 @@ exports.generateTypes = exports.generateTypesFromChain = void 0;
|
|
|
27
27
|
const dedot_1 = require("dedot");
|
|
28
28
|
const fs = __importStar(require("fs"));
|
|
29
29
|
const path = __importStar(require("path"));
|
|
30
|
-
const process = __importStar(require("process"));
|
|
31
30
|
const generator_1 = require("./generator");
|
|
31
|
+
const util_1 = require("@polkadot/util");
|
|
32
32
|
async function generateTypesFromChain(network, endpoint, outDir) {
|
|
33
33
|
const api = await dedot_1.Dedot.create(endpoint);
|
|
34
34
|
const { methods } = await api.rpc.rpc.methods();
|
|
35
35
|
const apis = api.runtimeVersion?.apis || [];
|
|
36
|
+
if (!network.chain) {
|
|
37
|
+
network.chain = (0, util_1.stringCamelCase)(api.runtimeVersion?.specName || api.runtimeChain || 'local');
|
|
38
|
+
}
|
|
36
39
|
await generateTypes(network, api.metadataLatest, methods, apis, outDir);
|
|
37
40
|
await api.disconnect();
|
|
38
41
|
}
|
|
39
42
|
exports.generateTypesFromChain = generateTypesFromChain;
|
|
40
43
|
async function generateTypes(network, metadata, rpcMethods, runtimeApis, outDir = '.') {
|
|
41
|
-
const dirPath = path.resolve(
|
|
44
|
+
const dirPath = path.resolve(outDir, network.chain);
|
|
42
45
|
const defTypesFileName = path.join(dirPath, `types.ts`);
|
|
43
46
|
const constsTypesFileName = path.join(dirPath, `consts.ts`);
|
|
44
47
|
const queryTypesFileName = path.join(dirPath, `query.ts`);
|
|
@@ -49,7 +52,7 @@ async function generateTypes(network, metadata, rpcMethods, runtimeApis, outDir
|
|
|
49
52
|
const runtimeApisFileName = path.join(dirPath, `runtime.ts`);
|
|
50
53
|
const txFileName = path.join(dirPath, `tx.ts`);
|
|
51
54
|
if (!fs.existsSync(dirPath)) {
|
|
52
|
-
fs.mkdirSync(dirPath);
|
|
55
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
53
56
|
}
|
|
54
57
|
const typesGen = new generator_1.TypesGen(metadata);
|
|
55
58
|
const constsGen = new generator_1.ConstsGen(typesGen);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.packageInfo = void 0;
|
|
5
|
-
exports.packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.
|
|
5
|
+
exports.packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.23' };
|
package/index.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { Dedot } from 'dedot';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator';
|
|
5
|
+
import { stringCamelCase } from '@polkadot/util';
|
|
6
6
|
export async function generateTypesFromChain(network, endpoint, outDir) {
|
|
7
7
|
const api = await Dedot.create(endpoint);
|
|
8
8
|
const { methods } = await api.rpc.rpc.methods();
|
|
9
9
|
const apis = api.runtimeVersion?.apis || [];
|
|
10
|
+
if (!network.chain) {
|
|
11
|
+
network.chain = stringCamelCase(api.runtimeVersion?.specName || api.runtimeChain || 'local');
|
|
12
|
+
}
|
|
10
13
|
await generateTypes(network, api.metadataLatest, methods, apis, outDir);
|
|
11
14
|
await api.disconnect();
|
|
12
15
|
}
|
|
13
16
|
export async function generateTypes(network, metadata, rpcMethods, runtimeApis, outDir = '.') {
|
|
14
|
-
const dirPath = path.resolve(
|
|
17
|
+
const dirPath = path.resolve(outDir, network.chain);
|
|
15
18
|
const defTypesFileName = path.join(dirPath, `types.ts`);
|
|
16
19
|
const constsTypesFileName = path.join(dirPath, `consts.ts`);
|
|
17
20
|
const queryTypesFileName = path.join(dirPath, `query.ts`);
|
|
@@ -22,7 +25,7 @@ export async function generateTypes(network, metadata, rpcMethods, runtimeApis,
|
|
|
22
25
|
const runtimeApisFileName = path.join(dirPath, `runtime.ts`);
|
|
23
26
|
const txFileName = path.join(dirPath, `tx.ts`);
|
|
24
27
|
if (!fs.existsSync(dirPath)) {
|
|
25
|
-
fs.mkdirSync(dirPath);
|
|
28
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
26
29
|
}
|
|
27
30
|
const typesGen = new TypesGen(metadata);
|
|
28
31
|
const constsGen = new ConstsGen(typesGen);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/codegen",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.24",
|
|
4
4
|
"description": "Generate types",
|
|
5
5
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
6
6
|
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/codegen",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo ./tsconfig.build.tsbuildinfo"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@dedot/codecs": "0.0.1-alpha.
|
|
20
|
-
"@dedot/shape": "0.0.1-alpha.
|
|
21
|
-
"@dedot/specs": "0.0.1-alpha.
|
|
22
|
-
"@dedot/utils": "0.0.1-alpha.
|
|
19
|
+
"@dedot/codecs": "0.0.1-alpha.24",
|
|
20
|
+
"@dedot/shape": "0.0.1-alpha.24",
|
|
21
|
+
"@dedot/specs": "0.0.1-alpha.24",
|
|
22
|
+
"@dedot/utils": "0.0.1-alpha.24",
|
|
23
23
|
"@polkadot/util": "^12.6.2",
|
|
24
|
-
"dedot": "0.0.1-alpha.
|
|
24
|
+
"dedot": "0.0.1-alpha.24",
|
|
25
25
|
"handlebars": "^4.7.8",
|
|
26
26
|
"prettier": "^3.0.3"
|
|
27
27
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"directory": "dist"
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "1f9e0958a787fbbd99b965e1955d7cdce076ca28",
|
|
34
34
|
"module": "./index.js",
|
|
35
35
|
"types": "./index.d.ts",
|
|
36
36
|
"exports": {
|
package/packageInfo.js
CHANGED