mwalajs 1.1.2 → 1.1.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.
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mwalajs",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "MwalaJS Framework CLI Tool and Web Framework for Backend and Frontend Development.",
5
5
  "type": "module",
6
6
  "main": "app.mjs",
package/utils/dbUtils.mjs CHANGED
@@ -55,6 +55,31 @@ const suggestDbSetup = () => {
55
55
  console.log(' DB_PASSWORD= ← can be empty (just leave blank)\n');
56
56
  };
57
57
 
58
+ // === WINDOWS MYSQL TOOLS AUTO-DETECTION ===
59
+ let mysqlTools = null;
60
+ if (process.platform === 'win32') {
61
+ const commonPaths = [
62
+ 'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin',
63
+ 'C:\\Program Files\\MySQL\\MySQL Server 8.4\\bin',
64
+ 'C:\\Program Files (x86)\\MySQL\\MySQL Server 8.0\\bin',
65
+ 'C:\\xampp\\mysql\\bin',
66
+ 'C:\\wamp64\\bin\\mysql\\mysql8.0.31\\bin',
67
+ 'C:\\laragon\\bin\\mysql\\mysql-8.0.30-winx64\\bin',
68
+ 'C:\\Program Files\\MariaDB 10.6\\bin',
69
+ ];
70
+
71
+ for (const basePath of commonPaths) {
72
+ if (fs.existsSync(basePath)) {
73
+ const mysqldump = path.join(basePath, 'mysqldump.exe');
74
+ const mysqlCmd = path.join(basePath, 'mysql.exe');
75
+ if (fs.existsSync(mysqldump) && fs.existsSync(mysqlCmd)) {
76
+ mysqlTools = { mysqldump, mysql: mysqlCmd };
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ }
82
+
58
83
  // Global connection cache
59
84
  let connection = null;
60
85
 
@@ -71,7 +96,7 @@ const getConnection = async () => {
71
96
  connection = await mysql.createConnection({
72
97
  host: DB_HOST,
73
98
  user: DB_USER,
74
- password: DB_PASSWORD, // Now safely allows empty string
99
+ password: DB_PASSWORD,
75
100
  database: DB_NAME,
76
101
  port: DB_PORT || 3306
77
102
  });
@@ -298,19 +323,43 @@ export const backupDatabase = () => {
298
323
 
299
324
  try {
300
325
  if (DB_TYPE === 'mysql') {
301
- execSync(`mysqldump -h ${DB_HOST} -u ${DB_USER} -p${DB_PASSWORD} ${DB_NAME} > "${file}"`);
326
+ let cmd;
327
+ if (process.platform === 'win32' && mysqlTools) {
328
+ // Use full path on Windows
329
+ cmd = `"${mysqlTools.mysqldump}" -h ${DB_HOST} -u ${DB_USER} ${DB_PASSWORD ? '-p' + DB_PASSWORD : ''} ${DB_NAME} > "${file}"`;
330
+ } else {
331
+ // Linux/macOS or if in PATH
332
+ cmd = `mysqldump -h ${DB_HOST} -u ${DB_USER} ${DB_PASSWORD ? '-p' + DB_PASSWORD : ''} ${DB_NAME} > "${file}"`;
333
+ }
334
+ execSync(cmd, { stdio: 'inherit' });
302
335
  }
303
336
  else if (DB_TYPE === 'postgresql') {
304
337
  process.env.PGPASSWORD = DB_PASSWORD;
305
- execSync(`pg_dump -h ${DB_HOST} -U ${DB_USER} ${DB_NAME} > "${file}"`);
338
+ execSync(`pg_dump -h ${DB_HOST} -U ${DB_USER} ${DB_NAME} > "${file}"`, { stdio: 'inherit' });
306
339
  }
307
340
  else if (DB_TYPE === 'sqlite') {
308
- fs.copyFileSync(path.join(process.cwd(), `${DB_NAME}.sqlite`), file.replace('.sql', '.sqlite'));
341
+ const source = path.join(process.cwd(), `${DB_NAME}.sqlite`);
342
+ const backupFile = file.replace('.sql', '.sqlite');
343
+ if (fs.existsSync(source)) {
344
+ fs.copyFileSync(source, backupFile);
345
+ console.log(` Backup saved: ${backupFile}`);
346
+ return;
347
+ } else {
348
+ console.log(' No SQLite database file found to backup.');
349
+ return;
350
+ }
309
351
  }
310
352
 
311
353
  console.log(` Backup saved: ${file}`);
312
354
  } catch (err) {
313
- console.error(' Backup failed:', err.message);
355
+ console.error(' Backup failed.');
356
+ if (process.platform === 'win32' && !mysqlTools) {
357
+ console.log('\n❌ mysqldump.exe not found.');
358
+ console.log(' Install MySQL or use XAMPP/WAMP/Laragon.');
359
+ console.log(' Or add MySQL bin folder to your system PATH.');
360
+ } else {
361
+ console.error(' Error:', err.message);
362
+ }
314
363
  }
315
364
  };
316
365
 
@@ -322,17 +371,26 @@ export const restoreDatabase = (file) => {
322
371
 
323
372
  try {
324
373
  if (DB_TYPE === 'mysql') {
325
- execSync(`mysql -h ${DB_HOST} -u ${DB_USER} -p${DB_PASSWORD} ${DB_NAME} < "${file}"`);
374
+ let cmd;
375
+ if (process.platform === 'win32' && mysqlTools) {
376
+ cmd = `"${mysqlTools.mysql}" -h ${DB_HOST} -u ${DB_USER} ${DB_PASSWORD ? '-p' + DB_PASSWORD : ''} ${DB_NAME} < "${file}"`;
377
+ } else {
378
+ cmd = `mysql -h ${DB_HOST} -u ${DB_USER} ${DB_PASSWORD ? '-p' + DB_PASSWORD : ''} ${DB_NAME} < "${file}"`;
379
+ }
380
+ execSync(cmd, { stdio: 'inherit' });
326
381
  }
327
382
  else if (DB_TYPE === 'postgresql') {
328
383
  process.env.PGPASSWORD = DB_PASSWORD;
329
- execSync(`psql -h ${DB_HOST} -U ${DB_USER} -d ${DB_NAME} -f "${file}"`);
384
+ execSync(`psql -h ${DB_HOST} -U ${DB_USER} -d ${DB_NAME} -f "${file}"`, { stdio: 'inherit' });
330
385
  }
331
386
  else if (DB_TYPE === 'sqlite') {
332
- fs.copyFileSync(file, path.join(process.cwd(), `${DB_NAME}.sqlite`));
387
+ const target = path.join(process.cwd(), `${DB_NAME}.sqlite`);
388
+ fs.copyFileSync(file, target);
389
+ console.log(` Restored SQLite database to: ${target}`);
390
+ return;
333
391
  }
334
392
 
335
- console.log(' Database restored from:', file);
393
+ console.log(` Database restored from: ${file}`);
336
394
  } catch (err) {
337
395
  console.error(' Restore failed:', err.message);
338
396
  }