@dedot/cli 0.0.1-alpha.400 → 0.0.1-alpha.41
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.d.ts +2 -0
- package/cjs/commands/chaintypes.js +52 -11
- package/cjs/commands/index.d.ts +2 -1
- package/cjs/commands/index.js +2 -1
- package/cjs/commands/typink.d.ts +10 -0
- package/cjs/commands/typink.js +76 -0
- package/cjs/dedot.js +3 -2
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +7 -2
- package/package.json +14 -4
- package/cjs/packageInfo.d.ts +0 -4
- package/cjs/packageInfo.js +0 -5
|
@@ -22,30 +22,51 @@ 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
|
|
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
|
-
const
|
|
35
|
-
|
|
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
|
+
}
|
|
59
|
+
console.log(`- DONE! Output: ${outDir}`);
|
|
36
60
|
},
|
|
37
61
|
builder: (yargs) => {
|
|
38
|
-
return yargs
|
|
62
|
+
return (yargs
|
|
39
63
|
.option('wsUrl', {
|
|
40
64
|
type: 'string',
|
|
41
65
|
describe: 'Websocket Url to fetch metadata',
|
|
42
66
|
alias: 'w',
|
|
67
|
+
default: 'ws://127.0.0.1:9944',
|
|
43
68
|
})
|
|
44
|
-
|
|
45
|
-
type: 'string',
|
|
46
|
-
describe: 'Path to metadata file',
|
|
47
|
-
alias: 'f',
|
|
48
|
-
})
|
|
69
|
+
// TODO add file input
|
|
49
70
|
.option('output', {
|
|
50
71
|
type: 'string',
|
|
51
72
|
describe: 'Output folder to put generated files',
|
|
@@ -55,6 +76,26 @@ exports.chaintypes = {
|
|
|
55
76
|
type: 'string',
|
|
56
77
|
describe: 'Chain name',
|
|
57
78
|
alias: 'c',
|
|
58
|
-
})
|
|
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,
|
|
91
|
+
})); // TODO check to verify inputs
|
|
59
92
|
},
|
|
60
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/cjs/commands/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './chaintypes';
|
|
1
|
+
export * from './chaintypes.js';
|
|
2
|
+
export * from './typink.js';
|
package/cjs/commands/index.js
CHANGED
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./chaintypes"), exports);
|
|
17
|
+
__exportStar(require("./chaintypes.js"), exports);
|
|
18
|
+
__exportStar(require("./typink.js"), exports);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.typink = void 0;
|
|
27
|
+
const codegen_1 = require("@dedot/codegen");
|
|
28
|
+
const utils_1 = require("@dedot/utils");
|
|
29
|
+
const fs = __importStar(require("node:fs"));
|
|
30
|
+
const path = __importStar(require("path"));
|
|
31
|
+
exports.typink = {
|
|
32
|
+
command: 'typink',
|
|
33
|
+
describe: 'Generate types & APIs for a ink! smart contracts',
|
|
34
|
+
handler: async (yargs) => {
|
|
35
|
+
const { contract, output = '', metadata, dts = true, subpath = true } = yargs;
|
|
36
|
+
(0, utils_1.assert)(metadata, 'Metadata file is required, -h or --help to known more about the command');
|
|
37
|
+
const outDir = path.resolve(output);
|
|
38
|
+
const metadataFile = path.resolve(metadata);
|
|
39
|
+
const extension = dts ? 'd.ts' : 'ts';
|
|
40
|
+
const rawMetadata = fs.readFileSync(metadataFile, 'utf-8');
|
|
41
|
+
console.log(`- Generating contract types via metadata ${metadata}`);
|
|
42
|
+
await (0, codegen_1.generateContractTypes)(rawMetadata, contract, outDir, extension, subpath);
|
|
43
|
+
console.log(`- DONE! Output: ${outDir}`);
|
|
44
|
+
},
|
|
45
|
+
builder: (yargs) => {
|
|
46
|
+
return yargs
|
|
47
|
+
.option('metadata', {
|
|
48
|
+
type: 'string',
|
|
49
|
+
describe: 'Path to contract metadata file (.json, .contract)',
|
|
50
|
+
alias: 'm',
|
|
51
|
+
demandOption: true,
|
|
52
|
+
})
|
|
53
|
+
.option('output', {
|
|
54
|
+
type: 'string',
|
|
55
|
+
describe: 'Output folder to put generated files',
|
|
56
|
+
alias: 'o',
|
|
57
|
+
})
|
|
58
|
+
.option('contract', {
|
|
59
|
+
type: 'string',
|
|
60
|
+
describe: 'Contract name',
|
|
61
|
+
alias: 'c',
|
|
62
|
+
})
|
|
63
|
+
.option('dts', {
|
|
64
|
+
type: 'boolean',
|
|
65
|
+
describe: 'Generate d.ts files',
|
|
66
|
+
alias: 'd',
|
|
67
|
+
default: true,
|
|
68
|
+
})
|
|
69
|
+
.option('subpath', {
|
|
70
|
+
type: 'boolean',
|
|
71
|
+
describe: 'Using subpath for shared packages',
|
|
72
|
+
alias: 's',
|
|
73
|
+
default: true,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
};
|
package/cjs/dedot.js
CHANGED
|
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.dedot = void 0;
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
8
|
const helpers_1 = require("yargs/helpers");
|
|
9
|
-
const
|
|
9
|
+
const index_js_1 = require("./commands/index.js");
|
|
10
10
|
const dedot = () => {
|
|
11
11
|
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
12
12
|
.scriptName('dedot')
|
|
13
13
|
.showHelpOnFail(true)
|
|
14
|
-
.command(
|
|
14
|
+
.command(index_js_1.chaintypes)
|
|
15
|
+
.command(index_js_1.typink)
|
|
15
16
|
.help('help', 'Show help instructions')
|
|
16
17
|
.alias('h', 'help')
|
|
17
18
|
.alias('v', 'version')
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { dedot } from './dedot';
|
|
1
|
+
import { dedot } from './dedot.js';
|
|
2
2
|
export { dedot };
|
package/cjs/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dedot = void 0;
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "dedot", { enumerable: true, get: function () { return
|
|
4
|
+
const dedot_js_1 = require("./dedot.js");
|
|
5
|
+
Object.defineProperty(exports, "dedot", { enumerable: true, get: function () { return dedot_js_1.dedot; } });
|
|
6
|
+
// We run this directly for development purpose via ts-node
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
if (process[Symbol.for('ts-node.register.instance')]) {
|
|
9
|
+
(0, dedot_js_1.dedot)();
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.41",
|
|
4
4
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
5
|
+
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/cli",
|
|
6
|
+
"repository": {
|
|
7
|
+
"directory": "packages/cli",
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dedotdev/dedot.git"
|
|
10
|
+
},
|
|
5
11
|
"bin": {
|
|
6
12
|
"dedot": "./bin/dedot",
|
|
7
13
|
"djs": "./bin/dedot"
|
|
8
14
|
},
|
|
9
15
|
"main": "./cjs/index.js",
|
|
16
|
+
"sideEffects": false,
|
|
10
17
|
"scripts": {
|
|
11
18
|
"build": "tsc --project tsconfig.build.cjs.json && cp -R ./bin ./dist",
|
|
12
19
|
"clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo ./tsconfig.build.cjs.tsbuildinfo && rm -rf ./src/codegen",
|
|
13
|
-
"
|
|
20
|
+
"start": "ts-node src/index.ts"
|
|
14
21
|
},
|
|
15
22
|
"dependencies": {
|
|
16
|
-
"@dedot/
|
|
23
|
+
"@dedot/api": "0.0.1-alpha.41",
|
|
24
|
+
"@dedot/codecs": "0.0.1-alpha.41",
|
|
25
|
+
"@dedot/codegen": "0.0.1-alpha.41",
|
|
26
|
+
"@polkadot/types-support": "^12.2.1",
|
|
17
27
|
"yargs": "^17.7.2"
|
|
18
28
|
},
|
|
19
29
|
"devDependencies": {
|
|
@@ -24,5 +34,5 @@
|
|
|
24
34
|
"directory": "dist"
|
|
25
35
|
},
|
|
26
36
|
"license": "Apache-2.0",
|
|
27
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "4c699c73281cf4525be2d8e31c416f4dd7dc2fdd"
|
|
28
38
|
}
|
package/cjs/packageInfo.d.ts
DELETED