create-walpole-ar 2.2.3 → 2.3.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.
- package/index.html +31 -0
- package/index.js +15 -13
- package/package.json +1 -1
- package/template/manifest.json +1 -1
- package/template/sw,js +1 -1
package/index.html
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>webpole-restaurante</title>
|
|
6
|
+
<link rel="manifest" href="/manifest.json">
|
|
7
|
+
<meta name="theme-color" content="">
|
|
8
|
+
<style>
|
|
9
|
+
body{font-family:sans-serif;text-align:center;padding:40px;}
|
|
10
|
+
button{padding:12px 20px;border:none;background-color:#c43434;border-radius:8px;}
|
|
11
|
+
</style>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
|
|
15
|
+
<h1>webpole-restaurante</h1>
|
|
16
|
+
<p>Powered by WebPole-AR PWA Core</p>
|
|
17
|
+
<button id="btnInstallApp" style="display:none;">Instalar App</button>
|
|
18
|
+
|
|
19
|
+
<script src="/core/install-manager.js"></script>
|
|
20
|
+
<script src="/core/update-manager.js"></script>
|
|
21
|
+
|
|
22
|
+
<script>
|
|
23
|
+
if ("serviceWorker" in navigator) {
|
|
24
|
+
window.addEventListener("load", () => {
|
|
25
|
+
navigator.serviceWorker.register("/core/sw-core.js");
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
package/index.js
CHANGED
|
@@ -8,38 +8,39 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
8
8
|
const __dirname = path.dirname(__filename);
|
|
9
9
|
|
|
10
10
|
const args = process.argv.slice(2);
|
|
11
|
-
const projectName = args[0];
|
|
12
11
|
const initMode = args.includes("--init");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
console.log("⚠ Debes indicar un nombre para el proyecto o usar --init.");
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
12
|
+
const projectNameArg = args.find(arg => arg !== "--init");
|
|
13
|
+
const projectName = projectNameArg || path.basename(process.cwd());
|
|
18
14
|
|
|
19
15
|
const projectPath = initMode ? process.cwd() : path.join(process.cwd(), projectName);
|
|
20
16
|
const templatePath = path.join(__dirname, "template");
|
|
21
17
|
|
|
22
|
-
// Evitar sobreescribir proyecto
|
|
18
|
+
// Evitar sobreescribir proyecto nuevo
|
|
23
19
|
if (!initMode && fs.existsSync(projectPath)) {
|
|
24
20
|
console.log("⚠ La carpeta ya existe.");
|
|
25
21
|
process.exit(1);
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
// Crear carpeta
|
|
24
|
+
// Crear carpeta para proyecto nuevo
|
|
29
25
|
if (!initMode) fs.mkdirSync(projectPath);
|
|
30
26
|
|
|
31
|
-
// Función para copiar
|
|
27
|
+
// Función para copiar archivos del template
|
|
32
28
|
function copyTemplateFiles() {
|
|
33
29
|
fs.readdirSync(templatePath).forEach(file => {
|
|
30
|
+
const targetFile = path.join(projectPath, file);
|
|
31
|
+
|
|
32
|
+
// Si es init y ya existe index.html, no sobrescribir
|
|
33
|
+
if (initMode && file === "index.html" && fs.existsSync(targetFile)) return;
|
|
34
|
+
|
|
34
35
|
const content = fs.readFileSync(path.join(templatePath, file), "utf-8");
|
|
35
|
-
const finalContent = content.replace(/{{projectName}}/g, projectName
|
|
36
|
-
fs.writeFileSync(
|
|
36
|
+
const finalContent = content.replace(/{{projectName}}/g, projectName);
|
|
37
|
+
fs.writeFileSync(targetFile, finalContent);
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
copyTemplateFiles();
|
|
41
42
|
|
|
42
|
-
//
|
|
43
|
+
// Para init, actualizar index.html existente con manifest y SW
|
|
43
44
|
if (initMode) {
|
|
44
45
|
const indexFile = path.join(projectPath, "index.html");
|
|
45
46
|
if (fs.existsSync(indexFile)) {
|
|
@@ -66,4 +67,5 @@ if('serviceWorker' in navigator){
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
console.log("✅ Operación completada. 🚀");
|
|
69
|
-
if (!initMode) console.log(`👉 cd ${projectName} && code .`);
|
|
70
|
+
if (!initMode) console.log(`👉 cd ${projectName} && code .`);
|
|
71
|
+
if (initMode) console.log("👉 Proyecto existente actualizado con PWA");
|
package/package.json
CHANGED
package/template/manifest.json
CHANGED
package/template/sw,js
CHANGED