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