|
||
---|---|---|
.. | ||
plugins | ||
index.ts | ||
readme.md |
sad.ovh build system
design goals:
- rewrite and generate custom HTML/TS/JS/whatever..
- allow for variables and other important features in buildsystem->html
- plugins, this ties together the top two
- HMR and HTML/CSS reloading (in the Dev plugin)
- Rewriteable file renaming
- Every plugin runs on the same set of files, and can rename and reinject multiple times
Psudeo-code build.ts
class Plugin {
.. whatever's needed to support the plugin system ..
}
if(.. not exist dist ..)
.. make dist ..
const plugins: Plugin[] = [];
.. dynamically load plugins into plugins ..
const srcFiles: File[] = []
.. get files into file ..
export function build () {
for(const file of srcFiles) {
const plugins = plugins.filter(z=>z.rewriteTriggers(file.type));
if(plugins.length == 0) continue;
for (const plugin of plugins) {
let filename = file.name + "." + file.type;
let newFilename = path.join("dist", file.name + "." + plugin.renameTo || file.type);
fs.writeFileSync(newFilename, plugin.rewriteFile(fs.readFileSync(filename), filename))
}
}
}
build();
Psudeo-code plugins
class DevPlugin extends Plugin {
rewriteTriggers: ["html"]
renameTo: undefined
longLasting: false;
.. websocket server ..
constructor(.. options from argv of the main executable..) {
.. ran on start of main index.ts executable ..
.. this would be long lasting, so leave if not using --dev ..
.. use a method on the server that rebuilds if required ..
.. Would run a web server too ..
}
rewriteFile(file: string, filePath: string) {
return file.replace("<head>", `<head><script>${script}</script>`)
}
}
class TSCompiler extends Plugin {
rewriteTriggers: ["ts"]
renameTo: "js"
rewriteFile(file: string, filePath: string) {
// use SWC or TS or esbuild, whatever
}
}
class MarkdownMetadataGenerator extends Plugin {
rewriteTriggers: ["md"]
renameTo: "json"
rewriteFile(file: string, filePath: string) {
return marked.parse(file);
}
}
class MarkdownCompiler extends Plugin {
rewriteTriggers: ["md"]
renameTo: "html"
rewriteFile(file: string, filePath: string) {
return marked.parse(file);
}
}