buncha stuff
This commit is contained in:
parent
1eba3a92b2
commit
e183025a16
12 changed files with 29 additions and 29 deletions
|
|
@ -1,7 +1,5 @@
|
|||
import { expect, test, beforeAll, afterAll } from "bun:test";
|
||||
import { expect, test } from "bun:test";
|
||||
import SSSG, { Plugin } from "../index";
|
||||
import { mkdirSync, existsSync, rmSync } from "fs";
|
||||
import { before } from "node:test";
|
||||
import { INPUT_FOLDER, nuke, OUTPUT_FOLDER } from "./util";
|
||||
|
||||
class DummyPlugin extends Plugin {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ export default class SSSG {
|
|||
}
|
||||
try {
|
||||
fs.rmSync(this.outputFolder, { recursive: true });
|
||||
} catch {}
|
||||
} catch {
|
||||
// I dont car 🌧️
|
||||
}
|
||||
|
||||
const sourceFiles = fs.readdirSync(this.inputFolder, {
|
||||
recursive: true,
|
||||
|
|
@ -102,7 +104,7 @@ export default class SSSG {
|
|||
data = rewritten;
|
||||
}
|
||||
|
||||
let rewrite = await plugin.rewriteFile(data, oldPath);
|
||||
const rewrite = await plugin.rewriteFile(data, oldPath);
|
||||
|
||||
if (!rewrite) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import CompileTimeJS from "../compile-time-js";
|
|||
test("CompileTimeJS evaluates JS expressions in curly braces", async () => {
|
||||
const plugin = new CompileTimeJS();
|
||||
const input = "Hello {& 2+2 &} World";
|
||||
const output = await plugin.rewriteFile(input, "test.html");
|
||||
const output = await plugin.rewriteFile(input);
|
||||
expect(output).toBe("Hello 4 World");
|
||||
});
|
||||
|
||||
|
|
@ -12,13 +12,13 @@ test("CompileTimeJS handles multiple expressions", async () => {
|
|||
const plugin = new CompileTimeJS();
|
||||
const input = "{& 1+1 &} and {& 3*3 &}";
|
||||
console.log(input)
|
||||
const output = await plugin.rewriteFile(input, "test.html");
|
||||
const output = await plugin.rewriteFile(input);
|
||||
expect(output).toBe("2 and 9");
|
||||
});
|
||||
|
||||
test("CompileTimeJS leaves input unchanged if no expressions", async () => {
|
||||
const plugin = new CompileTimeJS();
|
||||
const input = "No expressions here.";
|
||||
const output = await plugin.rewriteFile(input, "test.html");
|
||||
const output = await plugin.rewriteFile(input);
|
||||
expect(output).toBe("No expressions here.");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,16 +11,16 @@ const mockParseMetadata = (file: string) => {
|
|||
return undefined;
|
||||
};
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error Mocked.
|
||||
MarkdownCompiler.prototype["marked"] = mockMarked;
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error Mocked.
|
||||
MarkdownCompiler.prototype["parseMetadata"] = mockParseMetadata;
|
||||
|
||||
test("MarkdownCompiler compiles markdown to HTML", async () => {
|
||||
const plugin = new MarkdownCompiler();
|
||||
const input = "# Hello World";
|
||||
|
||||
const output = await plugin.rewriteFile(input, "test.md");
|
||||
const output = await plugin.rewriteFile(input);
|
||||
expect(typeof output).toBe("string");
|
||||
expect(output).toContain("Hello World");
|
||||
});
|
||||
|
|
@ -28,7 +28,7 @@ test("MarkdownCompiler compiles markdown to HTML", async () => {
|
|||
test("MarkdownCompiler uses metadata title if present", async () => {
|
||||
const plugin = new MarkdownCompiler();
|
||||
const input = "title=Hello\n=+\n# Some Content";
|
||||
const output = await plugin.rewriteFile(input, "test.md");
|
||||
const output = await plugin.rewriteFile(input);
|
||||
expect(output).toContain("Hello");
|
||||
expect(output).toContain("Some Content");
|
||||
});
|
||||
|
|
@ -36,6 +36,6 @@ test("MarkdownCompiler uses metadata title if present", async () => {
|
|||
test("MarkdownCompiler returns HTML for markdown without metadata", async () => {
|
||||
const plugin = new MarkdownCompiler();
|
||||
const input = "# Just Markdown";
|
||||
const output = await plugin.rewriteFile(input, "test.md");
|
||||
const output = await plugin.rewriteFile(input);
|
||||
expect(output).toContain("Just Markdown");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ uppercasePlugin.postcss = true;
|
|||
test("PostCSS applies plugins to CSS", async () => {
|
||||
const plugin = new PostCSS([uppercasePlugin()]);
|
||||
const input = "body { color: red; }";
|
||||
const output = await plugin.rewriteFile(input);
|
||||
const output = await plugin.rewriteFile(input, "test");
|
||||
expect(output).toContain("COLOR: RED;");
|
||||
});
|
||||
|
||||
test("PostCSS returns unchanged CSS if no plugins", async () => {
|
||||
const plugin = new PostCSS([]);
|
||||
const input = "body { color: blue; }";
|
||||
const output = await plugin.rewriteFile(input);
|
||||
const output = await plugin.rewriteFile(input, "test");
|
||||
expect(output).toBe(input);
|
||||
});
|
||||
|
||||
|
|
@ -43,6 +43,6 @@ test("PostCSS handles multiple plugins", async () => {
|
|||
|
||||
const plugin = new PostCSS([replaceRedPlugin(), uppercasePlugin()]);
|
||||
const input = "body { color: red; }";
|
||||
const output = await plugin.rewriteFile(input);
|
||||
const output = await plugin.rewriteFile(input, "test");
|
||||
expect(output).toContain("COLOR: GREEN;");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ TSCompiler.prototype["rewriteFile"] = async function (
|
|||
minify: this.minify,
|
||||
...this.esbuildOptions,
|
||||
});
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (result.errors.length != 0) {
|
||||
|
|
@ -51,6 +51,6 @@ test("TSCompiler returns undefined on build error", async () => {
|
|||
};
|
||||
const plugin = new TSCompiler(false);
|
||||
const output = await plugin.rewriteFile("invalid code", "test.ts");
|
||||
//@ts-expect-error
|
||||
//@ts-expect-error Argument of type undefined is not assignable to parameter of type string. (ts 2345)
|
||||
expect(output).toBe(undefined);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ export default class CompileTimeJS extends Plugin {
|
|||
longLasting = false;
|
||||
build = undefined;
|
||||
|
||||
async rewriteFile(file: string, filePath: string): Promise<string> {
|
||||
async rewriteFile(file: string): Promise<string> {
|
||||
let input = file;
|
||||
const regex = /\{\&([\s\S]*?)\&\}/gms;
|
||||
const regex = /\{&([\s\S]*?)&\}/gms;
|
||||
|
||||
let m;
|
||||
while ((m = regex.exec(input)) !== null) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export default class DevPlugin extends Plugin {
|
|||
if (cleanedPath == "/") cleanedPath = "/index.html";
|
||||
if (cleanedPath.endsWith("/")) cleanedPath = cleanedPath.slice(0, -1);
|
||||
|
||||
let fsPath = sssg.outputFolder + cleanedPath;
|
||||
const fsPath = sssg.outputFolder + cleanedPath;
|
||||
|
||||
if (fsPath.match(/\.\.\//g) !== null) {
|
||||
return undefined;
|
||||
|
|
@ -81,7 +81,7 @@ export default class DevPlugin extends Plugin {
|
|||
|
||||
this.allConnections.push(ws);
|
||||
},
|
||||
message(ws, message) {},
|
||||
message() {},
|
||||
close: (ws) => {
|
||||
this.allConnections = this.allConnections.filter(
|
||||
(z) => z.data != ws.data,
|
||||
|
|
@ -92,7 +92,7 @@ export default class DevPlugin extends Plugin {
|
|||
});
|
||||
}
|
||||
|
||||
async rewriteFile(file: string, filePath: string) {
|
||||
async rewriteFile() {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ export default class MarkdownCompiler extends Plugin {
|
|||
renameTo = "html";
|
||||
longLasting = false;
|
||||
|
||||
async rewriteFile(file: string, filePath: string) {
|
||||
async rewriteFile(file: string) {
|
||||
let text = file;
|
||||
const metadata = parseMetadata(text);
|
||||
if (metadata) {
|
||||
let textSplit = text.split("\n");
|
||||
const textSplit = text.split("\n");
|
||||
textSplit.splice(0, Object.keys(metadata).length);
|
||||
textSplit.unshift(metadata.title);
|
||||
text = textSplit.join("\n");
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export default class MarkdownMetadataGenerator extends Plugin {
|
|||
renameTo = "json";
|
||||
longLasting = false;
|
||||
|
||||
async rewriteFile(file: string, filePath: string) {
|
||||
async rewriteFile(file: string) {
|
||||
const metadata = parseMetadata(file);
|
||||
if (!metadata) return;
|
||||
return JSON.stringify(metadata);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ export default class PostCSS extends Plugin {
|
|||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
async rewriteFile(file: string) {
|
||||
const data = await postcss(this.plugins).process(file, { from: undefined });
|
||||
async rewriteFile(file: string, filePath: string) {
|
||||
const data = await postcss(this.plugins).process(file, { from: filePath });
|
||||
return data.css;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default class Variables extends Plugin {
|
|||
this.variables = this.varBuild();
|
||||
}
|
||||
|
||||
async rewriteFile(file: string, filePath: string): Promise<string> {
|
||||
async rewriteFile(file: string): Promise<string> {
|
||||
let prevfile = file;
|
||||
for (const a of Object.entries(this.variables)) {
|
||||
prevfile = prevfile.replaceAll(a[0], a[1]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue