format everything + support windows now

This commit is contained in:
Soph :3 2025-10-19 02:22:26 +03:00
parent bae2bac25b
commit d5b4341487
7 changed files with 27 additions and 25 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -11,6 +11,7 @@
}, },
"dependencies": { "dependencies": {
"@types/mime-types": "^2.1.4", "@types/mime-types": "^2.1.4",
"@types/node": "^24.7.1",
"esbuild": "^0.23.1", "esbuild": "^0.23.1",
"marked": "^14.1.0", "marked": "^14.1.0",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",

View file

@ -8,7 +8,7 @@ export abstract class Plugin {
abstract rewriteFile( abstract rewriteFile(
file: string | Buffer, file: string | Buffer,
filePath: string filePath: string,
): Promise<Buffer | string | undefined | null | void>; ): Promise<Buffer | string | undefined | null | void>;
} }
@ -51,7 +51,7 @@ export default class SSSG {
withFileTypes: true, withFileTypes: true,
}); });
const globalPlugins = this.plugins.filter((z) => const globalPlugins = this.plugins.filter((z) =>
z.rewriteTriggers.includes("*") z.rewriteTriggers.includes("*"),
); );
for await (const file of sourceFiles) { for await (const file of sourceFiles) {
@ -62,17 +62,17 @@ export default class SSSG {
const shortname = file.name.slice( const shortname = file.name.slice(
0, 0,
file.name.length - (type.length + 1) file.name.length - (type.length + 1),
); );
const availablePlugins = this.plugins.filter((z) => const availablePlugins = this.plugins.filter((z) =>
z.rewriteTriggers.includes(type) z.rewriteTriggers.includes(type),
); );
if (availablePlugins.length == 0) { if (availablePlugins.length == 0) {
const oldPath = path.join(file.parentPath, file.name); const oldPath = path.join(file.parentPath, file.name);
fs.cpSync( fs.cpSync(
oldPath, oldPath,
oldPath.replace(this.inputFolder, this.outputFolder) oldPath.replace(this.inputFolder, this.outputFolder),
); );
} }
@ -85,7 +85,7 @@ export default class SSSG {
"." + "." +
(plugin.rewriteTriggers.includes("*") || plugin.renameTo == "keep" (plugin.rewriteTriggers.includes("*") || plugin.renameTo == "keep"
? type ? type
: plugin.renameTo) : plugin.renameTo),
) )
.replace(this.inputFolder, this.outputFolder); .replace(this.inputFolder, this.outputFolder);
let data: string | Buffer = fs.readFileSync(oldPath); let data: string | Buffer = fs.readFileSync(oldPath);
@ -111,7 +111,7 @@ export default class SSSG {
newPath, newPath,
plugin.isBinary plugin.isBinary
? new Uint8Array(rewrite as Buffer) ? new Uint8Array(rewrite as Buffer)
: (rewrite as string) : (rewrite as string),
); );
} }
} }

View file

@ -1,6 +1,7 @@
import { Plugin } from ".."; import { Plugin } from "..";
import * as fs from "fs";
import * as esbuild from "esbuild"; import * as esbuild from "esbuild";
import * as path from "path";
export default class TSCompiler extends Plugin { export default class TSCompiler extends Plugin {
build: undefined; build: undefined;
@ -18,19 +19,19 @@ export default class TSCompiler extends Plugin {
this.minify = minify; this.minify = minify;
this.esbuildOptions = esbuildOptions; this.esbuildOptions = esbuildOptions;
} }
async rewriteFile(file: string, filePath: string) { async rewriteFile(file: string, filePath: string) {
let result; let result;
try { try {
const dir = path.dirname(filePath);
const ext = path.extname(filePath).slice(1) as "ts" | "tsx" | "jsx";
const base = path.basename(filePath);
result = await esbuild.build({ result = await esbuild.build({
stdin: { stdin: {
contents: file, contents: file,
resolveDir: filePath.split("/")?.slice(0, -1).join("/"), resolveDir: dir,
sourcefile: filePath.split("/").at(-1), sourcefile: base,
loader: filePath.split("/").at(-1)?.split(".").at(-1) as loader: ext,
| "ts"
| "tsx"
| "jsx",
}, },
jsxFragment: "Fragment", jsxFragment: "Fragment",
jsxFactory: "h", jsxFactory: "h",