2024-05-29 15:32:58 +03:00
|
|
|
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2024-08-02 13:30:02 +03:00
|
|
|
use std::{error::Error, path::PathBuf};
|
2024-05-29 15:32:58 +03:00
|
|
|
|
2024-08-02 13:30:02 +03:00
|
|
|
use tauri_utils::{
|
2024-08-19 19:33:39 +03:00
|
|
|
acl::{capability::Capability, Permission, Scopes},
|
2024-08-28 00:42:30 +03:00
|
|
|
config::Config,
|
2024-08-02 13:30:02 +03:00
|
|
|
write_if_changed,
|
|
|
|
};
|
2024-05-29 15:32:58 +03:00
|
|
|
|
2024-08-02 13:30:02 +03:00
|
|
|
macro_rules! schema {
|
|
|
|
($name:literal, $path:ty) => {
|
2024-08-28 00:42:30 +03:00
|
|
|
(concat!($name, ".schema.json"), schemars::schema_for!($path))
|
2024-08-02 13:30:02 +03:00
|
|
|
};
|
2024-05-29 15:32:58 +03:00
|
|
|
}
|
|
|
|
|
2024-08-02 13:30:02 +03:00
|
|
|
pub fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
let schemas = [
|
2024-08-28 00:42:30 +03:00
|
|
|
schema!("config", Config),
|
2024-08-02 13:30:02 +03:00
|
|
|
schema!("capability", Capability),
|
|
|
|
schema!("permission", Permission),
|
|
|
|
schema!("scope", Scopes),
|
|
|
|
];
|
|
|
|
|
|
|
|
let out = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?);
|
2024-08-28 00:42:30 +03:00
|
|
|
|
|
|
|
let schemas_dir = out.join("schemas");
|
|
|
|
std::fs::create_dir_all(&schemas_dir)?;
|
|
|
|
|
2024-08-02 13:30:02 +03:00
|
|
|
for (filename, schema) in schemas {
|
|
|
|
let schema = serde_json::to_string_pretty(&schema)?;
|
2024-08-28 00:42:30 +03:00
|
|
|
write_if_changed(schemas_dir.join(filename), &schema)?;
|
|
|
|
|
|
|
|
if filename.starts_with("config") {
|
|
|
|
write_if_changed(out.join("../tauri-cli/config.schema.json"), schema)?;
|
|
|
|
}
|
2024-08-02 13:30:02 +03:00
|
|
|
}
|
2024-05-29 15:32:58 +03:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|