distats-cli 0.0.1 → 0.0.3

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