1#![allow(dead_code)]
15
16use std::path::{Path, PathBuf};
17
18pub const PROJECT_CONFIG: &str = "mecha10.json";
24
25pub mod project {
27 pub const NODES_DIR: &str = "nodes";
29
30 pub const DRIVERS_DIR: &str = "drivers";
32
33 pub const TYPES_DIR: &str = "types";
35
36 pub const BEHAVIORS_DIR: &str = "behaviors";
38
39 pub const ASSETS_DIR: &str = "assets";
41
42 pub const ASSETS_IMAGES_DIR: &str = "assets/images";
44
45 pub const MODELS_DIR: &str = "models";
47
48 pub const LOGS_DIR: &str = "logs";
50
51 pub const SIMULATION_DIR: &str = "simulation";
53
54 pub const SIMULATION_MODELS_DIR: &str = "simulation/models";
56
57 pub const SIMULATION_ENVIRONMENTS_DIR: &str = "simulation/environments";
59
60 pub fn model_config(model_name: &str) -> String {
62 format!("simulation/models/{}/model.json", model_name)
63 }
64
65 pub fn environment_config(env_name: &str) -> String {
67 format!("simulation/environments/{}/environment.json", env_name)
68 }
69
70 pub const SIMULATION_GODOT_DIR: &str = "simulation/godot";
72
73 pub const TARGET_DIR: &str = "target";
75
76 pub const SRC_DIR: &str = "src";
78}
79
80pub mod config {
82 pub const DIR: &str = "configs";
84
85 pub const NODES_DIR: &str = "configs/nodes";
87
88 pub const NODES_MECHA10_DIR: &str = "configs/nodes/@mecha10";
90
91 pub const NODES_LOCAL_DIR: &str = "configs/nodes/@local";
93
94 pub const SIMULATION_DIR: &str = "configs/simulation";
96
97 pub const SIMULATION_CONFIG: &str = "configs/simulation/config.json";
99
100 pub fn framework_node(node_name: &str) -> String {
102 format!("configs/nodes/@mecha10/{}/config.json", node_name)
103 }
104
105 pub fn local_node(node_name: &str) -> String {
107 format!("configs/nodes/@local/{}/config.json", node_name)
108 }
109
110 pub fn project_node(node_name: &str) -> String {
112 format!("configs/nodes/{}/config.json", node_name)
113 }
114}
115
116pub mod docker {
118 pub const DIR: &str = "docker";
120
121 pub const COMPOSE_FILE: &str = "docker/docker-compose.yml";
123
124 pub const COMPOSE_REMOTE_FILE: &str = "docker/docker-compose.remote.yml";
126
127 pub const DOCKERFILE_REMOTE: &str = "docker/Dockerfile.remote";
129
130 pub const DOCKERFILE_ROBOT_BUILDER: &str = "docker/robot-builder.Dockerfile";
132}
133
134pub mod env {
136 pub const EXAMPLE: &str = ".env.example";
138
139 pub const FILE: &str = ".env";
141}
142
143pub mod meta {
145 pub const README: &str = "README.md";
147
148 pub const GITIGNORE: &str = ".gitignore";
150
151 pub const PACKAGE_JSON: &str = "package.json";
153
154 pub const REQUIREMENTS_TXT: &str = "requirements.txt";
156
157 pub const LS_LINT_CONFIG: &str = ".ls-lint.yml";
159}
160
161pub mod rust {
163 pub const CARGO_TOML: &str = "Cargo.toml";
165
166 pub const CARGO_LOCK: &str = "Cargo.lock";
168
169 pub const MAIN_RS: &str = "src/main.rs";
171
172 pub const LIB_RS: &str = "src/lib.rs";
174
175 pub const BUILD_RS: &str = "build.rs";
177
178 pub const RUSTFMT_TOML: &str = "rustfmt.toml";
180
181 pub const CARGO_CONFIG_DIR: &str = ".cargo";
183
184 pub const CARGO_CONFIG: &str = ".cargo/config.toml";
186}
187
188pub mod model {
190 pub const ONNX_FILE: &str = "model.onnx";
192
193 pub const LABELS_FILE: &str = "labels.txt";
195
196 pub const CONFIG_FILE: &str = "config.json";
198}
199
200pub mod user {
206 use std::path::PathBuf;
207
208 pub const MECHA10_DIR: &str = ".mecha10";
210
211 pub const CREDENTIALS_FILE: &str = ".mecha10/credentials.json";
213
214 pub const TEMPLATES_DIR: &str = ".mecha10/templates";
216
217 pub const SIMULATION_DIR: &str = ".mecha10/simulation";
219
220 pub const SIMULATION_CURRENT: &str = ".mecha10/simulation/current";
222
223 pub const SIMULATION_VERSION: &str = ".mecha10/simulation/version";
225
226 pub const BIN_DIR: &str = ".mecha10/bin";
228
229 pub fn mecha10_dir() -> PathBuf {
231 dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join(MECHA10_DIR)
232 }
233
234 pub fn credentials_file() -> PathBuf {
236 dirs::home_dir()
237 .unwrap_or_else(|| PathBuf::from("."))
238 .join(CREDENTIALS_FILE)
239 }
240
241 pub fn templates_dir() -> PathBuf {
243 mecha10_dir().join("templates")
244 }
245
246 pub fn simulation_dir() -> PathBuf {
248 mecha10_dir().join("simulation")
249 }
250
251 pub fn simulation_current() -> PathBuf {
253 mecha10_dir().join("simulation/current")
254 }
255
256 pub fn bin_dir() -> PathBuf {
258 mecha10_dir().join("bin")
259 }
260
261 pub fn bin(name: &str) -> PathBuf {
263 bin_dir().join(name)
264 }
265
266 pub fn cargo_bin(name: &str) -> PathBuf {
268 dirs::home_dir()
269 .unwrap_or_else(|| PathBuf::from("."))
270 .join(".cargo/bin")
271 .join(name)
272 }
273
274 pub fn local_bin(name: &str) -> PathBuf {
276 dirs::home_dir()
277 .unwrap_or_else(|| PathBuf::from("."))
278 .join(".local/bin")
279 .join(name)
280 }
281}
282
283pub mod container {
289 pub const PROJECT_ROOT: &str = "/project";
291
292 pub const FRAMEWORK_ROOT: &str = "/mecha10";
294
295 pub const APP_ROOT: &str = "/app";
297
298 pub const REMOTE_CONFIG: &str = "/app/mecha10.json";
300
301 pub const FRAMEWORK_GODOT_PROJECT: &str = "/mecha10/packages/simulation/godot-project";
303
304 pub const FRAMEWORK_GODOT_PROJECT_LEGACY: &str = "/mecha10/godot-project";
306
307 pub fn project_path(relative: &str) -> String {
309 format!("{}/{}", PROJECT_ROOT, relative)
310 }
311
312 pub fn framework_path(relative: &str) -> String {
314 format!("{}/{}", FRAMEWORK_ROOT, relative)
315 }
316}
317
318pub mod framework {
324 pub const PACKAGES_DIR: &str = "packages";
326
327 pub const NODES_DIR: &str = "packages/nodes";
329
330 pub const DRIVERS_DIR: &str = "packages/drivers";
332
333 pub const SERVICES_DIR: &str = "packages/services";
335
336 pub const SIMULATION_DIR: &str = "packages/simulation";
338
339 pub const SIMULATION_GODOT_DIR: &str = "packages/simulation/godot-project";
341
342 pub const SIMULATION_MODELS_DIR: &str = "packages/simulation/models";
344
345 pub const SIMULATION_ENVIRONMENTS_DIR: &str = "packages/simulation/environments";
347
348 pub const ROBOT_TASKS_DIR: &str = "packages/simulation/environments/robot-tasks";
350
351 pub const ROBOT_TASKS_CATALOG: &str = "packages/simulation/environments/robot-tasks/catalog.json";
353
354 pub const TASKRUNNER_DIR: &str = "packages/taskrunner";
356
357 pub const RELEASE_BINARY: &str = "target/release/mecha10";
359
360 pub const DEBUG_BINARY: &str = "target/debug/mecha10";
362
363 pub const NODE_RUNNER_RELEASE: &str = "target/release/mecha10-node-runner";
365
366 pub const NODE_RUNNER_DEBUG: &str = "target/debug/mecha10-node-runner";
368
369 pub fn node_package(node_name: &str) -> String {
371 format!("packages/nodes/{}", node_name)
372 }
373
374 pub fn node_config(node_name: &str) -> String {
376 format!("packages/nodes/{}/configs/config.json", node_name)
377 }
378
379 pub fn node_lib_rs(node_name: &str) -> String {
381 format!("packages/nodes/{}/src/lib.rs", node_name)
382 }
383}
384
385pub mod urls {
391 pub const USER_TOOLS_REPO: &str = "mecha-industries/user-tools";
393
394 pub const REMOTE_MANIFEST: &str =
396 "https://raw.githubusercontent.com/mecha-industries/user-tools/main/mecha10-remote/manifest.json";
397
398 pub const AUTH_URL: &str = "https://mecha.industries/api/auth";
400}
401
402pub fn target_path(profile: &str, binary: &str) -> String {
408 format!("target/{}/{}", profile, binary)
409}
410
411pub fn target_path_with_triple(target: Option<&str>, profile: &str) -> String {
413 match target {
414 Some(t) => format!("target/{}/{}", t, profile),
415 None => format!("target/{}", profile),
416 }
417}
418
419pub fn find_project_root(start: &Path) -> Option<PathBuf> {
421 let mut current = start.to_path_buf();
422 loop {
423 if current.join(PROJECT_CONFIG).exists() {
424 return Some(current);
425 }
426 if !current.pop() {
427 return None;
428 }
429 }
430}
431
432pub fn is_project_dir(dir: &Path) -> bool {
434 dir.join(PROJECT_CONFIG).exists()
435}
436
437#[cfg(test)]
438mod tests {
439 use super::*;
440
441 #[test]
442 fn test_config_paths() {
443 assert_eq!(
444 config::framework_node("object-detector"),
445 "configs/nodes/@mecha10/object-detector/config.json"
446 );
447 assert_eq!(
448 config::local_node("my-node"),
449 "configs/nodes/@local/my-node/config.json"
450 );
451 assert_eq!(config::project_node("camera"), "configs/nodes/camera/config.json");
452 }
453
454 #[test]
455 fn test_target_path() {
456 assert_eq!(target_path("release", "my-node"), "target/release/my-node");
457 assert_eq!(
458 target_path_with_triple(Some("aarch64-unknown-linux-gnu"), "release"),
459 "target/aarch64-unknown-linux-gnu/release"
460 );
461 assert_eq!(target_path_with_triple(None, "debug"), "target/debug");
462 }
463
464 #[test]
465 fn test_container_paths() {
466 assert_eq!(
467 container::project_path("configs/test.json"),
468 "/project/configs/test.json"
469 );
470 assert_eq!(container::framework_path("packages/core"), "/mecha10/packages/core");
471 }
472}