chore: add fonts

This commit is contained in:
Christopher Willis-Ford 2023-01-06 17:13:56 -08:00
parent 780dba67c0
commit 1d51aa443f
4 changed files with 95 additions and 0 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
/.vscode
/assets/fonts
/node_modules
/target

47
build.rs Normal file
View file

@ -0,0 +1,47 @@
use std::{path::Path, fs::{self, DirEntry}, io, ffi::OsStr};
fn main() {
copy_fonts();
}
fn copy_files<P: AsRef<Path>, Q: AsRef<Path>, R>(from_dir: P, to_dir: Q, predicate: R) -> io::Result<()>
where R: Fn(&DirEntry) -> bool
{
let dir_entries = fs::read_dir(from_dir.as_ref())?;
for dir_entry in dir_entries {
if let Ok(dir_entry) = dir_entry {
let src_path = dir_entry.path();
if let Some(file_name) = src_path.file_name() {
if predicate(&dir_entry) {
let dest_path = Path::new(to_dir.as_ref()).join(file_name);
eprintln!("copy_files copying {0} to {1}", src_path.display(), dest_path.display());
fs::copy(src_path, dest_path)?;
}
}
}
}
Ok(())
}
fn copy_fonts() {
let font_extensions = vec![
OsStr::new("ttf"),
OsStr::new("otf"),
];
let src_path = Path::new("node_modules/scratch-render-fonts/src");
let dst_path = Path::new("assets/fonts");
println!("cargo:rerun-if-changed={:?}/*.ttf", src_path);
fs::create_dir_all(dst_path).expect("failed to create fonts directory");
copy_files(src_path, dst_path, |dir_entry| {
let src_path = dir_entry.path();
eprintln!("copy_fonts checking {0}", src_path.display());
if !src_path.is_file() {
return false;
}
match src_path.extension() {
Some(ext) => font_extensions.contains(&ext),
None => false
}
}).expect("failed to copy fonts");
}

40
package-lock.json generated Normal file
View file

@ -0,0 +1,40 @@
{
"name": "scratch-tech-explorations",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"dependencies": {
"scratch-render-fonts": "1.0.0-prerelease.20221102164332"
}
},
"node_modules/base64-loader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base64-loader/-/base64-loader-1.0.0.tgz",
"integrity": "sha512-p32+F8dg+ANGx7s8QsZS74ZPHfIycmC2yZcoerzFgbersIYWitPbbF39G6SBx3gyvzyLH5nt1ooocxr0IHuWKA=="
},
"node_modules/scratch-render-fonts": {
"version": "1.0.0-prerelease.20221102164332",
"resolved": "https://registry.npmjs.org/scratch-render-fonts/-/scratch-render-fonts-1.0.0-prerelease.20221102164332.tgz",
"integrity": "sha512-22MbRDGUSArVEoHatg5rt7f/H0wWhMrcyN6HD0OQJeDqdlO3qSSX9/qvdzNJGYWwZkhrdJWcI5JGD1YuJfefmw==",
"dependencies": {
"base64-loader": "1.0.0"
}
}
},
"dependencies": {
"base64-loader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base64-loader/-/base64-loader-1.0.0.tgz",
"integrity": "sha512-p32+F8dg+ANGx7s8QsZS74ZPHfIycmC2yZcoerzFgbersIYWitPbbF39G6SBx3gyvzyLH5nt1ooocxr0IHuWKA=="
},
"scratch-render-fonts": {
"version": "1.0.0-prerelease.20221102164332",
"resolved": "https://registry.npmjs.org/scratch-render-fonts/-/scratch-render-fonts-1.0.0-prerelease.20221102164332.tgz",
"integrity": "sha512-22MbRDGUSArVEoHatg5rt7f/H0wWhMrcyN6HD0OQJeDqdlO3qSSX9/qvdzNJGYWwZkhrdJWcI5JGD1YuJfefmw==",
"requires": {
"base64-loader": "1.0.0"
}
}
}
}

6
package.json Normal file
View file

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"scratch-render-fonts": "1.0.0-prerelease.20221102164332"
}
}