prismpanel 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/@prism_panel/config.json +1 -1
- package/package.json +2 -1
- package/src/commands/create-user.js +58 -0
- package/src/commands/init.js +0 -2
- package/src/index.js +12 -1
- package/src/models/User.js +15 -0
package/@prism_panel/config.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
{"bot_token": "your_test_token_here", "test_key": "test_value", "mongodb_uri": "mongodb+srv://<user>:<password>@cluster.mongodb.net/prism?retryWrites=true&w=majority"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prismpanel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"chalk": "^5.6.2",
|
|
18
18
|
"inquirer": "^13.3.2",
|
|
19
|
+
"mongoose": "^9.4.1",
|
|
19
20
|
"ora": "^9.3.0"
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import ora from "ora";
|
|
5
|
+
import User from "../models/User.js";
|
|
6
|
+
import { getEnvVariables } from "../utils/config.js";
|
|
7
|
+
|
|
8
|
+
export async function createUser() {
|
|
9
|
+
const config = getEnvVariables();
|
|
10
|
+
|
|
11
|
+
if (!config) {
|
|
12
|
+
console.error(chalk.red("Error: Config file not found. Please run 'prismpanel init' first."));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const mongodbUri = config.mongodb_uri || config.MONGODB_URI || config.database_url;
|
|
17
|
+
|
|
18
|
+
if (!mongodbUri) {
|
|
19
|
+
console.error(chalk.red("Error: MongoDB URI not found in config. Please add 'mongodb_uri' to your @prism_panel/config.json."));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const answers = await inquirer.prompt([
|
|
24
|
+
{
|
|
25
|
+
type: "input",
|
|
26
|
+
name: "name",
|
|
27
|
+
message: "Enter user name:",
|
|
28
|
+
validate: (input) => input.length > 0 && input.length <= 60 ? true : "Name must be 1-60 characters.",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "password",
|
|
32
|
+
name: "password",
|
|
33
|
+
message: "Enter user password:",
|
|
34
|
+
mask: "*",
|
|
35
|
+
validate: (input) => input.length > 0 ? true : "Password is required.",
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
const spinner = ora("Connecting to MongoDB...").start();
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
await mongoose.connect(mongodbUri);
|
|
43
|
+
spinner.text = "Creating user...";
|
|
44
|
+
|
|
45
|
+
const newUser = new User({
|
|
46
|
+
name: answers.name,
|
|
47
|
+
password: answers.password, // Ideally hash this, but keeping same schema as user request
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await newUser.save();
|
|
51
|
+
spinner.succeed(chalk.green(`User '${answers.name}' created successfully.`));
|
|
52
|
+
} catch (error) {
|
|
53
|
+
spinner.fail(chalk.red("Failed to create user."));
|
|
54
|
+
console.error(chalk.red(error.message));
|
|
55
|
+
} finally {
|
|
56
|
+
await mongoose.disconnect();
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/commands/init.js
CHANGED
|
@@ -3,10 +3,8 @@ import fs from "fs";
|
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { createLoader } from "../utils/loader.js";
|
|
6
|
-
import { showWelcome } from "../utils/logger.js";
|
|
7
6
|
|
|
8
7
|
export async function init() {
|
|
9
|
-
showWelcome();
|
|
10
8
|
const getVisibleLength = (str) => str.replace(/\u001b\[\d+m/g, "").length;
|
|
11
9
|
const noteWidth = 55;
|
|
12
10
|
const borderCol = chalk.yellow;
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { init } from "./commands/init.js";
|
|
2
|
+
import { createUser } from "./commands/create-user.js";
|
|
2
3
|
import { getEnvVariables, GetEnvVaribels } from "./utils/config.js";
|
|
4
|
+
import { showWelcome } from "./utils/logger.js";
|
|
5
|
+
|
|
6
|
+
// Always show the welcome banner
|
|
7
|
+
showWelcome();
|
|
3
8
|
|
|
4
9
|
// Export the utility functions for use as a library
|
|
5
10
|
export { getEnvVariables, GetEnvVaribels };
|
|
@@ -11,8 +16,14 @@ if (command) {
|
|
|
11
16
|
case "init":
|
|
12
17
|
await init();
|
|
13
18
|
break;
|
|
19
|
+
|
|
20
|
+
case "create-user":
|
|
21
|
+
await createUser();
|
|
22
|
+
break;
|
|
14
23
|
|
|
15
24
|
default:
|
|
16
|
-
console.log("Unknown command");
|
|
25
|
+
console.log("Unknown command. Available commands: init, create-user");
|
|
17
26
|
}
|
|
27
|
+
} else {
|
|
28
|
+
console.log("Usage: prismpanel <command>\nAvailable commands: init, create-user");
|
|
18
29
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const UserSchema = new mongoose.Schema({
|
|
4
|
+
name: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: [true, "Please provide a name"],
|
|
7
|
+
maxlength: [60, "Name cannot be more than 60 characters"],
|
|
8
|
+
},
|
|
9
|
+
password: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: [true, "Please provide a password"],
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default mongoose.models.User || mongoose.model("User", UserSchema);
|