This repository was archived by the owner on Oct 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathcreate.ts
More file actions
98 lines (88 loc) · 2.97 KB
/
create.ts
File metadata and controls
98 lines (88 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import fs from "fs";
import inquirer from "inquirer";
import { error, info, success } from "signale";
import { Argv } from "yargs";
import { create } from "../../implementations/config/create";
import { getLogger } from "../../logger";
import { highlight } from "../../utils";
import { CreateConfigCommand, TestNetwork } from "./config.type";
import { NetworkCmdName } from "../networks";
const { trace } = getLogger("config:create");
export const command = "create [options]";
export const describe = "Create a config file";
export const builder = (yargs: Argv): Argv =>
yargs
.option("output-dir", {
alias: "od",
description: "Write output to a directory",
type: "string",
demandOption: true,
})
// encrypted wallet path is referenced from command.shared.ts as we need additional properties for this instance.
.option("encrypted-wallet-path", {
type: "string",
description: "Path to wallet.json file",
normalize: true,
demandOption: true,
});
export const handler = async (args: CreateConfigCommand): Promise<void> => {
trace(`Args: ${JSON.stringify(args, null, 2)}`);
if (!fs.existsSync(args.outputDir)) {
fs.mkdirSync(args.outputDir);
}
try {
info("Creating a new config file");
const { useTemplateUrl } = await inquirer.prompt({
type: "confirm",
name: "useTemplateUrl",
message: "Using a config template URL?",
});
if (useTemplateUrl) {
const { configTemplateUrl } = await inquirer.prompt({
type: "input",
name: "configTemplateUrl",
message: "Please enter the config template URL",
});
args.configTemplateUrl = configTemplateUrl;
} else {
const { configTemplatePath } = await inquirer.prompt({
type: "input",
name: "configTemplatePath",
message: "Please enter the config template path",
});
args.configTemplatePath = configTemplatePath;
}
const networks = [
TestNetwork.Local,
TestNetwork.Goerli,
TestNetwork.Sepolia,
TestNetwork.Mumbai,
TestNetwork.Apothem,
TestNetwork.Hedera
];
const { network } = await inquirer.prompt({
type: "list",
name: "network",
message: "Select Network",
choices: networks,
});
args.network = convertNetworkToNetworkCmdName(network);
const outputPath = await create(args);
success(`Config file successfully created and saved in ${highlight(outputPath)}`);
} catch (e) {
if (e instanceof Error) {
error(e.message);
}
}
};
const convertNetworkToNetworkCmdName = (selectedNetwork: TestNetwork): NetworkCmdName => {
const network = {
[TestNetwork.Local]: NetworkCmdName.Local,
[TestNetwork.Goerli]: NetworkCmdName.Goerli,
[TestNetwork.Sepolia]: NetworkCmdName.Sepolia,
[TestNetwork.Mumbai]: NetworkCmdName.Maticmum,
[TestNetwork.Apothem]: NetworkCmdName.XDCApothem,
[TestNetwork.Hedera]: NetworkCmdName.HederaTestnet,
};
return network[selectedNetwork];
};