feat: port css-in-elm to starmelon

This commit is contained in:
YetAnotherMinion 2022-04-02 23:54:12 +01:00 committed by nobody
commit 376a14480b
Signed by: GrocerPublishAgent
GPG key ID: D460CD54A9E3AB86
5 changed files with 465 additions and 0 deletions

View file

@ -7,6 +7,7 @@ use std::path::PathBuf;
use tracing::info_span;
mod astrid_pages;
mod css_in_elm;
mod fixtures;
mod scripting;
@ -58,6 +59,8 @@ pub(crate) fn exec(
if is_astrid_pages_route(tipe) {
ExecutionMode::AstridPagesRoute
} else if is_css_in_elm_stylesheet(tipe) {
ExecutionMode::CssInElm
} else {
let (input_type, output_type) = scripting::resolve_function_type(tipe)?;
ExecutionMode::Scripting(input_type, output_type)
@ -98,11 +101,20 @@ pub(crate) fn exec(
entrypoint,
output,
),
ExecutionMode::CssInElm => css_in_elm::run(
debug,
verbosity,
elm_project_dir,
source_checksum,
entrypoint,
output,
),
}
}
enum ExecutionMode {
AstridPagesRoute,
CssInElm,
Scripting(Option<scripting::InputType>, scripting::OutputType),
}
@ -115,6 +127,40 @@ fn is_astrid_pages_route(tipe: &elmi::Type) -> bool {
}
}
fn is_css_in_elm_stylesheet(tipe: &elmi::Type) -> bool {
match tipe {
elmi::Type::TType(module_name, name, args) => {
if module_name == "elm/core/List" && name == "List" && args.len() == 1 {
match &args[0] {
elmi::Type::TTuple(a, b, None) => {
match &**a {
elmi::Type::TType(module_name, name, _)
if module_name == "elm/core/String" && name == "String" => (),
_ => return false,
}
match &**b {
elmi::Type::TType(module_name, name, args)
if module_name == "elm/core/List" && name == "List" && args.len() == 1 =>
{
match &args[0] {
elmi::Type::TAlias(module_name, name, _, _)
if module_name == "ThinkAlexandria/css-in-elm/Css" && name == "Stylesheet" => return true,
_ => (),
}
}
_ => (),
}
}
_ => (),
}
}
}
_ => (),
}
false
}
mod runtime {
use crate::reporting::InterpreterError;
use deno_core::error::{type_error, AnyError};