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
mod cli;
pub use cli::cli;
use std::fs::DirBuilder;
pub fn mkdirs(base: &str) {
    let mut builder = DirBuilder::new();
    let builder = builder.recursive(true);
    vec![
        "public/css",
        "public/scripts",
        "public/img",
        "src/Partials",
        "src/Pages",
        "src/Utils",
        ".scripts",
    ]
    .iter()
    .for_each(|dir| builder.create(format!("{}/{}", base, dir)).unwrap());
    create_files(base);
}
pub fn create_files(base: &str) {
    vec![
        (
            "public/index.html",
            include_str!("../static_includes/index.html"),
        ),
        ("src/Main.elm", include_str!("../static_includes/Main.elm")),
        ("Makefile", include_str!("../static_includes/Makefile")),
        (
            ".scripts/filehash.sh",
            include_str!("../static_includes/filehash.sh"),
        ),
        (
            "elm.json",
            &include_str!("../static_includes/elm.json").replace("{{version}}", &elm_version()),
        ),
        (
            "config.prod.js",
            include_str!("../static_includes/config.js"),
        ),
        (
            "config.dev.js",
            include_str!("../static_includes/config.js"),
        ),
    ]
    .iter()
    .for_each(|(f, c)| {
        std::fs::write(format!("{}/{}", base, f), c).expect("cannot write needed files")
    });
}
fn elm_version() -> String {
    String::from_utf8_lossy(
        std::process::Command::new("elm")
            .arg("--version")
            .output()
            .expect("elm is not installed or not in the path")
            .stdout
            .as_slice(),
    )
    .trim()
    .into()
}