@mo7yw4ng/openape 1.0.6 → 2.0.4

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 (152) hide show
  1. package/bin/openape +29 -0
  2. package/bin/openape.js +32 -0
  3. package/package.json +24 -28
  4. package/LICENSE +0 -21
  5. package/README.md +0 -138
  6. package/esm/_dnt.polyfills.d.ts +0 -101
  7. package/esm/_dnt.polyfills.d.ts.map +0 -1
  8. package/esm/_dnt.polyfills.js +0 -127
  9. package/esm/_dnt.shims.d.ts +0 -6
  10. package/esm/_dnt.shims.d.ts.map +0 -1
  11. package/esm/_dnt.shims.js +0 -61
  12. package/esm/deno.d.ts +0 -25
  13. package/esm/deno.d.ts.map +0 -1
  14. package/esm/deno.js +0 -23
  15. package/esm/package.json +0 -3
  16. package/esm/src/commands/announcements.d.ts +0 -3
  17. package/esm/src/commands/announcements.d.ts.map +0 -1
  18. package/esm/src/commands/announcements.js +0 -71
  19. package/esm/src/commands/assignments.d.ts +0 -3
  20. package/esm/src/commands/assignments.d.ts.map +0 -1
  21. package/esm/src/commands/assignments.js +0 -229
  22. package/esm/src/commands/auth.d.ts +0 -3
  23. package/esm/src/commands/auth.d.ts.map +0 -1
  24. package/esm/src/commands/auth.js +0 -290
  25. package/esm/src/commands/calendar.d.ts +0 -3
  26. package/esm/src/commands/calendar.d.ts.map +0 -1
  27. package/esm/src/commands/calendar.js +0 -127
  28. package/esm/src/commands/courses.d.ts +0 -3
  29. package/esm/src/commands/courses.d.ts.map +0 -1
  30. package/esm/src/commands/courses.js +0 -312
  31. package/esm/src/commands/forums.d.ts +0 -3
  32. package/esm/src/commands/forums.d.ts.map +0 -1
  33. package/esm/src/commands/forums.js +0 -190
  34. package/esm/src/commands/grades.d.ts +0 -3
  35. package/esm/src/commands/grades.d.ts.map +0 -1
  36. package/esm/src/commands/grades.js +0 -84
  37. package/esm/src/commands/materials.d.ts +0 -3
  38. package/esm/src/commands/materials.d.ts.map +0 -1
  39. package/esm/src/commands/materials.js +0 -402
  40. package/esm/src/commands/quizzes.d.ts +0 -3
  41. package/esm/src/commands/quizzes.d.ts.map +0 -1
  42. package/esm/src/commands/quizzes.js +0 -236
  43. package/esm/src/commands/skills.d.ts +0 -3
  44. package/esm/src/commands/skills.d.ts.map +0 -1
  45. package/esm/src/commands/skills.js +0 -106
  46. package/esm/src/commands/upload.d.ts +0 -3
  47. package/esm/src/commands/upload.d.ts.map +0 -1
  48. package/esm/src/commands/upload.js +0 -55
  49. package/esm/src/commands/videos.d.ts +0 -3
  50. package/esm/src/commands/videos.d.ts.map +0 -1
  51. package/esm/src/commands/videos.js +0 -266
  52. package/esm/src/index.d.ts +0 -28
  53. package/esm/src/index.d.ts.map +0 -1
  54. package/esm/src/index.js +0 -164
  55. package/esm/src/lib/auth.d.ts +0 -66
  56. package/esm/src/lib/auth.d.ts.map +0 -1
  57. package/esm/src/lib/auth.js +0 -286
  58. package/esm/src/lib/config.d.ts +0 -6
  59. package/esm/src/lib/config.d.ts.map +0 -1
  60. package/esm/src/lib/config.js +0 -36
  61. package/esm/src/lib/logger.d.ts +0 -3
  62. package/esm/src/lib/logger.d.ts.map +0 -1
  63. package/esm/src/lib/logger.js +0 -26
  64. package/esm/src/lib/moodle.d.ts +0 -447
  65. package/esm/src/lib/moodle.d.ts.map +0 -1
  66. package/esm/src/lib/moodle.js +0 -1353
  67. package/esm/src/lib/session.d.ts +0 -8
  68. package/esm/src/lib/session.d.ts.map +0 -1
  69. package/esm/src/lib/session.js +0 -42
  70. package/esm/src/lib/token.d.ts +0 -38
  71. package/esm/src/lib/token.d.ts.map +0 -1
  72. package/esm/src/lib/token.js +0 -178
  73. package/esm/src/lib/types.d.ts +0 -189
  74. package/esm/src/lib/types.d.ts.map +0 -1
  75. package/esm/src/lib/types.js +0 -2
  76. package/esm/src/lib/utils.d.ts +0 -52
  77. package/esm/src/lib/utils.d.ts.map +0 -1
  78. package/esm/src/lib/utils.js +0 -122
  79. package/script/_dnt.polyfills.d.ts +0 -101
  80. package/script/_dnt.polyfills.d.ts.map +0 -1
  81. package/script/_dnt.polyfills.js +0 -130
  82. package/script/_dnt.shims.d.ts +0 -6
  83. package/script/_dnt.shims.d.ts.map +0 -1
  84. package/script/_dnt.shims.js +0 -65
  85. package/script/deno.d.ts +0 -25
  86. package/script/deno.d.ts.map +0 -1
  87. package/script/deno.js +0 -25
  88. package/script/package.json +0 -3
  89. package/script/src/commands/announcements.d.ts +0 -3
  90. package/script/src/commands/announcements.d.ts.map +0 -1
  91. package/script/src/commands/announcements.js +0 -74
  92. package/script/src/commands/assignments.d.ts +0 -3
  93. package/script/src/commands/assignments.d.ts.map +0 -1
  94. package/script/src/commands/assignments.js +0 -268
  95. package/script/src/commands/auth.d.ts +0 -3
  96. package/script/src/commands/auth.d.ts.map +0 -1
  97. package/script/src/commands/auth.js +0 -296
  98. package/script/src/commands/calendar.d.ts +0 -3
  99. package/script/src/commands/calendar.d.ts.map +0 -1
  100. package/script/src/commands/calendar.js +0 -133
  101. package/script/src/commands/courses.d.ts +0 -3
  102. package/script/src/commands/courses.d.ts.map +0 -1
  103. package/script/src/commands/courses.js +0 -315
  104. package/script/src/commands/forums.d.ts +0 -3
  105. package/script/src/commands/forums.d.ts.map +0 -1
  106. package/script/src/commands/forums.js +0 -193
  107. package/script/src/commands/grades.d.ts +0 -3
  108. package/script/src/commands/grades.d.ts.map +0 -1
  109. package/script/src/commands/grades.js +0 -87
  110. package/script/src/commands/materials.d.ts +0 -3
  111. package/script/src/commands/materials.d.ts.map +0 -1
  112. package/script/src/commands/materials.js +0 -408
  113. package/script/src/commands/quizzes.d.ts +0 -3
  114. package/script/src/commands/quizzes.d.ts.map +0 -1
  115. package/script/src/commands/quizzes.js +0 -239
  116. package/script/src/commands/skills.d.ts +0 -3
  117. package/script/src/commands/skills.d.ts.map +0 -1
  118. package/script/src/commands/skills.js +0 -112
  119. package/script/src/commands/upload.d.ts +0 -3
  120. package/script/src/commands/upload.d.ts.map +0 -1
  121. package/script/src/commands/upload.js +0 -61
  122. package/script/src/commands/videos.d.ts +0 -3
  123. package/script/src/commands/videos.d.ts.map +0 -1
  124. package/script/src/commands/videos.js +0 -272
  125. package/script/src/index.d.ts +0 -28
  126. package/script/src/index.d.ts.map +0 -1
  127. package/script/src/index.js +0 -171
  128. package/script/src/lib/auth.d.ts +0 -66
  129. package/script/src/lib/auth.d.ts.map +0 -1
  130. package/script/src/lib/auth.js +0 -296
  131. package/script/src/lib/config.d.ts +0 -6
  132. package/script/src/lib/config.d.ts.map +0 -1
  133. package/script/src/lib/config.js +0 -42
  134. package/script/src/lib/logger.d.ts +0 -3
  135. package/script/src/lib/logger.d.ts.map +0 -1
  136. package/script/src/lib/logger.js +0 -29
  137. package/script/src/lib/moodle.d.ts +0 -447
  138. package/script/src/lib/moodle.d.ts.map +0 -1
  139. package/script/src/lib/moodle.js +0 -1425
  140. package/script/src/lib/session.d.ts +0 -8
  141. package/script/src/lib/session.d.ts.map +0 -1
  142. package/script/src/lib/session.js +0 -45
  143. package/script/src/lib/token.d.ts +0 -38
  144. package/script/src/lib/token.d.ts.map +0 -1
  145. package/script/src/lib/token.js +0 -189
  146. package/script/src/lib/types.d.ts +0 -189
  147. package/script/src/lib/types.d.ts.map +0 -1
  148. package/script/src/lib/types.js +0 -3
  149. package/script/src/lib/utils.d.ts +0 -52
  150. package/script/src/lib/utils.d.ts.map +0 -1
  151. package/script/src/lib/utils.js +0 -167
  152. package/skills/openape/SKILL.md +0 -115
