@devaloop/devalang 0.0.1-alpha.16-hotfix.3 → 0.0.1-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/.cargo/config.toml +2 -0
  2. package/.devalang +10 -10
  3. package/.github/workflows/ci.yml +0 -1
  4. package/Cargo.toml +18 -2
  5. package/README.md +82 -34
  6. package/docs/CHANGELOG.md +91 -0
  7. package/docs/ROADMAP.md +7 -4
  8. package/docs/TODO.md +1 -1
  9. package/examples/index.deva +55 -35
  10. package/examples/pattern.deva +5 -5
  11. package/out-tsc/bin/index.d.ts +2 -0
  12. package/out-tsc/core/functions/index.d.ts +37 -0
  13. package/out-tsc/core/functions/index.js +76 -0
  14. package/out-tsc/core/index.d.ts +6 -0
  15. package/out-tsc/core/index.js +22 -0
  16. package/out-tsc/core/types/index.d.ts +4 -0
  17. package/out-tsc/core/types/index.js +20 -0
  18. package/out-tsc/core/types/plugin.d.ts +18 -0
  19. package/out-tsc/core/types/plugin.js +2 -0
  20. package/out-tsc/core/types/result.d.ts +27 -0
  21. package/out-tsc/core/types/result.js +2 -0
  22. package/out-tsc/core/types/statement.d.ts +106 -0
  23. package/out-tsc/core/types/statement.js +2 -0
  24. package/out-tsc/core/types/value.d.ts +43 -0
  25. package/out-tsc/core/types/value.js +2 -0
  26. package/out-tsc/index.d.ts +7 -0
  27. package/out-tsc/index.js +41 -2
  28. package/out-tsc/pkg/devalang_core.d.ts +7 -0
  29. package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +33 -0
  30. package/out-tsc/scripts/copy-wasm-dts.d.ts +1 -0
  31. package/out-tsc/scripts/copy-wasm-dts.js +73 -0
  32. package/out-tsc/scripts/postinstall.d.ts +1 -0
  33. package/out-tsc/scripts/postinstall.js +33 -23
  34. package/out-tsc/scripts/version/bump.d.ts +1 -0
  35. package/out-tsc/scripts/version/fetch.d.ts +1 -0
  36. package/out-tsc/scripts/version/index.d.ts +1 -0
  37. package/out-tsc/scripts/version/sync.d.ts +1 -0
  38. package/package.json +16 -4
  39. package/project-version.json +3 -3
  40. package/rust/cli/bank/api.rs +122 -0
  41. package/rust/cli/bank/commands.rs +275 -0
  42. package/rust/cli/bank/mod.rs +29 -0
  43. package/rust/cli/build/commands.rs +107 -0
  44. package/rust/cli/build/mod.rs +2 -0
  45. package/rust/cli/build/process.rs +146 -0
  46. package/rust/cli/{check.rs → check/mod.rs} +18 -31
  47. package/rust/cli/discover/commands.rs +253 -0
  48. package/rust/cli/discover/config.rs +111 -0
  49. package/rust/cli/discover/fs.rs +19 -0
  50. package/rust/cli/discover/install.rs +103 -0
  51. package/rust/cli/discover/metadata.rs +48 -0
  52. package/rust/cli/discover/mod.rs +5 -0
  53. package/rust/cli/{init.rs → init/commands.rs} +88 -87
  54. package/rust/cli/init/mod.rs +1 -0
  55. package/rust/cli/install/addon.rs +126 -0
  56. package/rust/cli/install/bank.rs +53 -0
  57. package/rust/cli/{install.rs → install/commands.rs} +9 -9
  58. package/rust/{installer → cli/install}/mod.rs +2 -3
  59. package/rust/cli/install/plugin.rs +61 -0
  60. package/rust/cli/{login.rs → login/commands.rs} +8 -11
  61. package/rust/cli/login/mod.rs +1 -0
  62. package/rust/cli/mod.rs +2 -2
  63. package/rust/cli/{driver.rs → parser.rs} +7 -2
  64. package/rust/cli/play/commands.rs +324 -0
  65. package/rust/cli/play/io.rs +17 -0
  66. package/rust/cli/play/mod.rs +5 -0
  67. package/rust/cli/play/process.rs +150 -0
  68. package/rust/cli/play/realtime.rs +91 -0
  69. package/rust/cli/play/utils.rs +23 -0
  70. package/rust/cli/{telemetry.rs → telemetry/commands.rs} +4 -4
  71. package/rust/cli/telemetry/event_creator.rs +80 -0
  72. package/rust/cli/telemetry/mod.rs +3 -0
  73. package/rust/cli/telemetry/send.rs +51 -0
  74. package/rust/cli/{template.rs → template/commands.rs} +1 -1
  75. package/rust/cli/template/mod.rs +1 -0
  76. package/rust/cli/{update.rs → update/commands.rs} +6 -6
  77. package/rust/cli/update/mod.rs +1 -0
  78. package/rust/config/driver.rs +57 -72
  79. package/rust/config/mod.rs +1 -2
  80. package/rust/config/ops.rs +26 -0
  81. package/rust/config/settings.rs +40 -42
  82. package/rust/core/audio/engine/helpers.rs +158 -0
  83. package/rust/core/audio/engine/mod.rs +7 -0
  84. package/rust/core/audio/engine/sample.rs +359 -0
  85. package/rust/core/audio/engine/synth.rs +325 -0
  86. package/rust/core/audio/evaluator.rs +68 -27
  87. package/rust/core/audio/interpreter/arrow_call.rs +113 -33
  88. package/rust/core/audio/interpreter/call.rs +232 -56
  89. package/rust/core/audio/interpreter/condition.rs +3 -2
  90. package/rust/core/audio/interpreter/driver.rs +206 -151
  91. package/rust/core/audio/interpreter/let_.rs +1 -1
  92. package/rust/core/audio/interpreter/load.rs +2 -1
  93. package/rust/core/audio/interpreter/loop_.rs +7 -6
  94. package/rust/core/audio/interpreter/sleep.rs +2 -1
  95. package/rust/core/audio/interpreter/spawn.rs +186 -54
  96. package/rust/core/audio/interpreter/tempo.rs +31 -10
  97. package/rust/core/audio/interpreter/trigger.rs +2 -2
  98. package/rust/core/audio/loader/trigger.rs +4 -7
  99. package/rust/core/audio/player.rs +6 -0
  100. package/rust/core/audio/renderer.rs +5 -7
  101. package/rust/core/audio/special/env.rs +3 -1
  102. package/rust/core/audio/special/math.rs +26 -6
  103. package/rust/core/audio/special/modulator.rs +2 -2
  104. package/rust/core/builder/mod.rs +9 -3
  105. package/rust/core/debugger/lexer.rs +1 -1
  106. package/rust/core/debugger/mod.rs +6 -0
  107. package/rust/core/debugger/module.rs +4 -4
  108. package/rust/core/debugger/preprocessor.rs +1 -1
  109. package/rust/core/debugger/store.rs +2 -2
  110. package/rust/core/error/mod.rs +189 -0
  111. package/rust/core/lexer/driver.rs +61 -0
  112. package/rust/core/lexer/handler/arrow.rs +1 -1
  113. package/rust/core/lexer/handler/at.rs +1 -1
  114. package/rust/core/lexer/handler/brace.rs +2 -2
  115. package/rust/core/lexer/handler/colon.rs +1 -1
  116. package/rust/core/lexer/handler/comment.rs +1 -1
  117. package/rust/core/lexer/handler/dot.rs +1 -1
  118. package/rust/core/lexer/handler/driver.rs +1 -1
  119. package/rust/core/lexer/handler/identifier.rs +4 -3
  120. package/rust/core/lexer/handler/mod.rs +1 -2
  121. package/rust/core/lexer/handler/number.rs +1 -1
  122. package/rust/core/lexer/handler/operator.rs +1 -1
  123. package/rust/core/lexer/handler/parenthesis.rs +2 -2
  124. package/rust/core/lexer/handler/slash.rs +1 -1
  125. package/rust/core/lexer/handler/string.rs +1 -1
  126. package/rust/core/lexer/mod.rs +1 -52
  127. package/rust/core/lexer/token.rs +91 -97
  128. package/rust/core/mod.rs +0 -1
  129. package/rust/core/parser/driver.rs +78 -22
  130. package/rust/core/parser/handler/arrow_call.rs +28 -8
  131. package/rust/core/parser/handler/at.rs +55 -21
  132. package/rust/core/parser/handler/bank.rs +14 -4
  133. package/rust/core/parser/handler/condition.rs +6 -3
  134. package/rust/core/parser/handler/dot.rs +5 -3
  135. package/rust/core/parser/handler/identifier/automate.rs +13 -16
  136. package/rust/core/parser/handler/identifier/call.rs +4 -4
  137. package/rust/core/parser/handler/identifier/emit.rs +9 -5
  138. package/rust/core/parser/handler/identifier/function.rs +20 -7
  139. package/rust/core/parser/handler/identifier/group.rs +11 -7
  140. package/rust/core/parser/handler/identifier/let_.rs +24 -9
  141. package/rust/core/parser/handler/identifier/mod.rs +6 -5
  142. package/rust/core/parser/handler/identifier/on.rs +16 -7
  143. package/rust/core/parser/handler/identifier/print.rs +6 -9
  144. package/rust/core/parser/handler/identifier/sleep.rs +12 -5
  145. package/rust/core/parser/handler/identifier/spawn.rs +4 -4
  146. package/rust/core/parser/handler/identifier/synth.rs +79 -9
  147. package/rust/core/parser/handler/loop_.rs +38 -13
  148. package/rust/core/parser/handler/mod.rs +1 -0
  149. package/rust/core/parser/handler/pattern.rs +74 -0
  150. package/rust/core/parser/handler/tempo.rs +9 -5
  151. package/rust/core/parser/mod.rs +0 -1
  152. package/rust/core/parser/statement.rs +6 -137
  153. package/rust/core/plugin/loader.rs +41 -27
  154. package/rust/core/plugin/runner.rs +68 -17
  155. package/rust/core/preprocessor/loader.rs +181 -99
  156. package/rust/core/preprocessor/processor.rs +9 -9
  157. package/rust/core/preprocessor/resolver/bank.rs +6 -8
  158. package/rust/core/preprocessor/resolver/call.rs +47 -23
  159. package/rust/core/preprocessor/resolver/condition.rs +6 -8
  160. package/rust/core/preprocessor/resolver/driver.rs +28 -28
  161. package/rust/core/preprocessor/resolver/function.rs +6 -6
  162. package/rust/core/preprocessor/resolver/group.rs +6 -8
  163. package/rust/core/preprocessor/resolver/loop_.rs +8 -10
  164. package/rust/core/preprocessor/resolver/mod.rs +1 -0
  165. package/rust/core/preprocessor/resolver/pattern.rs +75 -0
  166. package/rust/core/preprocessor/resolver/spawn.rs +45 -22
  167. package/rust/core/preprocessor/resolver/synth.rs +6 -8
  168. package/rust/core/preprocessor/resolver/tempo.rs +6 -8
  169. package/rust/core/preprocessor/resolver/trigger.rs +22 -19
  170. package/rust/core/preprocessor/resolver/value.rs +99 -4
  171. package/rust/core/store/export.rs +28 -28
  172. package/rust/core/store/function.rs +6 -0
  173. package/rust/core/store/global.rs +7 -1
  174. package/rust/core/store/import.rs +28 -28
  175. package/rust/core/store/variable.rs +16 -2
  176. package/rust/core/utils/mod.rs +0 -1
  177. package/rust/lib.rs +102 -9
  178. package/rust/main.rs +159 -45
  179. package/rust/types/Cargo.toml +11 -0
  180. package/rust/types/src/addons.rs +55 -0
  181. package/rust/types/src/ast.rs +202 -0
  182. package/rust/types/src/config.rs +74 -0
  183. package/rust/types/src/lib.rs +12 -0
  184. package/rust/types/src/telemetry.rs +85 -0
  185. package/rust/utils/Cargo.toml +26 -0
  186. package/rust/utils/{error.rs → src/error.rs} +186 -200
  187. package/rust/utils/src/file.rs +94 -0
  188. package/rust/utils/src/first_usage.rs +97 -0
  189. package/rust/utils/{mod.rs → src/lib.rs} +1 -1
  190. package/rust/utils/{logger.rs → src/logger.rs} +17 -12
  191. package/rust/utils/src/path.rs +88 -0
  192. package/rust/utils/src/signature.rs +41 -0
  193. package/rust/utils/{spinner.rs → src/spinner.rs} +3 -5
  194. package/rust/utils/src/version.rs +27 -0
  195. package/rust/utils/{watcher.rs → src/watcher.rs} +13 -1
  196. package/rust/web/cdn.rs +34 -0
  197. package/templates/minimal/README.md +98 -54
  198. package/templates/welcome/README.md +98 -54
  199. package/templates/welcome/src/index.deva +56 -8
  200. package/templates/welcome/src/variables.deva +2 -4
  201. package/tests/rust/TODO.md +0 -0
  202. package/tests/typescript/index.spec.ts +136 -0
  203. package/tests/typescript/playhead.spec.ts +36 -0
  204. package/tests/typescript/render_e2e.spec.ts +77 -0
  205. package/tsconfig.json +1 -1
  206. package/typescript/core/functions/index.ts +83 -0
  207. package/typescript/core/index.ts +6 -0
  208. package/typescript/core/types/index.ts +4 -0
  209. package/typescript/core/types/plugin.ts +19 -0
  210. package/typescript/core/types/result.ts +29 -0
  211. package/typescript/core/types/statement.ts +47 -0
  212. package/typescript/core/types/value.ts +29 -0
  213. package/typescript/index.ts +7 -2
  214. package/typescript/pkg/devalang_core.d.ts +4 -0
  215. package/typescript/scripts/copy-wasm-dts.ts +41 -0
  216. package/rust/cli/bank.rs +0 -462
  217. package/rust/cli/build.rs +0 -252
  218. package/rust/cli/play.rs +0 -1123
  219. package/rust/common/cdn.rs +0 -5
  220. package/rust/config/loader.rs +0 -165
  221. package/rust/config/stats.rs +0 -257
  222. package/rust/core/audio/engine.rs +0 -696
  223. package/rust/core/shared/bank.rs +0 -21
  224. package/rust/core/shared/duration.rs +0 -9
  225. package/rust/core/shared/mod.rs +0 -3
  226. package/rust/core/shared/value.rs +0 -35
  227. package/rust/core/utils/validation.rs +0 -35
  228. package/rust/installer/addon.rs +0 -84
  229. package/rust/installer/bank.rs +0 -62
  230. package/rust/installer/plugin.rs +0 -54
  231. package/rust/installer/utils.rs +0 -56
  232. package/rust/utils/file.rs +0 -38
  233. package/rust/utils/first_usage.rs +0 -83
  234. package/rust/utils/signature.rs +0 -19
  235. package/rust/utils/telemetry.rs +0 -292
  236. package/rust/utils/version.rs +0 -15
  237. /package/rust/{common → web}/api.rs +0 -0
  238. /package/rust/{common → web}/mod.rs +0 -0
  239. /package/rust/{common → web}/sso.rs +0 -0
