Jump to…
snowinitial commitqoxwzsukwmkx1mo
Matt W1//! Make the CodeMirror bundle optional at compile time.
Matt W2//!
Matt W3//! `assets/editor.min.js` is produced by esbuild in a Docker build stage, so it
Matt W4//! does not exist in a source checkout. `include_str!` needs *something*
Matt W5//! though, and a missing file would make `cargo build` fail outside Docker —
Matt W6//! which would mean the test suite could not run without a Node toolchain.
Matt W7//!
Matt W8//! An empty placeholder is the right fallback rather than a workaround: the
Matt W9//! edit page ships a working `<textarea>` and the bundle only enhances it, so a
Matt W10//! build without the bundle produces a product where editing still works,
Matt W11//! plainly. That is the documented behaviour when the script fails to load, and
Matt W12//! this makes it the behaviour when it was never built either.
Matt W13
Matt W14use std::path::Path;
Matt W15
Matt W16fn main() {
Matt W17 let bundle = Path::new("assets/editor.min.js");
Matt W18 println!("cargo:rerun-if-changed=assets/editor.min.js");
Matt W19
Matt W20 if !bundle.exists() {
Matt W21 std::fs::write(
Matt W22 bundle,
Matt W23 "/* No editor bundle in this build. The edit page falls back to a \
Matt W24 plain textarea, which is a working editor. */\n",
Matt W25 )
Matt W26 .expect("writing the editor placeholder");
Matt W27 println!(
Matt W28 "cargo:warning=assets/editor.min.js was not built; \
Matt W29 the web editor will fall back to a plain textarea"
Matt W30 );
Matt W31 }
Matt W32}

32 lines · Rust