-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathinstall.ts
76 lines (67 loc) · 2.61 KB
/
install.ts
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
import { SwankyCommand } from "../../lib/swankyCommand.js";
import { Flags } from "@oclif/core";
import { downloadNode, getSwankyConfig, swankyNodeVersions } from "../../lib/index.js";
import path from "node:path";
import inquirer from "inquirer";
import { ConfigBuilder } from "../../lib/config-builder.js";
import { DEFAULT_NODE_INFO } from "../../lib/consts.js";
import { choice, pickNodeVersion } from "../../lib/prompts.js";
import { InputError } from "../../lib/errors.js";
export class InstallNode extends SwankyCommand<typeof InstallNode> {
static description = "Install swanky node binary";
static flags = {
"set-version": Flags.string({
description:
"Specify version of swanky node to install. \n List of supported versions: " +
Array.from(swankyNodeVersions.keys()).join(", "),
required: false,
}),
};
async run(): Promise<void> {
const { flags } = await this.parse(InstallNode);
if (flags.verbose) {
this.spinner.verbose = true;
}
let nodeVersion = DEFAULT_NODE_INFO.version;
if (flags["set-version"]) {
nodeVersion = flags["set-version"];
if (!swankyNodeVersions.has(nodeVersion)) {
throw new InputError(
`Version ${nodeVersion} is not supported.\n List of supported versions: ${Array.from(swankyNodeVersions.keys()).join(", ")}`
);
}
} else {
const versions = Array.from(swankyNodeVersions.keys());
await inquirer.prompt([pickNodeVersion(versions)]).then((answers) => {
nodeVersion = answers.version;
});
}
const projectPath = path.resolve();
if (this.swankyConfig.node.localPath !== "") {
const { overwrite } = await inquirer.prompt([
choice("overwrite", "Swanky node already installed. Do you want to overwrite it?"),
]);
if (!overwrite) {
return;
}
}
const nodeInfo = swankyNodeVersions.get(nodeVersion)!;
const taskResult = (await this.spinner.runCommand(
() => downloadNode(projectPath, nodeInfo, this.spinner),
"Downloading Swanky node"
)) as string;
const nodePath = path.resolve(projectPath, taskResult);
await this.spinner.runCommand(async () => {
const newLocalConfig = new ConfigBuilder(getSwankyConfig("local"))
.updateNodeSettings({
localPath: nodePath,
polkadotPalletVersions: nodeInfo.polkadotPalletVersions,
supportedInk: nodeInfo.supportedInk,
version: nodeInfo.version,
})
.build();
await this.storeConfig(newLocalConfig, "local");
}, "Updating swanky config");
this.log("Swanky Node Installed successfully");
}
}