@@ -1,296 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findEdgePath = findEdgePath;
7
- exports.launchAuthenticated = launchAuthenticated;
8
- exports.closeBrowserSafely = closeBrowserSafely;
9
- exports.createApiContext = createApiContext;
10
- exports.createBrowserContext = createBrowserContext;
11
- const node_fs_1 = __importDefault(require("node:fs"));
12
- const node_path_1 = __importDefault(require("node:path"));
13
- const playwright_core_1 = require("playwright-core");
14
- const token_js_1 = require("./token.js");
15
- const logger_js_1 = require("./logger.js");
16
- const utils_js_1 = require("./utils.js");
17
- const session_js_1 = require("./session.js");
18
- /**
19
- * Find a Chromium-based browser executable on Windows, macOS, or Linux.
20
- * Priority: Edge → Chrome → Brave
21
- */
22
- function findEdgePath() {
23
- const platform = process.platform;
24
- if (platform === "darwin") {
25
- const candidates = [
26
- "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
27
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
28
- "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
29
- ];
30
- for (const candidate of candidates) {
31
- if (node_fs_1.default.existsSync(candidate))
32
- return candidate;
33
- }
34
- }
35
- else if (platform === "linux") {
36
- const candidates = [
37
- "/usr/bin/microsoft-edge",
38
- "/usr/bin/google-chrome",
39
- "/usr/bin/chromium-browser",
40
- "/usr/bin/chromium",
41
- "/usr/bin/brave-browser",
42
- ];
43
- for (const candidate of candidates) {
44
- if (node_fs_1.default.existsSync(candidate))
45
- return candidate;
46
- }
47
- }
48
- else if (platform === "win32") {
49
- const roots = [
50
- process.env.PROGRAMFILES,
51
- process.env["PROGRAMFILES(X86)"],
52
- process.env.LOCALAPPDATA,
53
- ].filter(Boolean);
54
- const browsers = [
55
- { suffix: "Microsoft\\Edge\\Application\\msedge.exe" },
56
- { suffix: "Google\\Chrome\\Application\\chrome.exe" },
57
- { suffix: "BraveSoftware\\Brave-Browser\\Application\\brave.exe" },
58
- ];
59
- for (const { suffix } of browsers) {
60
- for (const root of roots) {
61
- const candidate = node_path_1.default.join(root, suffix);
62
- if (node_fs_1.default.existsSync(candidate))
63
- return candidate;
64
- }
65
- }
66
- }
67
- else {
68
- throw new Error(`不支援的作業系統:${platform}`);
69
- }
70
- throw new Error("找不到可用的瀏覽器(Edge / Chrome / Brave)。請確認已安裝其中一種。");
71
- }
72
- /**
73
- * Launch a browser and return an authenticated context.
74
- * Tries to restore a saved session first; falls back to fresh OAuth login.
75
- * Also acquires Moodle Web Service Token for API calls.
76
- */
77
- async function launchAuthenticated(config, log) {
78
- const edgePath = findEdgePath();
79
- log.debug(`Using Edge: ${edgePath}`);
80
- // Wait a bit to ensure any previous browser process has fully terminated
81
- await new Promise(resolve => setTimeout(resolve, 1000));
82
- const browser = await playwright_core_1.chromium.launch({
83
- executablePath: edgePath,
84
- headless: config.headless,
85
- slowMo: config.slowMo,
86
- });
87
- // Try loading saved WS token first
88
- let wsToken = (0, token_js_1.loadWsToken)(config.authStatePath) ?? undefined;
89
- if (wsToken) {
90
- log.info("Loaded saved Web Service Token.");
91
- }
92
- // Try restoring a saved session
93
- const restored = await tryRestoreSession(browser, config, log);
94
- if (restored) {
95
- const page = restored.pages()[0] ?? (await restored.newPage());
96
- // If no saved WS token, try to acquire one
97
- if (!wsToken) {
98
- try {
99
- wsToken = await (0, token_js_1.acquireWsToken)(page, config, log);
100
- (0, token_js_1.saveWsToken)(config.authStatePath, wsToken);
101
- }
102
- catch {
103
- log.warn("Failed to acquire WS Token with restored session, continuing without it.");
104
- }
105
- }
106
- return { browser, context: restored, page, wsToken };
107
- }
108
- // Fresh login
109
- if (config.headless) {
110
- await browser.close().catch(() => { });
111
- throw new Error("找不到有效的 Session 或是 Session 已過期。\n" +
112
- "請先執行 `openape login` 進行手動登入,或是加上 `--headed` 參數執行目前的指令以開啟登入畫面。");
113
- }
114
- const context = await browser.newContext();
115
- const page = await context.newPage();
116
- await login(page, config, log);
117
- await saveSession(context, config.authStatePath, log);
118
- // Acquire WS Token after successful login
119
- if (!wsToken) {
120
- try {
121
- wsToken = await (0, token_js_1.acquireWsToken)(page, config, log);
122
- (0, token_js_1.saveWsToken)(config.authStatePath, wsToken);
123
- }
124
- catch {
125
- log.warn("Failed to acquire WS Token, continuing with sesskey-only auth.");
126
- }
127
- }
128
- return { browser, context, page, wsToken };
129
- }
130
- /**
131
- * Safely close browser and context with timeout.
132
- * Designed for AI agent usage - no human interaction needed.
133
- * If noWait is true, initiates cleanup but doesn't wait for completion.
134
- *
135
- * Note: Closes sequentially (context first, then browser) to avoid libuv
136
- * assertion failures on Windows when handles are closed concurrently.
137
- */
138
- async function closeBrowserSafely(browser, context, timeoutMs = 5000, noWait = false) {
139
- const closePromises = [];
140
- // Close context first with error handling
141
- if (context) {
142
- closePromises.push(Promise.race([
143
- context.close().catch(() => { }),
144
- new Promise(resolve => setTimeout(() => resolve(), timeoutMs))
145
- ]));
146
- }
147
- // Close browser after context with error handling
148
- closePromises.push(Promise.race([
149
- browser.close().catch(() => { }),
150
- new Promise(resolve => setTimeout(() => resolve(), timeoutMs))
151
- ]));
152
- if (noWait) {
153
- // Fire and forget - don't wait for cleanup
154
- Promise.allSettled(closePromises);
155
- return;
156
- }
157
- // Wait sequentially to avoid libuv issues on Windows
158
- for (const promise of closePromises) {
159
- await promise.catch(() => { });
160
- }
161
- }
162
- /**
163
- * Attempt to restore a session from stored state.
164
- * Returns null if the stored state doesn't exist or the session is expired.
165
- */
166
- async function tryRestoreSession(browser, config, log) {
167
- const statePath = node_path_1.default.resolve(config.authStatePath);
168
- if (!node_fs_1.default.existsSync(statePath)) {
169
- log.debug("No saved session found, will perform fresh login.");
170
- return null;
171
- }
172
- log.info("Restoring saved session...");
173
- const context = await browser.newContext({ storageState: statePath });
174
- const page = await context.newPage();
175
- try {
176
- await page.goto(`${config.moodleBaseUrl}/my/`, {
177
- waitUntil: "domcontentloaded",
178
- timeout: 15000,
179
- });
180
- // If we got redirected to a login page, the session is expired
181
- const url = page.url();
182
- if (url.includes("login") || url.includes("microsoftonline")) {
183
- log.warn("Saved session expired, will re-authenticate.");
184
- await context.close();
185
- return null;
186
- }
187
- log.success("Session restored successfully.");
188
- return context;
189
- }
190
- catch {
191
- log.warn("Failed to restore session, will re-authenticate.");
192
- await context.close();
193
- return null;
194
- }
195
- }
196
- /**
197
- * Save the current session state to disk for future reuse.
198
- */
199
- async function saveSession(context, statePath, log) {
200
- try {
201
- await context.storageState({ path: statePath });
202
- log.debug("Session saved for future reuse.");
203
- }
204
- catch (err) {
205
- log.warn(`Failed to save session: ${err}`);
206
- }
207
- }
208
- /**
209
- * Perform Microsoft OAuth login flow.
210
- */
211
- async function login(page, config, log) {
212
- log.info("Starting Microsoft OAuth login...");
213
- await page.goto(`${config.moodleBaseUrl}/auth/oauth2/login.php`, {
214
- waitUntil: "domcontentloaded",
215
- timeout: 30000,
216
- });
217
- // Wait for Microsoft login page or redirect back to Moodle
218
- try {
219
- await page.waitForURL((url) => url.toString().includes("microsoftonline") ||
220
- url.toString().includes("login.microsoftonline") ||
221
- (url.toString().includes("ilearning.cycu.edu.tw") &&
222
- !url.toString().includes("auth/oauth2/login")), { timeout: 10000 });
223
- const url = page.url().toString();
224
- if (url.includes("microsoftonline") || url.includes("login.microsoftonline")) {
225
- log.info("Microsoft login page detected. Please complete login in the browser.");
226
- log.info("Waiting for redirect back to Moodle...");
227
- await page.waitForURL((u) => u.toString().includes("ilearning.cycu.edu.tw") &&
228
- !u.toString().includes("microsoftonline") &&
229
- !u.toString().includes("login.microsoftonline"), { timeout: 300000 });
230
- }
231
- }
232
- catch {
233
- // Already logged in or redirected
234
- }
235
- // Verify we're logged in
236
- const finalUrl = page.url().toString();
237
- if (finalUrl.includes("login") ||
238
- finalUrl.includes("microsoftonline") ||
239
- finalUrl === config.moodleBaseUrl + "/auth/oauth2/login.php") {
240
- throw new Error(`登入後未重新導向回 Moodle。目前 URL: ${finalUrl}`);
241
- }
242
- log.success("Login completed successfully.");
243
- }
244
- /**
245
- * Create API context for WS token operations (no browser required).
246
- * Returns null if session is invalid or WS token is missing.
247
- */
248
- async function createApiContext(options, command) {
249
- const opts = command?.optsWithGlobals ? command.optsWithGlobals() : options;
250
- const outputFormat = command ? (0, utils_js_1.getOutputFormat)(command) : "json";
251
- const silent = outputFormat === "json" && !opts.verbose;
252
- const log = (0, logger_js_1.createLogger)(opts.verbose, silent, outputFormat);
253
- const sessionPath = (0, utils_js_1.getSessionPath)();
254
- const wsToken = (0, token_js_1.loadWsToken)(sessionPath);
255
- if (!wsToken) {
256
- log.error("未找到 WS token。請先執行 'openape login' 進行登入。");
257
- return null;
258
- }
259
- return {
260
- log,
261
- session: {
262
- wsToken,
263
- moodleBaseUrl: "https://ilearning.cycu.edu.tw",
264
- },
265
- };
266
- }
267
- /**
268
- * Create an authenticated browser context for commands that need page access.
269
- * Launches a browser, restores or creates a session, and extracts session info.
270
- */
271
- async function createBrowserContext(options, command) {
272
- const opts = command?.optsWithGlobals ? command.optsWithGlobals() : options;
273
- const outputFormat = command ? (0, utils_js_1.getOutputFormat)(command) : "json";
274
- const silent = outputFormat === "json" && !opts.verbose;
275
- const log = (0, logger_js_1.createLogger)(opts.verbose, silent, outputFormat);
276
- const sessionPath = (0, utils_js_1.getSessionPath)();
277
- const headed = "headed" in options ? options.headed : false;
278
- const config = {
279
- courseUrl: "",
280
- moodleBaseUrl: "https://ilearning.cycu.edu.tw",
281
- headless: !headed,
282
- slowMo: 0,
283
- authStatePath: sessionPath,
284
- ollamaBaseUrl: "",
285
- };
286
- try {
287
- log.info("啟動瀏覽器...");
288
- const { browser, context, page, wsToken } = await launchAuthenticated(config, log);
289
- const session = await (0, session_js_1.extractSessionInfo)(page, config, log, wsToken);
290
- return { log, page, session, browser, context };
291
- }
292
- catch (err) {
293
- log.error(err instanceof Error ? err.message : String(err));
294
- return null;
295
- }
296
- }
@@ -1,6 +0,0 @@
1
- import type { AppConfig } from "./types.js";
2
- /**
3
- * Load config from .env file (if it exists).
4
- */
5
- export declare function loadConfig(baseDir?: string): AppConfig;
6
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/src/lib/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAgBtD"}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.loadConfig = loadConfig;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- /**
10
- * Load config from .env file (if it exists).
11
- */
12
- function loadConfig(baseDir) {
13
- const envPath = baseDir ? node_path_1.default.resolve(baseDir, ".env") : node_path_1.default.resolve(".env");
14
- if (node_fs_1.default.existsSync(envPath)) {
15
- const envContent = node_fs_1.default.readFileSync(envPath, "utf8");
16
- for (const line of envContent.split("\n")) {
17
- const trimmed = line.trim();
18
- if (!trimmed || trimmed.startsWith("#"))
19
- continue;
20
- const eqIdx = trimmed.indexOf("=");
21
- if (eqIdx === -1)
22
- continue;
23
- const key = trimmed.slice(0, eqIdx).trim();
24
- const value = trimmed.slice(eqIdx + 1).trim();
25
- if (!process.env[key])
26
- process.env[key] = value;
27
- }
28
- }
29
- return buildConfig();
30
- }
31
- function buildConfig() {
32
- const moodleBaseUrl = (process.env.MOODLE_BASE_URL ?? "https://ilearning.cycu.edu.tw").replace(/\/$/, "");
33
- return {
34
- courseUrl: "",
35
- moodleBaseUrl,
36
- headless: process.env.HEADLESS !== "false",
37
- slowMo: parseInt(process.env.SLOW_MO ?? "0", 10),
38
- authStatePath: process.env.AUTH_STATE_PATH ?? ".auth/storage-state.json",
39
- ollamaModel: process.env.MODEL,
40
- ollamaBaseUrl: (process.env.OLLAMA_BASE_URL ?? "http://localhost:11434").replace(/\/$/, ""),
41
- };
42
- }
@@ -1,3 +0,0 @@
1
- import type { Logger, OutputFormat } from "./types.js";
2
- export declare function createLogger(verbose?: boolean, silent?: boolean, outputFormat?: OutputFormat): Logger;
3
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAOvD,wBAAgB,YAAY,CAAC,OAAO,UAAQ,EAAE,MAAM,UAAQ,EAAE,YAAY,GAAE,YAAqB,GAAG,MAAM,CAuBzG"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLogger = createLogger;
4
- const NO_COLOR = !!process.env.NO_COLOR;
5
- const c = (code, text) => NO_COLOR ? text : `\x1b[${code}m${text}\x1b[0m`;
6
- function createLogger(verbose = false, silent = false, outputFormat = "json") {
7
- const errorFn = outputFormat === "json"
8
- ? (msg) => console.error(JSON.stringify({ error: msg }))
9
- : (msg) => console.error(c("31", "[ERR]") + ` ${msg}`);
10
- if (silent) {
11
- return {
12
- info: (_msg) => { },
13
- success: (_msg) => { },
14
- warn: (_msg) => { },
15
- error: errorFn,
16
- debug: (_msg) => { },
17
- };
18
- }
19
- return {
20
- info: (msg) => console.error(c("36", "[INFO]") + ` ${msg}`),
21
- success: (msg) => console.error(c("32", "[OK]") + ` ${msg}`),
22
- warn: (msg) => console.error(c("33", "[WARN]") + ` ${msg}`),
23
- error: errorFn,
24
- debug: (msg) => {
25
- if (verbose)
26
- console.error(c("90", "[DBG]") + ` ${msg}`);
27
- },
28
- };
29
- }