quar 1.3.1 → 1.4.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.
Files changed (2) hide show
  1. package/index.js +102 -66
  2. package/package.json +2 -1
package/index.js CHANGED
@@ -1,66 +1,102 @@
1
- #!/usr/bin/env node
2
-
3
- import path from 'path';
4
- import minimist from 'minimist';
5
- import app from './server.js';
6
- import loadModels from './utils/loadModels.js';
7
- import open from 'open';
8
- import chalk from 'chalk';
9
- import mongoose from 'mongoose';
10
-
11
- const args = minimist(process.argv.slice(2));
12
-
13
- if (!args.model) {
14
- console.log(
15
- chalk.red.bold('[ERROR]') + ' Missing required flag: ' + chalk.yellow('--model')
16
- );
17
- console.log('Usage: ' + chalk.cyan('quar --model <model-folder> --db <database-name>'));
18
- process.exit(1);
19
- }
20
-
21
- if (typeof args.model !== 'string') {
22
- console.log(
23
- chalk.red.bold('[ERROR]') + ' The value for ' + chalk.yellow('--model') + ' must be a string.'
24
- );
25
- process.exit(1);
26
- }
27
-
28
- if (!args.db) {
29
- console.log(
30
- chalk.red.bold('[ERROR]') + ' Missing required flag: ' + chalk.yellow('--db')
31
- );
32
- console.log('Usage: ' + chalk.cyan('quar --model <model-folder> --db <database-name>'));
33
- process.exit(1);
34
- }
35
-
36
- if (typeof args.db !== 'string') {
37
- console.log(
38
- chalk.red.bold('[ERROR]') + ' The value for ' + chalk.yellow('--db') + ' must be a string.'
39
- );
40
- process.exit(1);
41
- }
42
-
43
- const modelDir = path.resolve(process.cwd(), args.model);
44
- const fullModelPath = path.resolve(modelDir);
45
-
46
- // 🔃 Load Models and Start Server
47
- try {
48
- loadModels(fullModelPath);
49
- app.locals.modelPath = fullModelPath;
50
-
51
- (async () => {
52
-
53
- await mongoose.connect(`${args.uri || "mongodb://localhost:27017/"}${args.db}`)
54
- console.log(chalk.blue.bold('[INFO]'), chalk.gray("Quar: Database connection established"))
55
-
56
- app.listen(app.get('port'), () => {
57
- const url = `http://127.0.0.1:${app.get('port')}`;
58
- console.log(chalk.green.bold('[SUCCESS]') + chalk.gray(` Server is running on ${chalk.underline(url)}`));
59
- if (args.open) open(url);
60
- });
61
- })();
62
- } catch (err) {
63
- console.log(chalk.red.bold('[FATAL ERROR]') + ' Failed to launch the server.');
64
- console.error(chalk.red(err.stack));
65
- process.exit(1);
66
- }
1
+ #!/usr/bin/env node
2
+
3
+ import path from "path";
4
+ import minimist from "minimist";
5
+ import app from "./server.js";
6
+ import loadModels from "./utils/loadModels.js";
7
+ import open from "open";
8
+ import chalk from "chalk";
9
+ import mongoose from "mongoose";
10
+ import { input } from "@inquirer/prompts";
11
+
12
+ const args = minimist(process.argv.slice(2));
13
+
14
+ if (!args.model) {
15
+ args.model = await input({
16
+ message: " What's your model folder?",
17
+ default: "./models",
18
+ required: true,
19
+ validate: (input) => {
20
+ if (!input) return "Please enter a valid model folder.";
21
+ return true;
22
+ },
23
+ });
24
+ }
25
+
26
+ if (typeof args.model !== "string") {
27
+ console.log(
28
+ chalk.red.bold("[ERROR]") +
29
+ " The value for " +
30
+ chalk.yellow("--model") +
31
+ " must be a string.",
32
+ );
33
+ process.exit(1);
34
+ }
35
+
36
+ if (!args.db) {
37
+ args.db = await input({
38
+ message: " What's your database name?",
39
+ default: "quarDB",
40
+ required: true,
41
+ validate: (input) => {
42
+ if (!input) return "Please enter a valid database name.";
43
+ return true;
44
+ },
45
+ });
46
+ }
47
+
48
+ if (typeof args.db !== "string") {
49
+ console.log(
50
+ chalk.red.bold("[ERROR]") +
51
+ " The value for " +
52
+ chalk.yellow("--db") +
53
+ " must be a string.",
54
+ );
55
+ process.exit(1);
56
+ }
57
+
58
+ if (!args.uri) {
59
+ args.uri = await input({
60
+ message: " What's your database URI?",
61
+ default: "mongodb://localhost:27017/",
62
+ required: true,
63
+ validate: (input) => {
64
+ if (!input) return "Please enter a valid database URI.";
65
+ return true;
66
+ },
67
+ });
68
+ }
69
+
70
+ const modelDir = path.resolve(process.cwd(), args.model);
71
+ const fullModelPath = path.resolve(modelDir);
72
+
73
+ // 🔃 Load Models and Start Server
74
+ try {
75
+ loadModels(fullModelPath);
76
+ app.locals.modelPath = fullModelPath;
77
+
78
+ (async () => {
79
+ await mongoose.connect(
80
+ `${args.uri || "mongodb://localhost:27017/"}${args.db}`,
81
+ );
82
+ console.log(
83
+ chalk.blue.bold("[INFO]"),
84
+ chalk.gray("Quar: Database connection established"),
85
+ );
86
+
87
+ app.listen(app.get("port"), () => {
88
+ const url = `http://127.0.0.1:${app.get("port")}`;
89
+ console.log(
90
+ chalk.green.bold("[SUCCESS]") +
91
+ chalk.gray(` Server is running on ${chalk.underline(url)}`),
92
+ );
93
+ if (args.open) open(url);
94
+ });
95
+ })();
96
+ } catch (err) {
97
+ console.log(
98
+ chalk.red.bold("[FATAL ERROR]") + " Failed to launch the server.",
99
+ );
100
+ console.error(chalk.red(err.stack));
101
+ process.exit(1);
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quar",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "This will load all Mongoose models from the folder and start a local web UI to Create, view, update, and delete documents.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,6 +14,7 @@
14
14
  "author": "@IsmailBinMujeeb (IsmailBinMujeeb@gmail.com)",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
+ "@inquirer/prompts": "^8.1.0",
17
18
  "chalk": "^5.4.1",
18
19
  "express": "^5.1.0",
19
20
  "minimist": "^1.2.8",