@alexandredeveloper/standalone 0.0.1 → 0.1.0

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/bin/standalone.js CHANGED
@@ -2,6 +2,7 @@
2
2
  const log = require("../src/logger");
3
3
  const { runPrompt } = require("../src/prompt");
4
4
  const { buildBot } = require("../src/builder");
5
+ const { startDevMode } = require("../src/devMode");
5
6
 
6
7
  const args = process.argv.slice(2);
7
8
 
@@ -12,6 +13,10 @@ if (!args.includes("--build")) {
12
13
 
13
14
  (async () => {
14
15
  log.sta("Standalone builder started");
16
+
15
17
  const answers = await runPrompt();
16
- await buildBot(answers);
17
- })();
18
+ const botData = await buildBot(answers);
19
+
20
+ if (botData.botPath) startDevMode(botData.botPath);
21
+ else log.warn("( ⚠️ ) Bot path not found, Dev Mode not activated");
22
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexandredeveloper/standalone",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Standalone — CLI para criar bots Discord automaticamente",
5
5
  "type": "commonjs",
6
6
  "main": "src/builder.js",
@@ -20,9 +20,10 @@
20
20
  "author": "Alexandre Developer",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "inquirer": "^8.2.6",
24
23
  "chalk": "^4.1.2",
25
- "fs-extra": "^11.2.0"
24
+ "chokidar": "^5.0.0",
25
+ "fs-extra": "^11.2.0",
26
+ "inquirer": "^8.2.6"
26
27
  },
27
28
  "publishConfig": {
28
29
  "access": "public"
package/src/builder.js CHANGED
@@ -3,7 +3,7 @@ const path = require("path");
3
3
  const log = require("./logger");
4
4
  const { installDeps, startBot } = require("./installer");
5
5
 
6
- async function buildBot({ token, botName, mode }) {
6
+ async function buildBot({ token, botName, mode, type }) {
7
7
  const isSlash = mode.toLowerCase() === "sl";
8
8
  const base = isSlash ? "slash" : "prefix";
9
9
 
@@ -32,7 +32,10 @@ async function buildBot({ token, botName, mode }) {
32
32
 
33
33
  log.ok("Bot ready");
34
34
  log.sta("Starting bot");
35
+
35
36
  startBot(targetPath);
37
+
38
+ return { botPath: targetPath };
36
39
  }
37
40
 
38
- module.exports = { buildBot };
41
+ module.exports = { buildBot };
package/src/devMode.js ADDED
@@ -0,0 +1,60 @@
1
+ const chokidar = require("chokidar");
2
+ const { spawn } = require("child_process");
3
+ const log = require("./logger");
4
+ const path = require("path");
5
+
6
+ let botProcess = null;
7
+ let isRestarting = false;
8
+
9
+ function startDevMode(botPath) {
10
+ if (!botPath) return;
11
+
12
+ const watchPaths = [
13
+ path.join(botPath, "commands"),
14
+ path.join(botPath, "events"),
15
+ path.join(botPath, "index.js"),
16
+ path.join(botPath, "config.json")
17
+ ];
18
+
19
+ log.sta("( 👁️ ) Dev Mode enabled: watching for changes...");
20
+
21
+ const watcher = chokidar.watch(watchPaths, {
22
+ ignored: /node_modules|\.git/,
23
+ ignoreInitial: true,
24
+ persistent: true
25
+ });
26
+
27
+ watcher.on("all", (event, filePath) => {
28
+ if (isRestarting) return;
29
+ log.sta(`( ⛓️‍💥 ) Change detected: ${path.relative(botPath, filePath)}`);
30
+ restartBot(botPath);
31
+ });
32
+
33
+ restartBot(botPath);
34
+ }
35
+
36
+ function restartBot(botPath) {
37
+ if (isRestarting) return;
38
+ isRestarting = true;
39
+
40
+ if (botProcess) {
41
+ log.sta("( 🔄 ) Restarting bot...");
42
+ botProcess.kill();
43
+ } else {
44
+ log.sta("( ⏳ ) Starting bot...");
45
+ }
46
+
47
+ setTimeout(() => {
48
+ botProcess = spawn("node", ["index.js"], {
49
+ cwd: botPath,
50
+ stdio: "inherit"
51
+ });
52
+
53
+ botProcess.on("exit", () => {});
54
+
55
+ isRestarting = false;
56
+ log.sta("( ✅ ) Bot is back online");
57
+ }, 300);
58
+ }
59
+
60
+ module.exports = { startDevMode };
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ const log = require("../src/logger");
3
+ const { runPrompt } = require("../src/prompt");
4
+ const { buildBot } = require("../src/builder");
5
+ const { startDevMode } = require("../src/devMode");
6
+
7
+ const args = process.argv.slice(2);
8
+
9
+ if (!args.includes("--build")) {
10
+ log.warn("Use: standalone --build");
11
+ process.exit(0);
12
+ }
13
+
14
+ (async () => {
15
+ log.sta("Standalone builder started");
16
+
17
+ const answers = await runPrompt();
18
+
19
+ const botData = await buildBot(answers);
20
+
21
+ if (botData.botPath) startDevMode(botData.botPath);
22
+ else log.warn("( ⚠️ ) Bot path not found, Dev Mode not activated");
23
+ })();