Skip to content

Instantly share code, notes, and snippets.

@jix
Created February 13, 2021 09:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jix/caf2d46cebecb12d25eea27878bfceac to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from livereload import Server, shell
import shlex
import sys
import os
import toml
config = toml.load('Cargo.toml')
cmd = 'cargo +nightly doc ' + shlex.join(sys.argv[1:])
server = Server()
try:
pkg_name = config['package']['name']
server.watch('src/**/*.rs', shell(cmd))
except KeyError:
pkg_name = config['workspace']['members'][0]
for pkg in config['workspace']['members']:
server.watch(f'{pkg}/src/**/*.rs', shell(cmd))
os.system(cmd)
with open('target/doc/index.html', 'w') as fp:
base_url = f'/{pkg_name}/index.html'
fp.write(
'<html><head>\n'
f'<meta http-equiv="refresh" content="0;{base_url}">\n'
'</head></html>\n'
)
server.serve(root='target/doc')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment