distats-cli 0.0.2 → 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 +2 -2
- package/src/commands/init.js +58 -38
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "distats-cli",
|
|
3
|
-
"version": "0.0.
|
|
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
|
-
"
|
|
10
|
+
"distats-cli": "./bin/index.js"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [],
|
|
13
13
|
"author": "",
|
package/src/commands/init.js
CHANGED
|
@@ -2,60 +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";
|
|
6
|
-
import { showWelcome } from "
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { showWelcome } from "../utils/logger.js";
|
|
9
8
|
|
|
10
9
|
export async function init() {
|
|
11
10
|
showWelcome();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.log(borderCol(` └${"─".repeat(noteWidth)}┘\n`));
|
|
27
|
-
|
|
28
|
-
const answers = await inquirer.prompt([
|
|
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([
|
|
29
25
|
{
|
|
30
26
|
type: "input",
|
|
31
27
|
name: "bot_token",
|
|
32
|
-
message: "Bot Token:",
|
|
28
|
+
message: "Your Bot Token:",
|
|
33
29
|
},
|
|
34
30
|
]);
|
|
35
31
|
|
|
36
|
-
const loader = createLoader("
|
|
32
|
+
const loader = createLoader("Starting Distats Panel installation...");
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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' });
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
// 4. Build Next.js
|
|
44
|
+
loader.update("Building Next.js application (npm run build)...");
|
|
45
|
+
execSync(`npm run build`, { stdio: 'ignore' });
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const configDir = path.join(
|
|
47
|
+
// 5. Save the configuration
|
|
48
|
+
loader.update("Finalizing setup...");
|
|
49
|
+
const configDir = path.join(currentDir, "@distats_panel");
|
|
51
50
|
if (!fs.existsSync(configDir)) {
|
|
52
51
|
fs.mkdirSync(configDir, { recursive: true });
|
|
53
52
|
}
|
|
53
|
+
|
|
54
54
|
const configPath = path.join(configDir, "config.json");
|
|
55
|
-
|
|
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
|
+
|
|
56
72
|
} catch (err) {
|
|
57
|
-
|
|
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"));
|
|
58
80
|
}
|
|
59
|
-
|
|
60
|
-
console.log("\nResult:", answers);
|
|
61
|
-
}
|
|
81
|
+
}
|
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:
|
|
25
|
+
console.log("Usage: distats-cli <command>\nAvailable commands: init, create-user");
|
|
26
26
|
}
|