dbcube 1.0.0 → 1.0.1

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/.npmignore DELETED
@@ -1,51 +0,0 @@
1
- # Directories
2
- examples
3
-
4
- # Ignorar dependencias y configuraciones de desarrollo
5
- node_modules/
6
- npm-debug.log*
7
- yarn-debug.log*
8
- yarn-error.log*
9
-
10
- # Ignorar carpetas y archivos irrelevantes
11
- .vscode/
12
- .lh
13
- .idea/
14
- .DS_Store
15
- Thumbs.db
16
- *.log
17
-
18
- # Ignorar configuraciones del proyecto
19
- .env
20
- .env.*.local
21
- package-lock.json
22
-
23
- # Ignorar archivos del sistema
24
- *.swp
25
- *.swo
26
- *.tmp
27
- *.temp
28
-
29
- # Ignorar carpetas de trabajo
30
- temp/
31
- logs/
32
- debug/
33
-
34
- # Ignorar archivos de compilación
35
- src/
36
- tsconfig.json
37
- tsconfig.tsbuildinfo
38
-
39
- # Ignorar pruebas y configuraciones
40
- tests/
41
- __tests__/
42
- __mocks__/
43
- coverage/
44
- jest.config.js
45
-
46
- # Ignorar documentación o ejemplos no necesarios
47
- docs/
48
- examples/
49
-
50
- # Asegurarse de incluir solo lo esencial
51
- !.npmignore
package/CONTRIBUTING.md DELETED
@@ -1,9 +0,0 @@
1
- ## Colaboración
2
-
3
- Si deseas contribuir a este proyecto, sigue estos pasos:
4
-
5
- 1. Haz un fork del repositorio.
6
- 2. Crea una nueva rama (`git checkout -b feature/nueva-caracteristica`).
7
- 3. Realiza tus cambios y haz commit de ellos (`git commit -am 'Añadir nueva característica'`).
8
- 4. Sube tu rama (`git push origin feature/nueva-caracteristica`).
9
- 5. Abre un Pull Request.
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Albert Araya - Dbcube
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
File without changes
package/dist/index.cjs DELETED
@@ -1,153 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- Dbcube: () => Dbcube
34
- });
35
- module.exports = __toCommonJS(index_exports);
36
-
37
- // src/lib/Dbcube.ts
38
- var import_core = require("@dbcube/core");
39
- var import_query_builder = require("@dbcube/query-builder");
40
-
41
- // src/lib/FileUtils.ts
42
- var fs = __toESM(require("fs"));
43
- var path = __toESM(require("path"));
44
- var FileUtils = class {
45
- /**
46
- * Verifica si un archivo existe (asincrónico).
47
- * @param filePath - Ruta del archivo.
48
- * @returns Promise que resuelve true si el archivo existe, false si no.
49
- */
50
- static async fileExists(filePath) {
51
- return new Promise((resolve2) => {
52
- fs.access(path.resolve(filePath), fs.constants.F_OK, (err) => {
53
- resolve2(!err);
54
- });
55
- });
56
- }
57
- /**
58
- * Verifica si un archivo existe (sincrónico).
59
- * @param filePath - Ruta del archivo.
60
- * @returns True si el archivo existe, false si no.
61
- */
62
- static fileExistsSync(filePath) {
63
- try {
64
- fs.accessSync(path.resolve(filePath), fs.constants.F_OK);
65
- return true;
66
- } catch {
67
- return false;
68
- }
69
- }
70
- /**
71
- * Extrae el nombre de la base de datos de un string con formato @database().
72
- * @param input - String de entrada que contiene la referencia a la base de datos.
73
- * @returns El nombre de la base de datos o null si no se encuentra.
74
- */
75
- static extractDatabaseName(input) {
76
- const match = input.match(/@database\(["']?([\w-]+)["']?\)/);
77
- return match ? match[1] : null;
78
- }
79
- /**
80
- * Lee recursivamente archivos que terminan en un sufijo dado y los ordena numéricamente.
81
- * @param dir - Directorio base (relativo o absoluto).
82
- * @param suffix - Sufijo de archivo (como 'table.cube').
83
- * @returns Rutas absolutas de los archivos encontrados y ordenados.
84
- */
85
- static getCubeFilesRecursively(dir, suffix) {
86
- const baseDir = path.resolve(dir);
87
- const cubeFiles = [];
88
- function recurse(currentDir) {
89
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
90
- for (const entry of entries) {
91
- const fullPath = path.join(currentDir, entry.name);
92
- if (entry.isDirectory()) {
93
- recurse(fullPath);
94
- } else if (entry.isFile() && entry.name.endsWith(suffix)) {
95
- cubeFiles.push(fullPath);
96
- }
97
- }
98
- }
99
- recurse(baseDir);
100
- cubeFiles.sort((a, b) => {
101
- const aNum = parseInt(path.basename(a));
102
- const bNum = parseInt(path.basename(b));
103
- return (isNaN(aNum) ? 0 : aNum) - (isNaN(bNum) ? 0 : bNum);
104
- });
105
- return cubeFiles;
106
- }
107
- };
108
- var FileUtils_default = FileUtils;
109
-
110
- // src/lib/Dbcube.ts
111
- var import_path = __toESM(require("path"));
112
- var Dbcube = class _Dbcube {
113
- static instance;
114
- configPath;
115
- config;
116
- databases;
117
- initialized;
118
- constructor() {
119
- if (_Dbcube.instance) {
120
- return _Dbcube.instance;
121
- }
122
- this.configPath = import_path.default.join(process.cwd(), "dbcube.config.js");
123
- this.config = new import_core.Config();
124
- this.databases = {};
125
- this.initialized = false;
126
- _Dbcube.instance = this;
127
- }
128
- async loadConfig() {
129
- const exists = await FileUtils_default.fileExists(this.configPath);
130
- exists ?? console.log("\u274C Dont exists config file, please create a dbcube.config.js file");
131
- }
132
- async init(configCreate = {}) {
133
- if (this.initialized) return;
134
- await this.loadConfig();
135
- const config = require(this.configPath);
136
- config(this.config);
137
- const databases = Object.keys(this.config.getAllDatabases());
138
- for (const database of databases) {
139
- this.databases[database] = new import_query_builder.Database(database);
140
- }
141
- if (configCreate.databaseName) {
142
- this.databases[configCreate.databaseName] = new import_query_builder.Database(configCreate.databaseName);
143
- }
144
- }
145
- database(databaseName) {
146
- return this.databases[databaseName];
147
- }
148
- };
149
- // Annotate the CommonJS export names for ESM import in node:
150
- 0 && (module.exports = {
151
- Dbcube
152
- });
153
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/Dbcube.ts","../src/lib/FileUtils.ts"],"sourcesContent":["import { Dbcube } from './lib/Dbcube';\r\n\r\n\r\nexport { Dbcube };","import { Config } from '@dbcube/core';\r\nimport { Database } from '@dbcube/query-builder';\r\nimport FileUtils from './FileUtils';\r\nimport path from 'path';\r\n\r\nexport class Dbcube {\r\n private static instance: Dbcube;\r\n private configPath!: string;\r\n private config: any;\r\n private databases!: Record<string, any>;\r\n private initialized!: boolean;\r\n\r\n\r\n constructor() {\r\n if (Dbcube.instance) {\r\n return Dbcube.instance;\r\n }\r\n this.configPath = path.join(process.cwd(), 'dbcube.config.js');\r\n this.config = new Config();\r\n this.databases = {};\r\n this.initialized = false;\r\n\r\n Dbcube.instance = this;\r\n }\r\n\r\n async loadConfig() {\r\n const exists = await FileUtils.fileExists(this.configPath);\r\n exists ?? console.log('❌ Dont exists config file, please create a dbcube.config.js file');\r\n }\r\n\r\n\r\n async init(configCreate: { databaseName?: string; motor?: string; configAnswers?: any } = {}) {\r\n if (this.initialized) return;\r\n await this.loadConfig();\r\n const config = require(this.configPath);\r\n \r\n config(this.config);\r\n const databases = Object.keys(this.config.getAllDatabases());\r\n \r\n for (const database of databases) {\r\n this.databases[database] = new Database(database);\r\n }\r\n if(configCreate.databaseName){\r\n this.databases[configCreate.databaseName] = new Database(configCreate.databaseName);\r\n }\r\n }\r\n\r\n database(databaseName: string){\r\n return this.databases[databaseName];\r\n }\r\n}\r\n\r\nexport default Dbcube;","import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nexport class FileUtils {\r\n /**\r\n * Verifica si un archivo existe (asincrónico).\r\n * @param filePath - Ruta del archivo.\r\n * @returns Promise que resuelve true si el archivo existe, false si no.\r\n */\r\n static async fileExists(filePath: string): Promise<boolean> {\r\n return new Promise<boolean>((resolve) => {\r\n fs.access(path.resolve(filePath), fs.constants.F_OK, (err) => {\r\n resolve(!err);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Verifica si un archivo existe (sincrónico).\r\n * @param filePath - Ruta del archivo.\r\n * @returns True si el archivo existe, false si no.\r\n */\r\n static fileExistsSync(filePath: string): boolean {\r\n try {\r\n fs.accessSync(path.resolve(filePath), fs.constants.F_OK);\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Extrae el nombre de la base de datos de un string con formato @database().\r\n * @param input - String de entrada que contiene la referencia a la base de datos.\r\n * @returns El nombre de la base de datos o null si no se encuentra.\r\n */\r\n static extractDatabaseName(input: string): string | null {\r\n const match = input.match(/@database\\([\"']?([\\w-]+)[\"']?\\)/);\r\n return match ? match[1] : null;\r\n }\r\n\r\n /**\r\n * Lee recursivamente archivos que terminan en un sufijo dado y los ordena numéricamente.\r\n * @param dir - Directorio base (relativo o absoluto).\r\n * @param suffix - Sufijo de archivo (como 'table.cube').\r\n * @returns Rutas absolutas de los archivos encontrados y ordenados.\r\n */\r\n static getCubeFilesRecursively(dir: string, suffix: string): string[] {\r\n const baseDir = path.resolve(dir); // ✅ Asegura que sea absoluto\r\n const cubeFiles: string[] = [];\r\n\r\n function recurse(currentDir: string): void {\r\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\r\n \r\n for (const entry of entries) {\r\n const fullPath = path.join(currentDir, entry.name);\r\n \r\n if (entry.isDirectory()) {\r\n recurse(fullPath);\r\n } else if (entry.isFile() && entry.name.endsWith(suffix)) {\r\n cubeFiles.push(fullPath); // Ya es absoluta\r\n }\r\n }\r\n }\r\n\r\n recurse(baseDir);\r\n\r\n // Ordenar por número si los archivos comienzan con un número\r\n cubeFiles.sort((a: string, b: string) => {\r\n const aNum = parseInt(path.basename(a));\r\n const bNum = parseInt(path.basename(b));\r\n return (isNaN(aNum) ? 0 : aNum) - (isNaN(bNum) ? 0 : bNum);\r\n });\r\n\r\n return cubeFiles;\r\n }\r\n}\r\n\r\nexport default FileUtils;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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private static instance;
3
- private configPath;
4
- private config;
5
- private databases;
6
- private initialized;
7
- constructor();
8
- loadConfig(): Promise<void>;
9
- init(configCreate?: {
10
- databaseName?: string;
11
- motor?: string;
12
- configAnswers?: any;
13
- }): Promise<void>;
14
- database(databaseName: string): any;
15
- }
16
-
17
- export { Dbcube };
package/dist/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- declare class Dbcube {
2
- private static instance;
3
- private configPath;
4
- private config;
5
- private databases;
6
- private initialized;
7
- constructor();
8
- loadConfig(): Promise<void>;
9
- init(configCreate?: {
10
- databaseName?: string;
11
- motor?: string;
12
- configAnswers?: any;
13
- }): Promise<void>;
14
- database(databaseName: string): any;
15
- }
16
-
17
- export { Dbcube };
package/dist/index.js DELETED
@@ -1,123 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- // src/lib/Dbcube.ts
9
- import { Config } from "@dbcube/core";
10
- import { Database } from "@dbcube/query-builder";
11
-
12
- // src/lib/FileUtils.ts
13
- import * as fs from "fs";
14
- import * as path from "path";
15
- var FileUtils = class {
16
- /**
17
- * Verifica si un archivo existe (asincrónico).
18
- * @param filePath - Ruta del archivo.
19
- * @returns Promise que resuelve true si el archivo existe, false si no.
20
- */
21
- static async fileExists(filePath) {
22
- return new Promise((resolve2) => {
23
- fs.access(path.resolve(filePath), fs.constants.F_OK, (err) => {
24
- resolve2(!err);
25
- });
26
- });
27
- }
28
- /**
29
- * Verifica si un archivo existe (sincrónico).
30
- * @param filePath - Ruta del archivo.
31
- * @returns True si el archivo existe, false si no.
32
- */
33
- static fileExistsSync(filePath) {
34
- try {
35
- fs.accessSync(path.resolve(filePath), fs.constants.F_OK);
36
- return true;
37
- } catch {
38
- return false;
39
- }
40
- }
41
- /**
42
- * Extrae el nombre de la base de datos de un string con formato @database().
43
- * @param input - String de entrada que contiene la referencia a la base de datos.
44
- * @returns El nombre de la base de datos o null si no se encuentra.
45
- */
46
- static extractDatabaseName(input) {
47
- const match = input.match(/@database\(["']?([\w-]+)["']?\)/);
48
- return match ? match[1] : null;
49
- }
50
- /**
51
- * Lee recursivamente archivos que terminan en un sufijo dado y los ordena numéricamente.
52
- * @param dir - Directorio base (relativo o absoluto).
53
- * @param suffix - Sufijo de archivo (como 'table.cube').
54
- * @returns Rutas absolutas de los archivos encontrados y ordenados.
55
- */
56
- static getCubeFilesRecursively(dir, suffix) {
57
- const baseDir = path.resolve(dir);
58
- const cubeFiles = [];
59
- function recurse(currentDir) {
60
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
61
- for (const entry of entries) {
62
- const fullPath = path.join(currentDir, entry.name);
63
- if (entry.isDirectory()) {
64
- recurse(fullPath);
65
- } else if (entry.isFile() && entry.name.endsWith(suffix)) {
66
- cubeFiles.push(fullPath);
67
- }
68
- }
69
- }
70
- recurse(baseDir);
71
- cubeFiles.sort((a, b) => {
72
- const aNum = parseInt(path.basename(a));
73
- const bNum = parseInt(path.basename(b));
74
- return (isNaN(aNum) ? 0 : aNum) - (isNaN(bNum) ? 0 : bNum);
75
- });
76
- return cubeFiles;
77
- }
78
- };
79
- var FileUtils_default = FileUtils;
80
-
81
- // src/lib/Dbcube.ts
82
- import path2 from "path";
83
- var Dbcube = class _Dbcube {
84
- static instance;
85
- configPath;
86
- config;
87
- databases;
88
- initialized;
89
- constructor() {
90
- if (_Dbcube.instance) {
91
- return _Dbcube.instance;
92
- }
93
- this.configPath = path2.join(process.cwd(), "dbcube.config.js");
94
- this.config = new Config();
95
- this.databases = {};
96
- this.initialized = false;
97
- _Dbcube.instance = this;
98
- }
99
- async loadConfig() {
100
- const exists = await FileUtils_default.fileExists(this.configPath);
101
- exists ?? console.log("\u274C Dont exists config file, please create a dbcube.config.js file");
102
- }
103
- async init(configCreate = {}) {
104
- if (this.initialized) return;
105
- await this.loadConfig();
106
- const config = __require(this.configPath);
107
- config(this.config);
108
- const databases = Object.keys(this.config.getAllDatabases());
109
- for (const database of databases) {
110
- this.databases[database] = new Database(database);
111
- }
112
- if (configCreate.databaseName) {
113
- this.databases[configCreate.databaseName] = new Database(configCreate.databaseName);
114
- }
115
- }
116
- database(databaseName) {
117
- return this.databases[databaseName];
118
- }
119
- };
120
- export {
121
- Dbcube
122
- };
123
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/Dbcube.ts","../src/lib/FileUtils.ts"],"sourcesContent":["import { Config } from '@dbcube/core';\r\nimport { Database } from '@dbcube/query-builder';\r\nimport FileUtils from './FileUtils';\r\nimport path from 'path';\r\n\r\nexport class Dbcube {\r\n private static instance: Dbcube;\r\n private configPath!: string;\r\n private config: any;\r\n private databases!: Record<string, any>;\r\n private initialized!: boolean;\r\n\r\n\r\n constructor() {\r\n if (Dbcube.instance) {\r\n return Dbcube.instance;\r\n }\r\n this.configPath = path.join(process.cwd(), 'dbcube.config.js');\r\n this.config = new Config();\r\n this.databases = {};\r\n this.initialized = false;\r\n\r\n Dbcube.instance = this;\r\n }\r\n\r\n async loadConfig() {\r\n const exists = await FileUtils.fileExists(this.configPath);\r\n exists ?? console.log('❌ Dont exists config file, please create a dbcube.config.js file');\r\n }\r\n\r\n\r\n async init(configCreate: { databaseName?: string; motor?: string; configAnswers?: any } = {}) {\r\n if (this.initialized) return;\r\n await this.loadConfig();\r\n const config = require(this.configPath);\r\n \r\n config(this.config);\r\n const databases = Object.keys(this.config.getAllDatabases());\r\n \r\n for (const database of databases) {\r\n this.databases[database] = new Database(database);\r\n }\r\n if(configCreate.databaseName){\r\n this.databases[configCreate.databaseName] = new Database(configCreate.databaseName);\r\n }\r\n }\r\n\r\n database(databaseName: string){\r\n return this.databases[databaseName];\r\n }\r\n}\r\n\r\nexport default Dbcube;","import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nexport class FileUtils {\r\n /**\r\n * Verifica si un archivo existe (asincrónico).\r\n * @param filePath - Ruta del archivo.\r\n * @returns Promise que resuelve true si el archivo existe, false si no.\r\n */\r\n static async fileExists(filePath: string): Promise<boolean> {\r\n return new Promise<boolean>((resolve) => {\r\n fs.access(path.resolve(filePath), fs.constants.F_OK, (err) => {\r\n resolve(!err);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Verifica si un archivo existe (sincrónico).\r\n * @param filePath - Ruta del archivo.\r\n * @returns True si el archivo existe, false si no.\r\n */\r\n static fileExistsSync(filePath: string): boolean {\r\n try {\r\n fs.accessSync(path.resolve(filePath), fs.constants.F_OK);\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Extrae el nombre de la base de datos de un string con formato @database().\r\n * @param input - String de entrada que contiene la referencia a la base de datos.\r\n * @returns El nombre de la base de datos o null si no se encuentra.\r\n */\r\n static extractDatabaseName(input: string): string | null {\r\n const match = input.match(/@database\\([\"']?([\\w-]+)[\"']?\\)/);\r\n return match ? match[1] : null;\r\n }\r\n\r\n /**\r\n * Lee recursivamente archivos que terminan en un sufijo dado y los ordena numéricamente.\r\n * @param dir - Directorio base (relativo o absoluto).\r\n * @param suffix - Sufijo de archivo (como 'table.cube').\r\n * @returns Rutas absolutas de los archivos encontrados y ordenados.\r\n */\r\n static getCubeFilesRecursively(dir: string, suffix: string): string[] {\r\n const baseDir = path.resolve(dir); // ✅ Asegura que sea absoluto\r\n const cubeFiles: string[] = [];\r\n\r\n function recurse(currentDir: string): void {\r\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\r\n \r\n for (const entry of entries) {\r\n const fullPath = path.join(currentDir, entry.name);\r\n \r\n if (entry.isDirectory()) {\r\n recurse(fullPath);\r\n } else if (entry.isFile() && entry.name.endsWith(suffix)) {\r\n cubeFiles.push(fullPath); // Ya es absoluta\r\n }\r\n }\r\n }\r\n\r\n recurse(baseDir);\r\n\r\n // Ordenar por número si los archivos comienzan con un número\r\n cubeFiles.sort((a: string, b: string) => {\r\n const aNum = parseInt(path.basename(a));\r\n const bNum = parseInt(path.basename(b));\r\n return (isNaN(aNum) ? 0 : aNum) - (isNaN(bNum) ? 0 : bNum);\r\n });\r\n\r\n return cubeFiles;\r\n }\r\n}\r\n\r\nexport default FileUtils;"],"mappings":";;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;;;ACDzB,YAAY,QAAQ;AACpB,YAAY,UAAU;AAEf,IAAM,YAAN,MAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrB,aAAa,WAAW,UAAoC;AAC1D,WAAO,IAAI,QAAiB,CAACA,aAAY;AACvC,MAAG,UAAY,aAAQ,QAAQ,GAAM,aAAU,MAAM,CAAC,QAAQ;AAC5D,QAAAA,SAAQ,CAAC,GAAG;AAAA,MACd,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,eAAe,UAA2B;AAC/C,QAAI;AACF,MAAG,cAAgB,aAAQ,QAAQ,GAAM,aAAU,IAAI;AACvD,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,oBAAoB,OAA8B;AACvD,UAAM,QAAQ,MAAM,MAAM,iCAAiC;AAC3D,WAAO,QAAQ,MAAM,CAAC,IAAI;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,wBAAwB,KAAa,QAA0B;AACpE,UAAM,UAAe,aAAQ,GAAG;AAChC,UAAM,YAAsB,CAAC;AAE7B,aAAS,QAAQ,YAA0B;AACzC,YAAM,UAAa,eAAY,YAAY,EAAE,eAAe,KAAK,CAAC;AAElE,iBAAW,SAAS,SAAS;AAC3B,cAAM,WAAgB,UAAK,YAAY,MAAM,IAA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,aAAa,cAAa;AACzB,WAAK,UAAU,aAAa,YAAY,IAAI,IAAI,SAAS,aAAa,YAAY;AAAA,IACtF;AAAA,EACJ;AAAA,EAEA,SAAS,cAAqB;AAC1B,WAAO,KAAK,UAAU,YAAY;AAAA,EACtC;AACJ;","names":["resolve","path","path"]}
package/tsup.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'], // Punto de entrada
5
- format: ['cjs', 'esm'], // Genera CommonJS y ES Modules
6
- dts: true, // Genera archivos de tipos
7
- clean: true, // Limpia el directorio de salida
8
- outDir: 'dist', // Directorio de salida
9
- splitting: false, // Desactiva la división de código
10
- sourcemap: true, // Genera sourcemaps
11
- outExtension: ({ format }) => ({ // Forzar extensiones personalizadas
12
- js: format === 'cjs' ? '.cjs' : '.js',
13
- }),
14
- });