mwalajs 1.1.0 → 1.1.2
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/bin/mwala.mjs +3 -3
- package/package.json +3 -1
- package/utils/dbUtils.mjs +42 -14
package/bin/mwala.mjs
CHANGED
|
@@ -43,7 +43,7 @@ const {
|
|
|
43
43
|
if (!command || command === 'help' || command === 'h') {
|
|
44
44
|
console.log(`
|
|
45
45
|
╔══════════════════════════════════════════════════════════╗
|
|
46
|
-
║ MwalaJS CLI
|
|
46
|
+
║ MwalaJS CLI ║
|
|
47
47
|
╚══════════════════════════════════════════════════════════╝
|
|
48
48
|
|
|
49
49
|
General:
|
|
@@ -181,7 +181,7 @@ switch (command) {
|
|
|
181
181
|
|
|
182
182
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
183
183
|
fs.writeFileSync(filePath, content);
|
|
184
|
-
console.log(
|
|
184
|
+
console.log(` ${name} ${type} created at ${folders[type]}/${name}.mjs`);
|
|
185
185
|
break;
|
|
186
186
|
}
|
|
187
187
|
|
|
@@ -189,7 +189,7 @@ switch (command) {
|
|
|
189
189
|
|
|
190
190
|
case 'create-db':
|
|
191
191
|
getDbConnection()
|
|
192
|
-
.then(() => console.log('
|
|
192
|
+
.then(() => console.log(' Database configured and connected successfully!'))
|
|
193
193
|
.catch(err => {
|
|
194
194
|
console.error('❌ Database setup failed:', err.message);
|
|
195
195
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mwalajs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "MwalaJS Framework CLI Tool and Web Framework for Backend and Frontend Development.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "app.mjs",
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
"postinstall": "echo 'Thanks for installing MwalaJS Framework! '"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"csv-parser": "^3.2.0",
|
|
23
|
+
"csv-stringify": "^6.6.0",
|
|
22
24
|
"dotenv": "^16.4.7",
|
|
23
25
|
"ejs": "^3.1.10",
|
|
24
26
|
"express": "^4.21.2",
|
package/utils/dbUtils.mjs
CHANGED
|
@@ -12,25 +12,47 @@ import sqlite3 from 'sqlite3';
|
|
|
12
12
|
import readlineSync from 'readline-sync';
|
|
13
13
|
import { fileURLToPath } from 'url';
|
|
14
14
|
|
|
15
|
-
// Load .env
|
|
16
|
-
|
|
15
|
+
// Load .env from current project directory (important!)
|
|
16
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
17
|
+
if (fs.existsSync(envPath)) {
|
|
18
|
+
dotenv.config({ path: envPath });
|
|
19
|
+
} else {
|
|
20
|
+
dotenv.config(); // fallback to default behavior
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
DB_TYPE,
|
|
25
|
+
DB_HOST = 'localhost',
|
|
26
|
+
DB_USER,
|
|
27
|
+
DB_PASSWORD = '', // Allow empty or missing password
|
|
28
|
+
DB_NAME,
|
|
29
|
+
DB_PORT
|
|
30
|
+
} = process.env;
|
|
31
|
+
|
|
32
|
+
// FIXED: Smart config check - allows empty password for MySQL/PostgreSQL
|
|
33
|
+
const isDbConfigured = () => {
|
|
34
|
+
if (!DB_TYPE || !DB_NAME) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
17
37
|
|
|
18
|
-
|
|
38
|
+
// SQLite and MongoDB don't need user/password
|
|
39
|
+
if (DB_TYPE === 'sqlite' || DB_TYPE === 'mongodb') {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
19
42
|
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
return DB_TYPE && DB_NAME && (DB_TYPE === 'sqlite' || (DB_USER && DB_PASSWORD));
|
|
43
|
+
// MySQL/PostgreSQL: need user, but password can be empty
|
|
44
|
+
return !!DB_USER; // Only require DB_USER, not DB_PASSWORD
|
|
23
45
|
};
|
|
24
46
|
|
|
25
47
|
const suggestDbSetup = () => {
|
|
26
48
|
console.log('\n⚠️ Database not configured or connection failed.');
|
|
27
49
|
console.log(' Run: mwala create-db → to set up your database interactively');
|
|
28
|
-
console.log(' Or manually create a .env file with:');
|
|
50
|
+
console.log(' Or manually create a .env file in your project folder with:');
|
|
29
51
|
console.log(' DB_TYPE=mysql|postgresql|sqlite|mongodb');
|
|
30
52
|
console.log(' DB_NAME=your_db_name');
|
|
31
53
|
console.log(' DB_HOST=localhost');
|
|
32
54
|
console.log(' DB_USER=your_user');
|
|
33
|
-
console.log(' DB_PASSWORD=
|
|
55
|
+
console.log(' DB_PASSWORD= ← can be empty (just leave blank)\n');
|
|
34
56
|
};
|
|
35
57
|
|
|
36
58
|
// Global connection cache
|
|
@@ -49,7 +71,7 @@ const getConnection = async () => {
|
|
|
49
71
|
connection = await mysql.createConnection({
|
|
50
72
|
host: DB_HOST,
|
|
51
73
|
user: DB_USER,
|
|
52
|
-
password: DB_PASSWORD,
|
|
74
|
+
password: DB_PASSWORD, // Now safely allows empty string
|
|
53
75
|
database: DB_NAME,
|
|
54
76
|
port: DB_PORT || 3306
|
|
55
77
|
});
|
|
@@ -63,7 +85,8 @@ const getConnection = async () => {
|
|
|
63
85
|
});
|
|
64
86
|
await connection.connect();
|
|
65
87
|
} else if (DB_TYPE === 'sqlite') {
|
|
66
|
-
|
|
88
|
+
const dbPath = path.join(process.cwd(), `${DB_NAME}.sqlite`);
|
|
89
|
+
connection = new sqlite3.Database(dbPath);
|
|
67
90
|
connection.serialize();
|
|
68
91
|
} else if (DB_TYPE === 'mongodb') {
|
|
69
92
|
const client = await MongoClient.connect(`mongodb://${DB_HOST}:${DB_PORT || 27017}`);
|
|
@@ -282,7 +305,7 @@ export const backupDatabase = () => {
|
|
|
282
305
|
execSync(`pg_dump -h ${DB_HOST} -U ${DB_USER} ${DB_NAME} > "${file}"`);
|
|
283
306
|
}
|
|
284
307
|
else if (DB_TYPE === 'sqlite') {
|
|
285
|
-
fs.copyFileSync(
|
|
308
|
+
fs.copyFileSync(path.join(process.cwd(), `${DB_NAME}.sqlite`), file.replace('.sql', '.sqlite'));
|
|
286
309
|
}
|
|
287
310
|
|
|
288
311
|
console.log(` Backup saved: ${file}`);
|
|
@@ -306,7 +329,7 @@ export const restoreDatabase = (file) => {
|
|
|
306
329
|
execSync(`psql -h ${DB_HOST} -U ${DB_USER} -d ${DB_NAME} -f "${file}"`);
|
|
307
330
|
}
|
|
308
331
|
else if (DB_TYPE === 'sqlite') {
|
|
309
|
-
fs.copyFileSync(file,
|
|
332
|
+
fs.copyFileSync(file, path.join(process.cwd(), `${DB_NAME}.sqlite`));
|
|
310
333
|
}
|
|
311
334
|
|
|
312
335
|
console.log(' Database restored from:', file);
|
|
@@ -333,8 +356,13 @@ export const showDatabaseSize = async () => {
|
|
|
333
356
|
console.log(`Database size: ${res.rows[0].size}`);
|
|
334
357
|
}
|
|
335
358
|
else if (DB_TYPE === 'sqlite') {
|
|
336
|
-
const
|
|
337
|
-
|
|
359
|
+
const dbFile = path.join(process.cwd(), `${DB_NAME}.sqlite`);
|
|
360
|
+
if (fs.existsSync(dbFile)) {
|
|
361
|
+
const stats = fs.statSync(dbFile);
|
|
362
|
+
console.log(`Database file size: ${(stats.size / 1024 / 1024).toFixed(2)} MB`);
|
|
363
|
+
} else {
|
|
364
|
+
console.log('Database file not created yet (0 MB)');
|
|
365
|
+
}
|
|
338
366
|
}
|
|
339
367
|
else if (DB_TYPE === 'mongodb') {
|
|
340
368
|
const stats = await conn.stats();
|