Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Port wasm-pack docs site (#120)
Browse files Browse the repository at this point in the history
* Port wasm-pack docs site

* remove images and css

* remove browserconfig.xml, add installer.rs

* update second index and remove another instance of wasm-pack

* one last wasm-pack -> wrangler update

* actually use installer.rs

* check if we're the installer and do the right thing

* make installer actually work

* run cargo fmt
  • Loading branch information
steveklabnik authored and ashleygwilliams committed May 23, 2019
1 parent dc74738 commit 456e9ac
Show file tree
Hide file tree
Showing 11 changed files with 565 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
categories = ["wasm"]

[dependencies]
atty = "0.2.11"
binary-install = "0.0.2"
clap = "2.32.0"
config = "0.9.2"
Expand Down
30 changes: 30 additions & 0 deletions docs/_installer/build-installer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::fs;

fn main() {
fs::create_dir_all("docs/installer").unwrap();
fs::copy(
"docs/_installer/wrangler.js",
"docs/installer/wrangler.js",
).unwrap();
let index = fs::read_to_string("docs/_installer/index.html").unwrap();
fs::write(
"docs/installer/index.html",
fixup(&index),
).unwrap();

let init = fs::read_to_string("docs/_installer/init.sh").unwrap();
fs::write(
"docs/installer/init.sh",
fixup(&init),
).unwrap();
}

fn fixup(input: &str) -> String {
let manifest = fs::read_to_string("Cargo.toml").unwrap();
let version = manifest.lines()
.find(|line| line.starts_with("version ="))
.unwrap();
let version = &version[version.find('"').unwrap() + 1..version.rfind('"').unwrap()];

input.replace("$VERSION", &format!("v{}", version))
}
47 changes: 47 additions & 0 deletions docs/_installer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>wrangler</title>
<link rel="manifest" href="./site.webmanifest">
<meta name="msapplication-TileColor" content="#00aba9">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<nav class="navbar">
<div class="container">
<ul class="navbar-list">
<li class="navbar-logo">
<a href="/wrangler">
<img src="./public/img/wrangler.png">
</a>
</a>
<li class="navbar-item">
<a href="https://github.com/cloudflare/wrangler/issues/new/choose">File an Issue</a>
</li>
<li class="navbar-item">
<a href="/wrangler/installer">Install</a>
</li>
</ul>
</div>
</nav>
<header>
<div class="container">
<div class="row">
<div class="seven columns" id="logo">
<h1><code>wrangler</code></h1>
<h2>🤠 wrangle your cloudflare workers</h2>
</div>
<div class="five columns" id="installer">
<a class="button button-primary" href="/wrangler/installer">✨ Install wrangler 0.1.1 ✨</a>
<p>4 Apr 2019 |
<a href="https://github.com/cloudflare/wrangler/releases/tag/v0.1.1">
Release Notes
</a>
</p>
</div>
</div>
</header>
</div>
</div>
<script type="text/javascript" src="installer/wrangler.js"></script>
</body>
190 changes: 190 additions & 0 deletions docs/_installer/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#!/bin/bash
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

# This is just a little script that can be downloaded from the internet to
# install wrangler. It just does platform detection, downloads the installer
# and runs it.

set -u

UPDATE_ROOT="https://github.com/cloudflare/wrangler/releases/download/$VERSION"

main() {
downloader --check
need_cmd uname
need_cmd mktemp
need_cmd chmod
need_cmd mkdir
need_cmd rm
need_cmd rmdir
need_cmd tar
need_cmd which
need_cmd dirname

get_architecture || return 1
local _arch="$RETVAL"
assert_nz "$_arch" "arch"

local _ext=""
case "$_arch" in
*windows*)
_ext=".exe"
;;
esac

which rustup > /dev/null 2>&1
need_ok "failed to find Rust installation, is rustup installed?"
local _rustup=`which rustup`
local _tardir="wrangler-$VERSION-${_arch}"
local _url="$UPDATE_ROOT/${_tardir}.tar.gz"
local _dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t wrangler)"
local _file="$_dir/input.tar.gz"
local _wasmpack="$_dir/wrangler$_ext"
local _wasmpackinit="$_dir/wrangler-init$_ext"

printf '%s\n' 'info: downloading wrangler' 1>&2

ensure mkdir -p "$_dir"
downloader "$_url" "$_file"
if [ $? != 0 ]; then
say "failed to download $_url"
say "this may be a standard network error, but it may also indicate"
say "that wrangler's release process is not working. When in doubt"
say "please feel free to open an issue!"
exit 1
fi
ensure tar xf "$_file" --strip-components 1 -C "$_dir"
mv "$_wasmpack" "$_wasmpackinit"

# The installer may want to ask for confirmation on stdin for various
# operations. We were piped through `sh` though so we probably don't have
# access to a tty naturally. If it looks like we're attached to a terminal
# (`-t 1`) then pass the tty down to the installer explicitly.
if [ -t 1 ]; then
"$_wasmpackinit" "$@" < /dev/tty
else
"$_wasmpackinit" "$@"
fi

local _retval=$?

ignore rm -rf "$_dir"

return "$_retval"
}

get_architecture() {
local _ostype="$(uname -s)"
local _cputype="$(uname -m)"

if [ "$_ostype" = Darwin -a "$_cputype" = i386 ]; then
# Darwin `uname -s` lies
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
local _cputype=x86_64
fi
fi

case "$_ostype" in
Linux)
local _ostype=unknown-linux-musl
;;

