Write html assets to build folder, and make sure it exists

This commit is contained in:
Chadtech 2021-03-23 22:25:16 -04:00
parent bf4b2b823f
commit 5b07b1c946
3 changed files with 561 additions and 3 deletions

View file

@ -16,6 +16,8 @@ use bumpalo::Bump;
use roc_collections::all::MutMap;
use std::path::{Path, PathBuf};
mod assets;
#[derive(Serialize)]
pub struct Template {
pub package_name: String,
@ -56,6 +58,17 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
modules: files_docs,
};
if !build_dir.exists() {
fs::create_dir_all(build_dir).expect("TODO gracefully handle unable to create build dir");
}
fs::write(build_dir.join("search.js"), assets::SEARCH_JS)
.expect("TODO gracefully handle failing to make the search javascript");
fs::write(build_dir.join("styles.css"), assets::STYLE_CSS)
.expect("TODO gracefully handle failing to make the stylesheet");
fs::write(build_dir.join("favicon.svg"), assets::FAVICON)
.expect("TODO gracefully handle failing to make the favicon");
// Register handlebars template
let mut handlebars = handlebars::Handlebars::new();
handlebars