@dedot/cli 0.0.1-alpha.30 → 0.0.1-alpha.32

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.
@@ -3,6 +3,8 @@ type Args = {
3
3
  wsUrl?: string;
4
4
  output?: string;
5
5
  chain?: string;
6
+ dts?: boolean;
7
+ subpath?: boolean;
6
8
  };
7
9
  export declare const chaintypes: CommandModule<Args, Args>;
8
10
  export {};
@@ -22,18 +22,40 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.chaintypes = void 0;
27
- const path = __importStar(require("path"));
30
+ const static_substrate_1 = require("@polkadot/types-support/metadata/static-substrate");
31
+ const substrate_hex_1 = __importDefault(require("@polkadot/types-support/metadata/v15/substrate-hex"));
32
+ const api_1 = require("@dedot/api");
33
+ const codecs_1 = require("@dedot/codecs");
28
34
  const codegen_1 = require("@dedot/codegen");
35
+ const path = __importStar(require("path"));
29
36
  exports.chaintypes = {
30
37
  command: 'chaintypes',
31
38
  describe: 'Generate chain types & APIs for a Substrate-based blockchain',
32
39
  handler: async (yargs) => {
33
- const { wsUrl, output = '', chain = '' } = yargs;
34
- console.log(`- Generating chaintypes via endpoint ${wsUrl}`);
35
- const outDir = path.resolve(output, './codegen');
36
- await (0, codegen_1.generateTypesFromEndpoint)(chain, wsUrl, outDir);
40
+ const { wsUrl, output = '', chain = '', dts = true, subpath = true } = yargs;
41
+ const outDir = path.resolve(output);
42
+ const extension = dts ? 'd.ts' : 'ts';
43
+ if (wsUrl === 'substrate') {
44
+ console.log(`- Generating generic chaintypes`);
45
+ const metadataHex = substrate_hex_1.default;
46
+ const rpcMethods = static_substrate_1.rpc.methods;
47
+ const metadata = codecs_1.$Metadata.tryDecode(metadataHex);
48
+ const runtimeVersion = getRuntimeVersion(metadata);
49
+ const runtimeApis = runtimeVersion.apis.reduce((acc, [name, version]) => {
50
+ acc[name] = version;
51
+ return acc;
52
+ }, {});
53
+ await (0, codegen_1.generateTypes)('substrate', metadata.latest, rpcMethods, runtimeApis, outDir, extension, subpath);
54
+ }
55
+ else {
56
+ console.log(`- Generating chaintypes via endpoint ${wsUrl}`);
57
+ await (0, codegen_1.generateTypesFromEndpoint)(chain, wsUrl, outDir, extension, subpath);
58
+ }
37
59
  console.log(`- DONE! Output: ${outDir}`);
38
60
  },
39
61
  builder: (yargs) => {
@@ -54,6 +76,26 @@ exports.chaintypes = {
54
76
  type: 'string',
55
77
  describe: 'Chain name',
56
78
  alias: 'c',
79
+ })
80
+ .option('dts', {
81
+ type: 'boolean',
82
+ describe: 'Generate d.ts files',
83
+ alias: 'd',
84
+ default: true,
85
+ })
86
+ .option('subpath', {
87
+ type: 'boolean',
88
+ describe: 'Using subpath for shared packages',
89
+ alias: 's',
90
+ default: true,
57
91
  })); // TODO check to verify inputs
58
92
  },
59
93
  };
94
+ const getRuntimeVersion = (metadata) => {
95
+ const registry = new codecs_1.PortableRegistry(metadata.latest);
96
+ const executor = new api_1.ConstantExecutor({
97
+ registry,
98
+ metadata,
99
+ });
100
+ return executor.execute('system', 'version');
101
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/cli",
3
- "version": "0.0.1-alpha.30",
3
+ "version": "0.0.1-alpha.32",
4
4
  "author": "Thang X. Vu <thang@coongcrafts.io>",
5
5
  "bin": {
6
6
  "dedot": "./bin/dedot",
@@ -14,7 +14,10 @@
14
14
  "start": "ts-node src/index.ts"
15
15
  },
16
16
  "dependencies": {
17
- "@dedot/codegen": "0.0.1-alpha.30",
17
+ "@dedot/api": "0.0.1-alpha.32",
18
+ "@dedot/codecs": "0.0.1-alpha.32",
19
+ "@dedot/codegen": "0.0.1-alpha.32",
20
+ "@polkadot/types-support": "^11.0.2",
18
21
  "yargs": "^17.7.2"
19
22
  },
20
23
  "devDependencies": {
@@ -25,5 +28,5 @@
25
28
  "directory": "dist"
26
29
  },
27
30
  "license": "Apache-2.0",
28
- "gitHead": "ebc78daa1c0786f16dbf3a1f2c7a385142860ebc"
31
+ "gitHead": "43501104eee360a19ae18a70fe506e16d9357835"
29
32
  }