mwalajs 1.1.11 → 1.1.13

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 CHANGED
@@ -38,8 +38,8 @@ const __dirname = path.dirname(__filename);
38
38
  // Dynamic imports with error handling
39
39
  // ────────────────────────────────────────────────
40
40
 
41
-
42
41
  let imports = {};
42
+ let setupMwalajs, createProject, dropAllTables, getDbConnection;
43
43
 
44
44
  try {
45
45
  const [
@@ -56,22 +56,28 @@ try {
56
56
  import(pathToFileURL(path.join(__dirname, '../config/dbUtils.mjs')).href),
57
57
  ]);
58
58
 
59
- // 🔥 FIX: handle default export OR named export safely
60
- const normalize = (mod) => mod?.default ?? mod ?? {};
59
+ const normalize = (mod) => mod?.default ?? mod ?? {};
61
60
 
62
- imports = {
63
- ...normalize(dbCfg),
64
- ...normalize(migrations),
65
- ...normalize(setup),
66
- ...normalize(proj),
67
- ...normalize(dbUtilsRaw),
68
- };
61
+ imports = {
62
+ ...normalize(dbCfg),
63
+ ...normalize(migrations),
64
+ ...normalize(setup),
65
+ ...normalize(proj),
66
+ ...normalize(dbUtilsRaw),
67
+ };
68
+
69
+ // 🔥 IMPORTANT FIX
70
+ ({
71
+ setupMwalajs,
72
+ createProject,
73
+ dropAllTables,
74
+ getDbConnection
75
+ } = imports);
69
76
 
70
77
  } catch (err) {
71
78
  error(`Failed to load required modules:\n${err.stack || err.message}`);
72
79
  process.exit(1);
73
80
  }
74
-
75
81
  const args = process.argv.slice(2);
76
82
  const command = args[0]?.toLowerCase();
77
83
 
@@ -276,9 +282,12 @@ function runSafeSync(fn, successMsg = 'Operation completed', errorPrefix = 'Oper
276
282
  console.log(`MwalaJS Version: ${pkg.version}`);
277
283
  break;
278
284
 
279
- case 'create-project':
280
- runSafeSync(createProject, 'Project created successfully');
281
- break;
285
+ case 'create-project':
286
+ await runSafe(async () => {
287
+ await createProject(args[1]);
288
+ }, 'Project created successfully');
289
+ break;
290
+
282
291
 
283
292
  case 'init':
284
293
  runSafe(setupMwalajs, 'MwalaJS initialized successfully');
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "mwalajs",
3
+ "version": "1.1.11",
4
+ "description": "MwalaJS Framework CLI Tool and Web Framework for Backend and Frontend Development.",
5
+ "type": "module",
6
+ "main": "app.mjs",
7
+ "exports": {
8
+ ".": "./index.mjs",
9
+ "./config/*": "./config/*.mjs",
10
+ "./migrations/*": "./migrations/*.mjs",
11
+ "./bin/*": "./bin/*.mjs"
12
+ },
13
+ "bin": {
14
+ "mwala": "bin/mwala.mjs"
15
+ },
16
+ "scripts": {
17
+ "start": "node app.mjs",
18
+ "cli": "node bin/mwala.mjs",
19
+ "test": "echo \"No test specified\" && exit 0",
20
+ "prepare": "npm run build",
21
+ "build": "echo 'Build step if needed'",
22
+ "postinstall": "echo 'Thanks for installing MwalaJS Framework! '"
23
+ },
24
+ "dependencies": {
25
+ "dotenv": "^16.4.7",
26
+ "ejs": "^3.1.10",
27
+ "express": "^4.21.2",
28
+ "fs-extra": "^11.3.4",
29
+ "mongodb": "^6.14.2",
30
+ "mongoose": "^8.12.1",
31
+ "mpath": "^0.9.0",
32
+ "multer": "^1.4.2",
33
+ "mwalajs": "^1.1.10",
34
+ "mysql2": "^3.13.0",
35
+ "pg": "^8.13.3",
36
+ "pg-hstore": "^2.3.4",
37
+ "readline-sync": "^1.4.10",
38
+ "sequelize": "^6.37.6",
39
+ "sqlite3": "^5.1.7"
40
+ },
41
+ "keywords": [
42
+ "mwalajs",
43
+ "mwala",
44
+ "framework",
45
+ "nodejs",
46
+ "express",
47
+ "mvc",
48
+ "cli",
49
+ "generator",
50
+ "backend",
51
+ "frontend",
52
+ "web-framework",
53
+ "orm",
54
+ "rest-api"
55
+ ],
56
+ "author": {
57
+ "name": "Hekima Ambalile Mwala",
58
+ "email": "biasharaboraofficials@gmail.com",
59
+ "url": "https://github.com/mwala400"
60
+ },
61
+ "license": "MIT",
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "https://github.com/mwala400/mwalajs.git"
65
+ },
66
+ "bugs": {
67
+ "url": "https://github.com/mwala400/mwalajs/issues"
68
+ },
69
+ "homepage": "https://github.com/mwala400/mwalajs#readme",
70
+ "engines": {
71
+ "node": ">=18.0.0"
72
+ },
73
+ "sideEffects": false,
74
+ "publishConfig": {
75
+ "access": "public"
76
+ }
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mwalajs",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "MwalaJS Framework CLI Tool and Web Framework for Backend and Frontend Development.",
5
5
  "type": "module",
