Monorepo for Aesthetic.Computer
aesthetic.computer
1// Shell, 24.09.02.18.46
2// Log backend lines to the shell with a filename trace.
3
4export const shell = {
5 log(...args) {
6 print("log", ...args);
7 },
8
9 warn(...args) {
10 print("warn", ...args);
11 },
12
13 error(...args) {
14 print("error", ...args);
15 },
16};
17
18// function print(type, ...args) {
19// const stack = new Error().stack;
20// const stackLine = stack.split("\n")[3]; // Get the line with the file and line number
21// const fileDetails = stackLine.match(/\/([^\/]+):(\d+):\d+/); // Extract file name and line number
22
23// if (fileDetails) {
24// const fileName = fileDetails[1];
25// const lineNumber = fileDetails[2];
26// console[type](`🟪 ${fileName}:${lineNumber} -`, ...args);
27// } else {
28// console[type](...args);
29// }
30// }
31function print(type, ...args) {
32 const stack = new Error().stack;
33 const stackLine = stack.split("\n")[3]; // Get the line with the file and line number
34 const fileDetails = stackLine.match(/\/([^\/]+):(\d+):(\d+)/); // Extract file name, line number, and column number
35 const fullPathMatch = stackLine.match(/\((.*):(\d+):\d+\)/); // Extract full path for the file URL
36
37 if (fileDetails && fullPathMatch) {
38 const fullPath = fullPathMatch[1];
39 const lineNumber = fileDetails[2];
40 const fileUrl = `${fileDetails[1]}:${lineNumber}`;
41 console[type](`🟪 ${fileUrl} -`, ...args);
42 } else {
43 console[type](...args);
44 }
45}