Darwin)
local _ostype=apple-darwin
;;

MINGW* | MSYS* | CYGWIN*)
local _ostype=pc-windows-msvc
;;

*)
err "no precompiled binaries available for OS: $_ostype"
;;
esac

case "$_cputype" in
x86_64 | x86-64 | x64 | amd64)
local _cputype=x86_64
;;
*)
err "no precompiled binaries available for CPU architecture: $_cputype"

esac

local _arch="$_cputype-$_ostype"

RETVAL="$_arch"
}

say() {
echo "wrangler-init: $1"
}

err() {
say "$1" >&2
exit 1
}

need_cmd() {
if ! check_cmd "$1"
then err "need '$1' (command not found)"
fi
}

check_cmd() {
command -v "$1" > /dev/null 2>&1
return $?
}

need_ok() {
if [ $? != 0 ]; then err "$1"; fi
}

assert_nz() {
if [ -z "$1" ]; then err "assert_nz $2"; fi
}

# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
"$@"
need_ok "command failed: $*"
}

# This is just for indicating that commands' results are being
# intentionally ignored. Usually, because it's being executed
# as part of error handling.
ignore() {
"$@"
}

# This wraps curl or wget. Try curl first, if not installed,
# use wget instead.
downloader() {
if check_cmd curl
then _dld=curl
elif check_cmd wget
then _dld=wget
else _dld='curl or wget' # to be used in error message of need_cmd
fi

if [ "$1" = --check ]
then need_cmd "$_dld"
elif [ "$_dld" = curl ]
then curl -sSfL "$1" -o "$2"
elif [ "$_dld" = wget ]
then wget "$1" -O "$2"
else err "Unknown downloader" # should not reach here
fi
}

main "$@" || exit 1
92 changes: 92 additions & 0 deletions docs/_installer/wrangler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
var platforms = ["default", "unknown", "win64", "unix"];
var platform_override = null;

function detect_platform() {
"use strict";

if (platform_override !== null) {
return platforms[platform_override];
}

var os = "unknown";

if (navigator.platform == "Linux x86_64") {os = "unix";}
if (navigator.platform == "Linux i686") {os = "unix";}
if (navigator.platform == "Linux i686 on x86_64") {os = "unix";}
if (navigator.platform == "Linux aarch64") {os = "unix";}
if (navigator.platform == "Linux armv6l") {os = "unix";}
if (navigator.platform == "Linux armv7l") {os = "unix";}
if (navigator.platform == "Linux armv8l") {os = "unix";}
if (navigator.platform == "Linux ppc64") {os = "unix";}
if (navigator.platform == "Linux mips") {os = "unix";}
if (navigator.platform == "Linux mips64") {os = "unix";}
if (navigator.platform == "Mac") {os = "unix";}
// if (navigator.platform == "Win32") {os = "win32";}
if (navigator.platform == "Win64" ||
navigator.userAgent.indexOf("WOW64") != -1 ||
navigator.userAgent.indexOf("Win64") != -1) { os = "win64"; }
if (navigator.platform == "FreeBSD x86_64") {os = "unix";}
if (navigator.platform == "FreeBSD amd64") {os = "unix";}
if (navigator.platform == "NetBSD x86_64") {os = "unix";}
if (navigator.platform == "NetBSD amd64") {os = "unix";}

// I wish I knew by now, but I don't. Try harder.
if (os == "unknown") {
// if (navigator.appVersion.indexOf("Win")!=-1) {os = "win32";}
if (navigator.appVersion.indexOf("Mac")!=-1) {os = "unix";}
// rust-www/#692 - FreeBSD epiphany!
if (navigator.appVersion.indexOf("FreeBSD")!=-1) {os = "unix";}
}

// Firefox Quantum likes to hide platform and appVersion but oscpu works
if (navigator.oscpu) {
// if (navigator.oscpu.indexOf("Win32")!=-1) {os = "win32";}
if (navigator.oscpu.indexOf("Win64")!=-1) {os = "win64";}
if (navigator.oscpu.indexOf("Mac")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("Linux")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("FreeBSD")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("NetBSD")!=-1) {os = "unix";}
}

return os;
}

function adjust_for_platform() {
"use strict";

var platform = detect_platform();

platforms.forEach(function (platform_elem) {
var platform_div = document.getElementById("platform-instructions-" + platform_elem);
platform_div.style.display = "none";
if (platform == platform_elem ||
(platform == 'unknown' && platform_elem == 'default')) {
platform_div.style.display = "block";
}
});
}

function go_to_default_platform() {
platform_override = 0;
adjust_for_platform();
}

function set_up_default_platform_buttons() {
var defaults_buttons = document.getElementsByClassName('default-platform-button');
for (var i = 0; i < defaults_buttons.length; i++) {
defaults_buttons[i].onclick = go_to_default_platform;
}
}

function fill_in_bug_report_values() {
var nav_plat = document.getElementById("nav-plat");
var nav_app = document.getElementById("nav-app");
nav_plat.textContent = navigator.platform;
nav_app.textContent = navigator.appVersion;
}

(function () {
adjust_for_platform();
set_up_default_platform_buttons();
fill_in_bug_report_values();
}());
Loading

0 comments on commit 456e9ac

Please sign in to comment.