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
131pub mod env {
133 pub const EXAMPLE: &str = ".env.example";
135
136 pub const FILE: &str = ".env";
138}
139
140pub mod meta {
142 pub const README: &str = "README.md";
144
145 pub const GITIGNORE: &str = ".gitignore";
147
148 pub const PACKAGE_JSON: &str = "package.json";
150
151 pub const REQUIREMENTS_TXT: &str = "requirements.txt";
153
154 pub const LS_LINT_CONFIG: &str = ".ls-lint.yml";
156}
157
158pub mod rust {
160 pub const CARGO_TOML: &str = "Cargo.toml";
162
163 pub const CARGO_LOCK: &str = "Cargo.lock";
165
166 pub const MAIN_RS: &str = "src/main.rs";
168
169 pub const LIB_RS: &str = "src/lib.rs";
171
172 pub const BUILD_RS: &str = "build.rs";
174
175 pub const RUSTFMT_TOML: &str = "rustfmt.toml";
177
178 pub const CARGO_CONFIG_DIR: &str = ".cargo";
180
181 pub const CARGO_CONFIG: &str = ".cargo/config.toml";
183}
184
185pub mod model {
187 pub const ONNX_FILE: &str = "model.onnx";
189
190 pub const LABELS_FILE: &str = "labels.txt";
192
193 pub const CONFIG_FILE: &str = "config.json";
195}
196
197pub mod user {
203 use std::path::PathBuf;
204
205 pub const MECHA10_DIR: &str = ".mecha10";
207
208 pub const CREDENTIALS_FILE: &str = ".mecha10/credentials.json";
210
211 pub const TEMPLATES_DIR: &str = ".mecha10/templates";
213
214 pub const SIMULATION_DIR: &str = ".mecha10/simulation";
216
217 pub const SIMULATION_CURRENT: &str = ".mecha10/simulation/current";
219
220 pub const SIMULATION_VERSION: &str = ".mecha10/simulation/version";
222
223 pub const BIN_DIR: &str = ".mecha10/bin";
225
226 pub fn mecha10_dir() -> PathBuf {
228 dirs::home_dir()
229 .unwrap_or_else(|| PathBuf::from("."))
230 .join(MECHA10_DIR)
231 }
232
233 pub fn credentials_file() -> PathBuf {
235 dirs::home_dir()
236 .unwrap_or_else(|| PathBuf::from("."))
237 .join(CREDENTIALS_FILE)
238 }
239
240 pub fn templates_dir() -> PathBuf {
242 mecha10_dir().join("templates")
243 }
244
245 pub fn simulation_dir() -> PathBuf {
247 mecha10_dir().join("simulation")
248 }
249
250 pub fn simulation_current() -> PathBuf {
252 mecha10_dir().join("simulation/current")
253 }
254
255 pub fn bin_dir() -> PathBuf {
257 mecha10_dir().join("bin")
258 }
259
260 pub fn bin(name: &str) -> PathBuf {
262 bin_dir().join(name)
263 }
264
265 pub fn cargo_bin(name: &str) -> PathBuf {
267 dirs::home_dir()
268 .unwrap_or_else(|| PathBuf::from("."))
269 .join(".cargo/bin")
270 .join(name)
271 }
272
273 pub fn local_bin(name: &str) -> PathBuf {
275 dirs::home_dir()
276 .unwrap_or_else(|| PathBuf::from("."))
277 .join(".local/bin")
278 .join(name)
279 }
280}
281
282pub mod container {
288 pub const PROJECT_ROOT: &str = "/project";
290
291 pub const FRAMEWORK_ROOT: &str = "/mecha10";
293
294 pub const APP_ROOT: &str = "/app";
296
297 pub const REMOTE_CONFIG: &str = "/app/mecha10.json";
299
300 pub const FRAMEWORK_GODOT_PROJECT: &str = "/mecha10/packages/simulation/godot-project";
302
303 pub const FRAMEWORK_GODOT_PROJECT_LEGACY: &str = "/mecha10/godot-project";
305
306 pub fn project_path(relative: &str) -> String {
308 format!("{}/{}", PROJECT_ROOT, relative)
309 }
310
311 pub fn framework_path(relative: &str) -> String {
313 format!("{}/{}", FRAMEWORK_ROOT, relative)
314 }
315}
316
317pub mod framework {
323 pub const PACKAGES_DIR: &str = "packages";
325
326 pub const NODES_DIR: &str = "packages/nodes";
328
329 pub const DRIVERS_DIR: &str = "packages/drivers";
331
332 pub const SERVICES_DIR: &str = "packages/services";
334
335 pub const SIMULATION_DIR: &str = "packages/simulation";
337
338 pub const SIMULATION_GODOT_DIR: &str = "packages/simulation/godot-project";
340
341 pub const SIMULATION_MODELS_DIR: &str = "packages/simulation/models";
343
344 pub const SIMULATION_ENVIRONMENTS_DIR: &str = "packages/simulation/environments";
346
347 pub const ROBOT_TASKS_DIR: &str = "packages/simulation/environments/robot-tasks";
349
350 pub const ROBOT_TASKS_CATALOG: &str = "packages/simulation/environments/robot-tasks/catalog.json";
352
353 pub const TASKRUNNER_DIR: &str = "packages/taskrunner";
355
356 pub const RELEASE_BINARY: &str = "target/release/mecha10";
358
359 pub const DEBUG_BINARY: &str = "target/debug/mecha10";
361
362 pub const NODE_RUNNER_RELEASE: &str = "target/release/mecha10-node-runner";
364
365 pub const NODE_RUNNER_DEBUG: &str = "target/debug/mecha10-node-runner";
367
368 pub fn node_package(node_name: &str) -> String {
370 format!("packages/nodes/{}", node_name)
371 }
372
373 pub fn node_config(node_name: &str) -> String {
375 format!("packages/nodes/{}/configs/config.json", node_name)
376 }
377
378 pub fn node_lib_rs(node_name: &str) -> String {
380 format!("packages/nodes/{}/src/lib.rs", node_name)
381 }
382}
383
384pub mod urls {
390 pub const USER_TOOLS_REPO: &str = "mecha-industries/user-tools";
392
393 pub const REMOTE_MANIFEST: &str =
395 "https://raw.githubusercontent.com/laboratory-one/user-tools/main/mecha10-remote/manifest.json";
396
397 pub const AUTH_URL: &str = "https://mecha.industries/api/auth";
399}
400
401pub fn target_path(profile: &str, binary: &str) -> String {
407 format!("target/{}/{}", profile, binary)
408}
409
410pub fn target_path_with_triple(target: Option<&str>, profile: &str) -> String {
412 match target {
413 Some(t) => format!("target/{}/{}", t, profile),
414 None => format!("target/{}", profile),
415 }
416}
417
418pub fn find_project_root(start: &Path) -> Option<PathBuf> {
420 let mut current = start.to_path_buf();
421 loop {
422 if current.join(PROJECT_CONFIG).exists() {
423 return Some(current);
424 }
425 if !current.pop() {
426 return None;
427 }
428 }
429}
430
431pub fn is_project_dir(dir: &Path) -> bool {
433 dir.join(PROJECT_CONFIG).exists()
434}
435
436#[cfg(test)]
437mod tests {
438 use super::*;
439
440 #[test]
441 fn test_config_paths() {
442 assert_eq!(
443 config::framework_node("object-detector"),
444 "configs/nodes/@mecha10/object-detector/config.json"
445 );
446 assert_eq!(
447 config::local_node("my-node"),
448 "configs/nodes/@local/my-node/config.json"
449 );
450 assert_eq!(
451 config::project_node("camera"),
452 "configs/nodes/camera/config.json"
453 );
454 }
455
456 #[test]
457 fn test_target_path() {
458 assert_eq!(target_path("release", "my-node"), "target/release/my-node");
459 assert_eq!(
460 target_path_with_triple(Some("aarch64-unknown-linux-gnu"), "release"),
461 "target/aarch64-unknown-linux-gnu/release"
462 );
463 assert_eq!(target_path_with_triple(None, "debug"), "target/debug");
464 }
465
466 #[test]
467 fn test_container_paths() {
468 assert_eq!(
469 container::project_path("configs/test.json"),
470 "/project/configs/test.json"
471 );
472 assert_eq!(
473 container::framework_path("packages/core"),
474 "/mecha10/packages/core"
475 );
476 }
477}