1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use std::{path::PathBuf, ffi::OsString};
use bpaf::Bpaf;
use cli::{recursive_template_search, bundle::{do_bundle_spa, IncludeElementChecker}};
use color_eyre::eyre::Result;
mod cli;
pub mod workarounds;
pub mod consts;
use crate::cli::codegen::*;
#[derive(Debug, Clone, Bpaf)]
#[bpaf(options, version)]
/// ARitz's Custom Element Template Engine With Markdown
pub(crate) enum CliAction {
#[bpaf(command("codegen"))]
/// Recursively generates boilerplate code for your custom elements.
Codegen {
/// Folder names to exclude, defaults to node_modules.
#[bpaf(argument("NAME"), short, long)]
exclude: Vec<OsString>,
/// Folder to scan for HTML template fragments and generate accompanying code.
#[bpaf(positional("PATH"))]
path: PathBuf
},
#[bpaf(command("bundle-single"))]
/// Bundles all template elements for a single-page application.
BundleSinglePageApp {
/// File name for the template bundle.
#[bpaf(argument("PATH"), short, long)]
output_file: PathBuf,
/// Elements to include in the bundle. By default, all elements will be included.
#[bpaf(argument("ELEMENT"), short, long)]
include: Vec<String>,
/// Elements to exclude from the bundle. By default, no elements will be excluded.
#[bpaf(argument("ELEMENT"), short, long)]
exclude: Vec<String>,
/// Folder to scan for HTML template fragments. Must contain a main_template.html.
#[bpaf(positional("PATH"))]
input_fragments: PathBuf
},
#[bpaf(command("bundle-multi"))]
/// Bundles all template elements for a multi-page application on a static-content server
BundleMultiPageApp {
/// Elements to include in the bundle. By default, all elements will be included.
#[bpaf(argument("ELEMENT"), short, long)]
include: Vec<String>,
/// Elements to exclude from the bundle. By default, no elements will be excluded.
#[bpaf(argument("ELEMENT"), short, long)]
exclude: Vec<String>,
/// The webroot directory to write to
#[bpaf(argument("PATH"), short, long)]
output_dir: PathBuf,
/// Folder to scan for HTML template fragments. Must contain a main_template.html.
#[bpaf(argument("PATH"), short('f'), long)]
input_fragments: PathBuf,
/// Folder to scan for pages
#[bpaf(argument("PATH"), short('p'), long)]
input_pages: PathBuf,
/// Bundle for a "fake" MPA, i.e. only output the full document for index.html
#[bpaf(short('F'), long)]
fake: bool
},
#[bpaf(command("bundle-server"))]
/// Bundles all template elements for the acetewm server.
BundleServer {
/// Elements to include in the bundle. By default, all elements will be included.
#[bpaf(argument("ELEMENT"), short, long)]
include: Vec<String>,
/// Elements to exclude from the bundle. By default, no elements will be excluded.
#[bpaf(argument("ELEMENT"), short, long)]
exclude: Vec<String>,
/// The webroot directory to write to
#[bpaf(argument("PATH"), short, long)]
output_dir: PathBuf,
/// Folder to scan for HTML template fragments. Must contain a main_template.html.
#[bpaf(argument("PATH"), short('f'), long)]
input_fragments: PathBuf
},
#[bpaf(command("start-server"))]
/// Starts the acetewm server, which converts page definitions to documents on-the-fly.
StartServer {
}
}
fn main() -> Result<()> {
color_eyre::install()?;
env_logger::init();
let options = cli_action().run();
match options {
CliAction::Codegen { exclude, path } => {
recursive_template_search(
path,
&{
if exclude.is_empty() {
vec!["node_modules".into()]
}else{
exclude
}
}.into_iter().collect(),
&mut do_code_gen
)?;
},
CliAction::BundleSinglePageApp {
output_file,
include,
exclude,
input_fragments
} => {
do_bundle_spa(
output_file,
IncludeElementChecker::from_string_vecs(include, exclude),
input_fragments
)?;
}
_ => todo!()
}
/*
let fragment = html!(r#"
<h1>Test fragment</h1>
<p>I am a paragraph with a <custom-elem>custom element</custom-elem></p>
<p>I am a paragraph with a <other-custom-elem>OTHER custom element</other-custom-elem></p>
"#);
let mut a = fragment.select(selector!("custom-elem, other-custom-elem"));
println!("Custom elenm {:#?}", a.next().unwrap().value());
println!("Custom eledddnm {:#?}", a.next().unwrap().value());
*/
Ok(())
}