@dedot/cli 0.2.0 → 0.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/cjs/commands/chaintypes.js +41 -22
- package/cjs/commands/typink.js +26 -7
- package/package.json +7 -6
|
@@ -32,41 +32,60 @@ const substrate_hex_1 = __importDefault(require("@polkadot/types-support/metadat
|
|
|
32
32
|
const api_1 = require("@dedot/api");
|
|
33
33
|
const codecs_1 = require("@dedot/codecs");
|
|
34
34
|
const codegen_1 = require("@dedot/codegen");
|
|
35
|
+
const ora_1 = __importDefault(require("ora"));
|
|
35
36
|
const path = __importStar(require("path"));
|
|
36
37
|
exports.chaintypes = {
|
|
37
38
|
command: 'chaintypes',
|
|
38
|
-
describe: 'Generate
|
|
39
|
+
describe: 'Generate Types & APIs for Substrate-based chains',
|
|
39
40
|
handler: async (yargs) => {
|
|
40
41
|
const { wsUrl, output = '', chain = '', dts = true, subpath = true } = yargs;
|
|
41
42
|
const outDir = path.resolve(output);
|
|
42
43
|
const extension = dts ? 'd.ts' : 'ts';
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
const spinner = (0, ora_1.default)().start();
|
|
45
|
+
const shouldGenerateGenericTypes = wsUrl === 'substrate';
|
|
46
|
+
try {
|
|
47
|
+
let generatedResult;
|
|
48
|
+
if (shouldGenerateGenericTypes) {
|
|
49
|
+
spinner.text = 'Generating Substrate generic chaintypes';
|
|
50
|
+
const metadataHex = substrate_hex_1.default;
|
|
51
|
+
const rpcMethods = static_substrate_1.rpc.methods;
|
|
52
|
+
const metadata = codecs_1.$Metadata.tryDecode(metadataHex);
|
|
53
|
+
const runtimeVersion = getRuntimeVersion(metadata);
|
|
54
|
+
const runtimeApis = runtimeVersion.apis.reduce((acc, [name, version]) => {
|
|
55
|
+
acc[name] = version;
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
generatedResult = await (0, codegen_1.generateTypes)(chain || 'substrate', metadata.latest, rpcMethods, runtimeApis, outDir, extension, subpath);
|
|
59
|
+
spinner.succeed('Generated Substrate generic chaintypes');
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
spinner.text = `Generating chaintypes via endpoint: ${wsUrl}`;
|
|
63
|
+
generatedResult = await (0, codegen_1.generateTypesFromEndpoint)(chain, wsUrl, outDir, extension, subpath);
|
|
64
|
+
spinner.succeed(`Generated chaintypes via endpoint: ${wsUrl}`);
|
|
65
|
+
}
|
|
66
|
+
console.log(` ➡ Output directory: file://${outDir}`);
|
|
67
|
+
console.log(` ➡ ChainApi interface: ${generatedResult.interfaceName}`);
|
|
68
|
+
console.log('🌈 Done!');
|
|
54
69
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (shouldGenerateGenericTypes) {
|
|
72
|
+
spinner.fail(`Failed to generate Substrate generic chaintypes`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
spinner.fail(`Failed to generate chaintypes via endpoint: ${wsUrl}`);
|
|
76
|
+
}
|
|
77
|
+
console.error(e);
|
|
58
78
|
}
|
|
59
|
-
|
|
79
|
+
spinner.stop();
|
|
60
80
|
},
|
|
61
81
|
builder: (yargs) => {
|
|
62
|
-
return
|
|
82
|
+
return yargs
|
|
63
83
|
.option('wsUrl', {
|
|
64
84
|
type: 'string',
|
|
65
|
-
describe: 'Websocket
|
|
85
|
+
describe: 'Websocket URL to fetch metadata',
|
|
66
86
|
alias: 'w',
|
|
67
87
|
default: 'ws://127.0.0.1:9944',
|
|
68
88
|
})
|
|
69
|
-
// TODO add file input
|
|
70
89
|
.option('output', {
|
|
71
90
|
type: 'string',
|
|
72
91
|
describe: 'Output folder to put generated files',
|
|
@@ -74,7 +93,7 @@ exports.chaintypes = {
|
|
|
74
93
|
})
|
|
75
94
|
.option('chain', {
|
|
76
95
|
type: 'string',
|
|
77
|
-
describe: '
|
|
96
|
+
describe: 'Custom chain name',
|
|
78
97
|
alias: 'c',
|
|
79
98
|
})
|
|
80
99
|
.option('dts', {
|
|
@@ -85,10 +104,10 @@ exports.chaintypes = {
|
|
|
85
104
|
})
|
|
86
105
|
.option('subpath', {
|
|
87
106
|
type: 'boolean',
|
|
88
|
-
describe: 'Using subpath for shared packages',
|
|
107
|
+
describe: 'Using subpath for shared packages (e.g: dedot/types)',
|
|
89
108
|
alias: 's',
|
|
90
109
|
default: true,
|
|
91
|
-
})
|
|
110
|
+
}); // TODO check to verify inputs
|
|
92
111
|
},
|
|
93
112
|
};
|
|
94
113
|
const getRuntimeVersion = (metadata) => {
|
package/cjs/commands/typink.js
CHANGED
|
@@ -22,25 +22,44 @@ 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.typink = void 0;
|
|
27
30
|
const codegen_1 = require("@dedot/codegen");
|
|
31
|
+
const contracts_1 = require("@dedot/contracts");
|
|
28
32
|
const utils_1 = require("@dedot/utils");
|
|
29
33
|
const fs = __importStar(require("node:fs"));
|
|
34
|
+
const ora_1 = __importDefault(require("ora"));
|
|
30
35
|
const path = __importStar(require("path"));
|
|
31
36
|
exports.typink = {
|
|
32
37
|
command: 'typink',
|
|
33
|
-
describe: 'Generate
|
|
38
|
+
describe: 'Generate Types & APIs for ink! smart contracts',
|
|
34
39
|
handler: async (yargs) => {
|
|
35
40
|
const { contract, output = '', metadata, dts = true, subpath = true } = yargs;
|
|
36
41
|
(0, utils_1.assert)(metadata, 'Metadata file is required, -h or --help to known more about the command');
|
|
37
42
|
const outDir = path.resolve(output);
|
|
38
43
|
const metadataFile = path.resolve(metadata);
|
|
39
44
|
const extension = dts ? 'd.ts' : 'ts';
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const spinner = (0, ora_1.default)().start();
|
|
46
|
+
try {
|
|
47
|
+
spinner.text = `Parsing contract metadata file: ${metadata}`;
|
|
48
|
+
const contractMetadata = (0, contracts_1.parseRawMetadata)(fs.readFileSync(metadataFile, 'utf-8'));
|
|
49
|
+
spinner.succeed(`Parsed contract metadata file: ${metadata}`);
|
|
50
|
+
spinner.text = 'Generating contract Types & APIs';
|
|
51
|
+
const { interfaceName } = await (0, codegen_1.generateContractTypes)(contractMetadata, contract, outDir, extension, subpath);
|
|
52
|
+
spinner.succeed('Generated contract Types & APIs');
|
|
53
|
+
console.log(` ➡ Output directory: file://${outDir}`);
|
|
54
|
+
console.log(` ➡ ContractApi interface: ${interfaceName}`);
|
|
55
|
+
console.log('🌈 Done!');
|
|
56
|
+
spinner.stop();
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
spinner.stop();
|
|
60
|
+
spinner.fail(`Failed to generate contract Types & APIs using metadata file: ${metadata}`);
|
|
61
|
+
console.error(e);
|
|
62
|
+
}
|
|
44
63
|
},
|
|
45
64
|
builder: (yargs) => {
|
|
46
65
|
return yargs
|
|
@@ -57,7 +76,7 @@ exports.typink = {
|
|
|
57
76
|
})
|
|
58
77
|
.option('contract', {
|
|
59
78
|
type: 'string',
|
|
60
|
-
describe: '
|
|
79
|
+
describe: 'Custom contract name, default is contract name from metadata',
|
|
61
80
|
alias: 'c',
|
|
62
81
|
})
|
|
63
82
|
.option('dts', {
|
|
@@ -68,7 +87,7 @@ exports.typink = {
|
|
|
68
87
|
})
|
|
69
88
|
.option('subpath', {
|
|
70
89
|
type: 'boolean',
|
|
71
|
-
describe: 'Using subpath for shared packages',
|
|
90
|
+
describe: 'Using subpath for shared packages (e.g: dedot/contracts)',
|
|
72
91
|
alias: 's',
|
|
73
92
|
default: true,
|
|
74
93
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
5
5
|
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/cli",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
"start": "ts-node src/index.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dedot/api": "0.
|
|
24
|
-
"@dedot/codecs": "0.
|
|
25
|
-
"@dedot/codegen": "0.
|
|
26
|
-
"@polkadot/types-support": "^12.2.
|
|
23
|
+
"@dedot/api": "0.4.0",
|
|
24
|
+
"@dedot/codecs": "0.4.0",
|
|
25
|
+
"@dedot/codegen": "0.4.0",
|
|
26
|
+
"@polkadot/types-support": "^12.2.3",
|
|
27
|
+
"ora": "^8.0.1",
|
|
27
28
|
"yargs": "^17.7.2"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
@@ -34,5 +35,5 @@
|
|
|
34
35
|
"directory": "dist"
|
|
35
36
|
},
|
|
36
37
|
"license": "Apache-2.0",
|
|
37
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f6271b5c12d8bf909e4b1a186417bf26db504c63"
|
|
38
39
|
}
|