@gzl10/osx-cli 4.0.0 → 4.0.2

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/dist/cli.js CHANGED
@@ -5,10 +5,44 @@ import {
5
5
  } from "./chunk-ILUPEXRP.js";
6
6
 
7
7
  // src/cli.ts
8
+ import { readFileSync as readFileSync2 } from "fs";
9
+ import { dirname, join as join2 } from "path";
10
+ import { fileURLToPath } from "url";
8
11
  import { program } from "commander";
9
12
 
10
13
  // src/commands/extract.ts
11
- import { writeFileSync } from "fs";
14
+ import { existsSync, readFileSync, writeFileSync } from "fs";
15
+ import { homedir } from "os";
16
+ import { join } from "path";
17
+ function loadHomeEnv() {
18
+ const envPath = join(homedir(), ".env");
19
+ if (!existsSync(envPath)) return {};
20
+ const content = readFileSync(envPath, "utf-8").replace(/^\uFEFF/, "");
21
+ const vars = {};
22
+ for (const line of content.split(/\r?\n/)) {
23
+ const trimmed = line.trim();
24
+ const match = trimmed.match(/^(\w+)=(.*)$/);
25
+ if (match) {
26
+ vars[match[1]] = match[2].replace(/^["']|["']$/g, "").trim();
27
+ }
28
+ }
29
+ if (vars.USER || vars.PWD) {
30
+ console.error(`Usando credenciales de ${envPath}`);
31
+ }
32
+ return {
33
+ user: vars.USER,
34
+ password: vars.PWD
35
+ };
36
+ }
37
+ function setupTnsAdmin() {
38
+ if (process.env.TNS_ADMIN) return;
39
+ const home = homedir();
40
+ const tnsPath = join(home, "tnsnames.ora");
41
+ if (existsSync(tnsPath)) {
42
+ process.env.TNS_ADMIN = home;
43
+ console.error(`Usando tnsnames.ora de ${home}`);
44
+ }
45
+ }
12
46
  function formatOracleError(message, tns, schema) {
13
47
  if (message.includes("ORA-01017")) {
14
48
  return `
@@ -83,15 +117,23 @@ function formatOracleError(message, tns, schema) {
83
117
  `;
84
118
  }
85
119
  async function extractCommand(tables, options) {
86
- const user = options.user || process.env.OSX_USER;
87
- const password = options.password || process.env.OSX_PASSWORD;
120
+ const homeEnv = loadHomeEnv();
121
+ const user = options.user || process.env.OSX_USER || homeEnv.user;
122
+ const password = options.password || process.env.OSX_PASSWORD || homeEnv.password;
88
123
  const schema = options.schema || options.tns;
124
+ if (!options.tns) {
125
+ console.error(
126
+ '\n\u274C Error: Debes especificar el TNS o conexi\xF3n\n\nUso:\n osx extract <TABLA> --tns <ALIAS> # Usa tnsnames.ora\n osx extract <TABLA> --tns host:port/sid # Easy Connect\n\nEjemplos:\n osx extract D0001 --tns MDI1\n osx extract D0001 --tns "BDMDI1:1523/MDI1"\n'
127
+ );
128
+ process.exit(1);
129
+ }
89
130
  if (!user || !password) {
90
131
  console.error(
91
- "\n\u274C Error: Credenciales de Oracle no proporcionadas\n\nDebes especificar usuario y password de una de estas formas:\n\n 1. Flags de l\xEDnea de comandos:\n osx extract D0001 --tns TRON_LD -u USUARIO -p PASSWORD\n\n 2. Variables de entorno:\n export OSX_USER=USUARIO\n export OSX_PASSWORD=PASSWORD\n osx extract D0001 --tns TRON_LD\n"
132
+ "\n\u274C Error: Credenciales de Oracle no proporcionadas\n\nEspecifica usuario y password de una de estas formas:\n\n 1. Flags de l\xEDnea de comandos:\n osx extract D0001 --tns MDI1 -u USUARIO -p PASSWORD\n\n 2. Variables de entorno (OSX_USER, OSX_PASSWORD):\n export OSX_USER=USUARIO\n export OSX_PASSWORD=PASSWORD\n\n 3. Archivo ~/.env con USER y PWD:\n USER=USUARIO\n PWD=PASSWORD\n"
92
133
  );
93
134
  process.exit(1);
94
135
  }
136
+ setupTnsAdmin();
95
137
  const oracle = new OracleService();
96
138
  try {
97
139
  console.error(`Conectando a ${options.tns}...`);
@@ -126,6 +168,8 @@ async function extractCommand(tables, options) {
126
168
  }
127
169
 
128
170
  // src/cli.ts
129
- program.name("osx").description("Oracle Schema Extractor - Genera JSON compatible con Atlas OriginType=BBDD").version("1.0.0");
130
- program.command("extract <tables>").description("Extrae esquema de tabla(s) Oracle. Tablas separadas por coma.").requiredOption("-t, --tns <alias>", "Alias TNS de tnsnames.ora").option("-s, --schema <name>", "Schema Oracle (default: mismo que TNS)").option("-u, --user <user>", "Usuario Oracle (o env: OSX_USER)").option("-p, --password <pass>", "Password Oracle (o env: OSX_PASSWORD)").option("-o, --output <file>", "Fichero de salida (default: stdout)").option("--pretty", "JSON formateado con indentacion").option("-d, --delay <ms>", "Delay entre tablas en ms", "0").action(extractCommand);
171
+ var __dirname2 = dirname(fileURLToPath(import.meta.url));
172
+ var pkg = JSON.parse(readFileSync2(join2(__dirname2, "..", "package.json"), "utf-8"));
173
+ program.name("osx").description("Oracle Schema Extractor - Genera JSON compatible con Atlas OriginType=BBDD").version(pkg.version);
174
+ program.command("extract <tables>").description("Extrae esquema de tabla(s) Oracle. Tablas separadas por coma.").option("-t, --tns <alias>", "Alias TNS o Easy Connect (host:port/service)").option("-s, --schema <name>", "Schema Oracle (default: mismo que TNS)").option("-u, --user <user>", "Usuario Oracle (o env: OSX_USER)").option("-p, --password <pass>", "Password Oracle (o env: OSX_PASSWORD)").option("-o, --output <file>", "Fichero de salida (default: stdout)").option("--pretty", "JSON formateado con indentacion").option("-d, --delay <ms>", "Delay entre tablas en ms", "0").action(extractCommand);
131
175
  program.parse();
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ interface TableSchema {
24
24
  * Opciones del comando extract
25
25
  */
26
26
  interface ExtractOptions {
27
- tns: string;
27
+ tns?: string;
28
28
  schema?: string;
29
29
  user?: string;
30
30
  password?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gzl10/osx-cli",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Oracle Schema Extractor CLI - Genera JSON compatible con Atlas OriginType=BBDD",
5
5
  "type": "module",
6
6
  "bin": {