mgpanel-cli 1.0.0 → 1.0.1

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 (3) hide show
  1. package/README.md +42 -0
  2. package/bin/mgpanel.js +119 -25
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # MGPanel CLI 🚀
2
+
3
+ MGPanel CLI es la herramienta oficial para crear y gestionar proyectos **MGPanel** desde tu computadora, usando **HTML, CSS y JavaScript puro**, sin frameworks, sin JSX y sin configuraciones complejas.
4
+
5
+ Diseñado para desarrolladores que quieren **control total del código**, con una estructura clara y preparada para sincronizarse con MGPanel (Node.js + MongoDB).
6
+
7
+ ---
8
+
9
+ ## ✨ Filosofía
10
+
11
+ MGPanel no es otro framework.
12
+
13
+ Es una forma moderna de trabajar con:
14
+ - **HTML**
15
+ - **CSS**
16
+ - **JavaScript**
17
+
18
+ Organizados por módulos, con tooling profesional y libertad total.
19
+
20
+ > Escribes código como siempre.
21
+ > MGPanel se encarga de la estructura y el futuro despliegue.
22
+
23
+ ---
24
+
25
+ ## 📦 Requisitos
26
+
27
+ Antes de empezar, necesitas tener instalado:
28
+
29
+ - **Node.js** (incluye npm y npx)
30
+
31
+ Verifica con:
32
+
33
+ ```bash
34
+ node -v
35
+ npm -v
36
+ ```
37
+
38
+ ## Comandos disponibles
39
+
40
+ Crear un módulo:
41
+
42
+ mgpanel make module home
package/bin/mgpanel.js CHANGED
@@ -1,38 +1,55 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require('fs');
4
- const path = require('path');
3
+ const fs = require("fs");
4
+ const path = require("path");
5
5
 
6
- const command = process.argv[2];
7
- const projectName = process.argv[3] || 'mgpanel-project';
6
+ function printHelp() {
7
+ console.log(`
8
+ MGPanel CLI
8
9
 
9
- if (command !== 'init') {
10
- console.log('❌ Comando no reconocido');
11
- console.log('👉 Usa: mgpanel init nombre-proyecto');
12
- process.exit(1);
10
+ Uso:
11
+ mgpanel init <nombre-proyecto>
12
+ mgpanel make module <nombre-modulo>
13
+
14
+ Ejemplos:
15
+ mgpanel init miweb
16
+ mgpanel make module home
17
+ `);
13
18
  }
14
19
 
15
- const projectPath = path.join(process.cwd(), projectName);
20
+ function ensureDir(dirPath) {
21
+ fs.mkdirSync(dirPath, { recursive: true });
22
+ }
16
23
 
