~damien/dotfiles

dotfiles/vim/bin/uno-hot-reload -rwxr-xr-x 1.9 KiB
6f4da805Damien Radtke Add vim-hcl 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /bin/bash
#
# This command runs the Uno hot reload server, downloading and
# building it if necessary.
#
# The server requires that you specify an HTTP port on which to
# run, via the --httpPort=<port> argument. Once it's running, you
# can build and run your Uno project (such as Skia GTK) with:
#
#   $ dotnet build -property:UnoRemoteControlPort=<port> && dotnet run --no-build
#
# Once it's running, the hot reload functionality should work as normal.
#
# Note: at time of writing, the server requires .NET Core 3.1, even though Uno
# supports up to .NET 5. If you're using the `asdf` SDK manager with the .NET
# Core plugin, you should be able to ensure you're using the correct version
# with:
#
#   $ asdf shell dotnet-core 3.1.401  # make sure it's installed
#   $ source ~/.asdf/plugins/dotnet-core/set-dotnet-home.bash
#   $ uno-hot-reload --httpPort=<port>
#

set -o errexit
set -o nounset

version="3.8.6"
install_only=false

if [[ -z "${DOTNET_ROOT:-}" ]]; then
	echo "DOTNET_ROOT is not set"
	exit 1
fi

usage() {
  echo "usage: uno-hot-reload [options] --httpPort=<port>

  --install      Install, but don't run"
  exit 0
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    --install) install_only=true; shift;;
    --help) usage;;
    *) break;;
  esac
done

cache_dir="${XDG_CACHE_HOME:-${HOME}/.cache}"
hot_reload_home="${cache_dir}/uno-remote-host"

{
  if [[ "${install_only}" = true ]]; then
    rm -rf "${hot_reload_home}"
  fi

  if [ ! -d "${hot_reload_home}" ]; then
    echo 'Installing uno-remote-host on first use... (will take a moment)'
	mkdir "${hot_reload_home}"
	tmp="$(mktemp -d)"
	pushd "${tmp}"
		git clone --depth=1 --single-branch --branch "${version}" \
			https://github.com/unoplatform/uno .
		pushd src/Uno.UI.RemoteControl.Host
			"${DOTNET_ROOT}/dotnet" build
			cp bin/Debug/*/* "${hot_reload_home}"
		popd
	popd
  fi

  if [[ "${install_only}" = true ]]; then
    exit 0
  fi
} 1>&2

"${hot_reload_home}"/Uno.UI.RemoteControl.Host "$@"