mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-07 17:28:53 +00:00
run formatter
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
import { AsyncLocalStorage } from "async_hooks";
|
||||
import { AsyncLocalStorage } from "async_hooks"
|
||||
|
||||
export namespace Context {
|
||||
export class NotFound extends Error {
|
||||
constructor(public readonly name: string) {
|
||||
super(`No context found for ${name}`);
|
||||
super(`No context found for ${name}`)
|
||||
}
|
||||
}
|
||||
|
||||
export function create<T>(name: string) {
|
||||
const storage = new AsyncLocalStorage<T>();
|
||||
const storage = new AsyncLocalStorage<T>()
|
||||
return {
|
||||
use() {
|
||||
const result = storage.getStore();
|
||||
const result = storage.getStore()
|
||||
if (!result) {
|
||||
throw new NotFound(name);
|
||||
throw new NotFound(name)
|
||||
}
|
||||
return result;
|
||||
return result
|
||||
},
|
||||
provide<R>(value: T, fn: () => R) {
|
||||
return storage.run<R>(value, fn);
|
||||
return storage.run<R>(value, fn)
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
import path from "path";
|
||||
import { AppPath } from "../app/path";
|
||||
import fs from "fs/promises";
|
||||
import path from "path"
|
||||
import { AppPath } from "../app/path"
|
||||
import fs from "fs/promises"
|
||||
export namespace Log {
|
||||
const write = {
|
||||
out: (msg: string) => {
|
||||
process.stdout.write(msg);
|
||||
process.stdout.write(msg)
|
||||
},
|
||||
err: (msg: string) => {
|
||||
process.stderr.write(msg);
|
||||
process.stderr.write(msg)
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function file(directory: string) {
|
||||
const outPath = path.join(AppPath.data(directory), "opencode.out.log");
|
||||
const errPath = path.join(AppPath.data(directory), "opencode.err.log");
|
||||
await fs.truncate(outPath).catch(() => {});
|
||||
await fs.truncate(errPath).catch(() => {});
|
||||
const out = Bun.file(outPath);
|
||||
const err = Bun.file(errPath);
|
||||
const outWriter = out.writer();
|
||||
const errWriter = err.writer();
|
||||
const outPath = path.join(AppPath.data(directory), "opencode.out.log")
|
||||
const errPath = path.join(AppPath.data(directory), "opencode.err.log")
|
||||
await fs.truncate(outPath).catch(() => {})
|
||||
await fs.truncate(errPath).catch(() => {})
|
||||
const out = Bun.file(outPath)
|
||||
const err = Bun.file(errPath)
|
||||
const outWriter = out.writer()
|
||||
const errWriter = err.writer()
|
||||
write["out"] = (msg) => {
|
||||
outWriter.write(msg);
|
||||
outWriter.flush();
|
||||
};
|
||||
outWriter.write(msg)
|
||||
outWriter.flush()
|
||||
}
|
||||
write["err"] = (msg) => {
|
||||
errWriter.write(msg);
|
||||
errWriter.flush();
|
||||
};
|
||||
errWriter.write(msg)
|
||||
errWriter.flush()
|
||||
}
|
||||
}
|
||||
|
||||
export function create(tags?: Record<string, any>) {
|
||||
tags = tags || {};
|
||||
tags = tags || {}
|
||||
|
||||
function build(message: any, extra?: Record<string, any>) {
|
||||
const prefix = Object.entries({
|
||||
@@ -40,25 +40,28 @@ export namespace Log {
|
||||
})
|
||||
.filter(([_, value]) => value !== undefined && value !== null)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(" ");
|
||||
return [new Date().toISOString(), prefix, message].filter(Boolean).join(" ") + "\n";
|
||||
.join(" ")
|
||||
return (
|
||||
[new Date().toISOString(), prefix, message].filter(Boolean).join(" ") +
|
||||
"\n"
|
||||
)
|
||||
}
|
||||
const result = {
|
||||
info(message?: any, extra?: Record<string, any>) {
|
||||
write.out(build(message, extra));
|
||||
write.out(build(message, extra))
|
||||
},
|
||||
error(message?: any, extra?: Record<string, any>) {
|
||||
write.err(build(message, extra));
|
||||
write.err(build(message, extra))
|
||||
},
|
||||
tag(key: string, value: string) {
|
||||
if (tags) tags[key] = value;
|
||||
return result;
|
||||
if (tags) tags[key] = value
|
||||
return result
|
||||
},
|
||||
clone() {
|
||||
return Log.create({ ...tags });
|
||||
return Log.create({ ...tags })
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const foo: string = "42";
|
||||
export const foo: string = "42"
|
||||
|
||||
export function dummyFunction(): void {
|
||||
console.log("This is a dummy function");
|
||||
console.log("This is a dummy function")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user