Skip to content

Commit 84da5b0

Browse files
authored
Merge pull request #12 from kb2abot/sync-cli-main
Sync cli main
2 parents 47e4a85 + 04fc7e3 commit 84da5b0

File tree

7 files changed

+97
-282
lines changed

7 files changed

+97
-282
lines changed

main/bootloader/checkInternet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
try {
1212
await checkInternetConnected(config);
1313
} catch (e) {
14-
throw `Vui long kiem tra lai ket noi internet!\nmessage:${e.message}`;
14+
throw `Vui long kiem tra lai ket noi internet! (${e.message})`;
1515
}
1616
}
1717
};

main/bootloader/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = {
2-
cli: require("./cli"),
2+
// cli: require("./cli"),
33
checkInternet: require("./checkInternet"),
44
checkNode: require("./checkNode"),
55
foolHeroku: require("./foolHeroku"),
66
preload: require("./preload"),
77
update: require("./update"),
8+
updateCli: require("./updateCli"),
89
};

main/bootloader/updateCli.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const {execShellCommand} = require("../utils/COMMON");
2+
const axios = require("axios");
3+
4+
module.exports = {
5+
des: "Kiem tra va cap nhat kb2abot-cli",
6+
fn: async () => {
7+
const {data} = await axios.get("https://raw.githubusercontent.com/kb2abot/kb2abot-cli/main/package.json");
8+
const {version} = data;
9+
let currentVersion;
10+
try {
11+
currentVersion = await execShellCommand("kb2abot-cli -v");
12+
}
13+
catch (e) {
14+
currentVersion = e.message;
15+
}
16+
if (currentVersion != version) {
17+
await execShellCommand("npm i kb2abot-cli@latest -g");
18+
}
19+
}
20+
};

main/helpers/PluginManager.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const Manager = require("./Manager");
2-
const logger = require("node-color-log");
32

43
module.exports = class CommandManager extends Manager {
54
constructor(plugins = {}) {
@@ -12,7 +11,7 @@ module.exports = class CommandManager extends Manager {
1211
for (const name in plugins) {
1312
for (const keyword of plugins[name].keywords) {
1413
if (checkKeyword[keyword]) {
15-
logger.warn(
14+
console.newLogger.warn(
1615
`Vui long kiem tra lai keyword cua plugin: ${name}.js va ${checkKeyword[keyword]}.js, bi trung keyword: ${keyword}`
1716
);
1817
}

main/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,27 @@ globalThis.kb2abot = Object.assign(k2babotGlobalModel, {
2727
/////////////////////////////////////////////////////
2828

2929

30-
const {cli, checkInternet, checkNode, foolHeroku, preload, update} = require("./bootloader");
30+
const {
31+
// cli,
32+
checkInternet,
33+
checkNode,
34+
foolHeroku,
35+
preload,
36+
update,
37+
updateCli
38+
} = require("./bootloader");
3139
const botsDir = path.join(__dirname, "../bots");
3240
const deployPath = path.join(__dirname, "./deploy/index.js");
3341

3442
const tasks = [];
3543
const isDev = process.argv.slice(2)[0] == "dev";
3644
tasks.push(checkInternet);
3745
!isDev && tasks.push(update);
46+
tasks.push(updateCli);
3847
tasks.push(foolHeroku);
3948
tasks.push(checkNode);
4049
tasks.push(preload);
41-
tasks.push(cli);
50+
// tasks.push(cli);
4251

4352
cluster.on("exit", (worker, code, signal) => {
4453
if (signal) {
@@ -56,7 +65,9 @@ const bootloader = async () => {
5665
await task.fn();
5766
}
5867
catch(e) {
59-
console.newLogger.error(e.message);
68+
console.log();
69+
console.newLogger.error(e);
70+
spinner.stop();
6071
process.exit();
6172
}
6273
spinner.succeed();

0 commit comments

Comments
 (0)