website/src
Soph :3 262032b4e3
All checks were successful
/ test (push) Successful in 12s
move blog to tsx
2024-07-23 11:51:16 +03:00
..
plugins move blog to tsx 2024-07-23 11:51:16 +03:00
index.ts website 2 2024-07-23 01:04:20 +03:00
readme.md website 2 2024-07-23 01:04:20 +03:00

sad.ovh build system

design goals:

  1. rewrite and generate custom HTML/TS/JS/whatever..
  2. allow for variables and other important features in buildsystem->html
  3. plugins, this ties together the top two
  4. HMR and HTML/CSS reloading (in the Dev plugin)
  5. Rewriteable file renaming
  6. 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); 
    }
}