@0xobelisk/sui-cli 1.2.0-pre.1 → 1.2.0-pre.100
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/README.md +3 -3
- package/dist/dubhe.js +125 -66
- package/dist/dubhe.js.map +1 -1
- package/package.json +31 -19
- package/src/commands/build.ts +47 -16
- package/src/commands/call.ts +83 -83
- package/src/commands/checkBalance.ts +12 -5
- package/src/commands/configStore.ts +12 -4
- package/src/commands/convertJson.ts +70 -0
- package/src/commands/doctor.ts +1515 -0
- package/src/commands/faucet.ts +11 -7
- package/src/commands/generateKey.ts +3 -2
- package/src/commands/index.ts +16 -7
- package/src/commands/info.ts +55 -0
- package/src/commands/loadMetadata.ts +57 -0
- package/src/commands/localnode.ts +22 -12
- package/src/commands/publish.ts +21 -7
- package/src/commands/query.ts +101 -101
- package/src/commands/schemagen.ts +15 -4
- package/src/commands/shell.ts +198 -0
- package/src/commands/switchEnv.ts +26 -0
- package/src/commands/test.ts +54 -11
- package/src/commands/upgrade.ts +11 -4
- package/src/commands/wait.ts +333 -22
- package/src/commands/watch.ts +2 -1
- package/src/dubhe.ts +12 -4
- package/src/utils/axios-downloader.ts +116 -0
- package/src/utils/callHandler.ts +118 -118
- package/src/utils/constants.ts +5 -0
- package/src/utils/generateAccount.ts +1 -1
- package/src/utils/index.ts +4 -3
- package/src/utils/metadataHandler.ts +16 -0
- package/src/utils/publishHandler.ts +295 -290
- package/src/utils/queryStorage.ts +141 -141
- package/src/utils/startNode.ts +165 -108
- package/src/utils/storeConfig.ts +6 -12
- package/src/utils/upgradeHandler.ts +147 -86
- package/src/utils/utils.ts +771 -54
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xobelisk/sui-cli",
|
|
3
|
-
"version": "1.2.0-pre.
|
|
3
|
+
"version": "1.2.0-pre.100",
|
|
4
4
|
"description": "Tookit for interacting with move eps framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
"move",
|
|
9
9
|
"blockchain"
|
|
10
10
|
],
|
|
11
|
-
"type": "module",
|
|
12
|
-
"author": "team@obelisk.build",
|
|
13
11
|
"homepage": "https://github.com/0xobelisk/dubhe/tree/main/packages/sui-cli#readme",
|
|
14
12
|
"bugs": "https://github.com/0xobelisk/dubhe/issues",
|
|
15
13
|
"repository": {
|
|
@@ -17,12 +15,8 @@
|
|
|
17
15
|
"url": "https://github.com/0xobelisk/dubhe.git"
|
|
18
16
|
},
|
|
19
17
|
"license": "Apache-2.0",
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": ">=18"
|
|
25
|
-
},
|
|
18
|
+
"author": "team@obelisk.build",
|
|
19
|
+
"type": "module",
|
|
26
20
|
"exports": {
|
|
27
21
|
".": "./dist/index.js"
|
|
28
22
|
},
|
|
@@ -31,34 +25,39 @@
|
|
|
31
25
|
"dubhe": "./dist/dubhe.js"
|
|
32
26
|
},
|
|
33
27
|
"dependencies": {
|
|
34
|
-
"@mysten/sui": "
|
|
35
|
-
"@types/sqlite3": "^3.1.11",
|
|
28
|
+
"@mysten/sui": "1.35.0",
|
|
36
29
|
"@types/wait-on": "^5.3.4",
|
|
30
|
+
"axios": "^1.12.0",
|
|
37
31
|
"chalk": "^5.0.1",
|
|
38
32
|
"child_process": "^1.0.2",
|
|
39
33
|
"chokidar": "^3.5.3",
|
|
34
|
+
"cli-progress": "^3.12.0",
|
|
35
|
+
"cli-table3": "^0.6.5",
|
|
40
36
|
"dotenv": "^16.0.3",
|
|
41
37
|
"ejs": "^3.1.8",
|
|
42
38
|
"execa": "^7.0.0",
|
|
43
39
|
"glob": "^8.0.3",
|
|
40
|
+
"http-proxy-agent": "^7.0.2",
|
|
41
|
+
"https-proxy-agent": "^7.0.6",
|
|
42
|
+
"inquirer": "^9.2.15",
|
|
44
43
|
"ora": "^5.4.1",
|
|
45
44
|
"path": "^0.12.7",
|
|
46
|
-
"
|
|
47
|
-
"sqlite3": "^5.1.7",
|
|
48
|
-
"typescript": "5.1.6",
|
|
45
|
+
"typescript": "^5.8.3",
|
|
49
46
|
"wait-on": "^7.0.1",
|
|
50
47
|
"yargs": "^17.7.1",
|
|
51
48
|
"zod": "^3.22.3",
|
|
52
49
|
"zod-validation-error": "^1.3.0",
|
|
53
|
-
"@0xobelisk/sui-client": "1.2.0-pre.
|
|
54
|
-
"@0xobelisk/sui-common": "1.2.0-pre.
|
|
50
|
+
"@0xobelisk/sui-client": "1.2.0-pre.100",
|
|
51
|
+
"@0xobelisk/sui-common": "1.2.0-pre.100"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
54
|
+
"@types/cli-progress": "^3.11.5",
|
|
57
55
|
"@types/ejs": "^3.1.1",
|
|
58
56
|
"@types/glob": "^7.2.0",
|
|
59
|
-
"@types/
|
|
57
|
+
"@types/inquirer": "^9.0.7",
|
|
58
|
+
"@types/node": "^22.16.0",
|
|
60
59
|
"@types/yargs": "^17.0.10",
|
|
61
|
-
"eslint": "^
|
|
60
|
+
"eslint": "^9.0.0",
|
|
62
61
|
"eslint-config-prettier": "^9.1.0",
|
|
63
62
|
"prettier": "3.3.3",
|
|
64
63
|
"ts-node": "^10.9.1",
|
|
@@ -66,15 +65,28 @@
|
|
|
66
65
|
"tsx": "^3.12.6",
|
|
67
66
|
"vitest": "0.31.4"
|
|
68
67
|
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=22.0.0"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
69
74
|
"scripts": {
|
|
70
75
|
"build": "pnpm run type-check && pnpm run build:js",
|
|
71
76
|
"build:js": "tsup && chmod +x ./dist/dubhe.js",
|
|
72
77
|
"clean": "pnpm run clean:js",
|
|
73
78
|
"clean:js": "rimraf dist",
|
|
74
79
|
"dev": "tsup --watch",
|
|
75
|
-
"lint": "eslint . --ext .ts",
|
|
76
80
|
"format": "prettier --write .",
|
|
77
81
|
"format:check": "prettier --check .",
|
|
82
|
+
"lint": "eslint . --ext .ts",
|
|
83
|
+
"test": "vitest run",
|
|
84
|
+
"test:all": "pnpm test && pnpm test:integration",
|
|
85
|
+
"test:coverage": "vitest run --coverage",
|
|
86
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
87
|
+
"test:localnet": "vitest run --config vitest.integration.config.ts tests/integration/localnet.test.ts",
|
|
88
|
+
"test:testnet": "vitest run --config vitest.integration.config.ts tests/integration/testnet.test.ts",
|
|
89
|
+
"test:watch": "vitest",
|
|
78
90
|
"type-check": "tsc --noEmit",
|
|
79
91
|
"validate": "pnpm format:check && pnpm type-check"
|
|
80
92
|
}
|
package/src/commands/build.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
|
-
import { execSync } from 'child_process';
|
|
2
|
+
import { execSync, exec } from 'child_process';
|
|
3
|
+
import nodePath from 'path';
|
|
3
4
|
import chalk from 'chalk';
|
|
4
5
|
import { DubheConfig, loadConfig } from '@0xobelisk/sui-common';
|
|
5
|
-
import {
|
|
6
|
+
import { handlerExit } from './shell';
|
|
7
|
+
import { getDefaultNetwork, switchEnv } from '../utils';
|
|
6
8
|
|
|
7
9
|
type Options = {
|
|
8
10
|
'config-path': string;
|
|
@@ -10,20 +12,49 @@ type Options = {
|
|
|
10
12
|
'dump-bytecode-as-base64'?: boolean;
|
|
11
13
|
};
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Core build logic for Dubhe contracts.
|
|
17
|
+
*
|
|
18
|
+
* - localnet: uses --build-env testnet + --pubfile-path Pub.localnet.toml so that
|
|
19
|
+
* dependency addresses are resolved through the ephemeral publication file created
|
|
20
|
+
* by publishHandler. Counter can only be built after dubhe is published on localnet.
|
|
21
|
+
* - Other networks: uses -e <network> (standard Sui CLI environment flag).
|
|
22
|
+
*/
|
|
23
|
+
export async function buildHandler(
|
|
24
|
+
dubheConfig: DubheConfig,
|
|
25
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
26
|
+
dumpBytecodeAsBase64: boolean = false
|
|
27
|
+
): Promise<string> {
|
|
28
|
+
const cwd = process.cwd();
|
|
29
|
+
const projectPath = nodePath.join(cwd, 'src', dubheConfig.name);
|
|
30
|
+
|
|
31
|
+
let command: string;
|
|
32
|
+
if (network === 'localnet') {
|
|
33
|
+
const pubfilePath = nodePath.join(cwd, 'Pub.localnet.toml');
|
|
34
|
+
command = `sui move build --build-env testnet --pubfile-path ${pubfilePath} --path ${projectPath}`;
|
|
35
|
+
} else {
|
|
36
|
+
command = `sui move build -e ${network} --path ${projectPath}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (dumpBytecodeAsBase64) command += ' --dump-bytecode-as-base64';
|
|
40
|
+
|
|
41
|
+
return execSync(command, { encoding: 'utf-8' });
|
|
42
|
+
}
|
|
43
|
+
|
|
13
44
|
const commandModule: CommandModule<Options, Options> = {
|
|
14
45
|
command: 'build',
|
|
15
|
-
describe: '
|
|
46
|
+
describe: 'Build Dubhe contracts',
|
|
16
47
|
builder(yargs) {
|
|
17
48
|
return yargs.options({
|
|
18
49
|
'config-path': {
|
|
19
50
|
type: 'string',
|
|
20
51
|
default: 'dubhe.config.ts',
|
|
21
|
-
description: '
|
|
52
|
+
description: 'Path to the Dubhe config file'
|
|
22
53
|
},
|
|
23
54
|
network: {
|
|
24
55
|
type: 'string',
|
|
25
|
-
default: '
|
|
26
|
-
choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
56
|
+
default: 'default',
|
|
57
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
|
|
27
58
|
desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
28
59
|
},
|
|
29
60
|
'dump-bytecode-as-base64': {
|
|
@@ -39,23 +70,23 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
39
70
|
network,
|
|
40
71
|
'dump-bytecode-as-base64': dumpBytecodeAsBase64
|
|
41
72
|
}) {
|
|
42
|
-
// Start an internal anvil process if no world address is provided
|
|
43
73
|
try {
|
|
74
|
+
if (network == 'default') {
|
|
75
|
+
network = await getDefaultNetwork();
|
|
76
|
+
console.log(chalk.yellow(`Use default network: [${network}]`));
|
|
77
|
+
}
|
|
44
78
|
console.log('🚀 Running move build');
|
|
45
79
|
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
46
|
-
const path = process.cwd();
|
|
47
|
-
const projectPath = `${path}/contracts/${dubheConfig.name}`;
|
|
48
80
|
await switchEnv(network);
|
|
49
|
-
await
|
|
50
|
-
const command = `sui move build --path ${projectPath} ${
|
|
51
|
-
dumpBytecodeAsBase64 ? ` --dump-bytecode-as-base64` : ''
|
|
52
|
-
}`;
|
|
53
|
-
const output = execSync(command, { encoding: 'utf-8' });
|
|
81
|
+
const output = await buildHandler(dubheConfig, network, dumpBytecodeAsBase64);
|
|
54
82
|
console.log(output);
|
|
83
|
+
exec(`pnpm dubhe convert-json --config-path ${configPath}`);
|
|
55
84
|
} catch (error: any) {
|
|
56
85
|
console.error(chalk.red('Error executing sui move build:'));
|
|
57
|
-
|
|
58
|
-
process.
|
|
86
|
+
if (error.stdout) process.stdout.write(error.stdout);
|
|
87
|
+
if (error.stderr) process.stderr.write(error.stderr);
|
|
88
|
+
if (!error.stdout && !error.stderr && error.message) process.stderr.write(error.message);
|
|
89
|
+
handlerExit(1);
|
|
59
90
|
}
|
|
60
91
|
}
|
|
61
92
|
};
|
package/src/commands/call.ts
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import type { CommandModule } from 'yargs';
|
|
2
|
-
import { logError } from '../utils/errors';
|
|
3
|
-
import { callHandler } from '../utils';
|
|
4
|
-
import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
1
|
+
// import type { CommandModule } from 'yargs';
|
|
2
|
+
// import { logError } from '../utils/errors';
|
|
3
|
+
// import { callHandler } from '../utils';
|
|
4
|
+
// import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
5
5
|
|
|
6
|
-
type Options = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
6
|
+
// type Options = {
|
|
7
|
+
// network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
8
|
+
// module: string;
|
|
9
|
+
// function: string;
|
|
10
|
+
// 'config-path'?: string;
|
|
11
|
+
// 'package-id'?: string;
|
|
12
|
+
// 'metadata-path'?: string;
|
|
13
|
+
// params?: any[];
|
|
14
|
+
// };
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const commandModule: CommandModule<Options, Options> = {
|
|
20
|
-
|
|
16
|
+
// /**
|
|
17
|
+
// * CLI command for calling a function in a module
|
|
18
|
+
// */
|
|
19
|
+
// const commandModule: CommandModule<Options, Options> = {
|
|
20
|
+
// command: 'call',
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// describe: 'Call a function in a module',
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
24
|
+
// builder: {
|
|
25
|
+
// network: {
|
|
26
|
+
// type: 'string',
|
|
27
|
+
// choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
28
|
+
// desc: 'Node network (mainnet/testnet/devnet/localnet)',
|
|
29
|
+
// default: 'localnet'
|
|
30
|
+
// },
|
|
31
|
+
// module: {
|
|
32
|
+
// type: 'string',
|
|
33
|
+
// desc: 'Module name',
|
|
34
|
+
// demandOption: true
|
|
35
|
+
// },
|
|
36
|
+
// function: {
|
|
37
|
+
// type: 'string',
|
|
38
|
+
// desc: 'Function name',
|
|
39
|
+
// demandOption: true
|
|
40
|
+
// },
|
|
41
|
+
// 'config-path': {
|
|
42
|
+
// type: 'string',
|
|
43
|
+
// default: 'dubhe.config.ts',
|
|
44
|
+
// desc: 'Configuration file path'
|
|
45
|
+
// },
|
|
46
|
+
// 'package-id': {
|
|
47
|
+
// type: 'string',
|
|
48
|
+
// desc: 'Package ID (optional)'
|
|
49
|
+
// },
|
|
50
|
+
// 'metadata-path': {
|
|
51
|
+
// type: 'string',
|
|
52
|
+
// desc: 'Path to metadata JSON file (optional)'
|
|
53
|
+
// },
|
|
54
|
+
// params: {
|
|
55
|
+
// type: 'array',
|
|
56
|
+
// desc: 'Params for the function',
|
|
57
|
+
// string: true
|
|
58
|
+
// }
|
|
59
|
+
// },
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
// async handler({
|
|
62
|
+
// network,
|
|
63
|
+
// 'config-path': configPath,
|
|
64
|
+
// module: moduleName,
|
|
65
|
+
// function: funcName,
|
|
66
|
+
// 'package-id': packageId,
|
|
67
|
+
// 'metadata-path': metadataPath,
|
|
68
|
+
// params
|
|
69
|
+
// }) {
|
|
70
|
+
// try {
|
|
71
|
+
// const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
73
|
+
// await callHandler({
|
|
74
|
+
// dubheConfig,
|
|
75
|
+
// moduleName,
|
|
76
|
+
// funcName,
|
|
77
|
+
// network,
|
|
78
|
+
// packageId,
|
|
79
|
+
// metadataFilePath: metadataPath,
|
|
80
|
+
// params
|
|
81
|
+
// });
|
|
82
|
+
// } catch (error: any) {
|
|
83
|
+
// logError(error);
|
|
84
|
+
// process.exit(1);
|
|
85
|
+
// }
|
|
86
|
+
// process.exit(0);
|
|
87
|
+
// }
|
|
88
|
+
// };
|
|
89
89
|
|
|
90
|
-
export default commandModule;
|
|
90
|
+
// export default commandModule;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { checkBalanceHandler } from '../utils/checkBalance';
|
|
3
|
+
import { handlerExit } from './shell';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { getDefaultNetwork } from '../utils';
|
|
3
6
|
|
|
4
7
|
type Options = {
|
|
5
|
-
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
8
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet' | 'default';
|
|
6
9
|
};
|
|
7
10
|
|
|
8
11
|
const commandModule: CommandModule<Options, Options> = {
|
|
@@ -11,19 +14,23 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
11
14
|
builder: {
|
|
12
15
|
network: {
|
|
13
16
|
type: 'string',
|
|
14
|
-
choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
17
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
|
|
15
18
|
desc: 'Network to check balance on',
|
|
16
|
-
default: '
|
|
19
|
+
default: 'default'
|
|
17
20
|
}
|
|
18
21
|
},
|
|
19
22
|
async handler({ network }) {
|
|
20
23
|
try {
|
|
24
|
+
if (network == 'default') {
|
|
25
|
+
network = await getDefaultNetwork();
|
|
26
|
+
console.log(chalk.yellow(`Use default network: [${network}]`));
|
|
27
|
+
}
|
|
21
28
|
await checkBalanceHandler(network);
|
|
22
29
|
} catch (error) {
|
|
23
30
|
console.error('Error checking balance:', error);
|
|
24
|
-
|
|
31
|
+
handlerExit(1);
|
|
25
32
|
}
|
|
26
|
-
|
|
33
|
+
handlerExit();
|
|
27
34
|
}
|
|
28
35
|
};
|
|
29
36
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { storeConfigHandler } from '../utils/storeConfig';
|
|
3
3
|
import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
4
|
+
import { handlerExit } from './shell';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { getDefaultNetwork } from '../utils';
|
|
4
7
|
|
|
5
8
|
type Options = {
|
|
6
9
|
'config-path': string;
|
|
7
|
-
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
10
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet' | 'default';
|
|
8
11
|
'output-ts-path': string;
|
|
9
12
|
};
|
|
10
13
|
|
|
@@ -21,7 +24,8 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
21
24
|
},
|
|
22
25
|
network: {
|
|
23
26
|
type: 'string',
|
|
24
|
-
choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
27
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
|
|
28
|
+
default: 'default',
|
|
25
29
|
desc: 'Network to store config for'
|
|
26
30
|
},
|
|
27
31
|
'output-ts-path': {
|
|
@@ -31,13 +35,17 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
31
35
|
},
|
|
32
36
|
async handler({ 'config-path': configPath, network, 'output-ts-path': outputTsPath }) {
|
|
33
37
|
try {
|
|
38
|
+
if (network == 'default') {
|
|
39
|
+
network = await getDefaultNetwork();
|
|
40
|
+
console.log(chalk.yellow(`Use default network: [${network}]`));
|
|
41
|
+
}
|
|
34
42
|
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
35
43
|
await storeConfigHandler(dubheConfig, network, outputTsPath);
|
|
36
44
|
} catch (error) {
|
|
37
45
|
console.error('Error storing config:', error);
|
|
38
|
-
|
|
46
|
+
handlerExit(1);
|
|
39
47
|
}
|
|
40
|
-
|
|
48
|
+
handlerExit();
|
|
41
49
|
}
|
|
42
50
|
};
|
|
43
51
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { CommandModule } from 'yargs';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { DubheConfig, loadConfig } from '@0xobelisk/sui-common';
|
|
4
|
+
import { generateConfigJson } from '../utils';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import { handlerExit } from './shell';
|
|
7
|
+
|
|
8
|
+
type Options = {
|
|
9
|
+
'config-path': string;
|
|
10
|
+
'output-path': string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const commandModule: CommandModule<Options, Options> = {
|
|
14
|
+
command: 'convert-json',
|
|
15
|
+
describe: 'Convert JSON from Dubhe config to config.json',
|
|
16
|
+
builder(yargs) {
|
|
17
|
+
return yargs.options({
|
|
18
|
+
'config-path': {
|
|
19
|
+
type: 'string',
|
|
20
|
+
default: 'dubhe.config.ts',
|
|
21
|
+
description: 'Options to pass to forge test'
|
|
22
|
+
},
|
|
23
|
+
'output-path': {
|
|
24
|
+
type: 'string',
|
|
25
|
+
default: 'dubhe.config.json',
|
|
26
|
+
description: 'Output path for the config.json file'
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async handler({ 'config-path': configPath, 'output-path': outputPath }) {
|
|
32
|
+
try {
|
|
33
|
+
console.log('🚀 Running convert json');
|
|
34
|
+
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
35
|
+
const schemaJson = JSON.parse(generateConfigJson(dubheConfig));
|
|
36
|
+
|
|
37
|
+
// Preserve runtime fields written by publishHandler (package IDs, checkpoint, etc.)
|
|
38
|
+
// so that re-running convert-json after publish does not wipe deployment info.
|
|
39
|
+
const RUNTIME_FIELDS = [
|
|
40
|
+
'original_package_id',
|
|
41
|
+
'dubhe_object_id',
|
|
42
|
+
'original_dubhe_package_id',
|
|
43
|
+
'start_checkpoint'
|
|
44
|
+
];
|
|
45
|
+
let existing: Record<string, unknown> = {};
|
|
46
|
+
if (fs.existsSync(outputPath)) {
|
|
47
|
+
try {
|
|
48
|
+
existing = JSON.parse(fs.readFileSync(outputPath, 'utf-8'));
|
|
49
|
+
} catch {
|
|
50
|
+
// ignore parse errors – start fresh
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const merged: Record<string, unknown> = { ...schemaJson };
|
|
54
|
+
for (const field of RUNTIME_FIELDS) {
|
|
55
|
+
if (existing[field] !== undefined) {
|
|
56
|
+
merged[field] = existing[field];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fs.writeFileSync(outputPath, JSON.stringify(merged, null, 2));
|
|
61
|
+
} catch (error: any) {
|
|
62
|
+
console.error(chalk.red('Error executing convert json:'));
|
|
63
|
+
console.log(error.stdout);
|
|
64
|
+
handlerExit(1);
|
|
65
|
+
}
|
|
66
|
+
handlerExit();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default commandModule;
|