mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-07-14 19:10:28 +03:00
fix(core): do not generate files if plugin has no permissions (#8815)
This commit is contained in:
parent
aa06a0534c
commit
dd7571a780
6
.changes/handle-empty-permissions.md
Normal file
6
.changes/handle-empty-permissions.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-plugin": patch:enhance
|
||||
"tauri-utils": patch:enhance
|
||||
---
|
||||
|
||||
Do not generate JSON schema and markdown reference file if the plugin does not define any permissions and delete those files if they exist.
|
@ -101,8 +101,17 @@ impl<'a> Builder<'a> {
|
||||
println!("cargo:rerun-if-changed=permissions");
|
||||
let permissions = acl::build::define_permissions("./permissions/**/*.*", &name, &out_dir)?;
|
||||
|
||||
acl::build::generate_schema(&permissions, "./permissions")?;
|
||||
acl::build::generate_docs(&permissions, &autogenerated)?;
|
||||
if permissions.is_empty() {
|
||||
let _ = std::fs::remove_file(format!(
|
||||
"./permissions/{}/{}",
|
||||
acl::build::PERMISSION_SCHEMAS_FOLDER_NAME,
|
||||
acl::build::PERMISSION_SCHEMA_FILE_NAME
|
||||
));
|
||||
let _ = std::fs::remove_file(autogenerated.join(acl::build::PERMISSION_DOCS_FILE_NAME));
|
||||
} else {
|
||||
acl::build::generate_schema(&permissions, "./permissions")?;
|
||||
acl::build::generate_docs(&permissions, &autogenerated)?;
|
||||
}
|
||||
|
||||
if let Some(global_scope_schema) = self.global_scope_schema {
|
||||
acl::build::define_global_scope_schema(global_scope_schema, &name, &out_dir)?;
|
||||
|
@ -38,6 +38,9 @@ pub const PERMISSION_SCHEMAS_FOLDER_NAME: &str = "schemas";
|
||||
/// Known filename of the permission schema JSON file
|
||||
pub const PERMISSION_SCHEMA_FILE_NAME: &str = "schema.json";
|
||||
|
||||
/// Known filename of the permission documentation file
|
||||
pub const PERMISSION_DOCS_FILE_NAME: &str = "reference.md";
|
||||
|
||||
/// Allowed capability file extensions
|
||||
const CAPABILITY_FILE_EXTENSIONS: &[&str] = &["json", "toml"];
|
||||
|
||||
@ -281,7 +284,7 @@ pub fn generate_docs(permissions: &[PermissionFile], out_dir: &Path) -> Result<(
|
||||
}
|
||||
}
|
||||
|
||||
let reference_path = out_dir.join("reference.md");
|
||||
let reference_path = out_dir.join(PERMISSION_DOCS_FILE_NAME);
|
||||
if docs != read_to_string(&reference_path).unwrap_or_default() {
|
||||
std::fs::write(reference_path, docs).map_err(Error::WriteFile)?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user