format everything + support windows now
This commit is contained in:
parent
bae2bac25b
commit
d5b4341487
7 changed files with 27 additions and 25 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -11,6 +11,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/node": "^24.7.1",
|
||||
"esbuild": "^0.23.1",
|
||||
"marked": "^14.1.0",
|
||||
"mime-types": "^2.1.35",
|
||||
|
|
|
|||
14
src/index.ts
14
src/index.ts
|
|
@ -8,7 +8,7 @@ export abstract class Plugin {
|
|||
|
||||
abstract rewriteFile(
|
||||
file: string | Buffer,
|
||||
filePath: string
|
||||
filePath: string,
|
||||
): Promise<Buffer | string | undefined | null | void>;
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ export default class SSSG {
|
|||
withFileTypes: true,
|
||||
});
|
||||
const globalPlugins = this.plugins.filter((z) =>
|
||||
z.rewriteTriggers.includes("*")
|
||||
z.rewriteTriggers.includes("*"),
|
||||
);
|
||||
|
||||
for await (const file of sourceFiles) {
|
||||
|
|
@ -62,17 +62,17 @@ export default class SSSG {
|
|||
|
||||
const shortname = file.name.slice(
|
||||
0,
|
||||
file.name.length - (type.length + 1)
|
||||
file.name.length - (type.length + 1),
|
||||
);
|
||||
const availablePlugins = this.plugins.filter((z) =>
|
||||
z.rewriteTriggers.includes(type)
|
||||
z.rewriteTriggers.includes(type),
|
||||
);
|
||||
|
||||
if (availablePlugins.length == 0) {
|
||||
const oldPath = path.join(file.parentPath, file.name);
|
||||
fs.cpSync(
|
||||
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"
|
||||
? type
|
||||
: plugin.renameTo)
|
||||
: plugin.renameTo),
|
||||
)
|
||||
.replace(this.inputFolder, this.outputFolder);
|
||||
let data: string | Buffer = fs.readFileSync(oldPath);
|
||||
|
|
@ -111,7 +111,7 @@ export default class SSSG {
|
|||
newPath,
|
||||
plugin.isBinary
|
||||
? new Uint8Array(rewrite as Buffer)
|
||||
: (rewrite as string)
|
||||
: (rewrite as string),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Plugin } from "..";
|
||||
import * as fs from "fs";
|
||||
|
||||
import * as esbuild from "esbuild";
|
||||
import * as path from "path";
|
||||
|
||||
export default class TSCompiler extends Plugin {
|
||||
build: undefined;
|
||||
|
|
@ -18,19 +19,19 @@ export default class TSCompiler extends Plugin {
|
|||
this.minify = minify;
|
||||
this.esbuildOptions = esbuildOptions;
|
||||
}
|
||||
|
||||
async rewriteFile(file: string, filePath: string) {
|
||||
let result;
|
||||
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({
|
||||
stdin: {
|
||||
contents: file,
|
||||
resolveDir: filePath.split("/")?.slice(0, -1).join("/"),
|
||||
sourcefile: filePath.split("/").at(-1),
|
||||
loader: filePath.split("/").at(-1)?.split(".").at(-1) as
|
||||
| "ts"
|
||||
| "tsx"
|
||||
| "jsx",
|
||||
resolveDir: dir,
|
||||
sourcefile: base,
|
||||
loader: ext,
|
||||
},
|
||||
jsxFragment: "Fragment",
|
||||
jsxFactory: "h",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue