@dedot/cli 0.17.0 → 0.17.1-next.6d398d60.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/commands/typink.js +26 -7
- package/package.json +5 -5
package/commands/typink.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { generateContractTypes } from '@dedot/codegen';
|
|
2
|
-
import { ensureSupportedContractMetadataVersion } from '@dedot/contracts';
|
|
3
|
-
import { assert } from '@dedot/utils';
|
|
1
|
+
import { generateContractTypes, generateSolContractTypes } from '@dedot/codegen';
|
|
2
|
+
import { ensureSupportedContractMetadataVersion, isInkAbi, isSolAbi } from '@dedot/contracts';
|
|
3
|
+
import { assert, DedotError } from '@dedot/utils';
|
|
4
4
|
import * as fs from 'node:fs';
|
|
5
5
|
import ora from 'ora';
|
|
6
6
|
import * as path from 'path';
|
|
@@ -17,13 +17,32 @@ export const typink = {
|
|
|
17
17
|
try {
|
|
18
18
|
spinner.text = `Parsing contract metadata file: ${metadata}`;
|
|
19
19
|
const contractMetadata = JSON.parse(fs.readFileSync(metadataFile, 'utf-8'));
|
|
20
|
-
|
|
20
|
+
const isInkContract = isInkAbi(contractMetadata);
|
|
21
|
+
const isSolidityContract = isSolAbi(contractMetadata);
|
|
22
|
+
if (isInkContract) {
|
|
23
|
+
ensureSupportedContractMetadataVersion(contractMetadata);
|
|
24
|
+
spinner.info(`Detected ink! contract metadata version: ${contractMetadata.version}`);
|
|
25
|
+
}
|
|
26
|
+
else if (isSolidityContract) {
|
|
27
|
+
spinner.info(`Detected Solidity ABI metadata`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new DedotError('Unknown metadata format (neither ink! nor Solidity ABI)');
|
|
31
|
+
}
|
|
21
32
|
spinner.succeed(`Parsed contract metadata file: ${metadata}`);
|
|
22
33
|
spinner.text = 'Generating contract Types & APIs';
|
|
23
|
-
|
|
34
|
+
let result;
|
|
35
|
+
if (isInkContract) {
|
|
36
|
+
result = await generateContractTypes(contractMetadata, contract, outDir, extension, subpath);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// For Solidity contract, we use the file name (without extension) as the contract name if not provided
|
|
40
|
+
const contractName = contract || path.basename(metadataFile).split('.')[0];
|
|
41
|
+
result = await generateSolContractTypes(contractMetadata, contractName, outDir, extension, subpath);
|
|
42
|
+
}
|
|
24
43
|
spinner.succeed('Generated contract Types & APIs');
|
|
25
|
-
console.log(` ➡ Output directory: file://${outputFolder}`);
|
|
26
|
-
console.log(` ➡ ContractApi interface: ${interfaceName}`);
|
|
44
|
+
console.log(` ➡ Output directory: file://${result.outputFolder}`);
|
|
45
|
+
console.log(` ➡ ContractApi interface: ${result.interfaceName}`);
|
|
27
46
|
console.log('🌈 Done!');
|
|
28
47
|
spinner.stop();
|
|
29
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/cli",
|
|
3
|
-
"version": "0.17.0",
|
|
3
|
+
"version": "0.17.1-next.6d398d60.0+6d398d60",
|
|
4
4
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
5
5
|
"homepage": "https://dedot.dev",
|
|
6
6
|
"repository": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"test": "npx vitest --watch=false"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@dedot/api": "0.17.0",
|
|
26
|
-
"@dedot/codecs": "0.17.0",
|
|
27
|
-
"@dedot/codegen": "0.17.0",
|
|
25
|
+
"@dedot/api": "0.17.1-next.6d398d60.0+6d398d60",
|
|
26
|
+
"@dedot/codecs": "0.17.1-next.6d398d60.0+6d398d60",
|
|
27
|
+
"@dedot/codegen": "0.17.1-next.6d398d60.0+6d398d60",
|
|
28
28
|
"@polkadot-api/wasm-executor": "^0.1.2",
|
|
29
29
|
"@polkadot/types-support": "^16.4.6",
|
|
30
30
|
"ora": "^8.2.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"node": ">=18"
|
|
42
42
|
},
|
|
43
43
|
"license": "Apache-2.0",
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "6d398d6002387fa7e78ca6df194e5f30595a6be8",
|
|
45
45
|
"module": "./index.js",
|
|
46
46
|
"types": "./index.d.ts"
|
|
47
47
|
}
|