diff --git a/compiler-cli/src/docs.rs b/compiler-cli/src/docs.rs index 9f578b7a15a..c5b148ef0c6 100644 --- a/compiler-cli/src/docs.rs +++ b/compiler-cli/src/docs.rs @@ -10,7 +10,7 @@ use gleam_core::{ docs::DocContext, error::Error, hex, - io::HttpClient as _, + io::{Content, HttpClient as _, OutputFile}, Result, }; @@ -119,7 +119,7 @@ pub(crate) fn build_documentation( config: &PackageConfig, compiled: &mut Package, is_hex_publish: DocContext, -) -> Result, Error> { +) -> Result, Error> { compiled.attach_doc_and_module_comments(); cli::print_generating_documentation(); let paths = crate::find_project_paths()?; @@ -139,6 +139,22 @@ pub(crate) fn build_documentation( is_hex_publish, ); + // add non-Gleam files to docs output + for path in crate::fs::non_gleam_files_excluding_gitignore(Utf8Path::new("src")) { + if path.exists() { + if let Ok(bytes) = crate::fs::read_bytes(&path) { + let content = Content::Binary(bytes); + if let Ok(output_path) = path.strip_prefix("src") { + let file = OutputFile { + path: output_path.to_path_buf(), + content, + }; + outputs.push(file) + } + } + } + } + outputs.push(gleam_core::docs::generate_json_package_interface( Utf8PathBuf::from("package-interface.json"), compiled, diff --git a/compiler-cli/src/fs.rs b/compiler-cli/src/fs.rs index e0dc2adffe8..34eb555c3f7 100644 --- a/compiler-cli/src/fs.rs +++ b/compiler-cli/src/fs.rs @@ -429,6 +429,20 @@ pub fn private_files_excluding_gitignore(dir: &Utf8Path) -> impl Iterator impl Iterator + '_ { + ignore::WalkBuilder::new(dir) + .follow_links(true) + .require_git(false) + .build() + .filter_map(Result::ok) + .filter(|e| e.file_type().map(|t| t.is_file()).unwrap_or(false)) + .map(ignore::DirEntry::into_path) + .map(|pb| Utf8PathBuf::from_path_buf(pb).expect("Non Utf-8 Path")) + .filter(move |d| !is_gleam_path(d, dir)) +} + pub fn erlang_files(dir: &Utf8Path) -> Result + '_> { Ok(read_dir(dir)? .flat_map(Result::ok)