@batistafull/deploy-server 3.0.0 → 4.0.0
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/README.md +18 -13
- package/lib/deploy.js +31 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ Crea `deploy.config.json` en la raíz de tu proyecto. **Este archivo lo creas t
|
|
|
58
58
|
"ftp": {
|
|
59
59
|
"enabled": false,
|
|
60
60
|
"host": "ftp.example.com",
|
|
61
|
+
"port": 21,
|
|
61
62
|
"secure": true,
|
|
62
63
|
"remotePath": "/public_html"
|
|
63
64
|
}
|
|
@@ -66,16 +67,18 @@ Crea `deploy.config.json` en la raíz de tu proyecto. **Este archivo lo creas t
|
|
|
66
67
|
|
|
67
68
|
### Campos
|
|
68
69
|
|
|
69
|
-
| Campo | Tipo | Descripción
|
|
70
|
-
| -------------- | --------------------- |
|
|
71
|
-
| `output` | `string` | Ruta destino
|
|
72
|
-
| `sources` | `string[]` | Carpetas, archivos o globs a copiar (ver abajo).
|
|
73
|
-
| `buildCommand` | `string` o `string[]` | Comando(s) de build. Si es un array, se ejecutan en orden.
|
|
74
|
-
| `exclude` | `string[]` | Rutas a excluir, relativas al proyecto (ver abajo).
|
|
75
|
-
| `ftp` | `object` | (Opcional) Configuración de subida por FTP/FTPS. Ver abajo.
|
|
70
|
+
| Campo | Tipo | Descripción |
|
|
71
|
+
| -------------- | --------------------- | --------------------------------------------------------------- |
|
|
72
|
+
| `output` | `string` | Ruta destino local (ver nota). Se ignora si el FTP está activo. |
|
|
73
|
+
| `sources` | `string[]` | Carpetas, archivos o globs a copiar (ver abajo). |
|
|
74
|
+
| `buildCommand` | `string` o `string[]` | Comando(s) de build. Si es un array, se ejecutan en orden. |
|
|
75
|
+
| `exclude` | `string[]` | Rutas a excluir, relativas al proyecto (ver abajo). |
|
|
76
|
+
| `ftp` | `object` | (Opcional) Configuración de subida por FTP/FTPS. Ver abajo. |
|
|
76
77
|
|
|
77
78
|
> **`output`:** si es una ruta **absoluta** se usa tal cual (ej: `C:/inetpub/app.host`);
|
|
78
79
|
> si es **relativa** se resuelve desde la raíz del proyecto (ej: `../deploy/app.host`).
|
|
80
|
+
> **Con FTP activo (`ftp.enabled: true`) no se deja copia local:** los archivos se
|
|
81
|
+
> preparan en una carpeta temporal, se suben y se borra. En ese caso `output` no es necesario.
|
|
79
82
|
|
|
80
83
|
### `sources` — qué se copia
|
|
81
84
|
|
|
@@ -98,12 +101,13 @@ Cada entrada es una ruta **relativa al proyecto** (no un nombre suelto), scopead
|
|
|
98
101
|
|
|
99
102
|
### FTP / FTPS
|
|
100
103
|
|
|
101
|
-
La subida por FTP está desactivada salvo que pongas `ftp.enabled: true`.
|
|
104
|
+
La subida por FTP está desactivada salvo que pongas `ftp.enabled: true`. **Cuando está activa, `output` se ignora** (no se genera copia local: se usa una carpeta temporal que se borra tras subir).
|
|
102
105
|
|
|
103
106
|
| Campo | Descripción |
|
|
104
107
|
| ---------------- | -------------------------------------------------------------------------- |
|
|
105
|
-
| `ftp.enabled` | `true` para activar la subida.
|
|
108
|
+
| `ftp.enabled` | `true` para activar la subida. Si está activo, `output` se ignora. |
|
|
106
109
|
| `ftp.host` | Host del servidor FTP (fallback de `FTP_HOST`). |
|
|
110
|
+
| `ftp.port` | Puerto (fallback de `FTP_PORT`). Por defecto `21`. |
|
|
107
111
|
| `ftp.secure` | `true` (por defecto) usa FTPS con TLS. Pon `false` solo si no hay soporte. |
|
|
108
112
|
| `ftp.remotePath` | Carpeta remota destino. |
|
|
109
113
|
|
|
@@ -126,10 +130,11 @@ Si el FTP está habilitado y faltan `FTP_HOST`, `FTP_USER` o `FTP_PASSWORD` (y t
|
|
|
126
130
|
## Qué hace, paso a paso
|
|
127
131
|
|
|
128
132
|
1. Carga el `deploy.config.json`.
|
|
129
|
-
2.
|
|
130
|
-
3.
|
|
131
|
-
4.
|
|
132
|
-
5.
|
|
133
|
+
2. Determina el destino: la carpeta `output`, o una temporal si el FTP está activo.
|
|
134
|
+
3. Si se pasa `--clean` (y hay `output` local), borra la carpeta de salida.
|
|
135
|
+
4. Ejecuta el/los `buildCommand`.
|
|
136
|
+
5. Copia cada entrada de `sources` → destino (aplicando `exclude`).
|
|
137
|
+
6. Si `ftp.enabled`, sube los archivos por FTP/FTPS y borra la carpeta temporal.
|
|
133
138
|
|
|
134
139
|
## Licencia
|
|
135
140
|
|
package/lib/deploy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
|
+
const os = require("os");
|
|
2
3
|
const fs = require("fs-extra");
|
|
3
4
|
const chalk = require("chalk");
|
|
4
5
|
const { execSync } = require("child_process");
|
|
@@ -80,10 +81,7 @@ module.exports = async function deploy(options) {
|
|
|
80
81
|
const config = require(path.resolve(process.cwd(), options.config));
|
|
81
82
|
|
|
82
83
|
const projectRoot = process.cwd();
|
|
83
|
-
|
|
84
|
-
if (!config.output) {
|
|
85
|
-
throw new Error("Falta 'output' en el config: indica la carpeta destino del deploy.");
|
|
86
|
-
}
|
|
84
|
+
const ftpEnabled = !!config.ftp?.enabled;
|
|
87
85
|
|
|
88
86
|
if (!Array.isArray(config.sources) || config.sources.length === 0) {
|
|
89
87
|
throw new Error(
|
|
@@ -91,17 +89,30 @@ module.exports = async function deploy(options) {
|
|
|
91
89
|
);
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
|
|
92
|
+
// Con FTP no se deja copia local: se usa una carpeta temporal solo para
|
|
93
|
+
// preparar la subida y se borra al terminar. Sin FTP se requiere 'output'.
|
|
94
|
+
let outputPath;
|
|
95
|
+
let staging = false;
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
if (ftpEnabled) {
|
|
98
|
+
outputPath = await fs.mkdtemp(path.join(os.tmpdir(), "deploy-server-"));
|
|
99
|
+
staging = true;
|
|
100
|
+
} else {
|
|
101
|
+
if (!config.output) {
|
|
102
|
+
throw new Error("Falta 'output' en el config: indica la carpeta destino del deploy.");
|
|
103
|
+
}
|
|
104
|
+
// 'output' es la ruta destino. Si es absoluta se usa tal cual;
|
|
105
|
+
// si es relativa se resuelve desde la raíz del proyecto.
|
|
106
|
+
outputPath = path.resolve(projectRoot, config.output);
|
|
107
|
+
|
|
108
|
+
// Clean
|
|
109
|
+
if (options.clean) {
|
|
110
|
+
console.log(chalk.gray("🧹 Cleaning output..."));
|
|
111
|
+
await fs.remove(outputPath);
|
|
112
|
+
}
|
|
103
113
|
|
|
104
|
-
|
|
114
|
+
await fs.ensureDir(outputPath);
|
|
115
|
+
}
|
|
105
116
|
|
|
106
117
|
// BUILD (ARRAY)
|
|
107
118
|
if (Array.isArray(config.buildCommand)) {
|
|
@@ -117,7 +128,7 @@ module.exports = async function deploy(options) {
|
|
|
117
128
|
await copySources(config.sources, outputPath, config.exclude || [], projectRoot);
|
|
118
129
|
|
|
119
130
|
// FTP (opcional)
|
|
120
|
-
if (
|
|
131
|
+
if (ftpEnabled) {
|
|
121
132
|
const client = new ftp.Client();
|
|
122
133
|
|
|
123
134
|
// Las credenciales se leen preferentemente de variables de entorno.
|
|
@@ -125,6 +136,7 @@ module.exports = async function deploy(options) {
|
|
|
125
136
|
const host = process.env.FTP_HOST || config.ftp.host;
|
|
126
137
|
const user = process.env.FTP_USER || config.ftp.user;
|
|
127
138
|
const password = process.env.FTP_PASSWORD || config.ftp.password;
|
|
139
|
+
const port = Number(process.env.FTP_PORT || config.ftp.port) || undefined;
|
|
128
140
|
// FTPS por defecto; poner ftp.secure=false en el config solo si el
|
|
129
141
|
// servidor no soporta TLS (no recomendado).
|
|
130
142
|
const secure = config.ftp.secure !== false;
|
|
@@ -138,7 +150,7 @@ module.exports = async function deploy(options) {
|
|
|
138
150
|
console.log(chalk.yellow(`📡 Connecting FTP (${secure ? "FTPS" : "sin cifrar"})...`));
|
|
139
151
|
|
|
140
152
|
try {
|
|
141
|
-
await client.access({ host, user, password, secure });
|
|
153
|
+
await client.access({ host, port, user, password, secure });
|
|
142
154
|
|
|
143
155
|
await client.ensureDir(config.ftp.remotePath);
|
|
144
156
|
await client.uploadFromDir(outputPath);
|
|
@@ -146,6 +158,10 @@ module.exports = async function deploy(options) {
|
|
|
146
158
|
console.log(chalk.green("🌐 FTP upload done"));
|
|
147
159
|
} finally {
|
|
148
160
|
client.close();
|
|
161
|
+
// Borra la carpeta temporal de preparación (no se deja copia local).
|
|
162
|
+
if (staging) {
|
|
163
|
+
await fs.remove(outputPath);
|
|
164
|
+
}
|
|
149
165
|
}
|
|
150
166
|
}
|
|
151
167
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@batistafull/deploy-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Config-driven deploy tool that builds and copies folders, files or globs to a target path, with optional FTP/FTPS upload",
|
|
5
5
|
"main": "bin/deploy-server.js",
|
|
6
6
|
"bin": {
|