2017-02-23 08:34:57 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
2017-03-08 04:21:45 +00:00
|
|
|
extern crate chrono;
|
2017-03-25 06:52:51 +00:00
|
|
|
extern crate term_painter;
|
2017-03-06 10:35:56 +00:00
|
|
|
extern crate staticfile;
|
|
|
|
extern crate iron;
|
|
|
|
extern crate mount;
|
|
|
|
extern crate notify;
|
2017-07-27 09:24:43 +00:00
|
|
|
extern crate url;
|
2017-03-06 10:35:56 +00:00
|
|
|
extern crate ws;
|
|
|
|
|
2017-07-01 07:47:41 +00:00
|
|
|
extern crate site;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate errors;
|
|
|
|
extern crate content;
|
|
|
|
extern crate front_matter;
|
|
|
|
extern crate utils;
|
|
|
|
|
2017-03-03 08:12:40 +00:00
|
|
|
use std::time::Instant;
|
2017-03-25 06:52:51 +00:00
|
|
|
|
2016-12-06 05:51:33 +00:00
|
|
|
mod cmd;
|
2017-03-25 06:52:51 +00:00
|
|
|
mod console;
|
2017-05-13 13:37:01 +00:00
|
|
|
mod rebuild;
|
2017-07-15 04:24:31 +00:00
|
|
|
mod cli;
|
2017-07-27 09:24:43 +00:00
|
|
|
mod prompt;
|
2016-12-06 06:55:17 +00:00
|
|
|
|
2016-12-06 05:51:33 +00:00
|
|
|
|
|
|
|
fn main() {
|
2017-07-15 04:24:31 +00:00
|
|
|
let matches = cli::build_cli().get_matches();
|
2016-12-06 05:51:33 +00:00
|
|
|
|
2017-03-25 04:18:15 +00:00
|
|
|
let config_file = matches.value_of("config").unwrap_or("config.toml");
|
|
|
|
|
2016-12-06 05:51:33 +00:00
|
|
|
match matches.subcommand() {
|
2016-12-19 07:58:03 +00:00
|
|
|
("init", Some(matches)) => {
|
2016-12-06 05:51:33 +00:00
|
|
|
match cmd::create_new_project(matches.value_of("name").unwrap()) {
|
2017-07-27 09:24:43 +00:00
|
|
|
Ok(()) => (),
|
2017-05-12 14:10:21 +00:00
|
|
|
Err(e) => {
|
|
|
|
console::unravel_errors("Failed to create the project", &e);
|
|
|
|
::std::process::exit(1);
|
|
|
|
},
|
2016-12-06 08:27:03 +00:00
|
|
|
};
|
|
|
|
},
|
2017-10-05 01:56:13 +00:00
|
|
|
("build", Some(matches)) => {
|
2017-03-25 06:52:51 +00:00
|
|
|
console::info("Building site...");
|
2017-03-03 08:12:40 +00:00
|
|
|
let start = Instant::now();
|
2017-12-29 18:25:06 +00:00
|
|
|
let output_dir = matches.value_of("output_dir").unwrap();
|
|
|
|
match cmd::build(config_file, matches.value_of("base_url"), output_dir) {
|
2017-05-12 14:10:21 +00:00
|
|
|
Ok(()) => console::report_elapsed_time(start),
|
|
|
|
Err(e) => {
|
|
|
|
console::unravel_errors("Failed to build the site", &e);
|
|
|
|
::std::process::exit(1);
|
|
|
|
},
|
2016-12-06 05:51:33 +00:00
|
|
|
};
|
|
|
|
},
|
2017-03-03 08:12:40 +00:00
|
|
|
("serve", Some(matches)) => {
|
|
|
|
let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
|
|
|
|
let port = matches.value_of("port").unwrap_or("1111");
|
2017-12-29 18:25:06 +00:00
|
|
|
let output_dir = matches.value_of("output_dir").unwrap();
|
2017-03-25 06:52:51 +00:00
|
|
|
console::info("Building site...");
|
2017-12-29 18:25:06 +00:00
|
|
|
match cmd::serve(interface, port, output_dir, config_file) {
|
2017-03-06 10:35:56 +00:00
|
|
|
Ok(()) => (),
|
2017-05-12 14:10:21 +00:00
|
|
|
Err(e) => {
|
2017-05-20 15:00:41 +00:00
|
|
|
console::unravel_errors("", &e);
|
2017-05-12 14:10:21 +00:00
|
|
|
::std::process::exit(1);
|
|
|
|
},
|
2017-03-03 08:12:40 +00:00
|
|
|
};
|
|
|
|
},
|
2016-12-06 05:51:33 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|