#![deny(warnings)] #![allow(clippy::unwrap_used)] #![allow(clippy::expect_used)]
use napi::bindgen_prelude::*;
use napi_derive::napi;
#[napi(object)]
pub struct RunResult {
pub code: i32,
pub stdout: String,
pub stderr: String,
}
#[napi]
pub fn version() -> String {
env!("CARGO_PKG_VERSION").to_string()
}
#[napi]
pub async fn run(args: Vec<String>) -> Result<RunResult> {
let result = ggen_cli_lib::run_for_node(args)
.await
.map_err(|e| Error::from_reason(format!("CLI execution failed: {}", e)))?;
Ok(RunResult {
code: result.code,
stdout: result.stdout,
stderr: result.stderr,
})
}
#[napi]
pub async fn market_search(query: String) -> Result<RunResult> {
let args = vec!["market".to_string(), "search".to_string(), query];
run(args).await
}
#[napi]
pub async fn market_add(package_id: String) -> Result<RunResult> {
let args = vec!["market".to_string(), "add".to_string(), package_id];
run(args).await
}
#[napi]
pub async fn market_list() -> Result<RunResult> {
let args = vec!["market".to_string(), "list".to_string()];
run(args).await
}
#[napi]
pub async fn market_categories() -> Result<RunResult> {
let args = vec!["market".to_string(), "categories".to_string()];
run(args).await
}
#[napi]
pub async fn market_remove(package_id: String) -> Result<RunResult> {
let args = vec!["market".to_string(), "remove".to_string(), package_id];
run(args).await
}
#[napi]
pub async fn lifecycle_init() -> Result<RunResult> {
let args = vec![
"lifecycle".to_string(),
"run".to_string(),
"init".to_string(),
];
run(args).await
}
#[napi]
pub async fn lifecycle_test() -> Result<RunResult> {
let args = vec![
"lifecycle".to_string(),
"run".to_string(),
"test".to_string(),
];
run(args).await
}
#[napi]
pub async fn lifecycle_build() -> Result<RunResult> {
let args = vec![
"lifecycle".to_string(),
"run".to_string(),
"build".to_string(),
];
run(args).await
}
#[napi]
pub async fn lifecycle_deploy(env: Option<String>) -> Result<RunResult> {
let mut args = vec![
"lifecycle".to_string(),
"run".to_string(),
"deploy".to_string(),
];
if let Some(environment) = env {
args.push("--env".to_string());
args.push(environment);
}
run(args).await
}
#[napi]
pub async fn lifecycle_validate(env: Option<String>) -> Result<RunResult> {
let mut args = vec!["lifecycle".to_string(), "validate".to_string()];
if let Some(environment) = env {
args.push("--env".to_string());
args.push(environment);
}
run(args).await
}
#[napi]
pub async fn lifecycle_readiness() -> Result<RunResult> {
let args = vec!["lifecycle".to_string(), "readiness".to_string()];
run(args).await
}
#[napi]
pub async fn lifecycle_readiness_update(
requirement_id: String, status: String,
) -> Result<RunResult> {
let args = vec![
"lifecycle".to_string(),
"readiness-update".to_string(),
requirement_id,
status,
];
run(args).await
}
#[napi]
pub async fn lifecycle_list() -> Result<RunResult> {
let args = vec!["lifecycle".to_string(), "list".to_string()];
run(args).await
}
#[napi]
pub async fn template_generate(
template_path: String, vars: Option<String>, manifest_path: Option<String>,
) -> Result<RunResult> {
let mut args = vec!["gen".to_string(), template_path];
if let Some(vars_str) = vars {
if let Ok(vars_obj) = serde_json::from_str::<serde_json::Value>(&vars_str) {
if let Some(obj) = vars_obj.as_object() {
args.push("--vars".to_string());
for (key, value) in obj {
if let Some(val_str) = value.as_str() {
args.push(format!("{}={}", key, val_str));
}
}
}
}
}
if let Some(manifest) = manifest_path {
args.push("--manifest-path".to_string());
args.push(manifest);
}
run(args).await
}
#[napi]
pub async fn template_list() -> Result<RunResult> {
let args = vec!["list".to_string()];
run(args).await
}
#[napi]
pub async fn ai_project(
description: String, name: Option<String>, language: Option<String>,
) -> Result<RunResult> {
let mut args = vec!["ai".to_string(), "project".to_string(), description];
if let Some(project_name) = name {
args.push("--name".to_string());
args.push(project_name);
}
if let Some(lang) = language {
args.push(format!("--{}", lang));
}
run(args).await
}
#[napi]
pub async fn ai_generate(description: String, output_path: String) -> Result<RunResult> {
let args = vec![
"ai".to_string(),
"generate".to_string(),
"-d".to_string(),
description,
"-o".to_string(),
output_path,
];
run(args).await
}
#[napi]
pub async fn ai_graph(description: String, output_path: String) -> Result<RunResult> {
let args = vec![
"ai".to_string(),
"graph".to_string(),
"-d".to_string(),
description,
"-o".to_string(),
output_path,
];
run(args).await
}
#[napi]
pub async fn ai_sparql(description: String, graph_path: Option<String>) -> Result<RunResult> {
let mut args = vec![
"ai".to_string(),
"sparql".to_string(),
"-d".to_string(),
description,
];
if let Some(graph) = graph_path {
args.push("-g".to_string());
args.push(graph);
}
run(args).await
}
#[napi]
pub async fn doctor() -> Result<RunResult> {
let args = vec!["doctor".to_string()];
run(args).await
}
#[napi]
pub async fn help(command: Option<String>) -> Result<RunResult> {
let mut args = vec![];
if let Some(cmd) = command {
args.push(cmd);
}
args.push("--help".to_string());
run(args).await
}