@@ -0,0 +1,94 @@
1
+ use include_dir::{Dir, DirEntry};
2
+ use std::{fs, path::Path};
3
+
4
+ pub fn copy_dir_recursive(dir: &Dir, target_root: &Path, base_path: &Path) {
5
+ for entry in dir.entries() {
6
+ match entry {
7
+ DirEntry::Dir(subdir) => {
8
+ copy_dir_recursive(subdir, target_root, base_path);
9
+ }
10
+ DirEntry::File(file) => {
11
+ // Compute the destination path relative to the provided base.
12
+ let rel_path = match file.path().strip_prefix(base_path) {
13
+ Ok(p) => p.to_owned(),
14
+ Err(_) => {
15
+ eprintln!(
16
+ "Warning: failed to compute relative path for {:?}, skipping",
17
+ file.path()
18
+ );
19
+ continue;
20
+ }
21
+ };
22
+
23
+ let dest_path = target_root.join(rel_path);
24
+
25
+ if let Some(parent) = dest_path.parent() {
26
+ if let Err(e) = fs::create_dir_all(parent) {
27
+ eprintln!(
28
+ "Warning: failed to create directory {}: {}",
29
+ parent.display(),
30
+ e
31
+ );
32
+ continue;
33
+ }
34
+ }
35
+
36
+ if let Err(e) = fs::write(&dest_path, file.contents()) {
37
+ eprintln!("Warning: failed to write {}: {}", dest_path.display(), e);
38
+ continue;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ pub fn format_file_size(bytes: u64) -> String {
46
+ const KB: u64 = 1024;
47
+ const MB: u64 = 1024 * 1024;
48
+
49
+ if bytes >= MB {
50
+ format!("{:.2} Mb", (bytes as f64) / (MB as f64))
51
+ } else if bytes >= KB {
52
+ format!("{:.2} Kb", (bytes as f64) / (KB as f64))
53
+ } else {
54
+ format!("{} bytes", bytes)
55
+ }
56
+ }
57
+
58
+ pub fn extract_zip_safely(archive_path: &Path, dest: &Path) -> Result<(), String> {
59
+ let file = std::fs::File::open(archive_path)
60
+ .map_err(|e| format!("Failed to open archive {}: {}", archive_path.display(), e))?;
61
+ let mut archive = zip::ZipArchive::new(file)
62
+ .map_err(|e| format!("Failed to read archive {}: {}", archive_path.display(), e))?;
63
+
64
+ for i in 0..archive.len() {
65
+ let mut file = archive
66
+ .by_index(i)
67
+ .map_err(|e| format!("Failed to access archive entry {}: {}", i, e))?;
68
+
69
+ let enclosed = match file.enclosed_name() {
70
+ Some(path) => path.to_owned(),
71
+ None => {
72
+ continue;
73
+ }
74
+ };
75
+
76
+ let outpath = dest.join(enclosed);
77
+
78
+ if file.name().ends_with('/') || file.is_dir() {
79
+ std::fs::create_dir_all(&outpath)
80
+ .map_err(|e| format!("Failed to create dir {}: {}", outpath.display(), e))?;
81
+ } else {
82
+ if let Some(p) = outpath.parent() {
83
+ std::fs::create_dir_all(p)
84
+ .map_err(|e| format!("Failed to create parent {}: {}", p.display(), e))?;
85
+ }
86
+ let mut outfile = std::fs::File::create(&outpath)
87
+ .map_err(|e| format!("Failed to create file {}: {}", outpath.display(), e))?;
88
+ std::io::copy(&mut file, &mut outfile)
89
+ .map_err(|e| format!("Failed to write file {}: {}", outpath.display(), e))?;
90
+ }
91
+ }
92
+
93
+ Ok(())
94
+ }
@@ -0,0 +1,97 @@
1
+ #[cfg(feature = "cli")]
2
+ use crossterm::style::{Attribute, SetAttribute};
3
+
4
+ #[cfg(feature = "cli")]
5
+ use std::fmt::Write;
6
+
7
+ use crate::logger::{LogLevel, Logger};
8
+ use crate::signature::get_signature;
9
+ use crate::version::get_version;
10
+ use std::env;
11
+ use std::path::PathBuf;
12
+
13
+ fn get_devalang_homedir() -> PathBuf {
14
+ // Prefer explicit env var, then HOME/USERPROFILE, fallback to current dir
15
+ if let Ok(p) = env::var("DEVALANG_HOME") {
16
+ return PathBuf::from(p);
17
+ }
18
+
19
+ if let Ok(p) = env::var("HOME") {
20
+ return PathBuf::from(p).join(".devalang");
21
+ }
22
+
23
+ if let Ok(p) = env::var("USERPROFILE") {
24
+ return PathBuf::from(p).join(".devalang");
25
+ }
26
+
27
+ env::current_dir()
28
+ .unwrap_or_else(|_| PathBuf::from("."))
29
+ .join(".devalang")
30
+ }
31
+
32
+ pub fn check_is_first_usage() -> bool {
33
+ if get_devalang_homedir().exists() == true {
34
+ false
35
+ } else {
36
+ first_usage_welcome();
37
+ true
38
+ }
39
+ }
40
+
41
+ pub fn first_usage_welcome() {
42
+ std::fs::create_dir_all(get_devalang_homedir()).ok();
43
+
44
+ let version = get_version();
45
+ print!("{}", get_signature(&version));
46
+
47
+ let homedir = get_devalang_homedir().display().to_string();
48
+
49
+ let welcome_msg = format!(
50
+ "Welcome to Devalang ! \n\
51
+ It looks like this is your first time using the tool.\n\
52
+ A configuration file will be created in your home directory.\n\
53
+ (location: '{}')",
54
+ homedir
55
+ );
56
+
57
+ #[cfg(feature = "cli")]
58
+ let mut s = String::new();
59
+ #[cfg(feature = "cli")]
60
+ {
61
+ write!(&mut s, "{}", SetAttribute(Attribute::Bold)).unwrap();
62
+ write!(&mut s, "{}", welcome_msg).unwrap();
63
+ write!(&mut s, "{}", SetAttribute(Attribute::Reset)).unwrap();
64
+
65
+ println!("");
66
+ println!("{}", s);
67
+ println!("");
68
+ }
69
+
70
+ #[cfg(not(feature = "cli"))]
71
+ {
72
+ // Fallback: plain output on non-cli (wasm) builds
73
+ println!("");
74
+ println!("{}", welcome_msg);
75
+ println!("");
76
+ }
77
+
78
+ first_usage_ask_for_telemetry();
79
+ }
80
+
81
+ pub fn first_usage_ask_for_telemetry() {
82
+ let telemetry_msg = "Would you like to enable anonymous telemetry ?";
83
+ let telemetry_desc = "This data helps us improve the tool. You can opt-out at any time.";
84
+
85
+ // Non-interactive fallback for first usage: default to telemetry disabled.
86
+ let _ = telemetry_msg;
87
+ let _ = telemetry_desc;
88
+
89
+ let logger = Logger::new();
90
+
91
+ println!("");
92
+ logger.log_message(
93
+ LogLevel::Info,
94
+ "Telemetry disabled by default. You can enable it at any time by using 'devalang telemetry enable'"
95
+ );
96
+ println!("");
97
+ }
@@ -2,8 +2,8 @@ pub mod error;
2
2
  pub mod file;
3
3
  pub mod first_usage;
4
4
  pub mod logger;
5
+ pub mod path;
5
6
  pub mod signature;
6
7
  pub mod spinner;
7
- pub mod telemetry;
8
8
  pub mod version;
9
9
  pub mod watcher;
@@ -1,5 +1,6 @@
1
1
  #[cfg(feature = "cli")]
2
2
  use crossterm::style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor};
3
+ #[cfg(feature = "cli")]
3
4
  use std::fmt::Write;
4
5
 
5
6
  #[derive(Debug, Clone, PartialEq)]
@@ -21,7 +22,15 @@ impl Logger {
21
22
  Logger
22
23
  }
23
24
 
24
- // --- log_message ---
25
+ // Some methods are only used in CLI builds; silence dead_code warnings for non-cli.
26
+ #[cfg(not(feature = "cli"))]
27
+ #[allow(dead_code)]
28
+ fn __wasm_only_allow_dead_code(&self) {}
29
+
30
+ // Additionally allow dead_code for the CLI-only formatting helpers when building without cli
31
+ #[cfg(not(feature = "cli"))]
32
+ #[allow(dead_code)]
33
+ fn __wasm_only_format_helpers(&self) {}
25
34
 
26
35
  #[cfg(feature = "cli")]
27
36
  pub fn log_message(&self, level: LogLevel, message: &str) {
@@ -39,8 +48,6 @@ impl Logger {
39
48
  // no-op for WASM
40
49
  }
41
50
 
42
- // --- log_message_with_trace ---
43
-
44
51
  #[cfg(feature = "cli")]
45
52
  pub fn log_message_with_trace(&self, level: LogLevel, message: &str, trace: Vec<&str>) {
46
53
  let formatted_status = self.format_status(level);
@@ -60,8 +67,6 @@ impl Logger {
60
67
  // no-op for WASM
61
68
  }
62
69
 
63
- // --- log_error_with_stacktrace ---
64
-
65
70
  #[cfg(feature = "cli")]
66
71
  pub fn log_error_with_stacktrace(&self, message: &str, stacktrace: &str) {
67
72
  let formatted_status = self.format_status(LogLevel::Error);
@@ -79,9 +84,9 @@ impl Logger {
79
84
  // no-op for WASM
80
85
  }
81
86
 
82
- // --- language_signature ---
83
-
84
87
  #[cfg(feature = "cli")]
88
+ #[allow(dead_code)]
89
+ #[cfg_attr(not(feature = "cli"), allow(dead_code))]
85
90
  fn language_signature(&self) -> String {
86
91
  let mut s = String::new();
87
92
 
@@ -94,7 +99,7 @@ impl Logger {
94
99
  SetForegroundColor(Color::Rgb {
95
100
  r: 29,
96
101
  g: 211,
97
- b: 176
102
+ b: 176,
98
103
  })
99
104
  )
100
105
  .unwrap();
@@ -110,12 +115,11 @@ impl Logger {
110
115
  }
111
116
 
112
117
  #[cfg(not(feature = "cli"))]
118
+ #[allow(dead_code)]
113
119
  fn language_signature(&self) -> String {
114
120
  "[Devalang]".to_string()
115
121
  }
116
122
 
117
- // --- format_status ---
118
-
119
123
  #[cfg(feature = "cli")]
120
124
  fn format_status(&self, level: LogLevel) -> String {
121
125
  let mut s = String::new();
@@ -180,8 +184,9 @@ impl Logger {
180
184
  }
181
185
 
182
186
  #[cfg(not(feature = "cli"))]
187
+ #[allow(dead_code)]
183
188
  fn format_status(&self, level: LogLevel) -> String {
184
- match level {
189
+ (match level {
185
190
  LogLevel::Success => "[SUCCESS]",
186
191
  LogLevel::Error => "[ERROR]",
187
192
  LogLevel::Info => "[INFO]",
@@ -189,7 +194,7 @@ impl Logger {
189
194
  LogLevel::Watcher => "[WATCHER]",
190
195
  LogLevel::Debug => "[DEBUG]",
191
196
  LogLevel::Print => "[PRINT]",
192
- }
197
+ })
193
198
  .to_string()
194
199
  }
195
200
  }
@@ -0,0 +1,88 @@
1
+ use std::{
2
+ env, fs,
3
+ path::{Path, PathBuf},
4
+ };
5
+
6
+ pub const DEVALANG_CONFIG: &str = ".devalang";
7
+ pub const DEVA_DIR: &str = ".deva";
8
+
9
+ /// Returns the current working directory.
10
+ pub fn get_cwd() -> PathBuf {
11
+ // In wasm (and some restricted environments) `env::current_dir()` is unsupported
12
+ // and will return an error. Avoid panicking here and fall back to `.` so the
13
+ // runtime can still operate in a virtual environment.
14
+ env::current_dir().unwrap_or_else(|_| PathBuf::from("."))
15
+ }
16
+
17
+ /// Returns true if the given directory looks like a devalang project root.
18
+ /// Preference is given to the presence of `.devalang` (config file),
19
+ /// but falling back to a `.deva` directory is allowed.
20
+ pub fn is_project_root(dir: &Path) -> bool {
21
+ let config = dir.join(DEVALANG_CONFIG);
22
+ if config.is_file() {
23
+ return true;
24
+ }
25
+ let deva = dir.join(DEVA_DIR);
26
+ deva.is_dir()
27
+ }
28
+
29
+ /// Walks upward from `start` to locate the first directory considered a project root.
30
+ pub fn find_project_root_from(start: &Path) -> Option<PathBuf> {
31
+ for ancestor in start.ancestors() {
32
+ if is_project_root(ancestor) {
33
+ return Some(ancestor.to_path_buf());
34
+ }
35
+ }
36
+ None
37
+ }
38
+
39
+ /// Finds the project root from the current working directory.
40
+ pub fn find_project_root() -> Option<PathBuf> {
41
+ find_project_root_from(&get_cwd())
42
+ }
43
+
44
+ /// Finds the package root using the `CARGO_MANIFEST_DIR` env var set by Cargo.
45
+ pub fn get_package_root() -> Option<PathBuf> {
46
+ let cargo_dir = env::var("CARGO_MANIFEST_DIR").ok()?;
47
+ Some(PathBuf::from(cargo_dir))
48
+ }
49
+
50
+ /// Gets the project root or returns a descriptive error if not found.
51
+ pub fn get_project_root() -> Result<PathBuf, String> {
52
+ find_project_root()
53
+ .ok_or_else(|| "Project root not found. Run 'devalang init' in your project.".to_string())
54
+ }
55
+
56
+ /// Returns the path to `.devalang` in the project root, ensuring it exists.
57
+ pub fn get_devalang_config_path() -> Result<PathBuf, String> {
58
+ let root = get_project_root()?;
59
+ let config_path = root.join(DEVALANG_CONFIG);
60
+ if !config_path.exists() {
61
+ return Err(format!(
62
+ "Config file not found at '{}'. Please run 'devalang init' before continuing.",
63
+ config_path.display()
64
+ ));
65
+ }
66
+ Ok(config_path)
67
+ }
68
+
69
+ /// Returns the `.deva` directory inside the project root (without creating it).
70
+ pub fn get_deva_dir() -> Result<PathBuf, String> {
71
+ let root = get_project_root()?;
72
+ Ok(root.join(DEVA_DIR))
73
+ }
74
+
75
+ /// Ensures the `.deva` directory exists in the project root and returns its path.
76
+ pub fn ensure_deva_dir() -> Result<PathBuf, String> {
77
+ let deva = get_deva_dir()?;
78
+ if !deva.exists() {
79
+ fs::create_dir_all(&deva).map_err(|e| {
80
+ format!(
81
+ "Failed to create Deva directory '{}': {}",
82
+ deva.display(),
83
+ e
84
+ )
85
+ })?;
86
+ }
87
+ Ok(deva)
88
+ }
@@ -0,0 +1,41 @@
1
+ #[cfg(feature = "cli")]
2
+ pub fn get_signature(version: &str) -> String {
3
+ let signature = format!(
4
+ r#"
5
+ /|_/|
6
+ / ^ ^(_o 🦊 Devalang
7
+ / __.'
8
+ / \ A programming language for music and sound.
9
+ / _ \_ Part of the Devaloop project.
10
+ (_) (_) '._
11
+ '.__ '. .-''-'. https://devalang.com
12
+ ( '. ('.____.''
13
+ _) )'_, ) v{}
14
+ (__/ (__/
15
+ "#,
16
+ version
17
+ );
18
+
19
+ signature
20
+ }
21
+
22
+ #[cfg(not(feature = "cli"))]
23
+ pub fn get_signature(version: &str) -> String {
24
+ let signature = format!(
25
+ r#"
26
+ /|_/|
27
+ / ^ ^(_o 🦊 Devalang
28
+ / __.'
29
+ / \ A programming language for music and sound.
30
+ / _ \_ Part of the Devaloop project.
31
+ (_) (_) '._
32
+ '.__ '. .-''-'. https://devalang.com
33
+ ( '. ('.____.''
34
+ _) )'_, ) v{}
35
+ (__/ (__/
36
+ "#,
37
+ version
38
+ );
39
+
40
+ signature
41
+ }
@@ -1,12 +1,10 @@
1
1
  #[cfg(feature = "cli")]
2
2
  use indicatif::{ProgressBar, ProgressStyle};
3
+ #[cfg(feature = "cli")]
3
4
  use std::time::Duration;
4
5
 
5
6
  #[cfg(feature = "cli")]
6
- pub fn with_spinner<T, F>(start_msg: &str, f: F) -> ProgressBar
7
- where
8
- F: FnOnce() -> T,
9
- {
7
+ pub fn start_spinner(start_msg: &str) -> ProgressBar {
10
8
  let spinner = ProgressBar::new_spinner();
11
9
  spinner.set_style(
12
10
  ProgressStyle::with_template("{spinner:.green} {msg}")
@@ -16,7 +14,7 @@ where
16
14
  spinner.set_message(start_msg.to_string());
17
15
  spinner.enable_steady_tick(Duration::from_millis(80));
18
16
 
19
- let _ = f();
17
+ std::thread::sleep(Duration::from_millis(750));
20
18
 
21
19
  spinner
22
20
  }
@@ -0,0 +1,27 @@
1
+ use crate::{path::get_package_root, signature::get_signature};
2
+
3
+ pub fn get_version() -> String {
4
+ if let Some(root) = get_package_root() {
5
+ let project_version_json = root.join("project-version.json");
6
+ if let Ok(version) = std::fs::read_to_string(project_version_json) {
7
+ if let Ok(parsed) = serde_json::from_str::<serde_json::Value>(&version) {
8
+ if let Some(version_val) = parsed.get("version") {
9
+ if let Some(s) = version_val.as_str() {
10
+ return s.to_string();
11
+ }
12
+ }
13
+ }
14
+ }
15
+ }
16
+
17
+ "0.0.0".to_string()
18
+ }
19
+
20
+ pub fn get_version_with_signature() -> String {
21
+ let version = get_version();
22
+ let signature = get_signature(&version);
23
+
24
+ println!("{}", signature);
25
+
26
+ "(c) 2025 Devaloop. All rights reserved.".to_string()
27
+ }
@@ -24,7 +24,19 @@ where
24
24
  }
25
25
  }
26
26
  Err(e) => {
27
- eprintln!("Channel error: {:?}", e);
27
+ // Prefer structured logging when available
28
+ #[cfg(feature = "cli")]
29
+ {
30
+ let logger = crate::logger::Logger::new();
31
+ logger.log_message(
32
+ crate::logger::LogLevel::Error,
33
+ &format!("Channel error: {:?}", e),
34
+ );
35
+ }
36
+ #[cfg(not(feature = "cli"))]
37
+ {
38
+ eprintln!("Channel error: {:?}", e);
39
+ }
28
40
  break;
29
41
  }
30
42
  }
@@ -0,0 +1,34 @@
1
+ use std::error::Error;
2
+ use std::fs::File;
3
+ use std::io::{Cursor, copy};
4
+ use std::path::Path;
5
+
6
+ pub fn get_cdn_url() -> String {
7
+ let cdn_url = "https://cdn.devalang.com";
8
+ // let cdn_url = "http://127.0.0.1:8888";
9
+ cdn_url.to_string()
10
+ }
11
+
12
+ pub async fn download_from_cdn(url: &str, destination: &Path) -> Result<(), Box<dyn Error>> {
13
+ if !url.starts_with(&get_cdn_url()) {
14
+ return Err(format!("Invalid CDN URL: {}", url).into());
15
+ }
16
+
17
+ let response = reqwest::get(url).await?;
18
+
19
+ if !response.status().is_success() {
20
+ return Err(format!("Failed to download file: HTTP {}", response.status()).into());
21
+ }
22
+
23
+ if let Some(parent) = destination.parent() {
24
+ std::fs::create_dir_all(parent)?;
25
+ }
26
+
27
+ let bytes = response.bytes().await?;
28
+ let mut content = Cursor::new(bytes);
29
+ let mut file = File::create(destination)?;
30
+
31
+ copy(&mut content, &mut file)?;
32
+
33
+ Ok(())
34
+ }