1mod cli;
2pub use cli::cli;
3use std::fs::DirBuilder;
4pub fn mkdirs(base: &str) {
5 let mut builder = DirBuilder::new();
6 let builder = builder.recursive(true);
7 vec![
8 "public/css",
9 "public/scripts",
10 "public/img",
11 "src/Partials",
12 "src/Pages",
13 "src/Utils",
14 ".scripts",
15 ]
16 .iter()
17 .for_each(|dir| builder.create(format!("{}/{}", base, dir)).unwrap());
18 create_files(base);
19}
20pub fn create_files(base: &str) {
21 vec![
22 (
23 "public/index.html",
24 include_str!("../static_includes/index.html"),
25 ),
26 ("src/Main.elm", include_str!("../static_includes/Main.elm")),
27 ("Makefile", include_str!("../static_includes/Makefile")),
28 (
29 ".scripts/filehash.sh",
30 include_str!("../static_includes/filehash.sh"),
31 ),
32 (
33 "elm.json",
34 &include_str!("../static_includes/elm.json").replace("{{version}}", &elm_version()),
35 ),
36 (
37 "config.prod.js",
38 include_str!("../static_includes/config.js"),
39 ),
40 (
41 "config.dev.js",
42 include_str!("../static_includes/config.js"),
43 ),
44 (".gitignore", include_str!("../static_includes/gitignore")),
45 (".ctags", include_str!("../static_includes/ctags")),
46 ]
47 .iter()
48 .for_each(|(f, c)| {
49 std::fs::write(format!("{}/{}", base, f), c).expect("cannot write needed files")
50 });
51}
52fn elm_version() -> String {
53 String::from_utf8_lossy(
54 std::process::Command::new("elm")
55 .arg("--version")
56 .output()
57 .expect("elm is not installed or not in the path")
58 .stdout
59 .as_slice(),
60 )
61 .trim()
62 .into()
63}