17
- if (fs.existsSync(projectPath)) {
18
- console.log('❌ La carpeta ya existe');
19
- process.exit(1);
24
+ function writeFileIfNotExists(filePath, content) {
25
+ if (fs.existsSync(filePath)) return false;
26
+ fs.writeFileSync(filePath, content, "utf8");
27
+ return true;
20
28
  }
21
29
 
22
- console.log('🚀 Creando proyecto MGPanel:', projectName);
30
+ /**
31
+ * mgpanel init <projectName>
32
+ */
33
+ function cmdInit(projectName = "mgpanel-project") {
34
+ const projectPath = path.join(process.cwd(), projectName);
23
35
 
24
- // Crear carpetas
25
- fs.mkdirSync(projectPath);
26
- fs.mkdirSync(path.join(projectPath, 'modules'));
27
- fs.mkdirSync(path.join(projectPath, 'assets'));
28
- fs.mkdirSync(path.join(projectPath, 'assets/css'));
29
- fs.mkdirSync(path.join(projectPath, 'assets/js'));
36
+ if (fs.existsSync(projectPath)) {
37
+ console.log("❌ La carpeta ya existe:", projectName);
38
+ process.exit(1);
39
+ }
30
40
 
31
- // Crear index.html
32
- const indexHTML = `<!DOCTYPE html>
41
+ console.log("🚀 Creando proyecto MGPanel:", projectName);
42
+
43
+ ensureDir(projectPath);
44
+ ensureDir(path.join(projectPath, "modules"));
45
+ ensureDir(path.join(projectPath, "assets", "css"));
46
+ ensureDir(path.join(projectPath, "assets", "js"));
47
+
48
+ const indexHTML = `<!doctype html>
33
49
  <html lang="es">
34
50
  <head>
35
- <meta charset="UTF-8">
51
+ <meta charset="utf-8" />
52
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
36
53
  <title>MGPanel</title>
37
54
  </head>
38
55
  <body>
@@ -41,7 +58,84 @@ const indexHTML = `<!DOCTYPE html>
41
58
  </html>
42
59
  `;
43
60
 
44
- fs.writeFileSync(path.join(projectPath, 'index.html'), indexHTML);
61
+ fs.writeFileSync(path.join(projectPath, "index.html"), indexHTML, "utf8");
62
+
63
+ console.log("✅ Proyecto creado correctamente");
64
+ }
65
+
66
+ /**
67
+ * mgpanel make module <moduleName>
68
+ */
69
+ function cmdMakeModule(moduleName) {
70
+ if (!moduleName) {
71
+ console.log("❌ Falta el nombre del módulo");
72
+ console.log("👉 Usa: mgpanel make module <nombre-modulo>");
73
+ process.exit(1);
74
+ }
75
+
76
+ // Validación básica: slug simple
77
+ const valid = /^[a-z0-9-]+$/i.test(moduleName);
78
+ if (!valid) {
79
+ console.log("❌ Nombre de módulo inválido. Usa letras/números/guiones, ej: home, about-us");
80
+ process.exit(1);
81
+ }
82
+
83
+ const cwd = process.cwd();
84
+ const modulesDir = path.join(cwd, "modules");
85
+ const moduleDir = path.join(modulesDir, moduleName);
86
+
87
+ ensureDir(moduleDir);
45
88
 
46
- console.log('✅ Proyecto creado correctamente');
47
-
89
+ const htmlPath = path.join(moduleDir, `${moduleName}.html`);
90
+ const cssPath = path.join(moduleDir, `${moduleName}.css`);
91
+ const jsPath = path.join(moduleDir, `${moduleName}.js`);
92
+
93
+ const htmlContent = `<!-- Module: ${moduleName} -->
94
+ <section class="${moduleName}">
95
+ <h2>${moduleName}</h2>
96
+ <p>Módulo creado con MGPanel ✅</p>
97
+ </section>
98
+ `;
99
+
100
+ const cssContent = `/* Module: ${moduleName} */
101
+ .${moduleName} {
102
+ font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
103
+ }
104
+ `;
105
+
106
+ const jsContent = `// Module: ${moduleName}
107
+ console.log("[MGPanel] Module loaded:", "${moduleName}");
108
+ `;
109
+
110
+ const created = [];
111
+ const skipped = [];
112
+
113
+ (writeFileIfNotExists(htmlPath, htmlContent) ? created : skipped).push(`${moduleName}.html`);
114
+ (writeFileIfNotExists(cssPath, cssContent) ? created : skipped).push(`${moduleName}.css`);
115
+ (writeFileIfNotExists(jsPath, jsContent) ? created : skipped).push(`${moduleName}.js`);
116
+
117
+ console.log(`🧩 Módulo "${moduleName}" listo en: modules/${moduleName}/`);
118
+ if (created.length) console.log("✅ Archivos creados:", created.join(", "));
119
+ if (skipped.length) console.log("↩️ Ya existían:", skipped.join(", "));
120
+ }
121
+
122
+ // ------------------ Router simple ------------------
123
+
124
+ const args = process.argv.slice(2);
125
+
126
+ if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
127
+ printHelp();
128
+ process.exit(0);
129
+ }
130
+
131
+ const [cmd1, cmd2, cmd3] = args;
132
+
133
+ if (cmd1 === "init") {
134
+ cmdInit(cmd2);
135
+ } else if (cmd1 === "make" && cmd2 === "module") {
136
+ cmdMakeModule(cmd3);
137
+ } else {
138
+ console.log("❌ Comando no reconocido.");
139
+ printHelp();
140
+ process.exit(1);
141
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mgpanel-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "MGPanel CLI",
5
5
  "bin": {
6
6
  "mgpanel": "./bin/mgpanel.js"