@cat-indev/catops-cli 0.0.1-alpha.11 → 0.0.1-alpha.12

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 CHANGED
@@ -5,7 +5,7 @@ Framework para pipelines DevOps, escrito en **TypeScript** (100% usable desde Ja
5
5
  Trae:
6
6
 
7
7
  - Un **ExecutionContext** compartido (`flags`, `params`, `env`, `vars`, `results`, `logger`, `services`, `notifier`) para que ninguna task tenga que recibir parámetros manualmente.
8
- - **15 servicios** listos (`shell`, `docker`, `git`, `kubectl`, `helm`, `npm`, `archive`, `terraform`, `ansible`, `argocd`, `tekton`, `oc`, `az`, `azdo`, `http`) + un **cliente REST API** para Azure DevOps (`AzureDevOpsApi`) + un **motor de pipelines** declarativo con dependencias (`Pipeline`).
8
+ - **16 servicios** listos (`shell`, `docker`, `git`, `kubectl`, `helm`, `npm`, `archive`, `terraform`, `ansible`, `argocd`, `tekton`, `oc`, `az`, `azdo`, `http`, `yaml`) + un **cliente REST API** para Azure DevOps (`AzureDevOpsApi`) + un **motor de pipelines** declarativo con dependencias (`Pipeline`).
9
9
  - **Servicio HTTP** con interceptores de request/response, registry de agentes nombrados, configuración global, query params, dry-run y timeout.
10
10
  - **Menús interactivos** con navegación anidada y **selección automática por flag** (para correr pipelines sin prompts, ideal para CI).
11
11
  - **retry / timeout / dryRun** en cada comando de shell.
@@ -52,10 +52,10 @@ Cualquiera de las 4 deja disponibles dos cosas en el proyecto consumidor:
52
52
 
53
53
  1. La librería, tanto desde TS como desde JS puro:
54
54
  ```typescript
55
- import { Context, Menu, services, type MenuDefinition } from "catops-cli";
55
+ import { Context, Menu, services, YamlService, type MenuDefinition } from "catops-cli";
56
56
  ```
57
57
  ```javascript
58
- const { Context, Menu, services } = require("catops-cli");
58
+ const { Context, Menu, services, YamlService } = require("catops-cli");
59
59
  ```
60
60
  2. El binario: `npx catops-cli` (o `catops-cli` si lo instalaste global con `-g`).
61
61
 
@@ -89,7 +89,8 @@ src/
89
89
  http.ts -> cliente HTTP con interceptores de request/response, múltiples instancias
90
90
  http-types.ts -> tipos del servicio HTTP (HttpRequest, HttpResponse, interceptors, ...)
91
91
  docker.ts, git.ts, kubectl.ts, helm.ts, npm.ts, archive.ts
92
- terraform.ts, ansible.ts, argocd.ts, tekton.ts, oc.ts, az.ts, azdo.ts, azdo-api.ts, pipeline.ts
92
+ terraform.ts, ansible.ts, argocd.ts, tekton.ts, oc.ts, az.ts, azdo.ts, azdo-api.ts, pipeline.ts
93
+ yaml.ts -> YamlService: manipulación de archivos YAML con prepare(), multidocument, comentarios
93
94
  index.ts -> registra todos los servicios anteriores (ServicesRegistry)
94
95
  index.ts -> entry point público: Context, Menu, Notifier, senders, classifiers, messages, services, http, tipos
95
96
  bin/
@@ -100,8 +101,8 @@ test/
100
101
  context.test.js, shell.test.js, services.test.js, menu-selector.test.js,
101
102
  notifier.test.js, senders.test.js, hooks-integration.test.js,
102
103
  http.test.js, kubectl.test.js, oc.test.js, deployment-group.test.js,
103
- exec-options-passthrough.test.js, azdo-api.test.js, pipeline.test.js,
104
- service-notify.test.js
104
+ exec-options-passthrough.test.js, azdo-api.test.js, pipeline.test.js,
105
+ service-notify.test.js, yaml.test.js
105
106
  ```
106
107
 
107
108
  ## Uso rápido: menú con `devops.pipeline.js` + el bin
@@ -1223,6 +1224,170 @@ const docker = ctx.wrap(ctx.services.docker, "docker");
1223
1224
  docker.version; // pasa directo, sin proxy
1224
1225
  ```
1225
1226
 
1227
+ ## Servicio YAML: manipulación de archivos de configuración (`ctx.services.yaml`)
1228
+
1229
+ Un servicio para leer, modificar y serializar archivos YAML con soporte para operaciones declarativas, comentarios, y documentos múltiples.
1230
+
1231
+ ### Uso básico
1232
+
1233
+ ```typescript
1234
+ // Parsear YAML desde string
1235
+ ctx.services.yaml.fromYaml(`
1236
+ apiVersion: v1
1237
+ kind: ConfigMap
1238
+ metadata:
1239
+ name: app-config
1240
+ data:
1241
+ ENV: production
1242
+ `);
1243
+
1244
+ // Obtener valores
1245
+ ctx.services.yaml.yamlGet("metadata.name"); // "app-config"
1246
+ ctx.services.yaml.yamlGet("data.ENV", "default"); // "production"
1247
+
1248
+ // Asignar valores (crea paths nuevos si no existen)
1249
+ ctx.services.yaml.yamlSet(["data", "DEBUG"], "false");
1250
+
1251
+ // Serializar a YAML
1252
+ const yamlString = ctx.services.yaml.yamlify();
1253
+
1254
+ // Serializar a JSON
1255
+ const jsonString = ctx.services.yaml.stringify();
1256
+ ```
1257
+
1258
+ ### Trabajar con JSON
1259
+
1260
+ ```typescript
1261
+ // Convertir JSON a YAML interno
1262
+ ctx.services.yaml.fromJson({
1263
+ apiVersion: "v1",
1264
+ kind: "Service",
1265
+ metadata: { name: "api-service" }
1266
+ });
1267
+
1268
+ // Obtener como objeto JSON
1269
+ const obj = ctx.services.yaml.jsonify();
1270
+ ```
1271
+
1272
+ ### Arrays y omisión de keys
1273
+
1274
+ ```typescript
1275
+ // Agregar elementos a un array
1276
+ ctx.services.yaml.yamlPush(["data", "ALLOWED_HOSTS"], ["host1.example.com", "host2.example.com"]);
1277
+
1278
+ // Concatenar al inicio de un string
1279
+ ctx.services.yaml.yamlConcatInitAndSet(["data", "PREFIX"], "prod-"); // "prod-valor-anterior"
1280
+
1281
+ // Eliminar paths del documento
1282
+ ctx.services.yaml.yamlOmit(["data", "DEBUG", "data", "TEMP"]);
1283
+ ```
1284
+
1285
+ ### Comentarios
1286
+
1287
+ ```typescript
1288
+ // Agregar commentBefore a un nodo específico
1289
+ ctx.services.yaml.comment("Configuración del backend", ["data", "BACKEND_URL"]);
1290
+ ```
1291
+
1292
+ ### Declaraciones batch con `prepare()`
1293
+
1294
+ `prepare()` permite aplicar múltiples mutaciones en una sola llamada — ideal para transformaciones complejas:
1295
+
1296
+ ```typescript
1297
+ ctx.services.yaml.prepare({
1298
+ // Asignar valores por path
1299
+ $set: [
1300
+ { path: "apiVersion", value: "v1" },
1301
+ { path: "metadata.labels.env", value: "production" }
1302
+ ],
1303
+
1304
+ // Agregar a arrays
1305
+ $push: [
1306
+ { path: "spec.containers", value: { name: "sidecar", image: "proxy:v1" } }
1307
+ ],
1308
+
1309
+ // Fusionar objetos existentes
1310
+ $spread: [
1311
+ { path: "metadata.labels", value: { version: "v2", team: "platform" } }
1312
+ ],
1313
+
1314
+ // Asignar el mismo valor a múltiples paths
1315
+ $superSet: {
1316
+ value: "true",
1317
+ $set: ["data.ENABLE_FEATURE_A", "data.ENABLE_FEATURE_B"],
1318
+ $init: ["data.PREFIX"] // concatena al inicio en vez de reemplazar
1319
+ },
1320
+
1321
+ // Asignar valores por path (shorthand)
1322
+ $merge: {
1323
+ "data.RETRY_COUNT": "3",
1324
+ "data.TIMEOUT": "30000"
1325
+ },
1326
+
1327
+ // Eliminar keys
1328
+ $delete: ["data.DEBUG", "data.TEMP"]
1329
+ });
1330
+ ```
1331
+
1332
+ ### Documentos múltiples
1333
+
1334
+ Para archivos YAML con múltiples documentos separados por `---`:
1335
+
1336
+ ```typescript
1337
+ // Crear documentos múltiples
1338
+ ctx.services.yaml.multidocument(
1339
+ { yaml: "kind: Deployment\nmetadata:\n name: api", name: "deployment" },
1340
+ { replicas: 3 } // apply extra values sobre el nuevo doc
1341
+ );
1342
+
1343
+ ctx.services.yaml.multidocument(
1344
+ { yaml: "kind: Service\nmetadata:\n name: api-svc", name: "service" }
1345
+ );
1346
+
1347
+ // Cambiar entre documentos
1348
+ ctx.services.yaml.use("deployment");
1349
+ console.log(ctx.services.yaml.yamlify()); // imprime el doc "deployment"
1350
+
1351
+ ctx.services.yaml.use("service");
1352
+ console.log(ctx.services.yaml.yamlify()); // imprime el doc "service"
1353
+
1354
+ // Verificar si un documento existe
1355
+ ctx.services.yaml.existDocument("deployment"); // true
1356
+ ```
1357
+
1358
+ ### Clonar
1359
+
1360
+ ```typescript
1361
+ const clone = ctx.services.yaml.clone();
1362
+ // clone es independiente — modificar uno no afecta al otro
1363
+ ```
1364
+
1365
+ ### Parsear YAML vacío
1366
+
1367
+ ```typescript
1368
+ ctx.services.yaml.fromYaml(""); // crea documento vacío, no lanza error
1369
+ ```
1370
+
1371
+ ### Ejemplo completo: modificar un Deployment de Kubernetes
1372
+
1373
+ ```typescript
1374
+ ctx.services.yaml.fromYaml(readFileSync("deployment.yaml", "utf8"));
1375
+
1376
+ ctx.services.yaml.prepare({
1377
+ $set: [
1378
+ { path: "spec.template.metadata.labels.version", value: "v2.1.0" },
1379
+ { path: "spec.template.spec.containers.0.image", value: "registry/app:v2.1.0" }
1380
+ ],
1381
+ $spread: [
1382
+ { path: "spec.template.metadata.annotations", value: { "deployed-at": new Date().toISOString() } }
1383
+ ],
1384
+ $delete: ["spec.template.spec.initContainers"]
1385
+ });
1386
+
1387
+ const updatedYaml = ctx.services.yaml.yamlify();
1388
+ writeFileSync("deployment.yaml", updatedYaml);
1389
+ ```
1390
+
1226
1391
  ## Tests
1227
1392
 
1228
1393
  ```bash
@@ -1245,6 +1410,7 @@ npm test
1245
1410
  - `azdo-api.test.js` — AzureDevOpsApi contra mock server: proyectos, repos, branches, commits, PRs, builds, pipelines, work items, overrides
1246
1411
  - `pipeline.test.js` — Pipeline motor: stages/jobs/tasks, dependencias cross-level con paths dotted, resultados jerárquicos (stage.job.task), fluent API, registry, reset, ctx access, detección de tipo por propiedad, PipelineResultsAccessor
1247
1412
  - `service-notify.test.js` — ServiceError, ctx.wrap(), Notifier con service/method/args, classifiers.byService/messages.byService, unwrap de ServiceError en byCommand/byPattern/byRule, integración completa, backward compat
1413
+ - `yaml.test.js` — YamlService: fromYaml/fromJson, yamlGet/yamlSet/yamlPush/yamlOmit, comment(), prepare() con $set/$push/$spread/$superSet/$merge/$delete, multidocument/use/clone
1248
1414
 
1249
1415
  ## Siguientes pasos posibles
1250
1416
 
@@ -1252,3 +1418,4 @@ npm test
1252
1418
  - Agregar más plugins (`ansible-lint`, `trivy`, `sonar-scanner`) con el mismo patrón que `terraform.ts`/`docker.ts`.
1253
1419
  - CI propio (GitHub Actions/Azure Pipelines) que corra `npm test` en cada PR antes de `npm publish`.
1254
1420
  - `--catch=throw` (o similar) para que un item de menú fallido mate el proceso completo en vez de solo loguear y seguir — útil corriendo vía `--menu-selector` dentro de un step de Azure Pipelines.
1421
+ - Exportar tipos YAML (`YamlPrepareActions`) y crear helpers para templates comunes (Kubernetes manifests, Helm values, etc.).
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export { services } from "./services";
8
8
  export type { ServicesRegistry } from "./services";
9
9
  export { PipelineRegistry, Pipeline, PipelineStage, PipelineJob, PipelineTask, PipelineResultsAccessor } from "./services/pipeline";
10
10
  export type { PipelineConfig, PipelineStageConfig, PipelineJobConfig, PipelineTaskConfig, PipelineTaskBase, CallbackTaskConfig, PipelineRunResult, PipelineEntityStatus } from "./services/pipeline";
11
+ export { YamlService } from "./services/yaml";
12
+ export type { YamlPrepareActions } from "./services/yaml";
11
13
  export { http, HttpService, HttpRegistry } from "./services/http";
12
14
  export type { HttpMethod, HttpRequest, HttpResponse, HttpServiceConfig, RequestInterceptor, ResponseInterceptor, RequestContext, ResponseContext } from "./services/http-types";
13
15
  export { AzureDevOpsApi } from "./services/azdo-api";
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ServiceError = exports.messages = exports.classifiers = exports.senders = exports.Notifier = exports.AzureDevOpsApi = exports.HttpRegistry = exports.HttpService = exports.http = exports.PipelineResultsAccessor = exports.PipelineTask = exports.PipelineJob = exports.PipelineStage = exports.Pipeline = exports.PipelineRegistry = exports.services = exports.prompt = exports.logger = exports.Menu = exports.Context = void 0;
36
+ exports.ServiceError = exports.messages = exports.classifiers = exports.senders = exports.Notifier = exports.AzureDevOpsApi = exports.HttpRegistry = exports.HttpService = exports.http = exports.YamlService = exports.PipelineResultsAccessor = exports.PipelineTask = exports.PipelineJob = exports.PipelineStage = exports.Pipeline = exports.PipelineRegistry = exports.services = exports.prompt = exports.logger = exports.Menu = exports.Context = void 0;
37
37
  var Context_1 = require("./core/Context");
38
38
  Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return Context_1.Context; } });
39
39
  var Menu_1 = require("./core/Menu");
@@ -50,6 +50,8 @@ Object.defineProperty(exports, "PipelineStage", { enumerable: true, get: functio
50
50
  Object.defineProperty(exports, "PipelineJob", { enumerable: true, get: function () { return pipeline_1.PipelineJob; } });
51
51
  Object.defineProperty(exports, "PipelineTask", { enumerable: true, get: function () { return pipeline_1.PipelineTask; } });
52
52
  Object.defineProperty(exports, "PipelineResultsAccessor", { enumerable: true, get: function () { return pipeline_1.PipelineResultsAccessor; } });
53
+ var yaml_1 = require("./services/yaml");
54
+ Object.defineProperty(exports, "YamlService", { enumerable: true, get: function () { return yaml_1.YamlService; } });
53
55
  var http_1 = require("./services/http");
54
56
  Object.defineProperty(exports, "http", { enumerable: true, get: function () { return http_1.http; } });
55
57
  Object.defineProperty(exports, "HttpService", { enumerable: true, get: function () { return http_1.HttpService; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAyC;AAAhC,kGAAA,OAAO,OAAA;AAGhB,oCAAmC;AAA1B,4FAAA,IAAI,OAAA;AAEb,wCAAuC;AAA9B,gGAAA,MAAM,OAAA;AAGf,wDAAwC;AAExC,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAGjB,gDAAoI;AAA3H,4GAAA,gBAAgB,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,wGAAA,YAAY,OAAA;AAAE,mHAAA,uBAAuB,OAAA;AAYtG,wCAAkE;AAAzD,4FAAA,IAAI,OAAA;AAAE,mGAAA,WAAW,OAAA;AAAE,oGAAA,YAAY,OAAA;AAYxC,gDAAqD;AAA5C,0GAAA,cAAc,OAAA;AA6BvB,4CAA2C;AAAlC,oGAAA,QAAQ,OAAA;AACjB,0DAA0C;AAC1C,kEAAkD;AAClD,4DAA4C;AAmB5C,sCAA4C;AAAnC,qGAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAyC;AAAhC,kGAAA,OAAO,OAAA;AAGhB,oCAAmC;AAA1B,4FAAA,IAAI,OAAA;AAEb,wCAAuC;AAA9B,gGAAA,MAAM,OAAA;AAGf,wDAAwC;AAExC,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAGjB,gDAAoI;AAA3H,4GAAA,gBAAgB,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,wGAAA,YAAY,OAAA;AAAE,mHAAA,uBAAuB,OAAA;AAYtG,wCAA8C;AAArC,mGAAA,WAAW,OAAA;AAGpB,wCAAkE;AAAzD,4FAAA,IAAI,OAAA;AAAE,mGAAA,WAAW,OAAA;AAAE,oGAAA,YAAY,OAAA;AAYxC,gDAAqD;AAA5C,0GAAA,cAAc,OAAA;AA6BvB,4CAA2C;AAAlC,oGAAA,QAAQ,OAAA;AACjB,0DAA0C;AAC1C,kEAAkD;AAClD,4DAA4C;AAmB5C,sCAA4C;AAAnC,qGAAA,YAAY,OAAA"}
@@ -14,6 +14,7 @@ import * as az from "./az";
14
14
  import * as azdo from "./azdo";
15
15
  import * as http from "./http";
16
16
  import { PipelineRegistry } from "./pipeline";
17
+ import { YamlService } from "./yaml";
17
18
  export declare const services: {
18
19
  shell: import("./shell").Shell;
19
20
  docker: typeof docker;
@@ -31,7 +32,10 @@ export declare const services: {
31
32
  azdo: typeof azdo;
32
33
  http: typeof http;
33
34
  pipeline: PipelineRegistry;
35
+ yaml: YamlService;
34
36
  };
35
37
  export type ServicesRegistry = typeof services;
36
38
  export { shell, docker, git, kubectl, helm, npm, archive, terraform, ansible, argocd, tekton, oc, az, azdo, http };
37
39
  export { PipelineRegistry } from "./pipeline";
40
+ export { YamlService } from "./yaml";
41
+ export type { YamlPrepareActions } from "./yaml";
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.PipelineRegistry = exports.http = exports.azdo = exports.az = exports.oc = exports.tekton = exports.argocd = exports.ansible = exports.terraform = exports.archive = exports.npm = exports.helm = exports.kubectl = exports.git = exports.docker = exports.shell = exports.services = void 0;
36
+ exports.YamlService = exports.PipelineRegistry = exports.http = exports.azdo = exports.az = exports.oc = exports.tekton = exports.argocd = exports.ansible = exports.terraform = exports.archive = exports.npm = exports.helm = exports.kubectl = exports.git = exports.docker = exports.shell = exports.services = void 0;
37
37
  const shell_1 = require("./shell");
38
38
  Object.defineProperty(exports, "shell", { enumerable: true, get: function () { return shell_1.shell; } });
39
39
  const docker = __importStar(require("./docker"));
@@ -65,6 +65,7 @@ exports.azdo = azdo;
65
65
  const http = __importStar(require("./http"));
66
66
  exports.http = http;
67
67
  const pipeline_1 = require("./pipeline");
68
+ const yaml_1 = require("./yaml");
68
69
  exports.services = {
69
70
  shell: shell_1.shell,
70
71
  docker,
@@ -81,8 +82,11 @@ exports.services = {
81
82
  az,
82
83
  azdo,
83
84
  http,
84
- pipeline: new pipeline_1.PipelineRegistry()
85
+ pipeline: new pipeline_1.PipelineRegistry(),
86
+ yaml: new yaml_1.YamlService()
85
87
  };
86
88
  var pipeline_2 = require("./pipeline");
87
89
  Object.defineProperty(exports, "PipelineRegistry", { enumerable: true, get: function () { return pipeline_2.PipelineRegistry; } });
90
+ var yaml_2 = require("./yaml");
91
+ Object.defineProperty(exports, "YamlService", { enumerable: true, get: function () { return yaml_2.YamlService; } });
88
92
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAgC;AAuC5B,sFAvCK,aAAK,OAuCL;AAtCT,iDAAmC;AAuC/B,wBAAM;AAtCV,2CAA6B;AAuCzB,kBAAG;AAtCP,mDAAqC;AAuCjC,0BAAO;AAtCX,6CAA+B;AAuC3B,oBAAI;AAtCR,2CAA6B;AAuCzB,kBAAG;AAtCP,mDAAqC;AAuCjC,0BAAO;AAtCX,uDAAyC;AAuCrC,8BAAS;AAtCb,mDAAqC;AAuCjC,0BAAO;AAtCX,iDAAmC;AAuC/B,wBAAM;AAtCV,iDAAmC;AAuC/B,wBAAM;AAtCV,yCAA2B;AAuCvB,gBAAE;AAtCN,yCAA2B;AAuCvB,gBAAE;AAtCN,6CAA+B;AAuC3B,oBAAI;AAtCR,6CAA+B;AAuC3B,oBAAI;AAtCR,yCAA8C;AAEjC,QAAA,QAAQ,GAAG;IACpB,KAAK,EAAL,aAAK;IACL,MAAM;IACN,GAAG;IACH,OAAO;IACP,IAAI;IACJ,GAAG;IACH,OAAO;IACP,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;IACN,EAAE;IACF,EAAE;IACF,IAAI;IACJ,IAAI;IACJ,QAAQ,EAAE,IAAI,2BAAgB,EAAE;CACnC,CAAC;AAsBF,uCAA8C;AAArC,4GAAA,gBAAgB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAgC;AAyC5B,sFAzCK,aAAK,OAyCL;AAxCT,iDAAmC;AAyC/B,wBAAM;AAxCV,2CAA6B;AAyCzB,kBAAG;AAxCP,mDAAqC;AAyCjC,0BAAO;AAxCX,6CAA+B;AAyC3B,oBAAI;AAxCR,2CAA6B;AAyCzB,kBAAG;AAxCP,mDAAqC;AAyCjC,0BAAO;AAxCX,uDAAyC;AAyCrC,8BAAS;AAxCb,mDAAqC;AAyCjC,0BAAO;AAxCX,iDAAmC;AAyC/B,wBAAM;AAxCV,iDAAmC;AAyC/B,wBAAM;AAxCV,yCAA2B;AAyCvB,gBAAE;AAxCN,yCAA2B;AAyCvB,gBAAE;AAxCN,6CAA+B;AAyC3B,oBAAI;AAxCR,6CAA+B;AAyC3B,oBAAI;AAxCR,yCAA8C;AAC9C,iCAAqC;AAExB,QAAA,QAAQ,GAAG;IACpB,KAAK,EAAL,aAAK;IACL,MAAM;IACN,GAAG;IACH,OAAO;IACP,IAAI;IACJ,GAAG;IACH,OAAO;IACP,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;IACN,EAAE;IACF,EAAE;IACF,IAAI;IACJ,IAAI;IACJ,QAAQ,EAAE,IAAI,2BAAgB,EAAE;IAChC,IAAI,EAAE,IAAI,kBAAW,EAAE;CAC1B,CAAC;AAsBF,uCAA8C;AAArC,4GAAA,gBAAgB,OAAA;AACzB,+BAAqC;AAA5B,mGAAA,WAAW,OAAA"}
@@ -0,0 +1,47 @@
1
+ import * as yamlLib from "yaml";
2
+ export interface YamlPrepareActions {
3
+ $set?: Array<{
4
+ path: string | string[];
5
+ value: any;
6
+ }>;
7
+ $push?: Array<{
8
+ path: string | string[];
9
+ value: any;
10
+ }>;
11
+ $spread?: Array<{
12
+ path: string | string[];
13
+ value: Record<string, any>;
14
+ }>;
15
+ $superSet?: Array<{
16
+ value: any;
17
+ $set?: Array<string | string[]>;
18
+ $init?: Array<string | string[]>;
19
+ }>;
20
+ $merge?: Record<string, any>;
21
+ $delete?: string[];
22
+ }
23
+ export declare class YamlService {
24
+ metadata: yamlLib.Document;
25
+ documents: Record<string, yamlLib.Document>;
26
+ using: string;
27
+ fromYaml(yaml?: string): yamlLib.Document;
28
+ fromJson(json?: Record<string, any>): yamlLib.Document;
29
+ yamlify(json?: Record<string, any>): string;
30
+ jsonify(): any;
31
+ stringify(): string;
32
+ yamlGet(propPath: string, defaultValue?: any): any;
33
+ yamlSet(path: string[], value: any): void;
34
+ yamlPush(path: string[], value: any): void;
35
+ yamlConcatInitAndSet(path: string[], value: any): void;
36
+ yamlOmit(paths?: string[]): void;
37
+ comment(text: string, afterPath?: string[]): void;
38
+ prepare(actions: YamlPrepareActions): void;
39
+ multidocument(params: {
40
+ yaml?: string;
41
+ json?: Record<string, any>;
42
+ name: string;
43
+ }, extra?: Record<string, any>): void;
44
+ use(name: string): yamlLib.Document;
45
+ existDocument(name: string): boolean;
46
+ clone(): YamlService;
47
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.YamlService = void 0;
37
+ const yamlLib = __importStar(require("yaml"));
38
+ const lodash_1 = require("lodash");
39
+ class YamlService {
40
+ constructor() {
41
+ this.metadata = new yamlLib.Document();
42
+ this.documents = {};
43
+ this.using = "default";
44
+ }
45
+ fromYaml(yaml) {
46
+ this.metadata = yamlLib.parseDocument(yaml || "");
47
+ return this.metadata;
48
+ }
49
+ fromJson(json) {
50
+ return this.fromYaml(this.yamlify(json));
51
+ }
52
+ yamlify(json) {
53
+ return json ? yamlLib.stringify(json) : this.metadata.toString();
54
+ }
55
+ jsonify() {
56
+ return this.metadata.toJSON();
57
+ }
58
+ stringify() {
59
+ return JSON.stringify(this.jsonify(), null, 2);
60
+ }
61
+ yamlGet(propPath, defaultValue) {
62
+ return (0, lodash_1.get)(this.jsonify(), propPath) || defaultValue;
63
+ }
64
+ yamlSet(path, value) {
65
+ this.metadata.setIn(path, value);
66
+ }
67
+ yamlPush(path, value) {
68
+ const original = this.yamlGet(path.join("."), []);
69
+ original.push(...(Array.isArray(value) ? value : [value]));
70
+ this.yamlSet(path, original);
71
+ }
72
+ yamlConcatInitAndSet(path, value) {
73
+ const original = this.yamlGet(path.join("."));
74
+ this.yamlSet(path, `${value}${original}`);
75
+ }
76
+ yamlOmit(paths) {
77
+ const data = this.jsonify();
78
+ this.fromJson((0, lodash_1.omit)(data, paths || []));
79
+ }
80
+ comment(text, afterPath) {
81
+ let actualProp = this.metadata;
82
+ for (const prop of afterPath || []) {
83
+ actualProp = actualProp.get(prop, true);
84
+ }
85
+ actualProp.commentBefore = `##!!COMMENT!!## ${text}`;
86
+ }
87
+ prepare(actions) {
88
+ for (const sa of actions.$set || []) {
89
+ const key = typeof sa.path === "string" ? sa.path.split(".") : sa.path;
90
+ this.yamlSet(key, sa.value);
91
+ }
92
+ for (const pa of actions.$push || []) {
93
+ const key = typeof pa.path === "string" ? pa.path.split(".") : pa.path;
94
+ this.yamlPush(key, pa.value);
95
+ }
96
+ for (const spa of actions.$spread || []) {
97
+ const key = typeof spa.path === "string" ? spa.path.split(".") : spa.path;
98
+ this.yamlSet(key, { ...this.yamlGet(key.join(".")), ...spa.value });
99
+ }
100
+ for (const ssa of actions.$superSet || []) {
101
+ for (const ssaKey of ssa.$set || []) {
102
+ const key = typeof ssaKey === "string" ? ssaKey.split(".") : ssaKey;
103
+ this.yamlSet(key, ssa.value);
104
+ }
105
+ for (const ssaKey of ssa.$init || []) {
106
+ const key = typeof ssaKey === "string" ? ssaKey.split(".") : ssaKey;
107
+ this.yamlConcatInitAndSet(key, ssa.value);
108
+ }
109
+ }
110
+ for (const [key, value] of Object.entries(actions.$merge || {})) {
111
+ this.yamlSet(key.split("."), value);
112
+ }
113
+ this.yamlOmit(actions.$delete);
114
+ }
115
+ multidocument(params, extra) {
116
+ (0, lodash_1.set)(this.documents, this.using, this.metadata);
117
+ this.using = params.name;
118
+ if (params.yaml)
119
+ this.fromYaml(params.yaml);
120
+ else if (params.json)
121
+ this.fromJson(params.json);
122
+ if (extra)
123
+ this.prepare({ $merge: { ...extra } });
124
+ (0, lodash_1.set)(this.documents, params.name, this.metadata);
125
+ }
126
+ use(name) {
127
+ (0, lodash_1.set)(this.documents, this.using, this.metadata);
128
+ this.metadata = (0, lodash_1.get)(this.documents, name);
129
+ this.using = name;
130
+ return this.metadata;
131
+ }
132
+ existDocument(name) {
133
+ return (0, lodash_1.has)(this.documents, name);
134
+ }
135
+ clone() {
136
+ const clone = new YamlService();
137
+ clone.metadata = yamlLib.parseDocument(this.metadata.toString());
138
+ clone.using = this.using;
139
+ for (const [key, doc] of Object.entries(this.documents)) {
140
+ clone.documents[key] = yamlLib.parseDocument(doc.toString());
141
+ }
142
+ return clone;
143
+ }
144
+ }
145
+ exports.YamlService = YamlService;
146
+ //# sourceMappingURL=yaml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.js","sourceRoot":"","sources":["../../src/services/yaml.ts"],"names":[],"mappings":";;;;;;;;;;;;;;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AAY;QACZ,IAAA,YAAG,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,QAAQ,GAAG,IAAA,YAAG,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,OAAO,IAAA,YAAG,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,KAAK;QACD,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAEzB,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACtD,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAjID,kCAiIC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cat-indev/catops-cli",
3
- "version": "0.0.1-alpha.11",
3
+ "version": "0.0.1-alpha.12",
4
4
  "description": "Framework CLI para pipelines DevOps (shell, docker, git, kubectl, helm, npm, terraform, ansible, argocd, tekton, oc, az) sobre un ExecutionContext compartido, con menus interactivos y selectores automaticos por flag. Escrito en TypeScript, 100% usable desde JavaScript.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -51,8 +51,13 @@
51
51
  "node": ">=18"
52
52
  },
53
53
  "devDependencies": {
54
+ "@types/lodash": "^4.17.25",
54
55
  "@types/node": "^20.14.0",
55
56
  "typescript": "^5.5.0"
56
57
  },
57
- "license": "MIT"
58
+ "license": "MIT",
59
+ "dependencies": {
60
+ "lodash": "^4.18.1",
61
+ "yaml": "^2.9.0"
62
+ }
58
63
  }