6
6
  "main": "app.mjs",
@@ -30,7 +30,7 @@
30
30
  "mongoose": "^8.12.1",
31
31
  "mpath": "^0.9.0",
32
32
  "multer": "^1.4.2",
33
- "mwalajs": "^1.1.10",
33
+ "mwalajs": "^1.1.11",
34
34
  "mysql2": "^3.13.0",
35
35
  "pg": "^8.13.3",
36
36
  "pg-hstore": "^2.3.4",
package/setupMwalajs.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ // setupMwalajs.mjs
2
+
1
3
  import fs from 'fs';
2
4
  import path from 'path';
3
5
  import os from 'os';
package/createProject.mjs DELETED
@@ -1,120 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import readline from 'readline';
4
- import { exec } from 'child_process';
5
- import os from 'os';
6
-
7
- /**
8
- * Detect base source path from environment or defaults
9
- */
10
- function getMwalajsPath() {
11
- const envPath = process.env.MWALAJSPATH;
12
-
13
- if (envPath && fs.existsSync(envPath)) return envPath;
14
-
15
- const defaultPaths = {
16
- win32: 'C:\\Program Files\\mwalajs',
17
- linux: '/usr/local/lib/mwalajs',
18
- darwin: '/usr/local/lib/mwalajs'
19
- };
20
-
21
- const fallback = defaultPaths[os.platform()];
22
- if (fs.existsSync(fallback)) return fallback;
23
-
24
- console.warn(" mwalajs source path not found. Using current directory.");
25
- return process.cwd(); // fallback
26
- }
27
-
28
- /**
29
- * Function to create a new project folder, copy required files, and auto-enter the directory.
30
- */
31
- async function createProject() {
32
- const rl = readline.createInterface({
33
- input: process.stdin,
34
- output: process.stdout
35
- });
36
-
37
- rl.question(" Enter the name of the new project: ", async (projectName) => {
38
- const currentDir = process.cwd();
39
- const newProjectPath = path.join(currentDir, projectName);
40
-
41
- const mwalajsSourcePath = getMwalajsPath();
42
-
43
- try {
44
- if (fs.existsSync(newProjectPath)) {
45
- console.error(` Error: Folder '${projectName}' already exists.`);
46
- rl.close();
47
- return;
48
- }
49
-
50
- console.log(` Creating folder: ${newProjectPath}...`);
51
- fs.mkdirSync(newProjectPath);
52
-
53
- const itemsToCopy = [
54
- "app.mjs", "controllers", "migrations", "routes",
55
- "views", "middlewares", "models",
56
- "README.md","public"
57
- ];
58
-
59
- for (const item of itemsToCopy) {
60
- const src = path.join(mwalajsSourcePath, item);
61
- const dest = path.join(newProjectPath, item);
62
-
63
- if (fs.existsSync(src)) {
64
- console.log(` Copying '${item}'...`);
65
- fs.copySync(src, dest);
66
- } else {
67
- console.warn(` '${item}' not found in source. Skipping...`);
68
- }
69
- }
70
-
71
- console.log(` Project '${projectName}' created successfully!`);
72
- console.log(` Location: ${newProjectPath}`);
73
-
74
- // Open terminal automatically
75
- const platform = os.platform();
76
-
77
- if (platform === 'win32') {
78
- exec(`start cmd.exe /K "cd /d ${newProjectPath}"`);
79
- } else if (platform === 'darwin') {
80
- exec(`open -a Terminal "${newProjectPath}"`);
81
- } else if (platform === 'linux') {
82
- // Try gnome-terminal, x-terminal-emulator, or konsole
83
- const termCmds = [
84
- `gnome-terminal -- bash -c 'cd "${newProjectPath}" && bash'`,
85
- `x-terminal-emulator -e 'bash -c "cd \\"${newProjectPath}\\"; exec bash"'`,
86
- `konsole --workdir "${newProjectPath}"`
87
- ];
88
- let opened = false;
89
-
90
- for (const cmd of termCmds) {
91
- try {
92
- exec(cmd, (error) => {
93
- if (!error && !opened) opened = true;
94
- });
95
- break;
96
- } catch {}
97
- }
98
-
99
- if (!opened) {
100
- console.log(" Please manually open the folder:", newProjectPath);
101
- }
102
- } else {
103
- console.log(" Unknown OS. Please open manually:", newProjectPath);
104
- }
105
-
106
- } catch (err) {
107
- console.error(" Project creation failed:", err.message);
108
- } finally {
109
- rl.close();
110
- }
111
- });
112
- }
113
-
114
- // Export if used as a module
115
- export { createProject };
116
-
117
- // Run directly
118
- if (import.meta.url === `file://${process.argv[1]}`) {
119
- createProject();
120
- }