distats-cli 0.0.2 → 0.0.4

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "distats-cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "bin": {
10
- "prismpanel": "./bin/index.js"
10
+ "distats-cli": "./bin/index.js"
11
11
  },
12
12
  "keywords": [],
13
13
  "author": "",
@@ -3,7 +3,7 @@ import chalk from "chalk";
3
3
  import ora from "ora";
4
4
  import crypto from "crypto";
5
5
  import { getDatabase, runQuery } from "../utils/database.js";
6
- import { showWelcome } from "./utils/logger.js";
6
+ import { showWelcome } from "../utils/logger.js";
7
7
 
8
8
 
9
9
  /**
@@ -2,60 +2,82 @@ import path from "path";
2
2
  import fs from "fs";
3
3
  import inquirer from "inquirer";
4
4
  import chalk from "chalk";
5
+ import crypto from "crypto";
6
+ import { execSync } from "child_process";
5
7
  import { createLoader } from "../utils/loader.js";
6
- import { showWelcome } from "./utils/logger.js";
7
-
8
-
8
+ import { showWelcome } from "../utils/logger.js";
9
9
 
10
10
  export async function init() {
11
11
  showWelcome();
12
- const getVisibleLength = (str) => str.replace(/\u001b\[\d+m/g, "").length;
13
- const noteWidth = 55;
14
- const borderCol = chalk.yellow;
15
-
16
- const titleStr = ` ${chalk.yellow.bold("⚠ PRIVACY NOTICE")} `;
17
- const line1 = ` Your Bot Token is used exclusively for features.`;
18
- const line2 = ` It will never be stored or used elsewhere.`;
19
-
20
- console.log(borderCol(` ┌${"─".repeat(noteWidth)}┐`));
21
- [titleStr, line1, line2].forEach(line => {
22
- const visibleLength = getVisibleLength(line);
23
- const padding = " ".repeat(Math.max(0, noteWidth - visibleLength));
24
- console.log(` ${borderCol("│")}${line}${padding}${borderCol("│")}`);
25
- });
26
- console.log(borderCol(` └${"─".repeat(noteWidth)}┘\n`));
27
-
28
- const answers = await inquirer.prompt([
12
+
13
+ // 1. Check if the directory is empty
14
+ const currentDir = process.cwd();
15
+ const files = fs.readdirSync(currentDir);
16
+
17
+ if (files.length > 0) {
18
+ console.log(chalk.red(`\n✖ Error: The current directory is not empty (${currentDir}).`));
19
+ console.log(chalk.yellow(" Please run 'init' in an empty folder to avoid overwriting files.\n"));
20
+ return;
21
+ }
22
+
23
+ const github_repo = "https://github.com/Distats/Panel.git";
24
+
25
+ const promptAnswers = await inquirer.prompt([
29
26
  {
30
27
  type: "input",
31
28
  name: "bot_token",
32
- message: "Bot Token:",
29
+ message: "Your Bot Token:",
33
30
  },
34
31
  ]);
35
32
 
36
- const loader = createLoader("Creating project...");
33
+ const loader = createLoader("Starting Distats Panel installation...");
37
34
 
38
- // simulate progress over 4 seconds
39
- await new Promise((resolve) => {
40
- setTimeout(() => loader.update("Setting up files..."), 1000);
41
- setTimeout(() => loader.update("Installing dependencies..."), 2000);
42
- setTimeout(() => loader.update("Finalizing..."), 3000);
43
- setTimeout(resolve, 4000);
44
- });
35
+ try {
36
+ // 2. Clone the repo
37
+ loader.update(`Downloading panel from ${github_repo}...`);
38
+ execSync(`git clone ${github_repo} .`, { stdio: 'ignore' });
39
+
40
+ // 3. Install packages
41
+ loader.update("Installing packages (npm install)... this may take a moment.");
42
+ execSync(`npm install`, { stdio: 'ignore' });
45
43
 
46
- loader.succeed("Project created successfully!\nUse 'distats-panel-cli create-user' to create a user.");
44
+ // 4. Build Next.js
45
+ loader.update("Building Next.js application (npm run build)...");
46
+ execSync(`npm run build`, { stdio: 'ignore' });
47
47
 
48
- // Save the config
49
- try {
50
- const configDir = path.join(process.cwd(), "@distats_panel");
48
+ // 5. Save the configuration
49
+ loader.update("Finalizing setup...");
50
+ const configDir = path.join(currentDir, "@distats_panel");
51
51
  if (!fs.existsSync(configDir)) {
52
52
  fs.mkdirSync(configDir, { recursive: true });
53
53
  }
54
+
54
55
  const configPath = path.join(configDir, "config.json");
55
- fs.writeFileSync(configPath, JSON.stringify(answers, null, 2));
56
+ const configData = {
57
+ bot_token: promptAnswers.bot_token,
58
+ session_secret: crypto.randomBytes(64).toString("hex"),
59
+ database_type: "sqlite",
60
+ db_path: "./@distats_panel/database.sqlite",
61
+ installed_at: new Date().toISOString(),
62
+ repo: github_repo
63
+ };
64
+
65
+ fs.writeFileSync(configPath, JSON.stringify(configData, null, 2));
66
+
67
+ loader.succeed("Distats Panel installed successfully!");
68
+
69
+ console.log(chalk.green("\n Success! Your Distats Panel is ready to go."));
70
+ console.log(chalk.white("\n Commands:"));
71
+ console.log(chalk.cyan(` - npm start : `) + chalk.white("to start the panel"));
72
+ console.log(chalk.cyan(` - npx distats-cli create-user : `) + chalk.white("to create a first user\n"));
73
+
56
74
  } catch (err) {
57
- console.log(chalk.red("\nError saving configuration: " + err.message));
75
+ loader.stop();
76
+ console.log(chalk.red("\n✖ Installation failed."));
77
+ console.log(chalk.red(` Détails: ${err.message}`));
78
+ console.log(chalk.yellow("\n Possible fixes:"));
79
+ console.log(chalk.gray(" 1. Make sure Git is installed."));
80
+ console.log(chalk.gray(" 2. Check your internet connection."));
81
+ console.log(chalk.gray(" 3. Make sure you have Node.js installed.\n"));
58
82
  }
59
-
60
- console.log("\nResult:", answers);
61
- }
83
+ }
package/src/index.js CHANGED
@@ -22,5 +22,5 @@ if (command) {
22
22
  console.log("Unknown command. Available commands: init, create-user");
23
23
  }
24
24
  } else {
25
- console.log("Usage: prismpanel <command>\nAvailable commands: init, create-user");
25
+ console.log("Usage: distats-cli <command>\nAvailable commands: init, create-user");
26
26
  }