Finish npm exorcism

This commit is contained in:
Tristan D. 2025-03-25 02:49:18 +01:00
parent 5ced6ee0bf
commit 918248d3b1
Signed by: tristan
SSH key fingerprint: SHA256:9oFM1J63hYWJjCnLG6C0fxBS15rwNcWwdQNMOHYKJ/4
18 changed files with 233 additions and 4503 deletions

5
.gitignore vendored
View file

@ -31,3 +31,8 @@ llamafile.git
*/dist/
.aider*
darm_test/style/encr.css
darm_test/public/main.*
darm_test/public/datastar.*
darm_test/public/css/*.css

4446
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -20,7 +20,7 @@ lto = "fat"
panic = "abort"
[workspace]
members = ["darm_test", "llama_forge_rs", "llama_proxy_man", "redvault_el_rs"]
members = ["darm_test", "llama_proxy_man", "redvault_el_rs"]
resolver = "2"
[workspace.package]

View file

@ -5,6 +5,8 @@ load_cargo_aliases = false
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
# DB_REPOS
[tasks.default]
alias = "all"
@ -28,11 +30,11 @@ dependencies = [
[tasks.docset]
workspace = false
dependencies = ["mksitedir", "make-docset", "cp-docset"]
dependencies = ["make-docset", "cp-docset"]
[tasks.make-docset]
workspace = false
dependencies = ["mksitedir"]
dependencies = []
script = "cargo docset --workspace --no-clean --platform-family redvault-ai && sleep 1 && sync"
[tasks.cp-docset]

2
darm_test/Makefile.toml Normal file
View file

@ -0,0 +1,2 @@
[tasks.pre-build]
script = "./scripts/build_css.rs"

View file

@ -1,6 +1,6 @@
* TODOS (newnewnewest)
- no npm for css
- finish basic setup with rsass + encro_css + lightningcss
- [X] finish basic setup with rsass + encro_css + lightningcss
- encro icons & typography
- add encro animate ???
- simplify build scripts

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1 +0,0 @@
datastar-1-0-0-beta-9-3caff1580ebe0e7c.js

12
darm_test/public/datastar.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

139
darm_test/scripts/build_css.rs Executable file
View file

@ -0,0 +1,139 @@
#!/usr/bin/env rust-script
//! This is a regular crate doc comment, but it also contains a partial
//! Cargo manifest. Note the use of a *fenced* code block, and the
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! encre-css = "0.14"
//! walkdir = "2"
//! grass = { version = "0.13.4", features = ["macro", "nightly"] }
//! lightningcss = { version = "1.0.0-alpha.65", features = ["bundler", "browserslist"] }
//! anyhow = "1"
//! async-compression = { version = "0.4", features = ["tokio", "zstd"] }
//! tokio = { version = "1", features = [ "full" ] }
//! ```
use std::{collections::BTreeSet, fs, path::Path};
use async_compression::tokio::write::ZstdEncoder;
use encre_css::{Config, Scanner};
use lightningcss::{
bundler::{Bundler, FileProvider},
stylesheet::{ParserOptions, PrinterOptions},
targets::{Browsers, Targets},
};
use tokio::io::AsyncWriteExt as _; // for `write_all` and `shutdown`
use walkdir::WalkDir;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
eprintln!("WEGL CSS 💅 © 2025==========================================");
eprintln!("look mum no js/npm");
eprintln!("Reading! Step 1/5 🚶 (Walking Dirs)");
// Walk through the directory structure
let contents = WalkDir::new("./")
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| {
e.file_type().is_file()
&& e.path()
.extension()
.map_or(false, |ext| ["rs", "scss"].into_iter().any(|e| e == ext))
})
.map(|entry| {
let path = entry.path();
// eprintln!("Processing file: {}", path.display());
let content = fs::read_to_string(path).expect("Failed to read");
let bx = Box::new(content);
let static_ref: &'static str = Box::leak(bx);
static_ref
});
let config = {
let mut config = Config::default();
// FIXME TODO Add moar colors
config.scanner = Scanner::from_fn(|val| {
let mut is_arbitrary = false;
val.split(|ch| {
// Escape all characters in arbitrary values prefixed by a dash (used to avoid
// ignoring values in, for example, JS arrays, given that they are defined
// using square brackets)
match ch {
'[' => {
is_arbitrary = true;
false
}
']' => {
is_arbitrary = false;
false
}
_ => {
ch == ' '
|| (!is_arbitrary
&& ['.', '\'', '"', '`', '\n'].into_iter().any(|c| c == ch))
}
}
})
.collect::<BTreeSet<&str>>()
});
// config
// .theme
// .colors
// .add("blue-500", "oklch(.623 .214 259.815)");
// config.theme.colors.add("blue", "rgb(.1, .1, .9)");
config
};
eprintln!("Building Utilities Step 2/5 ⚙️ (EncrCSS)");
let generated = encre_css::generate(contents, &config);
tokio::fs::write("./public/css/encr.css", &generated).await?;
tokio::fs::write("./style/encr.css", &generated).await?;
eprintln!("Compiling SCSS Step 3/5 🏗 (Grass Compile)");
let compiled = grass::from_path("./style/main.scss", &grass::Options::default())?;
tokio::fs::write("./public/css/main.css", compiled.clone()).await?;
eprintln!("Bundling & Minifying Step 4/5 ⚡️ (Lightning CSS)");
let fs: FileProvider = FileProvider::new();
let fs: &'static _ = Box::leak(Box::new(fs)); // yolo it's a script, and we need a 'static ref
let mut bundler = Bundler::new(fs, None, ParserOptions::default());
let stylesheet = bundler.bundle(Path::new("./public/css/main.css"))?;
// Serialize it to a string.
let optimized_opts = PrinterOptions {
minify: true,
targets: Targets {
browsers: Browsers::from_browserslist([
"> 0.5%, last 3 versions, Firefox ESR, not dead"
])?,
..Default::default()
},
..Default::default()
};
let res = stylesheet.to_css(Default::default()).unwrap();
let opt_res = stylesheet.to_css(optimized_opts).unwrap();
// println!("{}", res.code);
tokio::fs::write("./public/main.css", res.code.clone()).await?;
tokio::fs::write("./public/main.min.css", opt_res.code).await?;
eprintln!("Compressing... Step 5/5 🐁️ (Zstd)");
async fn compress(in_data: &[u8]) -> anyhow::Result<Vec<u8>> {
let mut encoder = ZstdEncoder::new(Vec::new());
encoder.write_all(in_data).await?;
encoder.shutdown().await?;
Ok(encoder.into_inner())
}
// tokio::fs::write(
// "./public/main.min.css.zstd",
// compress(res.code.as_bytes()).await?,
// )
// .await?;
eprintln!("Done ! =====================================================");
Ok(())
}

View file

@ -1,79 +0,0 @@
#!/usr/bin/env rust-script
//! This is a regular crate doc comment, but it also contains a partial
//! Cargo manifest. Note the use of a *fenced* code block, and the
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! encre-css = "0.14"
//! walkdir = "2"
//! ```
use std::{
collections::BTreeSet,
fs::{self, File},
io::{self, Write},
path::Path,
};
use encre_css::{utils::split_ignore_arbitrary, Config, Scanner};
use walkdir::WalkDir;
fn main() -> io::Result<()> {
// Define the source directory to scan
let source_dir = "./"; // Change this to your source directory
eprintln!("Scanning directory: {}", source_dir);
// Walk through the directory structure
let contents = WalkDir::new(source_dir)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| {
e.file_type().is_file()
&& e.path()
.extension()
.map_or(false, |ext| ext == "rs" || ext == "scss")
})
.map(|entry| {
let path = entry.path();
eprintln!("Processing file: {}", path.display());
let content = fs::read_to_string(path).expect("Failed to read");
let bx = Box::new(content);
let static_ref: &'static str = Box::leak(bx);
static_ref
});
let mut config = Config::default();
config.scanner = Scanner::from_fn(|val| {
let mut is_arbitrary = false;
val.split(|ch| {
// Escape all characters in arbitrary values prefixed by a dash (used to avoid
// ignoring values in, for example, JS arrays, given that they are defined
// using square brackets)
match ch {
'[' => {
is_arbitrary = true;
false
}
']' => {
is_arbitrary = false;
false
}
_ => {
ch == ' '
|| (!is_arbitrary
&& (ch == '.' || ch == '\'' || ch == '"' || ch == '`' || ch == '\n'))
}
}
})
.collect::<BTreeSet<&str>>()
});
let generated = encre_css::generate(contents, &config);
println!("{generated}");
Ok(())
}

View file

@ -11,7 +11,7 @@ pub fn main_page(body: impl Renderable) -> impl Renderable {
meta name="viewport" content="width=device-width, initial-scale=1.0";
title { "LLM Chat App" }
script type="module" src="/dist/datastar.min.js" {}
link rel="stylesheet" href="/dist/styles.min.css";
link rel="stylesheet" href="/dist/main.min.css";
link rel="icon" href="/dist/favicon.ico";
}
body class="bg-gray-100" {

View file

@ -54,6 +54,8 @@ impl UiController {
tokio::time::sleep(Duration::from_millis(250)).await;
// bg-blue-500
// .bg-blue-500
yield MergeFragments::new(maud! { div #llm-1 class="mb-2 animated animated-bounce" { strong { "LLM:" } "This is a mock response."} }.render())
.selector("#chat")
.merge_mode(FragmentMergeMode::Append)
@ -75,7 +77,7 @@ impl UiController {
}
form id="chat-form" {
textarea #user-input .p-2 .m-2 .w-full .rounded-lg .border data-bind-msginput placeholder="Type your message..." {}
button #send-btn class="btn" type="button" data-on-click="@get('/msg')" {
button #send-btn .bg-blue-500 .rounded-lg .text-white .p-2 type="button" data-on-click="@get('/msg')" {
"Send"
}
}

View file

@ -1,10 +1,2 @@
// @use '../../node_modules/@unocss/reset/normalize.css';
@use '../../node_modules/@unocss/reset/tailwind-compat.css';
// @use '../../node_modules/animate.css/animate.min.css';
// @use 'uno';
@use 'encr';
.btn {
// p-2 text-white bg-blue-500 rounded-lg
@extend .p-2, .text-white, .bg-blue-500, .rounded-lg;
}
@import url("encr.css");
// @use "encr";