use super::descriptors::DerivedMacroRegistration;
use super::registry::decorator_metadata;
use serde::{Deserialize, Serialize};
#[cfg(feature = "node")]
use napi_derive::napi;
#[cfg_attr(feature = "node", napi(object))]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MacroManifestEntry {
pub name: String,
pub kind: String,
pub description: String,
pub package: String,
}
#[cfg_attr(feature = "node", napi(object))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DecoratorManifestEntry {
pub module: String,
pub export: String,
pub kind: String,
pub docs: String,
}
#[cfg_attr(feature = "node", napi(object))]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct MacroManifest {
pub version: u32,
pub macros: Vec<MacroManifestEntry>,
pub decorators: Vec<DecoratorManifestEntry>,
}
pub fn get_manifest() -> MacroManifest {
let macros: Vec<MacroManifestEntry> = inventory::iter::<DerivedMacroRegistration>
.into_iter()
.map(|entry| {
let name = if entry.descriptor.kind == crate::ts_syn::abi::MacroKind::Call {
format!("${}", entry.descriptor.name)
} else {
entry.descriptor.name.to_string()
};
MacroManifestEntry {
name,
kind: format!("{:?}", entry.descriptor.kind).to_lowercase(),
description: entry.descriptor.description.to_string(),
package: entry.descriptor.package.to_string(),
}
})
.collect();
let decorators: Vec<DecoratorManifestEntry> = decorator_metadata()
.into_iter()
.map(|d| DecoratorManifestEntry {
module: d.module.to_string(),
export: d.export.to_string(),
kind: format!("{:?}", d.kind).to_lowercase(),
docs: d.docs.to_string(),
})
.collect();
MacroManifest {
version: 1,
macros,
decorators,
}
}