I am trying to get Wallaby to run inside of an escript, but it depends on a small wrapper script (run_phantom.js) that lives in the priv folder and is not bundled when my app is built as an escript. My understanding is this run_phantom.sh wrapper script is critical because it protects against the phantomjs becoming a zombie process.
run_phantom.sh is currently being started by Port.open/2
with the following code.
def init(_) do
port = find_available_port()
local_storage = tmp_local_storage()
Port.open({:spawn_executable, String.to_charlist(script_path())},
[:binary, :stream, :use_stdio, :exit_status, args: script_args(port, local_storage)])
{:ok, %{running: false, awaiting_url: [], base_url: "http://localhost:#{port}/", local_storage: local_storage}}
end
def script_args(port, local_storage) do
[
phantomjs_path(),
"--webdriver=#{port}",
"--local-storage-path=#{local_storage}"
] ++ args()
end
defp script_path do
Path.absname("priv/run_phantom.sh", Application.app_dir(:wallaby))
end
However, since I can’t access the priv folder from an escript, I thought I might save the script contents into a module variable like this:
@external_resource "priv/run_phantom.sh"
@run_phantom_contents File.read! "priv/run_phantom.sh"
Since the original command was run like ./priv/run_phantom.sh phantom --webdriver=4444
, what would be the equivalent command if the contents of the wrapper script was saved in @run_phantom_contents
? I tried using eval
but it’s a shell command and not an executable so it doesn’t seem like it’s compatible with Port.open/2
.