Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use tera::{Context, Tera};
struct Data {
versions: Vec<FeatureList>,
unstable: FeatureList,
build_id: String,
}

#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -150,6 +151,7 @@ fn collect_data() -> anyhow::Result<Data> {
let mut data = Data {
versions: Vec::new(),
unstable: FeatureList { version: None, features: Vec::new() },
build_id: std::env::var("BUILD_ID").context("expected BUILD_ID env var")?,
};

let mut versions: BTreeMap<String, VersionData> =
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if ('WebAssembly' in window) {

// Load main app
async function main() {
await init('/caniuse_rs.wasm');
await init(`/caniuse_rs.${build_id()}.wasm`);
run();
}
main()
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "skel.html" %}
{% block content %}
<script defer src="/caniuse_rs.js"></script>
<script defer src="/caniuse_rs.{{ build_id }}.js"></script>

<body>
<main></main>
Expand Down
2 changes: 1 addition & 1 deletion templates/skel.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<link rel="icon" sizes="any" href="/favicon.svg" type="image/svg+xml">

<link rel="stylesheet" href="/normalize.css">
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/style.{{ build_id }}.css">

{% block content %}{% endblock content %}

Expand Down
21 changes: 18 additions & 3 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
fs, io,
net::{Ipv6Addr, SocketAddr},
time::{SystemTime, UNIX_EPOCH},
};

use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -39,13 +40,27 @@ fn main() -> anyhow::Result<()> {
fn build(dev: bool) -> anyhow::Result<()> {
let sh = Shell::new()?;

cmd!(sh, "wasm-pack build --no-typescript --target web").args(dev.then_some("--dev")).run()?;
fs::copy("pkg/caniuse_rs_bg.wasm", "public/caniuse_rs.wasm")?;
cmd!(sh, "rollup src/main.js --format iife --file public/caniuse_rs.js").run()?;
let build_id = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
let build_id = &build_id.to_string();

cmd!(sh, "wasm-pack build --no-typescript --target web")
.args(dev.then_some("--dev"))
.env("BUILD_ID", build_id)
.run()?;
fs::copy("pkg/caniuse_rs_bg.wasm", format!("public/caniuse_rs.{build_id}.wasm"))?;
cmd!(
sh,
"rollup src/main.js
--format iife
--outro 'function build_id() { return \"'{build_id}'\"; }'
--file public/caniuse_rs.{build_id}.js"
)
.run()?;

let static_files: Vec<_> =
fs::read_dir("static")?.map(|entry| Ok(entry?.path())).collect::<io::Result<_>>()?;
cmd!(sh, "cp -r {static_files...} public/").run()?;
cmd!(sh, "mv public/style.css public/style.{build_id}.css").run()?;

Ok(())
}
Expand Down