2018-12-15 21:06:27 +00:00
|
|
|
extern crate rsass;
|
2019-03-20 16:56:17 +00:00
|
|
|
extern crate ructe;
|
2018-12-06 17:54:16 +00:00
|
|
|
use ructe::*;
|
2019-03-16 14:33:28 +00:00
|
|
|
use std::process::{Command, Stdio};
|
2019-03-20 16:56:17 +00:00
|
|
|
use std::{env, fs::*, io::Write, path::PathBuf};
|
2019-03-16 14:33:28 +00:00
|
|
|
|
|
|
|
fn compute_static_hash() -> String {
|
2019-05-10 14:15:30 +00:00
|
|
|
//"find static/ -type f ! -path 'static/media/*' | sort | xargs stat -c'%n %Y' | openssl dgst -r"
|
2019-03-16 14:33:28 +00:00
|
|
|
|
|
|
|
let find = Command::new("find")
|
|
|
|
.args(&["static/", "-type", "f", "!", "-path", "static/media/*"])
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("failed find command");
|
|
|
|
|
|
|
|
let sort = Command::new("sort")
|
|
|
|
.stdin(find.stdout.unwrap())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("failed sort command");
|
|
|
|
|
|
|
|
let xargs = Command::new("xargs")
|
2019-05-10 14:15:30 +00:00
|
|
|
.args(&["stat", "-c'%n %Y'"])
|
2019-03-16 14:33:28 +00:00
|
|
|
.stdin(sort.stdout.unwrap())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("failed xargs command");
|
|
|
|
|
2019-05-10 14:15:30 +00:00
|
|
|
let mut sha = Command::new("openssl")
|
|
|
|
.args(&["dgst", "-r"])
|
2019-03-16 14:33:28 +00:00
|
|
|
.stdin(xargs.stdout.unwrap())
|
|
|
|
.output()
|
2019-05-10 14:15:30 +00:00
|
|
|
.expect("failed openssl command");
|
2019-03-16 14:33:28 +00:00
|
|
|
|
2019-05-10 14:15:30 +00:00
|
|
|
sha.stdout.resize(64, 0);
|
2019-03-16 14:33:28 +00:00
|
|
|
String::from_utf8(sha.stdout).unwrap()
|
|
|
|
}
|
|
|
|
|
2018-12-06 17:54:16 +00:00
|
|
|
fn main() {
|
|
|
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
2019-03-20 16:56:17 +00:00
|
|
|
let in_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("templates");
|
2018-12-06 17:54:16 +00:00
|
|
|
compile_templates(&in_dir, &out_dir).expect("compile templates");
|
|
|
|
|
2019-05-18 12:09:51 +00:00
|
|
|
println!("cargo:rerun-if-changed=static/css/_article.scss");
|
|
|
|
println!("cargo:rerun-if-changed=static/css/_forms.scss");
|
|
|
|
println!("cargo:rerun-if-changed=static/css/_global.scss");
|
|
|
|
println!("cargo:rerun-if-changed=static/css/_header.scss");
|
|
|
|
println!("cargo:rerun-if-changed=static/css/_variables.scss");
|
|
|
|
println!("cargo:rerun-if-changed=static/css/main.scss");
|
2018-12-15 21:06:27 +00:00
|
|
|
let mut out = File::create("static/css/main.css").expect("Couldn't create main.css");
|
|
|
|
out.write_all(
|
2019-03-20 16:56:17 +00:00
|
|
|
&rsass::compile_scss_file(
|
|
|
|
"static/css/main.scss".as_ref(),
|
|
|
|
rsass::OutputStyle::Compressed,
|
|
|
|
)
|
|
|
|
.expect("Error during SCSS compilation"),
|
|
|
|
)
|
|
|
|
.expect("Couldn't write CSS output");
|
2018-12-25 10:51:40 +00:00
|
|
|
|
2019-03-16 14:33:28 +00:00
|
|
|
let cache_id = &compute_static_hash()[..8];
|
2019-03-15 15:06:10 +00:00
|
|
|
println!("cargo:rerun-if-changed=target/deploy/plume-front.wasm");
|
2018-12-25 10:51:40 +00:00
|
|
|
copy("target/deploy/plume-front.wasm", "static/plume-front.wasm")
|
|
|
|
.and_then(|_| read_to_string("target/deploy/plume-front.js"))
|
2019-03-20 16:56:17 +00:00
|
|
|
.and_then(|js| {
|
|
|
|
write(
|
|
|
|
"static/plume-front.js",
|
|
|
|
js.replace(
|
|
|
|
"\"plume-front.wasm\"",
|
|
|
|
&format!("\"/static/cached/{}/plume-front.wasm\"", cache_id),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.ok();
|
2019-03-16 14:33:28 +00:00
|
|
|
|
|
|
|
println!("cargo:rustc-env=CACHE_ID={}", cache_id)
|
2018-12-06 17:54:16 +00:00
|
|
|
}
|