mirror of
https://github.com/CIMEngine/cimengine-build-tools.git
synced 2025-02-22 12:13:16 +03:00
feat!: init project v2
This commit is contained in:
parent
f10f91c676
commit
ff8e88b39b
25 changed files with 924 additions and 4115 deletions
1
src/build/mod.rs
Normal file
1
src/build/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub fn build() {}
|
23
src/init.rs
Normal file
23
src/init.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use std::{fs, path::Path};
|
||||
|
||||
pub fn init(name: String) {
|
||||
let config = include_str!("./templates/config.toml");
|
||||
let country_config = include_str!("./templates/country.toml");
|
||||
let geojson = include_str!("./templates/sample.geojson");
|
||||
|
||||
let root_folder = Path::new(&name);
|
||||
let country_folder = Path::new(&name).join("countries").join("sample_country_id");
|
||||
let nature_folder = Path::new(&name).join("nature");
|
||||
|
||||
fs::create_dir_all(&country_folder).unwrap();
|
||||
fs::create_dir_all(&nature_folder).unwrap();
|
||||
|
||||
fs::write(root_folder.join("config.toml"), config).unwrap();
|
||||
|
||||
fs::write(country_folder.join("country.toml"), country_config).unwrap();
|
||||
fs::write(country_folder.join("country.geojson"), geojson).unwrap();
|
||||
|
||||
fs::write(nature_folder.join("water.geojson"), geojson).unwrap();
|
||||
fs::write(nature_folder.join("sand.geojson"), geojson).unwrap();
|
||||
fs::write(nature_folder.join("grass.geojson"), geojson).unwrap();
|
||||
}
|
17
src/main.rs
Normal file
17
src/main.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use clap::Parser;
|
||||
|
||||
mod build;
|
||||
mod init;
|
||||
mod types;
|
||||
|
||||
use types::Commands;
|
||||
|
||||
fn main() {
|
||||
let args = types::Cli::parse();
|
||||
|
||||
match args.cmd {
|
||||
Commands::Build => build::build(),
|
||||
Commands::Init { name } => init::init(name),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
39
src/templates/config.toml
Normal file
39
src/templates/config.toml
Normal file
|
@ -0,0 +1,39 @@
|
|||
[country]
|
||||
# Order matters when building countries. This affects the processing of area intersections
|
||||
layers = ["sample_country_id"]
|
||||
|
||||
[[processing]]
|
||||
output_folder = "out"
|
||||
countries_file = "countries.json"
|
||||
geo_file = "geo.geojson"
|
||||
|
||||
# generate_colors = false
|
||||
# show_markers = false
|
||||
|
||||
# Include or exclude countries based on tags
|
||||
# Glob syntax is supported
|
||||
[[processing.tags]]
|
||||
include = [] # [] = not filtered
|
||||
# exclude = ["test", "test2"]
|
||||
|
||||
# [[processing.countries_rewrite]]
|
||||
# name = "name"
|
||||
# color = "#000000"
|
||||
|
||||
# Information for public repository in cimengine. See: https://github.com/CIMEngine/MapList
|
||||
# [[processing.public]]
|
||||
# name = "Sample Map"
|
||||
# geo = "https://example.com/geo.geojson"
|
||||
# countries = "https://example.com/countries.json"
|
||||
|
||||
[[nature]]
|
||||
id = "water"
|
||||
color = "#75cff0"
|
||||
|
||||
[[nature]]
|
||||
id = "sand"
|
||||
color = "#efe9e1"
|
||||
|
||||
[[nature]]
|
||||
id = "grass"
|
||||
color = "#d1e6be"
|
5
src/templates/country.toml
Normal file
5
src/templates/country.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
name = "Sample Country"
|
||||
description = "This is a sample country"
|
||||
foundation_date = "2024-01-01"
|
||||
flag = "https://example.com/flag.png"
|
||||
about = "https://example.com/about.html"
|
4
src/templates/sample.geojson
Normal file
4
src/templates/sample.geojson
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"type": "FeatureCollection",
|
||||
"features": []
|
||||
}
|
87
src/types.rs
Normal file
87
src/types.rs
Normal file
|
@ -0,0 +1,87 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "cimengine", bin_name = "cimengine")]
|
||||
#[command(about = "CIMEngine build tools")]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub cmd: Commands,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
#[clap(author, version, about)]
|
||||
pub enum Commands {
|
||||
/// Build project
|
||||
Build,
|
||||
/// Initialize a new project
|
||||
Init {
|
||||
#[clap(default_value = "map")]
|
||||
name: String,
|
||||
},
|
||||
/// Fix geospatial file
|
||||
Fix {
|
||||
/// Path to geospatial file supported by cimengine
|
||||
#[clap(short, long)]
|
||||
path: String,
|
||||
},
|
||||
/// Utility for creating countries, roads, etc.
|
||||
New {
|
||||
#[command(subcommand)]
|
||||
cmd: NewCommands,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum NewCommands {
|
||||
/// Create new country
|
||||
Country { name: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
country: CountryConfig,
|
||||
processing: Vec<ProcessingConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CountryConfig {
|
||||
layers: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ProcessingConfig {
|
||||
generate_colors: Option<bool>,
|
||||
show_markers: Option<bool>,
|
||||
output_folder: String,
|
||||
countries_file: String,
|
||||
geo_file: String,
|
||||
|
||||
tags: Option<ProcessingTagsConfig>,
|
||||
countries_rewrite: Option<CountryRewriteConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ProcessingTagsConfig {
|
||||
include: Vec<String>,
|
||||
exclude: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CountryRewriteConfig {
|
||||
name: Option<String>,
|
||||
description: Option<String>,
|
||||
foundation_date: Option<String>,
|
||||
flag: Option<String>,
|
||||
about: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Country {
|
||||
name: String,
|
||||
description: String,
|
||||
foundation_date: String,
|
||||
flag: String,
|
||||
about: Option<String>,
|
||||
tags: Option<Vec<String>>,
|
||||
}
|
Loading…
Add table
Reference in a new issue