@mks2508/better-logger 0.0.2-alpha.2 → 0.3.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.
Files changed (326) hide show
  1. package/.claude/settings.local.json +18 -2
  2. package/.github/workflows/ci-quality.yml +357 -0
  3. package/.github/workflows/docs-demo.yml +119 -0
  4. package/.github/workflows/releases-core.yml +512 -0
  5. package/.github/workflows/releases-full.yml +582 -0
  6. package/.github/{workflows → workflows-backup}/ci.yml +12 -110
  7. package/.github/workflows-backup/nightly.yml +196 -0
  8. package/.github/workflows-backup/release-optimized.yml +373 -0
  9. package/.release-notes-0.2.0.md +129 -0
  10. package/.yamllint +28 -0
  11. package/CHANGELOG.json +783 -0
  12. package/CLAUDE.md +92 -1
  13. package/README.md +198 -490
  14. package/bun.lock +323 -0
  15. package/demo.html +9 -2
  16. package/dist/.tsbuildinfo +1 -0
  17. package/dist/Logger.d.ts +272 -0
  18. package/dist/Logger.d.ts.map +1 -0
  19. package/dist/Logger.js +680 -0
  20. package/dist/ScopedLogger.d.ts +126 -0
  21. package/dist/ScopedLogger.d.ts.map +1 -0
  22. package/dist/ScopedLogger.js +234 -0
  23. package/dist/chunks/Logger-BpeuYIxR.js +2 -0
  24. package/dist/chunks/Logger-BpeuYIxR.js.map +1 -0
  25. package/dist/chunks/Logger-Didxtr23.js +3275 -0
  26. package/dist/chunks/Logger-Didxtr23.js.map +1 -0
  27. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
  28. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
  29. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
  30. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
  31. package/dist/chunks/environment-Bxbnw4pd.js +544 -0
  32. package/dist/chunks/environment-Bxbnw4pd.js.map +1 -0
  33. package/dist/chunks/environment-Dm66zOML.js +4 -0
  34. package/dist/chunks/environment-Dm66zOML.js.map +1 -0
  35. package/dist/chunks/formatting-C0riPC5_.js +95 -0
  36. package/dist/chunks/formatting-C0riPC5_.js.map +1 -0
  37. package/dist/chunks/formatting-DNCAV66-.js +2 -0
  38. package/dist/chunks/formatting-DNCAV66-.js.map +1 -0
  39. package/dist/cli/CommandProcessor.d.ts +103 -0
  40. package/dist/cli/CommandProcessor.d.ts.map +1 -0
  41. package/dist/cli/CommandProcessor.js +184 -0
  42. package/dist/cli/commands/ConfigCommand.d.ts +17 -0
  43. package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
  44. package/dist/cli/commands/ConfigCommand.js +88 -0
  45. package/dist/cli/commands/ExportCommand.d.ts +51 -0
  46. package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
  47. package/dist/cli/commands/ExportCommand.js +243 -0
  48. package/dist/cli/commands/HistoryCommand.d.ts +50 -0
  49. package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
  50. package/dist/cli/commands/HistoryCommand.js +96 -0
  51. package/dist/cli/commands/StatusCommand.d.ts +33 -0
  52. package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
  53. package/dist/cli/commands/StatusCommand.js +93 -0
  54. package/dist/cli/commands/ThemeCommand.d.ts +33 -0
  55. package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
  56. package/dist/cli/commands/ThemeCommand.js +79 -0
  57. package/dist/cli/help.d.ts +15 -0
  58. package/dist/cli/help.d.ts.map +1 -0
  59. package/dist/cli/help.js +118 -0
  60. package/dist/cli/index.d.ts +15 -0
  61. package/dist/cli/index.d.ts.map +1 -0
  62. package/dist/cli/index.js +46 -0
  63. package/dist/constants.d.ts +122 -0
  64. package/dist/constants.d.ts.map +1 -0
  65. package/dist/constants.js +159 -0
  66. package/dist/core.cjs +1 -1
  67. package/dist/core.cjs.map +1 -1
  68. package/dist/core.d.ts +134 -0
  69. package/dist/core.d.ts.map +1 -0
  70. package/dist/core.js +315 -242
  71. package/dist/core.js.map +1 -1
  72. package/dist/example.d.ts +18 -0
  73. package/dist/example.d.ts.map +1 -0
  74. package/dist/example.js +154 -0
  75. package/dist/exports-module.d.ts +203 -0
  76. package/dist/exports-module.d.ts.map +1 -0
  77. package/dist/exports-module.js +260 -0
  78. package/dist/exports.cjs +1 -1
  79. package/dist/exports.cjs.map +1 -1
  80. package/dist/exports.js +5 -4
  81. package/dist/exports.js.map +1 -1
  82. package/dist/handlers/AnalyticsLogHandler.d.ts +11 -0
  83. package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
  84. package/dist/handlers/AnalyticsLogHandler.js +19 -0
  85. package/dist/handlers/ExportLogHandler.d.ts +103 -0
  86. package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
  87. package/dist/handlers/ExportLogHandler.js +516 -0
  88. package/dist/handlers/FileLogHandler.d.ts +36 -0
  89. package/dist/handlers/FileLogHandler.d.ts.map +1 -0
  90. package/dist/handlers/FileLogHandler.js +156 -0
  91. package/dist/handlers/RemoteLogHandler.d.ts +14 -0
  92. package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
  93. package/dist/handlers/RemoteLogHandler.js +37 -0
  94. package/dist/handlers/index.d.ts +8 -0
  95. package/dist/handlers/index.d.ts.map +1 -0
  96. package/dist/handlers/index.js +7 -0
  97. package/dist/index.cjs +1 -1
  98. package/dist/index.cjs.map +1 -1
  99. package/dist/index.d.ts +86 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +89 -103
  102. package/dist/index.js.map +1 -1
  103. package/dist/main.d.ts +2 -0
  104. package/dist/main.d.ts.map +1 -0
  105. package/dist/main.js +139 -0
  106. package/dist/styling/LogStyleBuilder.d.ts +149 -0
  107. package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
  108. package/dist/styling/LogStyleBuilder.js +289 -0
  109. package/dist/styling/SemanticStyles.d.ts +181 -0
  110. package/dist/styling/SemanticStyles.d.ts.map +1 -0
  111. package/dist/styling/SemanticStyles.js +339 -0
  112. package/dist/styling/SmartPresets.d.ts +25 -0
  113. package/dist/styling/SmartPresets.d.ts.map +1 -0
  114. package/dist/styling/SmartPresets.js +276 -0
  115. package/dist/styling/StyleBuilder.d.ts +140 -0
  116. package/dist/styling/StyleBuilder.d.ts.map +1 -0
  117. package/dist/styling/StyleBuilder.js +280 -0
  118. package/dist/styling/banners.d.ts +45 -0
  119. package/dist/styling/banners.d.ts.map +1 -0
  120. package/dist/styling/banners.js +155 -0
  121. package/dist/styling/index.d.ts +10 -0
  122. package/dist/styling/index.d.ts.map +1 -0
  123. package/dist/styling/index.js +9 -0
  124. package/dist/styling/themes.d.ts +10 -0
  125. package/dist/styling/themes.d.ts.map +1 -0
  126. package/dist/styling/themes.js +231 -0
  127. package/dist/styling-module.d.ts +185 -0
  128. package/dist/styling-module.d.ts.map +1 -0
  129. package/dist/styling-module.js +199 -0
  130. package/dist/styling.cjs +1 -1
  131. package/dist/styling.cjs.map +1 -1
  132. package/dist/styling.js +6 -6
  133. package/dist/styling.js.map +1 -1
  134. package/dist/types/Logger.d.ts +268 -0
  135. package/dist/types/Logger.d.ts.map +1 -0
  136. package/dist/types/ScopedLogger.d.ts +123 -0
  137. package/dist/types/ScopedLogger.d.ts.map +1 -0
  138. package/dist/types/cli/CommandProcessor.d.ts +100 -0
  139. package/dist/types/cli/CommandProcessor.d.ts.map +1 -0
  140. package/dist/types/cli/commands/ConfigCommand.d.ts +14 -0
  141. package/dist/types/cli/commands/ConfigCommand.d.ts.map +1 -0
  142. package/dist/types/cli/commands/ExportCommand.d.ts +48 -0
  143. package/dist/types/cli/commands/ExportCommand.d.ts.map +1 -0
  144. package/dist/types/cli/commands/HistoryCommand.d.ts +47 -0
  145. package/dist/types/cli/commands/HistoryCommand.d.ts.map +1 -0
  146. package/dist/types/cli/commands/StatusCommand.d.ts +30 -0
  147. package/dist/types/cli/commands/StatusCommand.d.ts.map +1 -0
  148. package/dist/types/cli/commands/ThemeCommand.d.ts +30 -0
  149. package/dist/types/cli/commands/ThemeCommand.d.ts.map +1 -0
  150. package/dist/types/cli/help.d.ts +12 -0
  151. package/dist/types/cli/help.d.ts.map +1 -0
  152. package/dist/types/cli/index.d.ts +15 -0
  153. package/dist/types/cli/index.d.ts.map +1 -0
  154. package/dist/types/constants.d.ts +119 -0
  155. package/dist/types/constants.d.ts.map +1 -0
  156. package/dist/types/core.d.ts +125 -211
  157. package/dist/types/core.d.ts.map +1 -0
  158. package/dist/types/core.js +13 -0
  159. package/dist/types/example.d.ts +18 -0
  160. package/dist/types/example.d.ts.map +1 -0
  161. package/dist/types/exports-module.d.ts +196 -0
  162. package/dist/types/exports-module.d.ts.map +1 -0
  163. package/dist/types/handlers/AnalyticsLogHandler.d.ts +8 -0
  164. package/dist/types/handlers/AnalyticsLogHandler.d.ts.map +1 -0
  165. package/dist/types/handlers/ExportLogHandler.d.ts +100 -0
  166. package/dist/types/handlers/ExportLogHandler.d.ts.map +1 -0
  167. package/dist/types/handlers/FileLogHandler.d.ts +33 -0
  168. package/dist/types/handlers/FileLogHandler.d.ts.map +1 -0
  169. package/dist/types/handlers/RemoteLogHandler.d.ts +11 -0
  170. package/dist/types/handlers/RemoteLogHandler.d.ts.map +1 -0
  171. package/dist/types/handlers/index.d.ts +8 -0
  172. package/dist/types/handlers/index.d.ts.map +1 -0
  173. package/dist/types/handlers.d.ts +88 -0
  174. package/dist/types/handlers.d.ts.map +1 -0
  175. package/dist/types/handlers.js +4 -0
  176. package/dist/types/index.d.ts +7 -675
  177. package/dist/types/index.d.ts.map +1 -0
  178. package/dist/types/index.js +4 -0
  179. package/dist/types/main.d.ts +2 -0
  180. package/dist/types/main.d.ts.map +1 -0
  181. package/dist/types/styling/LogStyleBuilder.d.ts +146 -0
  182. package/dist/types/styling/LogStyleBuilder.d.ts.map +1 -0
  183. package/dist/types/styling/SemanticStyles.d.ts +178 -0
  184. package/dist/types/styling/SemanticStyles.d.ts.map +1 -0
  185. package/dist/types/styling/SmartPresets.d.ts +22 -0
  186. package/dist/types/styling/SmartPresets.d.ts.map +1 -0
  187. package/dist/types/styling/StyleBuilder.d.ts +140 -0
  188. package/dist/types/styling/StyleBuilder.d.ts.map +1 -0
  189. package/dist/types/styling/banners.d.ts +42 -0
  190. package/dist/types/styling/banners.d.ts.map +1 -0
  191. package/dist/types/styling/index.d.ts +10 -0
  192. package/dist/types/styling/index.d.ts.map +1 -0
  193. package/dist/types/styling/themes.d.ts +7 -0
  194. package/dist/types/styling/themes.d.ts.map +1 -0
  195. package/dist/types/styling-module.d.ts +178 -0
  196. package/dist/types/styling-module.d.ts.map +1 -0
  197. package/dist/types/types/core.d.ts +125 -0
  198. package/dist/types/types/core.d.ts.map +1 -0
  199. package/dist/types/types/handlers.d.ts +85 -0
  200. package/dist/types/types/handlers.d.ts.map +1 -0
  201. package/dist/types/types/index.d.ts +7 -0
  202. package/dist/types/types/index.d.ts.map +1 -0
  203. package/dist/types/utils/environment.d.ts +47 -0
  204. package/dist/types/utils/environment.d.ts.map +1 -0
  205. package/dist/types/utils/formatting.d.ts +37 -0
  206. package/dist/types/utils/formatting.d.ts.map +1 -0
  207. package/dist/types/utils/index.d.ts +7 -0
  208. package/dist/types/utils/index.d.ts.map +1 -0
  209. package/dist/types/utils/opentui-detection.d.ts +34 -0
  210. package/dist/types/utils/opentui-detection.d.ts.map +1 -0
  211. package/dist/types/utils/output.d.ts +41 -0
  212. package/dist/types/utils/output.d.ts.map +1 -0
  213. package/dist/types/utils/stackTrace.d.ts +6 -0
  214. package/dist/types/utils/stackTrace.d.ts.map +1 -0
  215. package/dist/types/utils/timestamps.d.ts +20 -0
  216. package/dist/types/utils/timestamps.d.ts.map +1 -0
  217. package/dist/utils/environment.d.ts +47 -0
  218. package/dist/utils/environment.d.ts.map +1 -0
  219. package/dist/utils/environment.js +85 -0
  220. package/dist/utils/formatting.d.ts +40 -0
  221. package/dist/utils/formatting.d.ts.map +1 -0
  222. package/dist/utils/formatting.js +117 -0
  223. package/dist/utils/index.d.ts +7 -0
  224. package/dist/utils/index.d.ts.map +1 -0
  225. package/dist/utils/index.js +6 -0
  226. package/dist/utils/opentui-detection.d.ts +34 -0
  227. package/dist/utils/opentui-detection.d.ts.map +1 -0
  228. package/dist/utils/opentui-detection.js +116 -0
  229. package/dist/utils/output.d.ts +44 -0
  230. package/dist/utils/output.d.ts.map +1 -0
  231. package/dist/utils/output.js +150 -0
  232. package/dist/utils/stackTrace.d.ts +9 -0
  233. package/dist/utils/stackTrace.d.ts.map +1 -0
  234. package/dist/utils/stackTrace.js +81 -0
  235. package/dist/utils/timestamps.d.ts +20 -0
  236. package/dist/utils/timestamps.d.ts.map +1 -0
  237. package/dist/utils/timestamps.js +71 -0
  238. package/docs/API.md +691 -0
  239. package/docs/CORE.md +10 -10
  240. package/docs/DEVELOPMENT.md +731 -0
  241. package/docs/PACKAGES.md +244 -0
  242. package/docs/_config.yml +36 -0
  243. package/docs/index.md +179 -0
  244. package/examples/README.md +208 -0
  245. package/examples/basic-logging.js +75 -0
  246. package/examples/data-export.js +234 -0
  247. package/examples/package.json +16 -0
  248. package/examples/performance-timing.js +170 -0
  249. package/examples/simplified-api.js +124 -0
  250. package/examples/styling-themes.js +207 -0
  251. package/package.json +37 -21
  252. package/packages/core/package.json +57 -0
  253. package/packages/exports/package.json +41 -0
  254. package/packages/nodejs-opentui/README.md +232 -0
  255. package/packages/nodejs-opentui/package.json +72 -0
  256. package/packages/nodejs-opentui/src/LogRenderer.ts +171 -0
  257. package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +178 -0
  258. package/packages/nodejs-opentui/src/components/LogBadge.tsx +131 -0
  259. package/packages/nodejs-opentui/src/index.ts +133 -0
  260. package/packages/nodejs-opentui/src/types.ts +158 -0
  261. package/packages/nodejs-opentui/tsconfig.json +20 -0
  262. package/packages/styling/package.json +41 -0
  263. package/project-utils/README.md +172 -0
  264. package/project-utils/auto-release-gemini.ts +1193 -0
  265. package/project-utils/auto-release-ui.ts +1329 -0
  266. package/project-utils/commit-generator.ts +1385 -0
  267. package/project-utils/commit-ui.ts +264 -0
  268. package/project-utils/git-utils.ts +199 -0
  269. package/project-utils/github-release-manager.ts +466 -0
  270. package/project-utils/project-config.ts +260 -0
  271. package/project-utils/prompt-templates.js +345 -0
  272. package/project-utils/prompt-templates.ts +422 -0
  273. package/project-utils/version-manager.ts +1078 -0
  274. package/src/Logger.ts +251 -16
  275. package/src/ScopedLogger.ts +262 -0
  276. package/src/cli/CommandProcessor.ts +173 -2
  277. package/src/cli/commands/HistoryCommand.ts +117 -0
  278. package/src/cli/index.ts +12 -0
  279. package/src/constants.ts +84 -2
  280. package/src/core.ts +119 -46
  281. package/src/example.ts +4 -4
  282. package/src/exports-module.ts +1 -1
  283. package/src/handlers/ExportLogHandler.ts +141 -0
  284. package/src/handlers/FileLogHandler.ts +144 -5
  285. package/src/index.ts +1 -1
  286. package/src/main.ts +3 -3
  287. package/src/styling/LogStyleBuilder.ts +355 -0
  288. package/src/styling/SemanticStyles.ts +380 -0
  289. package/src/styling/SmartPresets.ts +288 -0
  290. package/src/styling/StyleBuilder.ts +14 -0
  291. package/src/styling/index.ts +16 -1
  292. package/src/styling-module.ts +1 -1
  293. package/src/types/core.ts +60 -0
  294. package/src/types/index.ts +6 -0
  295. package/src/utils/environment.ts +94 -0
  296. package/src/utils/formatting.ts +142 -0
  297. package/src/utils/index.ts +3 -0
  298. package/src/utils/opentui-detection.ts +138 -0
  299. package/src/utils/output.ts +66 -8
  300. package/test-core-browser.html +237 -0
  301. package/test-core-node.js +63 -0
  302. package/tests/test-conflict-resolution.ts +391 -0
  303. package/tests/validate-workflows.sh +131 -0
  304. package/tests/yaml-autofix.sh +146 -0
  305. package/vite.config.ts +189 -50
  306. package/.npmrc.bak +0 -1
  307. package/dist/chunks/Logger-BQhMKy_T.js +0 -2
  308. package/dist/chunks/Logger-BQhMKy_T.js.map +0 -1
  309. package/dist/chunks/Logger-BrFKFZcD.js +0 -978
  310. package/dist/chunks/Logger-BrFKFZcD.js.map +0 -1
  311. package/dist/chunks/core-2opW4Pi3.js +0 -194
  312. package/dist/chunks/core-2opW4Pi3.js.map +0 -1
  313. package/dist/chunks/core-DyugwSYZ.js +0 -4
  314. package/dist/chunks/core-DyugwSYZ.js.map +0 -1
  315. package/dist/chunks/exports-BNP3R7dp.js +0 -421
  316. package/dist/chunks/exports-BNP3R7dp.js.map +0 -1
  317. package/dist/chunks/exports-U1xLBXrY.js +0 -2
  318. package/dist/chunks/exports-U1xLBXrY.js.map +0 -1
  319. package/dist/chunks/styling-DhUDzwlE.js +0 -654
  320. package/dist/chunks/styling-DhUDzwlE.js.map +0 -1
  321. package/dist/chunks/styling-tmRDI28D.js +0 -2
  322. package/dist/chunks/styling-tmRDI28D.js.map +0 -1
  323. package/dist/types/exports.d.ts +0 -600
  324. package/dist/types/styling.d.ts +0 -751
  325. package/src/Logger.ts.backup +0 -1684
  326. /package/.github/{workflows → workflows-backup}/release.yml +0 -0
