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
use crate::{Port, DEFAULT_PORT, DEFAULT_PORT_WS};

/// Configuration struct for `Unreact`
///
/// Use `Config::default()` for default values
///
/// ## Summary
///
/// - `strict`: Whether [`Handlebars`](handlebars) uses 'strict mode'
/// - `minify`: Whether output files should be minified
///
/// Folders:
///
/// - `build`: Output folder for built files
/// - `templates`: Source folder for template files
/// - `styles`: Source folder for style files
/// - `public`: Source folder for static public files
///
/// Development Options:
///
/// - `port`: Port to serve *dev server* on - Only used with `"dev"` feature
/// - `port_ws`: Port to serve *dev server* **websockets** on - Only used with `"watch"` feature
/// - `watch_logs`: Whether to log update information - Only used with `"watch"` feature
#[derive(Debug)]
pub struct Config {
    /// Output folder for built files
    ///
    /// Overridden with DEV_BUILD_DIR if in dev mode
    ///
    /// Subfolders of build directory cannot be configured
    ///
    /// Default: `build` (or `.devbuild` in dev mode)
    pub build: String,
    /// Source folder for template files
    ///
    /// Default: `templates`
    pub templates: String,
    /// Source folder for style files
    ///
    /// Default: `styles`
    pub styles: String,
    /// Source folder for static public files
    ///
    /// Default: `public`
    pub public: String,

    /// Whether [`Handlebars`](handlebars) uses 'strict mode'
    ///
    /// If `true`, undefined variables and partials throw an error
    pub strict: bool,
    /// Whether output files should be minified
    ///
    /// Only affects `html` and `css` output files
    pub minify: bool,

    /// Port for main *dev server* to be hosted on
    ///
    /// Only used with `"dev"` feature, but must be defined always
    pub port: Port,
    /// Port for websocket server to be hosted on
    ///
    /// Only used with `"watch"` feature, but must be defined always
    pub port_ws: Port,

    /// Whether logs should be sent to stdout for update events
    ///
    /// Only used with `"watch"` feature, but must be defined always
    ///
    /// Events that would be logged:
    ///
    /// - Recompile (reloads server)
    /// - Client connect
    /// - Client disconnect
    pub watch_logs: bool,
}

impl Default for Config {
    fn default() -> Self {
        Self {
            build: "build".to_string(),
            templates: "templates".to_string(),
            styles: "styles".to_string(),
            public: "public".to_string(),

            strict: false,
            minify: true,

            port: DEFAULT_PORT,
            port_ws: DEFAULT_PORT_WS,

            watch_logs: false,
        }
    }
}