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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ export default class CompileTimeJS extends Plugin {
|
|||
rewriteTriggers = ["html", "*"]
|
||||
longLasting = false;
|
||||
build = undefined;
|
||||
|
||||
|
||||
async rewriteFile(file: string, filePath: string): Promise<string> {
|
||||
let input = file;
|
||||
const regex = /{&(.+)&}/gms;
|
||||
|
||||
let m;
|
||||
|
||||
|
||||
while ((m = regex.exec(file)) !== null) {
|
||||
if (m.index === regex.lastIndex) {
|
||||
regex.lastIndex++;
|
||||
|
|
@ -22,4 +22,4 @@ export default class CompileTimeJS extends Plugin {
|
|||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ const script = `let reconnectTimeout,waitingForReconnect=!1;function connect(){c
|
|||
|
||||
export default class DevPlugin extends Plugin {
|
||||
build: undefined;
|
||||
|
||||
|
||||
name = "dev";
|
||||
rewriteTriggers = [];
|
||||
renameTo = undefined;
|
||||
longLasting = true;
|
||||
server!: Server;
|
||||
allConnections: ServerWebSocket<number>[] = [];
|
||||
|
||||
|
||||
constructor(sssg: SSSG, headers: Record<string, string>) {
|
||||
super();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,16 +9,16 @@ export default class MarkdownCompiler extends Plugin {
|
|||
rewriteTriggers = ["md"]
|
||||
renameTo = "html"
|
||||
longLasting = false;
|
||||
|
||||
|
||||
async rewriteFile(file: string, filePath: string) {
|
||||
let text = file;
|
||||
const metadata = parseMetadata(text);
|
||||
if(metadata) {
|
||||
if(metadata) {
|
||||
let textSplit = text.split('\n');
|
||||
textSplit.splice(0, Object.keys(metadata).length);
|
||||
textSplit.unshift(metadata.title)
|
||||
text = textSplit.join("\n");
|
||||
}
|
||||
return await marked.parse(text);
|
||||
return await marked.parse(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -47,7 +48,7 @@ export default class TSCompiler extends Plugin {
|
|||
console.log("Errored!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (result.errors.length != 0) {
|
||||
console.log("TS compiler errored.");
|
||||
result.errors.forEach((element) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue