Wednesday, April 16, 2025

Techniques: Dev inplace replacement code

You have your utils.js with the classic document.querySelector shortcut:

function q(selector) {
    return document.querySelector(selector);
}

Lets say that the "assertion" is that this should be only called when we know the selector will always match a single element (for the other cases we simply call other functions)

We leave this "efficient" version, and we replicate the an error checking version of it in a new file utils.dev.js:

function q(selector) {
    const res = document.querySelectorAll(selector);
    if (res.length == 1) return res[0];
    throw `Found ${res.length} matches for '${selector}'`;
}

And then in the "build system" we specify one of the files based on the release mode.



done_

Monday, April 7, 2025

Web: Bundle and deploy with php and make

 We want to put all the things into a single index.html and then uploaded. We just:

index.html: index.php $(shell find src -type f)
    php index.php > index.html

upload: index.html
    cp index.html /run/user/1000/gvfs/ftps:host=[website]/project/
    touch upload

We dont have php in the server, we just use php to bundle all the html, js and css files into one file using php statements like this:

    <style>
    <?php foreach (glob("src/*.css") as $i) include $i ?>
    </style>

And then we let make file generate the index.hml and we upload to our server with a cp (linux things) when changes have been made



done_