I asked chat gpt to create a mac os version of my .bat script, however I don’t own a mac so could anyone review the code / test it and confirm if this works ?
Here’s the script: TWNodeJSLauncher/TWNodeJSLauncher_MacOS.sh at main · Telumire/TWNodeJSLauncher (github.com)
And here’s what it (should) do:
- Check for Node.js Installation: The script first checks if Node.js is installed on the system. If it’s not found, it informs the user that Node.js needs to be installed, provides a link to the Node.js website, opens that link in the default web browser for convenience, and then exits to prevent the script from running further.
- Check for TiddlyWiki Installation: Next, it checks if TiddlyWiki is installed globally on the system. If TiddlyWiki isn’t found, it proceeds to install TiddlyWiki globally using npm (Node Package Manager).
-
Initialize Variables: It initializes some variables, including an empty
name
variable for the wiki name, astartPort
variable set to 80 for the starting search port for the server, and afreePort
variable to store the discovered free port. -
Find a Free Port Function: The script defines a function,
find_free_port
, that iterates starting from port 80 (or whateverstartPort
is set to) upwards until it finds a port that is not in use. It checks port availability by attempting to connect to each port onlocalhost
and increments the port number until a free one is found. - Main Logic:
- If the script is run with a single argument ending in
.html
, it assumes the user wants to convert a single-file TiddlyWiki into a wiki folder. It does so using thetiddlywiki --load
command, saving the result to a new folder named after the HTML file without its extension. - If no argument or a different argument is provided, the script then prompts the user to enter a name for the wiki or uses the provided argument as the name.
- It removes any quotation marks from the wiki name.
- The script looks for a free port by calling the
find_free_port
function. - It checks if the specified wiki folder exists and is empty. If so, it initializes a new TiddlyWiki in that folder.
- It then opens the wiki in the default web browser at
localhost
on the discovered free port. - If the wiki folder doesn’t have a
start.sh
script, it creates one to facilitate starting the wiki server in the future. - It checks for a site title file within the wiki’s
tiddlers
folder. If not found, it creates a JSON file with the wiki’s name as the site title and loads it into the wiki. - Finally, it starts the TiddlyWiki server with filesystem and tiddlyweb plugins enabled, listening on the discovered free port.