mwalajs 1.1.13 → 1.1.15
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/createProject.mjs +140 -0
- package/package.json +1 -1
- package/test/README.md +591 -0
- package/test/app.mjs +28 -0
- package/test/controllers/fileController.mjs +15 -0
- package/test/controllers/homeController.mjs +28 -0
- package/test/migrations/20250308115724_create_users.mjs +45 -0
- package/test/migrations/20250724111240_create_transactions.mjs +19 -0
- package/test/migrations/20260321052103_create_users.mjs +19 -0
- package/test/migrations/20260321052120_create_logs.mjs +19 -0
- package/test/migrations/20260321073512_create_user12.mjs +20 -0
- package/test/migrations/migration_log.json +1 -0
- package/test/models/exampleModel.mjs +5 -0
- package/test/models/h.mjs +1 -0
- package/test/public/styles.css +115 -0
- package/test/routes/homeRoutes.mjs +12 -0
- package/test/views/about.ejs +159 -0
- package/test/views/h.ejs +10 -0
- package/test/views/h.ejs.mjs +10 -0
- package/test/views/h.mjs +10 -0
- package/test/views/index.ejs +227 -0
- package/test/views/sitemap.xml +1 -0
- package/test/views/steps.ejs +514 -0
- package/test/views/welcome.ejs +257 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import readline from 'readline';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get global template path (FIXED)
|
|
9
|
+
*/
|
|
10
|
+
function getMwalajsPath() {
|
|
11
|
+
const envPath = process.env.MWALAJSPATH;
|
|
12
|
+
|
|
13
|
+
if (envPath && fs.existsSync(envPath)) {
|
|
14
|
+
return envPath;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* IMPORTANT FIX:
|
|
19
|
+
* Get path of installed npm package, NOT cwd
|
|
20
|
+
*/
|
|
21
|
+
try {
|
|
22
|
+
const modulePath = path.dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
|
|
24
|
+
// go up to package root
|
|
25
|
+
const rootPath = path.resolve(modulePath, '..');
|
|
26
|
+
|
|
27
|
+
if (fs.existsSync(path.join(rootPath, 'app.mjs'))) {
|
|
28
|
+
return rootPath;
|
|
29
|
+
}
|
|
30
|
+
} catch (err) {}
|
|
31
|
+
|
|
32
|
+
const fallbackPaths = {
|
|
33
|
+
win32: 'C:\\Program Files\\mwalajs',
|
|
34
|
+
linux: '/usr/local/lib/mwalajs',
|
|
35
|
+
darwin: '/usr/local/lib/mwalajs'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const fallback = fallbackPaths[os.platform()];
|
|
39
|
+
|
|
40
|
+
if (fallback && fs.existsSync(fallback)) {
|
|
41
|
+
return fallback;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new Error("❌ MwalaJS template source not found. Set MWALAJSPATH.");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Ask helper
|
|
49
|
+
*/
|
|
50
|
+
function askQuestion(rl, question) {
|
|
51
|
+
return new Promise(resolve => {
|
|
52
|
+
rl.question(question, ans => resolve(ans.trim()));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create project
|
|
58
|
+
*/
|
|
59
|
+
export async function createProject(projectArg) {
|
|
60
|
+
const rl = readline.createInterface({
|
|
61
|
+
input: process.stdin,
|
|
62
|
+
output: process.stdout
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
let projectName = projectArg?.trim();
|
|
67
|
+
|
|
68
|
+
if (!projectName) {
|
|
69
|
+
projectName = await askQuestion(rl, "Enter project name: ");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!projectName) {
|
|
73
|
+
console.error("❌ Project name required");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const newProjectPath = path.join(process.cwd(), projectName);
|
|
78
|
+
|
|
79
|
+
const templatePath = getMwalajsPath();
|
|
80
|
+
|
|
81
|
+
if (!fs.existsSync(templatePath)) {
|
|
82
|
+
throw new Error("Template path not found: " + templatePath);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (fs.existsSync(newProjectPath)) {
|
|
86
|
+
console.error(`❌ Folder already exists: ${projectName}`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log(`📦 Creating project: ${projectName}`);
|
|
91
|
+
console.log(`📁 From template: ${templatePath}`);
|
|
92
|
+
|
|
93
|
+
fs.mkdirSync(newProjectPath, { recursive: true });
|
|
94
|
+
|
|
95
|
+
const itemsToCopy = [
|
|
96
|
+
"app.mjs",
|
|
97
|
+
"controllers",
|
|
98
|
+
"migrations",
|
|
99
|
+
"routes",
|
|
100
|
+
"views",
|
|
101
|
+
"middlewares",
|
|
102
|
+
"models",
|
|
103
|
+
"public",
|
|
104
|
+
"README.md"
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
let copied = 0;
|
|
108
|
+
|
|
109
|
+
for (const item of itemsToCopy) {
|
|
110
|
+
const src = path.join(templatePath, item);
|
|
111
|
+
const dest = path.join(newProjectPath, item);
|
|
112
|
+
|
|
113
|
+
if (fs.existsSync(src)) {
|
|
114
|
+
console.log(`✔ Copying ${item}`);
|
|
115
|
+
fs.copySync(src, dest);
|
|
116
|
+
copied++;
|
|
117
|
+
} else {
|
|
118
|
+
console.warn(`⚠ Missing template item: ${item}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log("\n━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
123
|
+
console.log(`✅ Project created: ${projectName}`);
|
|
124
|
+
console.log(`📁 Location: ${newProjectPath}`);
|
|
125
|
+
console.log(`📦 Files copied: ${copied}/${itemsToCopy.length}`);
|
|
126
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
127
|
+
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error("❌ Create project failed:", err.message);
|
|
130
|
+
} finally {
|
|
131
|
+
rl.close();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* CLI support
|
|
137
|
+
*/
|
|
138
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
139
|
+
createProject(process.argv[2]);
|
|
140
|
+
}
|