@@ -0,0 +1,466 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * GitHub Release Manager para Better Logger
5
+ * Crea releases automáticamente en GitHub con los archivos de distribución
6
+ */
7
+
8
+ import { readFileSync, existsSync, readdirSync, statSync } from 'fs';
9
+ import { join, basename } from 'path';
10
+
11
+ interface ReleaseInfo {
12
+ version: string;
13
+ prefix?: string;
14
+ baseVersion: string;
15
+ path: string;
16
+ files: string[];
17
+ readme: string;
18
+ isPrerelease: boolean;
19
+ }
20
+
21
+ interface ChangelogEntry {
22
+ type: 'feature' | 'fix' | 'improvement' | 'breaking';
23
+ title: string;
24
+ description: string;
25
+ }
26
+
27
+ interface VersionData {
28
+ version: string;
29
+ date: string;
30
+ type: 'initial' | 'major' | 'minor' | 'patch';
31
+ title: string;
32
+ changes: ChangelogEntry[];
33
+ technical_notes: string;
34
+ breaking_changes: string[];
35
+ }
36
+
37
+ class GitHubReleaseManager {
38
+ private projectRoot: string;
39
+ private releasesDir: string;
40
+ private changelogPath: string;
41
+
42
+ constructor() {
43
+ this.projectRoot = process.cwd();
44
+ this.releasesDir = join(this.projectRoot, 'dist');
45
+ this.changelogPath = join(this.projectRoot, 'CHANGELOG.json');
46
+ }
47
+
48
+ /**
49
+ * Ejecuta comando gh CLI
50
+ */
51
+ private async ghCommand(args: string[]): Promise<string> {
52
+ const { spawn } = await import('child_process');
53
+
54
+ return new Promise((resolve, reject) => {
55
+ const proc = spawn('gh', args, {
56
+ cwd: this.projectRoot,
57
+ stdio: ['pipe', 'pipe', 'pipe']
58
+ });
59
+
60
+ let stdout = '';
61
+ let stderr = '';
62
+
63
+ proc.stdout?.on('data', (data) => {
64
+ stdout += data.toString();
65
+ });
66
+
67
+ proc.stderr?.on('data', (data) => {
68
+ stderr += data.toString();
69
+ });
70
+
71
+ proc.on('exit', (code) => {
72
+ if (code !== 0) {
73
+ reject(new Error(`GitHub CLI error: ${stderr || 'gh command failed'}`));
74
+ } else {
75
+ resolve(stdout.trim());
76
+ }
77
+ });
78
+
79
+ proc.on('error', (error) => {
80
+ reject(error);
81
+ });
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Verifica si gh CLI está instalado y autenticado
87
+ */
88
+ private async checkGitHubCLI(): Promise<void> {
89
+ try {
90
+ await this.ghCommand(['auth', 'status']);
91
+ console.log('✅ GitHub CLI autenticado correctamente');
92
+ } catch (error) {
93
+ console.error('❌ GitHub CLI no está instalado o no estás autenticado');
94
+ console.log('💡 Instala gh CLI: https://cli.github.com/');
95
+ console.log('💡 Autentica con: gh auth login');
96
+ throw error;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Obtiene todas las releases existentes en GitHub
102
+ */
103
+ private async getExistingReleases(): Promise<Set<string>> {
104
+ try {
105
+ const output = await this.ghCommand(['release', 'list', '--json', 'tagName']);
106
+ const releases = JSON.parse(output);
107
+ return new Set(releases.map((r: any) => r.tagName));
108
+ } catch (error) {
109
+ console.warn('⚠️ No se pudieron obtener releases existentes:', error);
110
+ return new Set();
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Obtiene información de la release actual desde package.json y dist/
116
+ */
117
+ private getCurrentRelease(): ReleaseInfo | null {
118
+ try {
119
+ // Leer versión de package.json
120
+ const packagePath = join(this.projectRoot, 'package.json');
121
+ if (!existsSync(packagePath)) {
122
+ console.warn('⚠️ package.json no existe');
123
+ return null;
124
+ }
125
+
126
+ const packageData = JSON.parse(readFileSync(packagePath, 'utf-8'));
127
+ const version = packageData.version;
128
+
129
+ if (!existsSync(this.releasesDir)) {
130
+ console.warn('⚠️ Directorio dist/ no existe');
131
+ return null;
132
+ }
133
+
134
+ // Obtener solo archivos de la distribución (no directorios)
135
+ const files = readdirSync(this.releasesDir)
136
+ .map(file => join(this.releasesDir, file))
137
+ .filter(filePath => {
138
+ try {
139
+ const stat = statSync(filePath);
140
+ return stat.isFile();
141
+ } catch {
142
+ return false;
143
+ }
144
+ });
145
+
146
+ // Determinar si es prerelease
147
+ const isPrerelease = version.includes('-alpha') || version.includes('-beta') || version.includes('-rc') || version.includes('-pre');
148
+
149
+ // Extraer prefix y base version
150
+ const match = version.match(/^(.*?)(-alpha|-beta|-rc|-pre)?(.*)$/);
151
+ const baseVersion = match ? match[1] + (match[3] || '') : version;
152
+ const prefix = match && match[2] ? match[2].substring(1) : undefined;
153
+ return {
154
+ version,
155
+ prefix,
156
+ baseVersion,
157
+ path: this.releasesDir,
158
+ files,
159
+ readme: this.generateREADME(version),
160
+ isPrerelease
161
+ };
162
+ } catch (error) {
163
+ console.error('❌ Error obteniendo release actual:', error);
164
+ return null;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Genera README básico para la release
170
+ */
171
+ private generateREADME(version: string): string {
172
+ const date = new Date().toISOString().split('T')[0];
173
+ return `# Better Logger v${version}
174
+
175
+ ## Instalación
176
+
177
+ \`\`\`bash
178
+ npm install @mks2508/better-logger@${version}
179
+ \`\`\`
180
+
181
+ ## Uso
182
+
183
+ \`\`\`javascript
184
+ import { Logger } from '@mks2508/better-logger';
185
+
186
+ const logger = new Logger();
187
+ logger.info('¡Hola mundo!');
188
+ \`\`\`
189
+
190
+ ---
191
+
192
+ *Release generada automáticamente el ${date}*`;
193
+ }
194
+
195
+ /**
196
+ * Carga información del changelog para una versión específica
197
+ */
198
+ private getChangelogForVersion(version: string): VersionData | null {
199
+ try {
200
+ const changelogData = JSON.parse(readFileSync(this.changelogPath, 'utf-8'));
201
+ return changelogData.versions.find((v: VersionData) => v.version === version) || null;
202
+ } catch (error) {
203
+ console.warn(`⚠️ No se pudo cargar changelog para ${version}`);
204
+ return null;
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Genera las release notes basadas en changelog y README
210
+ */
211
+ private generateReleaseNotes(release: ReleaseInfo): string {
212
+ const changelog = this.getChangelogForVersion(release.version);
213
+
214
+ let notes = `# Better Logger - ${release.version}\n\n`;
215
+
216
+ if (changelog) {
217
+ notes += `## 📋 Resumen\n${changelog.title}\n\n`;
218
+
219
+ // Agrupar cambios por tipo
220
+ const features = changelog.changes.filter(c => c.type === 'feature');
221
+ const fixes = changelog.changes.filter(c => c.type === 'fix');
222
+ const improvements = changelog.changes.filter(c => c.type === 'improvement');
223
+ const breaking = changelog.changes.filter(c => c.type === 'breaking');
224
+
225
+ if (features.length > 0) {
226
+ notes += `## ✨ Nuevas Funcionalidades\n`;
227
+ features.forEach(f => notes += `- ${f.title}\n`);
228
+ notes += '\n';
229
+ }
230
+
231
+ if (fixes.length > 0) {
232
+ notes += `## 🐛 Correcciones\n`;
233
+ fixes.forEach(f => notes += `- ${f.title}\n`);
234
+ notes += '\n';
235
+ }
236
+
237
+ if (improvements.length > 0) {
238
+ notes += `## 🚀 Mejoras\n`;
239
+ improvements.forEach(i => notes += `- ${i.title}\n`);
240
+ notes += '\n';
241
+ }
242
+
243
+ if (breaking.length > 0) {
244
+ notes += `## 💥 Cambios Importantes\n`;
245
+ breaking.forEach(b => notes += `- ${b.title}\n`);
246
+ notes += '\n';
247
+ }
248
+ }
249
+
250
+ // Agregar información de instalación del README
251
+ const readmeLines = release.readme.split('\n');
252
+ const installIndex = readmeLines.findIndex(line => line.includes('## Instalación'));
253
+ const compatIndex = readmeLines.findIndex(line => line.includes('## Compatibilidad'));
254
+
255
+ if (installIndex !== -1) {
256
+ notes += `## 📦 Instalación\n\n`;
257
+ const endIndex = compatIndex !== -1 ? compatIndex : readmeLines.length;
258
+ const installSection = readmeLines.slice(installIndex + 1, endIndex);
259
+ notes += installSection.join('\n') + '\n\n';
260
+ }
261
+
262
+ // Información de archivos
263
+ notes += `## 📁 Archivos de la Release\n\n`;
264
+ release.files.forEach(file => {
265
+ const fileName = basename(file);
266
+ const stats = statSync(file);
267
+ const sizeMB = (stats.size / 1024 / 1024).toFixed(1);
268
+ notes += `- **${fileName}** (${sizeMB} MB)\n`;
269
+ });
270
+
271
+ notes += `\n---\n\n`;
272
+ notes += `🏗️ **Plataforma objetivo**: Universal (Browser/Node.js)\n`;
273
+ notes += `🗓️ **Fecha**: ${changelog?.date || new Date().toISOString().split('T')[0]}\n`;
274
+
275
+ if (release.isPrerelease) {
276
+ notes += `\n⚠️ **Nota**: Esta es una versión ${release.prefix} en desarrollo. No recomendada para producción.\n`;
277
+ }
278
+
279
+ return notes;
280
+ }
281
+
282
+ /**
283
+ * Crea una release en GitHub
284
+ */
285
+ private async createGitHubRelease(release: ReleaseInfo): Promise<void> {
286
+ console.log(`🚀 Creando release ${release.version}...`);
287
+
288
+ const tagName = `v${release.version}`;
289
+ const title = `Better Logger v${release.version}`;
290
+ const notes = this.generateReleaseNotes(release);
291
+
292
+ // Crear archivo temporal con las release notes
293
+ const notesFile = join(this.projectRoot, `.release-notes-${release.version}.md`);
294
+ const { writeFileSync } = await import('fs');
295
+ writeFileSync(notesFile, notes, 'utf-8');
296
+
297
+ try {
298
+ // Crear la release
299
+ const args = [
300
+ 'release', 'create', tagName,
301
+ '--title', title,
302
+ '--notes-file', notesFile,
303
+ ...release.files
304
+ ];
305
+
306
+ if (release.isPrerelease) {
307
+ args.push('--prerelease');
308
+ }
309
+
310
+ await this.ghCommand(args);
311
+ console.log(`✅ Release ${release.version} creada exitosamente`);
312
+
313
+ // Limpiar archivo temporal
314
+ const { unlinkSync } = await import('fs');
315
+ try { unlinkSync(notesFile); } catch {}
316
+
317
+ } catch (error) {
318
+ console.error(`❌ Error creando release ${release.version}:`, error);
319
+ throw error;
320
+ }
321
+ }
322
+
323
+ /**
324
+ * Procesa todas las releases
325
+ */
326
+ async processReleases(force = false): Promise<void> {
327
+ console.log('🔍 GitHub Release Manager iniciado\n');
328
+
329
+ try {
330
+ await this.checkGitHubCLI();
331
+
332
+ const currentRelease = this.getCurrentRelease();
333
+
334
+ if (!currentRelease) {
335
+ console.log('❌ No se pudo obtener información de la release actual');
336
+ return;
337
+ }
338
+
339
+ console.log(`📦 Release actual: ${currentRelease.version}`);
340
+
341
+ const existingReleases = await this.getExistingReleases();
342
+ console.log(`📋 ${existingReleases.size} releases ya existen en GitHub`);
343
+
344
+ const tagName = `v${currentRelease.version}`;
345
+
346
+ if (existingReleases.has(tagName) && !force) {
347
+ console.log(`⏭️ Release ${currentRelease.version} ya existe, omitiendo`);
348
+ console.log('💡 Usa --force para forzar recreación');
349
+ return;
350
+ }
351
+
352
+ if (force && existingReleases.has(tagName)) {
353
+ console.log(`🔄 Eliminando release existente ${currentRelease.version}...`);
354
+ try {
355
+ await this.ghCommand(['release', 'delete', tagName, '--yes']);
356
+ } catch (error) {
357
+ console.warn(`⚠️ No se pudo eliminar release ${tagName}:`, error);
358
+ }
359
+ }
360
+
361
+ await this.createGitHubRelease(currentRelease);
362
+ console.log(`\n✅ Procesamiento completado: Release ${currentRelease.version} creada exitosamente`);
363
+
364
+ } catch (error) {
365
+ console.error('❌ Error en el procesamiento:', error);
366
+ throw error;
367
+ }
368
+ }
369
+
370
+ /**
371
+ * Monitorea el directorio releases para cambios
372
+ */
373
+ async watchForNewReleases(): Promise<void> {
374
+ console.log('👀 Monitoreando directorio releases para nuevas versiones...');
375
+ // Implementación futura con file watchers
376
+ console.log('💡 Funcionalidad de monitoreo en desarrollo');
377
+ }
378
+ }
379
+
380
+ // Función helper para obtener releases existentes (fix de scope)
381
+ async function getExistingReleases(): Promise<Set<string>> {
382
+ try {
383
+ const { spawn } = await import('child_process');
384
+
385
+ return new Promise((resolve, reject) => {
386
+ const proc = spawn('gh', ['release', 'list', '--json', 'tagName'], {
387
+ stdio: ['pipe', 'pipe', 'pipe']
388
+ });
389
+
390
+ let stdout = '';
391
+ let stderr = '';
392
+
393
+ proc.stdout?.on('data', (data) => {
394
+ stdout += data.toString();
395
+ });
396
+
397
+ proc.stderr?.on('data', (data) => {
398
+ stderr += data.toString();
399
+ });
400
+
401
+ proc.on('exit', (code) => {
402
+ if (code !== 0) {
403
+ resolve(new Set());
404
+ } else {
405
+ try {
406
+ const releases = JSON.parse(stdout);
407
+ resolve(new Set(releases.map((r: any) => r.tagName)));
408
+ } catch {
409
+ resolve(new Set());
410
+ }
411
+ }
412
+ });
413
+
414
+ proc.on('error', () => {
415
+ resolve(new Set());
416
+ });
417
+ });
418
+ } catch (error) {
419
+ return new Set();
420
+ }
421
+ }
422
+
423
+ // Ejecutar script
424
+ if (import.meta.main) {
425
+ const manager = new GitHubReleaseManager();
426
+
427
+ const args = process.argv.slice(2);
428
+ const force = args.includes('--force') || args.includes('-f');
429
+ const watch = args.includes('--watch') || args.includes('-w');
430
+ const autoApprove = args.includes('--auto-approve');
431
+ const quiet = args.includes('--quiet');
432
+
433
+ if (args.includes('--help') || args.includes('-h')) {
434
+ console.log(`
435
+ 🚀 GitHub Release Manager para Better Logger
436
+
437
+ Uso:
438
+ node project-utils/github-release-manager.ts [opciones]
439
+
440
+ Opciones:
441
+ --auto-approve Crear release automáticamente sin confirmación
442
+ --force, -f Recrear releases existentes
443
+ --quiet Ejecución silenciosa (solo errores y resultados)
444
+ --watch, -w Monitorear cambios (en desarrollo)
445
+ --help, -h Mostrar esta ayuda
446
+
447
+ Ejemplos:
448
+ node project-utils/github-release-manager.ts # Release interactiva
449
+ node project-utils/github-release-manager.ts --auto-approve # Release automática
450
+ node project-utils/github-release-manager.ts --force --auto-approve # Forzar recreación
451
+ node project-utils/github-release-manager.ts --quiet --auto-approve # Para workflows
452
+ `);
453
+ process.exit(0);
454
+ }
455
+
456
+ try {
457
+ if (watch) {
458
+ await manager.watchForNewReleases();
459
+ } else {
460
+ await manager.processReleases(force);
461
+ }
462
+ } catch (error) {
463
+ console.error('❌ Error:', error);
464
+ process.exit(1);
465
+ }
466
+ }