This commit is contained in:
parent
a7aaff537f
commit
262032b4e3
7 changed files with 186 additions and 78 deletions
|
|
@ -11,37 +11,46 @@ export default class TSCompiler extends Plugin {
|
|||
minify = false;
|
||||
constructor() {
|
||||
super();
|
||||
if(process.argv.includes("--prod")) {
|
||||
if (process.argv.includes("--prod")) {
|
||||
this.minify = true;
|
||||
}
|
||||
}
|
||||
async rewriteFile(file: string, filePath: string) {
|
||||
|
||||
const 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"
|
||||
},
|
||||
jsxFragment: "Fragment",
|
||||
jsxFactory: "Nano.h",
|
||||
jsxImportSource: "nano-jsx",
|
||||
jsx: "transform",
|
||||
write: false,
|
||||
bundle: true,
|
||||
outdir: 'out',
|
||||
minify: this.minify,
|
||||
});
|
||||
let result;
|
||||
try {
|
||||
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",
|
||||
},
|
||||
jsxFragment: "Fragment",
|
||||
jsxFactory: "Nano.h",
|
||||
jsxImportSource: "nano-jsx",
|
||||
jsx: "transform",
|
||||
write: false,
|
||||
bundle: true,
|
||||
outdir: "out",
|
||||
minify: this.minify,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.log("Errored!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(result.errors.length != 0) {
|
||||
console.log("TS compiler errored.")
|
||||
result.errors.forEach(element => {
|
||||
console.error(element);
|
||||
});
|
||||
if (result.errors.length != 0) {
|
||||
console.log("TS compiler errored.");
|
||||
result.errors.forEach((element) => {
|
||||
console.error(element);
|
||||
});
|
||||
} else {
|
||||
const output = result.outputFiles[0].contents;
|
||||
return (new TextDecoder()).decode(output);
|
||||
return new TextDecoder().decode(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export default class Variables extends Plugin {
|
|||
constructor() {
|
||||
super();
|
||||
this.variables["__BLOG_POSTS__"] = JSON.stringify(
|
||||
fs.readdirSync("./website/blogs")
|
||||
fs.readdirSync("./website/blogs").map((z) => z.replace(".md", ""))
|
||||
);
|
||||
const templatePath = path.resolve(__dirname, "../../website/templates");
|
||||
if (fs.existsSync(templatePath)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue