|
|
@@ -1,14 +1,23 @@ |
|
|
|
use std::fs::create_dir; |
|
|
|
use std::fs::{create_dir, canonicalize}; |
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
use errors::Result; |
|
|
|
use utils::fs::create_file; |
|
|
|
|
|
|
|
use prompt::{ask_bool, ask_url}; |
|
|
|
use console; |
|
|
|
|
|
|
|
|
|
|
|
const CONFIG: &'static str = r#" |
|
|
|
title = "My site" |
|
|
|
# replace the url below with yours |
|
|
|
base_url = "https://example.com" |
|
|
|
# The URL the site will be built for |
|
|
|
base_url = "%BASE_URL%" |
|
|
|
|
|
|
|
# Whether to automatically compile all Sass files in the sass directory |
|
|
|
compile_sass = %COMPILE_SASS% |
|
|
|
|
|
|
|
# Whether to do syntax highlighting |
|
|
|
# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Gutenberg |
|
|
|
highlight_code = %HIGHLIGHT% |
|
|
|
|
|
|
|
[extra] |
|
|
|
# Put all your custom variables here |
|
|
@@ -17,23 +26,38 @@ base_url = "https://example.com" |
|
|
|
|
|
|
|
pub fn create_new_project(name: &str) -> Result<()> { |
|
|
|
let path = Path::new(name); |
|
|
|
|
|
|
|
// Better error message than the rust default |
|
|
|
if path.exists() && path.is_dir() { |
|
|
|
bail!("Folder `{}` already exists", path.to_string_lossy().to_string()); |
|
|
|
} |
|
|
|
|
|
|
|
// main folder |
|
|
|
create_dir(path)?; |
|
|
|
create_file(&path.join("config.toml"), CONFIG.trim_left())?; |
|
|
|
console::info("Welcome to Gutenberg!"); |
|
|
|
|
|
|
|
// content folder |
|
|
|
create_dir(path.join("content"))?; |
|
|
|
let base_url = ask_url("> What is the URL of your site?", "https://example.com")?; |
|
|
|
let compile_sass = ask_bool("> Do you want to enable Sass compilation?", true)?; |
|
|
|
let highlight = ask_bool("> Do you want to enable syntax highlighting?", false)?; |
|
|
|
|
|
|
|
// layouts folder |
|
|
|
create_dir(path.join("templates"))?; |
|
|
|
let config = CONFIG |
|
|
|
.trim_left() |
|
|
|
.replace("%BASE_URL%", &base_url) |
|
|
|
.replace("%COMPILE_SASS%", &format!("{}", compile_sass)) |
|
|
|
.replace("%HIGHLIGHT%", &format!("{}", highlight)); |
|
|
|
|
|
|
|
create_file(&path.join("config.toml"), &config)?; |
|
|
|
|
|
|
|
create_dir(path.join("content"))?; |
|
|
|
create_dir(path.join("templates"))?; |
|
|
|
create_dir(path.join("static"))?; |
|
|
|
if compile_sass { |
|
|
|
create_dir(path.join("sass"))?; |
|
|
|
} |
|
|
|
|
|
|
|
println!(); |
|
|
|
console::success(&format!("Done! Your site was created in {:?}", canonicalize(path).unwrap())); |
|
|
|
println!(); |
|
|
|
console::info("Get started by using the built-in server: `gutenberg serve`"); |
|
|
|
println!("There is no built-in theme so you will see a white page."); |
|
|
|
println!("Visit https://github.com/Keats/gutenberg for the full documentation."); |
|
|
|
Ok(()) |
|
|
|
} |