Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 6x 2x 2x 4x 4x 4x 4x 4x 4x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 3x 3x 3x 4x 1x 1x 1x 6x 14x 14x 14x 14x 14x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 14x 14x 14x 14x 14x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 14x 14x 14x 14x 14x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 3x 4x 4x 4x 4x 4x 4x 3x 3x 3x 2x 2x 3x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 3x 6x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 7x 7x 7x 7x 7x 7x 7x 14x 14x 14x 14x 14x 35x 25x 25x 10x 10x 10x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 10x 2x 2x 10x 35x 14x 14x 14x 14x 14x 10x 4x 4x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 2x 2x 6x 4x 4x 4x 2x 4x 2x 2x 2x 2x 2x 6x 6x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 6x 2x 2x 6x 10x 14x 14x 14x 14x 14x 19x 19x 19x 19x 19x 19x 19x 19x 19x 14x 14x 14x | const {
Document,
Paragraph,
TextRun,
Table,
TableRow,
TableCell,
WidthType,
AlignmentType,
HeadingLevel,
ExternalHyperlink,
BorderStyle,
Packer,
ShadingType,
} = require("docx");
const fs = require("fs").promises;
const StyleConfig = require("../config/StyleConfig");
/**
* DevToolsGeneratorV2 - Genera documentos Word de pases a producción
*
* Genera documentos profesionales replicando exactamente la plantilla estándar:
*
* Estructura del documento:
* 1. Título: {{TITULO_PASE}} (Heading 2)
* 2. Sección: 🗂️ Información del pase (Heading 2)
* 3. Tabla 0: Información básica (5 filas x 2 columnas)
* 4. Sección: 🔖 Documentación del pase (Heading 2)
* 5. Tabla 1: Documentos y PRs (8 filas x 2 columnas)
* 6. Sección: 📋 Listado de los requerimientos (Heading 2)
* 7. Tabla 2: Work Items (encabezado + datos)
*
* @author Thunderlight Team
*/
class DevToolsGeneratorV2 {
/**
* @param {string|null} styleConfigPath - Ruta al archivo de configuración de estilos
*/
constructor(styleConfigPath = null) {
// Cargar configuración de estilos
this.styleConfig = new StyleConfig(styleConfigPath);
}
/**
* Genera un documento Word completo replicando Plantilla.docx
* @param {Object} data - Datos para el documento
* @param {string} outputPath - Ruta donde guardar el documento
* @returns {Promise<{success: boolean, path: string}>} Resultado de la generación
* @throws {Error} Si faltan parámetros o hay error en la generación
*/
async generateDocument(data, outputPath) {
if (!data || !outputPath) {
throw new Error("data y outputPath son requeridos para generateDocument");
}
try {
const sections = [];
// 1. TÍTULO PRINCIPAL
const titulo =
data.TITULO_PASE || `Pase a producción ${data.NUMERO_PASE || ""}`;
sections.push(
new Paragraph({
text: titulo,
heading: HeadingLevel.HEADING_2,
}),
new Paragraph({ text: "" }), // Espacio
);
// 2. SECCIÓN: Información del pase
sections.push(
new Paragraph({
text: "🗂️ Información del pase",
heading: HeadingLevel.HEADING_2,
}),
new Paragraph({
text: "Detalle del pase, se debe indicar el número de publicación generada por el power",
style: "Normal",
}),
new Paragraph({ text: "" }),
);
// 3. TABLA 0: Información básica (5 filas x 2 columnas)
sections.push(this.createInfoTable(data));
sections.push(new Paragraph({ text: "" }));
// 4. SECCIÓN: Documentación del pase
sections.push(
new Paragraph({
text: "🔖 Documentación del pase",
heading: HeadingLevel.HEADING_2,
}),
new Paragraph({
text: "Apartado para colocar los archivos y vistos buenos, generados para la documentación",
style: "Normal",
}),
new Paragraph({ text: "" }),
);
// 5. TABLA 1: Documentos y PRs (8 filas x 2 columnas)
sections.push(this.createDocumentsTable(data));
sections.push(new Paragraph({ text: "" }));
// 6. SECCIÓN: Listado de requerimientos
sections.push(
new Paragraph({
text: "📋 Listado de los requerimientos",
heading: HeadingLevel.HEADING_2,
}),
new Paragraph({
text: "Listado de tareas (este query se obtuvo, generando una consulta de elementos por usuario):",
style: "Normal",
}),
new Paragraph({ text: "" }),
);
// 7. TABLA 2: Work Items
sections.push(
this.createWorkItemsTable(data.workItems || [], data.azureOrganization),
);
// Crear el documento
const doc = new Document({
sections: [
{
properties: {},
children: sections,
},
],
});
// Guardar
const buffer = await Packer.toBuffer(doc);
await fs.writeFile(outputPath, buffer);
return { success: true, path: outputPath };
} catch (error) {
console.error("Error generando documento:", error);
throw error;
}
}
/**
* Crea la TABLA 0: Información básica (5 filas x 2 columnas)
*/
createInfoTable(data) {
const rows = [
// Fila 0: Número de pase
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Número de pase" })],
width: { size: 30, type: WidthType.PERCENTAGE },
}),
new TableCell({
children: [new Paragraph({ text: data.NUMERO_PASE || "" })],
width: { size: 70, type: WidthType.PERCENTAGE },
}),
],
}),
// Fila 1: Objetivo
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Objetivo" })],
}),
new TableCell({
children: [new Paragraph({ text: data.OBJETIVO_PASE || "" })],
}),
],
}),
// Fila 2: Áreas afectadas
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Áreas afectadas de negocio" })],
}),
new TableCell({
children: [new Paragraph({ text: data.AREA_AFECTADA || "" })],
}),
],
}),
// Fila 3: Fecha de publicación
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Fecha de publicación" })],
}),
new TableCell({
children: [new Paragraph({ text: "Pendiente" })],
}),
],
}),
// Fila 4: Aspectos importantes
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Aspectos importantes" })],
}),
new TableCell({
children: [
new Paragraph({ text: data.ASPECTOS_IMPORTANTES || "" }),
],
}),
],
}),
];
return new Table({
rows,
width: { size: 100, type: WidthType.PERCENTAGE },
borders: this.getTableBorders(),
});
}
/**
* Crea la TABLA 1: Documentos y PRs (8 filas x 2 columnas)
*/
createDocumentsTable(data) {
// Los documentos ahora vienen directamente en data, no en data.sharePointDocuments
const pullRequests = data.pullRequests || data.PR_AZURE || [];
const azureOrganization = data.azureOrganization || null;
const rows = [
// Fila 0: Plan de montaje
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Plan de montaje" })],
width: { size: 30, type: WidthType.PERCENTAGE },
}),
new TableCell({
children: this.formatDocumentList(data.PLAN_MONTAJE || []),
width: { size: 70, type: WidthType.PERCENTAGE },
}),
],
}),
// Fila 1: Presentación Técnica
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Presentación Técnica" })],
}),
new TableCell({
children: [
new Paragraph({ text: "Documento de la ppt:" }),
...this.formatDocumentList(data.PPT_CRT || []),
],
}),
],
}),
// Fila 2: Vbs Base de Datos
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Vbs Base de Datos" })],
}),
new TableCell({
children: this.formatDocumentList(data.VB_DB || []),
}),
],
}),
// Fila 3: Vbs CRT
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Vbs CRT" })],
}),
new TableCell({
children: this.formatDocumentList(data.VB_CRT || []),
}),
],
}),
// Fila 4: Ciclos de Pruebas
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Ciclos de Pruebas" })],
}),
new TableCell({
children: this.formatDocumentList(data.CICLOS_PRUEBA || []),
}),
],
}),
// Fila 5: Vb de Negocio (texto fijo)
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Vb de Negocio" })],
}),
new TableCell({
children: [
new Paragraph({
text: "Para estos ajustes, no se requiere un Vb adicional de negocios.",
}),
],
}),
],
}),
// Fila 6: Pull Request Azure
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Pull Request Azure" })],
}),
new TableCell({
children: this.formatPullRequestList(
pullRequests,
azureOrganization,
),
}),
],
}),
// Fila 7: Evidencias de preproducción
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Evidencias de preproducción" })],
}),
new TableCell({
children: this.formatDocumentList(data.PRUEBAS_PREPROD || []),
}),
],
}),
];
return new Table({
rows,
width: { size: 100, type: WidthType.PERCENTAGE },
borders: this.getTableBorders(),
});
}
/**
* Crea la TABLA 2: Work Items
*/
createWorkItemsTable(workItems, azureOrganization = null) {
const rows = [];
// Fila de encabezados con formato BOLD
rows.push(
new TableRow({
children: [
new TableCell({
children: [
new Paragraph({
children: [new TextRun({ text: "ID", bold: true })],
}),
],
width: { size: 15, type: WidthType.PERCENTAGE },
}),
new TableCell({
children: [
new Paragraph({
children: [new TextRun({ text: "Work Item Type", bold: true })],
}),
],
width: { size: 20, type: WidthType.PERCENTAGE },
}),
new TableCell({
children: [
new Paragraph({
children: [new TextRun({ text: "Title", bold: true })],
}),
],
width: { size: 40, type: WidthType.PERCENTAGE },
}),
new TableCell({
children: [
new Paragraph({
children: [new TextRun({ text: "Iteration Path", bold: true })],
}),
],
width: { size: 25, type: WidthType.PERCENTAGE },
}),
],
}),
);
// Filas de datos
if (workItems && workItems.length > 0) {
workItems.forEach((wi) => {
const fields = wi.fields || {};
const wiId = wi.id?.toString() || "N/A";
// Construir URL del work item en Azure DevOps
let wiUrl = "#";
if (azureOrganization && wi.id) {
// URL formato: https://dev.azure.com/{org}/{project}/_workitems/edit/{id}
const project = fields["System.TeamProject"] || "";
if (project) {
wiUrl = `https://dev.azure.com/${azureOrganization}/${project}/_workitems/edit/${wi.id}`;
}
}
rows.push(
new TableRow({
children: [
new TableCell({
children: [
new Paragraph({
children: [
wiUrl !== "#"
? new ExternalHyperlink({
children: [
new TextRun({
text: wiId,
style: "Hyperlink",
underline: {},
color: "0563C1",
}),
],
link: wiUrl,
})
: new TextRun({ text: wiId }),
],
}),
],
}),
new TableCell({
children: [
new Paragraph({
text: fields["System.WorkItemType"] || "N/A",
}),
],
}),
new TableCell({
children: [
new Paragraph({
text: fields["System.Title"] || "Sin título",
}),
],
}),
new TableCell({
children: [
new Paragraph({
text: fields["System.IterationPath"] || "N/A",
}),
],
}),
],
}),
);
});
} else {
// Si no hay work items, agregar fila de ejemplo
rows.push(
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ text: "Sin work items" })],
columnSpan: 4,
}),
],
}),
);
}
return new Table({
rows,
width: { size: 100, type: WidthType.PERCENTAGE },
borders: this.getTableBorders(),
});
}
/**
* Formatea lista de documentos como párrafos con hipervínculos
*/
formatDocumentList(docs) {
if (!docs || docs.length === 0) {
return [new Paragraph({ text: "Sin documentos" })];
}
return docs.map((doc) => {
if (doc.url && doc.url !== "#") {
return new Paragraph({
children: [
new ExternalHyperlink({
children: [
new TextRun({
text: doc.name || "Documento",
style: "Hyperlink",
underline: {},
color: "0563C1",
}),
],
link: doc.url,
}),
],
});
} else {
return new Paragraph({ text: doc.name || "Sin nombre" });
}
});
}
/**
* Formatea lista de Pull Requests con formato "ID - Título" como hipervínculos
*/
formatPullRequestList(pullRequests, azureOrganization = null) {
if (!pullRequests || pullRequests.length === 0) {
return [new Paragraph({ text: "No hay Pull Requests" })];
}
return pullRequests.map((pr) => {
const id = pr.pullRequestId || "N/A";
const titulo = pr.title || "Sin título";
const texto = `${id} - ${titulo}`;
// Construir URL del PR en Azure DevOps
let url = null;
// Intentar varias formas de construir la URL
if (pr.repository && pr.repository.webUrl && id !== "N/A") {
// Formato 1: usar webUrl del repositorio + /pullrequest/ID
url = `${pr.repository.webUrl}/pullrequest/${id}`;
} else if (
pr.projectName &&
pr.repository &&
pr.repository.name &&
id !== "N/A"
) {
// Formato 2: construir URL completa desde cero
// Usar la organización del PR si existe, sino usar azureOrganization
const orgToUse = pr.organization || azureOrganization;
url = `https://dev.azure.com/${orgToUse}/${pr.projectName}/_git/${pr.repository.name}/pullrequest/${id}`;
}
if (url) {
return new Paragraph({
children: [
new ExternalHyperlink({
children: [
new TextRun({
text: texto,
style: "Hyperlink",
underline: {},
color: "0563C1",
}),
],
link: url,
}),
],
});
} else {
return new Paragraph({ text: texto });
}
});
}
/**
* Define los bordes de las tablas (estilo simple)
*/
getTableBorders() {
return {
top: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
bottom: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
left: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
right: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
insideHorizontal: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
insideVertical: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
};
}
}
module.exports = DevToolsGeneratorV2;
|