Open idbrii opened 3 years ago
postbuild = [
"unzip {build_directory}/lovejs/projectname-lovejs.zip -d {build_directory}/lovejs",
"start http://127.0.0.1:8000", # use open or xdg-open on macos/linux
"python -m http.server 8000 --bind 127.0.0.1 --directory {build_directory}/lovejs/projectname",
]
Iteration is now much quicker:
An --open
flag would be nice to make this more accessible, but this workaround works well.
What exactly would that --open
flag do?
Maybe there should be a switch like --run
that simply executes commands in a new kind of optional postbuild action. Did you have something like that in mind? If makelove was Linux only, I would absolutely just suggest to use a Makefile/shell wrapper for that, but the fact that most people probably don't have make installed on their Windows machines and don't like to mess around with batch or powershell files, I think that might be a good addition.
Passing --open
would do different steps depending on the requested config. Not sure how it should interact with multiple targets. This is something that could be done from postbuild, but testing makelove's output seems relevant enough to include in the project.
unzip the package and do subprocess.run(path_to_executable)
. I think this should work for all platforms?
unzip the package and do:
import http.server
import socketserver
import webbrowser
import os
PORT = 8000
# open first because serve_forever blocks
webbrowser.open(f'http://127.0.0.1:{PORT}')
# SimpleHTTPRequestHandler hosts cwd
os.chdir("{build_directory}/lovejs/{projectname}".format(**get_makelove_params())) # TODO
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
try:
httpd.serve_forever()
except Exception:
httpd.shutdown()
Since lovejs seems to be tricky to get working, it would be nice to have a better flow for testing it.
Currently:
lovejs doesn't have an "artifacts" option for creating unzipped packages.
In theory, you could do something like this:
However, I've found that when makelove executes commands it doesn't seem to have the same PATH as where makelove is executed from, so unzip.exe and python.exe are not in the PATH (I'm on Win10 and both are installed via scoop). Using absolute paths fixes unzip, but I cannot get python to execute -- it always fails with "Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python".
However, since makelove is python, these steps should be doable entirely internally. An
--open
command that would launch the executable for desktop platforms and unzip and open an http.server for lovejs.