mirror of
https://github.com/CIMEngine/cimengine-build-tools.git
synced 2024-11-05 20:53:58 +03:00
feat: tags
This commit is contained in:
parent
2da4604a67
commit
2f309bd389
3 changed files with 21 additions and 13 deletions
22
src/build.rs
22
src/build.rs
|
@ -2,7 +2,7 @@ use std::{fs, path::Path};
|
|||
|
||||
use geojson::{Feature, FeatureCollection};
|
||||
use serde_json::json;
|
||||
use wax::Glob;
|
||||
use wax::{Glob, Pattern};
|
||||
|
||||
use crate::{
|
||||
types::CountryData,
|
||||
|
@ -19,15 +19,31 @@ pub fn build() {
|
|||
|
||||
let mut countries: Vec<CountryData> = vec![];
|
||||
|
||||
let tags = processing_item.tags.unwrap_or(vec!["*".to_string()]);
|
||||
let globs: Vec<Glob> = tags.iter().map(|tag| Glob::new(tag).unwrap()).collect();
|
||||
|
||||
for country_id in &config.main.layers {
|
||||
let mut country = get_country(country_id.to_owned());
|
||||
|
||||
// TODO: Add tags support
|
||||
let mut matches = false;
|
||||
for glob in &globs {
|
||||
for tag in &country.config.tags.clone().unwrap_or(vec![]) {
|
||||
if glob.is_match(tag.as_str()) {
|
||||
matches = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !matches {
|
||||
continue;
|
||||
}
|
||||
|
||||
features.append(&mut country.geo.features);
|
||||
countries.push(country);
|
||||
}
|
||||
|
||||
// TODO: Country diff
|
||||
|
||||
// TODO: Add country_rewrite support
|
||||
// TODO: let countries = vec![rewrite_info];
|
||||
|
||||
|
@ -40,7 +56,7 @@ pub fn build() {
|
|||
}
|
||||
.to_string();
|
||||
|
||||
let countries = serde_json::to_string(&serde_json::Map::from_iter(
|
||||
let countries = serde_json::to_string_pretty(&serde_json::Map::from_iter(
|
||||
countries
|
||||
.iter()
|
||||
.map(|country| (country.id.clone(), json!(country.config))),
|
||||
|
|
|
@ -16,9 +16,7 @@ output_folder = "./out/map"
|
|||
|
||||
# Include or exclude countries based on tags
|
||||
# Glob syntax is supported
|
||||
# [processing.tags]
|
||||
# include = [] # [] = not filtered
|
||||
# exclude = ["test", "test2"]
|
||||
# tags = ["test-[!2]"]
|
||||
|
||||
# Rewrite properties of all countries. All fields are optional.
|
||||
# [processing.countries_rewrite]
|
||||
|
|
|
@ -74,17 +74,11 @@ pub struct ProcessingConfig {
|
|||
pub show_markers: Option<bool>,
|
||||
pub output_folder: String,
|
||||
|
||||
pub tags: Option<ProcessingTagsConfig>,
|
||||
pub tags: Option<Vec<String>>,
|
||||
pub countries_rewrite: Option<CountryRewriteConfig>,
|
||||
pub public: Option<PublicConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ProcessingTagsConfig {
|
||||
pub include: Option<Vec<String>>,
|
||||
pub exclude: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CountryRewriteConfig {
|
||||
pub name: Option<String>,
|
||||
|
|
Loading…
Reference in a new issue