-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateBloctoExamples.mjs
97 lines (86 loc) · 3.23 KB
/
updateBloctoExamples.mjs
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
// updateBloctoExamples
//
// This script is used to update the dependencies of Blocto SDK sample projects.
//
// Usage:
// 1. Ensure Node.js is installed before running the script.
// 2. Place the script in the root directory of the sample project.
// 3. Execute `node updateBloctoExamples.mjs` in the command line to start the script.
// 4. The script will prompt you to choose the type of samples to update (EVM or Aptos) or update all samples.
// 5. Follow the prompts and inputs; once completed, the script will update the Blocto SDK version for the selected samples.
//
// Notes:
// - Before running the script, ensure all sample files are backed up to prevent data loss in unforeseen circumstances.
// - When entering the version number, ensure the correct Blocto SDK version is provided.
// - Feel free to raise any issues or suggestions in the Issues section.
//
// Modules used:
// - fs module for file reading and writing.
// - path module for handling file paths.
// - prompts module for fetching user input in the command line.
import prompts from "prompts";
import { getDirectories, updatePackageJSON } from "./utils.js";
(async () => {
const firstResponse = await prompts({
type: "select",
name: "chain",
message: "Which chain's example do you want to update?",
choices: [
{ title: "All", value: "all" },
{ title: "EVM", value: "evm" },
{ title: "Aptos", value: "aptos" },
],
});
let secondResponse;
let thirdResponse;
if (firstResponse.chain === "all") {
thirdResponse = await prompts({
type: "text",
name: "sdkVersion",
message: "Enter the version of Blocto SDK to update for all examples:",
});
const evmDirectories = await getDirectories("./src/evm");
const aptosDirectories = await getDirectories("./src/aptos");
const allDirectories = [...evmDirectories, ...aptosDirectories];
await updatePackageJSON(
"./src/evm",
evmDirectories,
thirdResponse?.sdkVersion
);
await updatePackageJSON(
"./src/aptos",
aptosDirectories,
thirdResponse?.sdkVersion
);
console.log("✅ You've chosen to update all examples. 🎉", allDirectories);
return;
}
if (firstResponse.chain === "evm" || firstResponse.chain === "aptos") {
const folderPath =
firstResponse.chain === "evm" ? "./src/evm" : "./src/aptos";
const examples = await getDirectories(folderPath);
secondResponse = await prompts({
type: "multiselect",
name: `${firstResponse.chain}Examples`,
message: `Which ${firstResponse.chain.toUpperCase()} examples do you want to update?`,
choices: examples.map((dir) => ({ title: dir, value: dir })),
});
}
if (secondResponse) {
thirdResponse = await prompts({
type: "text",
name: "sdkVersion",
message: "Enter the version of Blocto SDK to update:",
});
}
if (
secondResponse &&
thirdResponse &&
(secondResponse.evmExamples || secondResponse.aptosExamples)
) {
const folderPath = secondResponse.evmExamples ? "./src/evm" : "./src/aptos";
const examples = secondResponse.evmExamples || secondResponse.aptosExamples;
const version = thirdResponse.sdkVersion;
await updatePackageJSON(folderPath, examples, version);
}
})();