@devaloop/devalang 0.0.1-alpha.8 → 0.0.1-beta.1
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.
- package/.cargo/config.toml +2 -0
- package/.devalang +10 -4
- package/.github/workflows/ci.yml +103 -0
- package/Cargo.toml +80 -48
- package/README.md +135 -158
- package/docs/CHANGELOG.md +413 -1
- package/docs/CONTRIBUTING.md +101 -0
- package/docs/ROADMAP.md +10 -7
- package/docs/TODO.md +21 -9
- package/examples/automation.deva +42 -0
- package/examples/bank.deva +7 -0
- package/examples/condition.deva +8 -12
- package/examples/duration.deva +9 -0
- package/examples/events.deva +12 -0
- package/examples/function.deva +15 -0
- package/examples/group.deva +3 -3
- package/examples/index.deva +57 -10
- package/examples/loop.deva +7 -12
- package/examples/pattern.deva +8 -0
- package/examples/plugin.deva +16 -0
- package/examples/synth.deva +14 -0
- package/examples/variables.deva +2 -2
- package/out-tsc/bin/index.d.ts +2 -0
- package/out-tsc/bin/index.js +51 -7
- package/out-tsc/core/functions/index.d.ts +37 -0
- package/out-tsc/core/functions/index.js +76 -0
- package/out-tsc/core/index.d.ts +6 -0
- package/out-tsc/core/index.js +22 -0
- package/out-tsc/core/types/index.d.ts +4 -0
- package/out-tsc/core/types/index.js +20 -0
- package/out-tsc/core/types/plugin.d.ts +18 -0
- package/out-tsc/core/types/plugin.js +2 -0
- package/out-tsc/core/types/result.d.ts +27 -0
- package/out-tsc/core/types/result.js +2 -0
- package/out-tsc/core/types/statement.d.ts +106 -0
- package/out-tsc/core/types/statement.js +2 -0
- package/out-tsc/core/types/value.d.ts +43 -0
- package/out-tsc/core/types/value.js +2 -0
- package/out-tsc/index.d.ts +7 -0
- package/out-tsc/index.js +42 -1
- package/out-tsc/pkg/devalang_core.d.ts +13 -0
- package/out-tsc/pkg/devalang_core.js +50 -0
- package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +33 -0
- package/out-tsc/scripts/copy-wasm-dts.d.ts +1 -0
- package/out-tsc/scripts/copy-wasm-dts.js +73 -0
- package/out-tsc/scripts/postinstall.d.ts +1 -0
- package/out-tsc/scripts/postinstall.js +83 -0
- package/out-tsc/scripts/version/bump.d.ts +1 -0
- package/out-tsc/scripts/version/fetch.d.ts +1 -0
- package/out-tsc/scripts/version/fetch.js +1 -5
- package/out-tsc/scripts/version/index.d.ts +1 -0
- package/out-tsc/scripts/version/sync.d.ts +1 -0
- package/package.json +28 -7
- package/project-version.json +4 -4
- package/rust/cli/bank/api.rs +122 -0
- package/rust/cli/bank/commands.rs +275 -0
- package/rust/cli/bank/mod.rs +29 -0
- package/rust/cli/build/commands.rs +103 -0
- package/rust/cli/build/mod.rs +2 -0
- package/rust/cli/build/process.rs +146 -0
- package/rust/cli/check/mod.rs +208 -0
- package/rust/cli/discover/commands.rs +253 -0
- package/rust/cli/discover/config.rs +111 -0
- package/rust/cli/discover/fs.rs +19 -0
- package/rust/cli/discover/install.rs +103 -0
- package/rust/cli/discover/metadata.rs +48 -0
- package/rust/cli/discover/mod.rs +5 -0
- package/rust/cli/{init.rs → init/commands.rs} +32 -23
- package/rust/cli/init/mod.rs +1 -0
- package/rust/cli/install/addon.rs +118 -0
- package/rust/cli/install/bank.rs +53 -0
- package/rust/cli/install/commands.rs +35 -0
- package/rust/cli/install/mod.rs +4 -0
- package/rust/cli/install/plugin.rs +61 -0
- package/rust/cli/login/commands.rs +124 -0
- package/rust/cli/login/mod.rs +1 -0
- package/rust/cli/mod.rs +12 -205
- package/rust/cli/parser.rs +314 -0
- package/rust/cli/play/commands.rs +324 -0
- package/rust/cli/play/io.rs +17 -0
- package/rust/cli/play/mod.rs +5 -0
- package/rust/cli/play/process.rs +150 -0
- package/rust/cli/play/realtime.rs +91 -0
- package/rust/cli/play/utils.rs +23 -0
- package/rust/cli/telemetry/commands.rs +22 -0
- package/rust/cli/telemetry/event_creator.rs +80 -0
- package/rust/cli/telemetry/mod.rs +3 -0
- package/rust/cli/telemetry/send.rs +51 -0
- package/rust/cli/{template.rs → template/commands.rs} +69 -57
- package/rust/cli/template/mod.rs +1 -0
- package/rust/cli/update/commands.rs +6 -0
- package/rust/cli/update/mod.rs +1 -0
- package/rust/config/driver.rs +103 -0
- package/rust/config/mod.rs +3 -16
- package/rust/config/ops.rs +26 -0
- package/rust/config/settings.rs +101 -0
- package/rust/core/audio/engine/helpers.rs +170 -0
- package/rust/core/audio/engine/mod.rs +7 -0
- package/rust/core/audio/engine/sample.rs +366 -0
- package/rust/core/audio/engine/synth.rs +325 -0
- package/rust/core/audio/evaluator.rs +310 -31
- package/rust/core/audio/interpreter/arrow_call.rs +311 -0
- package/rust/core/audio/interpreter/automate.rs +18 -0
- package/rust/core/audio/interpreter/call.rs +294 -42
- package/rust/core/audio/interpreter/condition.rs +71 -65
- package/rust/core/audio/interpreter/driver.rs +542 -204
- package/rust/core/audio/interpreter/function.rs +26 -0
- package/rust/core/audio/interpreter/let_.rs +38 -19
- package/rust/core/audio/interpreter/load.rs +19 -18
- package/rust/core/audio/interpreter/loop_.rs +114 -59
- package/rust/core/audio/interpreter/mod.rs +14 -11
- package/rust/core/audio/interpreter/sleep.rs +28 -36
- package/rust/core/audio/interpreter/spawn.rs +252 -65
- package/rust/core/audio/interpreter/tempo.rs +40 -16
- package/rust/core/audio/interpreter/trigger.rs +239 -69
- package/rust/core/audio/loader/mod.rs +1 -1
- package/rust/core/audio/loader/trigger.rs +97 -52
- package/rust/core/audio/mod.rs +7 -6
- package/rust/core/audio/player.rs +70 -54
- package/rust/core/audio/renderer.rs +54 -57
- package/rust/core/audio/special/easing.rs +189 -0
- package/rust/core/audio/special/env.rs +45 -0
- package/rust/core/audio/special/math.rs +134 -0
- package/rust/core/audio/special/mod.rs +9 -0
- package/rust/core/audio/special/modulator.rs +143 -0
- package/rust/core/builder/mod.rs +86 -80
- package/rust/core/debugger/lexer.rs +27 -27
- package/rust/core/debugger/mod.rs +30 -21
- package/rust/core/debugger/module.rs +55 -0
- package/rust/core/debugger/preprocessor.rs +27 -27
- package/rust/core/debugger/store.rs +40 -25
- package/rust/core/error/mod.rs +269 -60
- package/rust/core/lexer/driver.rs +61 -0
- package/rust/core/lexer/handler/arrow.rs +82 -0
- package/rust/core/lexer/handler/at.rs +21 -21
- package/rust/core/lexer/handler/brace.rs +41 -41
- package/rust/core/lexer/handler/colon.rs +21 -21
- package/rust/core/lexer/handler/comment.rs +30 -30
- package/rust/core/lexer/handler/dot.rs +21 -21
- package/rust/core/lexer/handler/driver.rs +337 -215
- package/rust/core/lexer/handler/identifier.rs +47 -40
- package/rust/core/lexer/handler/indent.rs +66 -52
- package/rust/core/lexer/handler/mod.rs +15 -13
- package/rust/core/lexer/handler/newline.rs +23 -23
- package/rust/core/lexer/handler/number.rs +31 -31
- package/rust/core/lexer/handler/operator.rs +46 -44
- package/rust/core/lexer/handler/parenthesis.rs +41 -0
- package/rust/core/lexer/handler/slash.rs +21 -0
- package/rust/core/lexer/handler/string.rs +63 -63
- package/rust/core/lexer/mod.rs +3 -30
- package/rust/core/lexer/token.rs +21 -12
- package/rust/core/mod.rs +10 -10
- package/rust/core/parser/driver.rs +584 -312
- package/rust/core/parser/handler/arrow_call.rs +253 -0
- package/rust/core/parser/handler/at.rs +279 -162
- package/rust/core/parser/handler/bank.rs +104 -41
- package/rust/core/parser/handler/condition.rs +83 -74
- package/rust/core/parser/handler/dot.rs +148 -112
- package/rust/core/parser/handler/identifier/automate.rs +254 -0
- package/rust/core/parser/handler/identifier/call.rs +91 -0
- package/rust/core/parser/handler/identifier/emit.rs +70 -0
- package/rust/core/parser/handler/identifier/function.rs +113 -0
- package/rust/core/parser/handler/identifier/group.rs +89 -0
- package/rust/core/parser/handler/identifier/let_.rs +173 -0
- package/rust/core/parser/handler/identifier/mod.rs +55 -0
- package/rust/core/parser/handler/identifier/on.rs +107 -0
- package/rust/core/parser/handler/identifier/print.rs +49 -0
- package/rust/core/parser/handler/identifier/sleep.rs +43 -0
- package/rust/core/parser/handler/identifier/spawn.rs +91 -0
- package/rust/core/parser/handler/identifier/synth.rs +135 -0
- package/rust/core/parser/handler/loop_.rs +194 -66
- package/rust/core/parser/handler/mod.rs +9 -7
- package/rust/core/parser/handler/pattern.rs +74 -0
- package/rust/core/parser/handler/tempo.rs +57 -47
- package/rust/core/parser/mod.rs +3 -4
- package/rust/core/parser/statement.rs +11 -88
- package/rust/core/plugin/loader.rs +137 -0
- package/rust/core/plugin/mod.rs +2 -0
- package/rust/core/plugin/runner.rs +347 -0
- package/rust/core/preprocessor/loader.rs +637 -179
- package/rust/core/preprocessor/mod.rs +4 -4
- package/rust/core/preprocessor/module.rs +60 -53
- package/rust/core/preprocessor/processor.rs +114 -67
- package/rust/core/preprocessor/resolver/bank.rs +49 -47
- package/rust/core/preprocessor/resolver/call.rs +124 -53
- package/rust/core/preprocessor/resolver/condition.rs +95 -66
- package/rust/core/preprocessor/resolver/driver.rs +324 -182
- package/rust/core/preprocessor/resolver/function.rs +69 -0
- package/rust/core/preprocessor/resolver/group.rs +94 -118
- package/rust/core/preprocessor/resolver/let_.rs +32 -0
- package/rust/core/preprocessor/resolver/loop_.rs +318 -145
- package/rust/core/preprocessor/resolver/mod.rs +16 -10
- package/rust/core/preprocessor/resolver/pattern.rs +83 -0
- package/rust/core/preprocessor/resolver/spawn.rs +99 -53
- package/rust/core/preprocessor/resolver/synth.rs +54 -0
- package/rust/core/preprocessor/resolver/tempo.rs +48 -49
- package/rust/core/preprocessor/resolver/trigger.rs +116 -111
- package/rust/core/preprocessor/resolver/value.rs +176 -0
- package/rust/core/store/export.rs +28 -28
- package/rust/core/store/function.rs +40 -0
- package/rust/core/store/global.rs +61 -39
- package/rust/core/store/import.rs +28 -28
- package/rust/core/store/mod.rs +5 -4
- package/rust/core/store/variable.rs +51 -28
- package/rust/core/utils/mod.rs +1 -2
- package/rust/core/utils/path.rs +37 -46
- package/rust/lib.rs +308 -117
- package/rust/main.rs +364 -65
- package/rust/types/Cargo.toml +11 -0
- package/rust/types/src/addons.rs +55 -0
- package/rust/types/src/ast.rs +202 -0
- package/rust/types/src/config.rs +74 -0
- package/rust/types/src/lib.rs +12 -0
- package/rust/types/src/telemetry.rs +85 -0
- package/rust/utils/Cargo.toml +26 -0
- package/rust/utils/src/error.rs +186 -0
- package/rust/utils/src/file.rs +94 -0
- package/rust/utils/src/first_usage.rs +97 -0
- package/rust/utils/{mod.rs → src/lib.rs} +9 -6
- package/rust/utils/{logger.rs → src/logger.rs} +200 -123
- package/rust/utils/src/path.rs +88 -0
- package/rust/utils/src/signature.rs +41 -0
- package/rust/utils/{spinner.rs → src/spinner.rs} +20 -21
- package/rust/utils/src/version.rs +27 -0
- package/rust/utils/{watcher.rs → src/watcher.rs} +46 -33
- package/rust/web/api.rs +5 -0
- package/rust/web/cdn.rs +34 -0
- package/rust/web/mod.rs +3 -0
- package/rust/web/sso.rs +5 -0
- package/templates/minimal/README.md +143 -127
- package/templates/welcome/README.md +143 -127
- package/templates/welcome/src/index.deva +56 -8
- package/templates/welcome/src/variables.deva +2 -4
- package/tests/integration.rs +21 -0
- package/tests/rust/cli_check_build.rs +21 -0
- package/tests/rust/cli_help.rs +12 -0
- package/tests/rust/cli_template_list.rs +10 -0
- package/tests/rust/cli_version.rs +11 -0
- package/tests/typescript/index.spec.ts +136 -0
- package/tests/typescript/playhead.spec.ts +36 -0
- package/tests/typescript/render_e2e.spec.ts +77 -0
- package/tsconfig.json +12 -10
- package/typescript/bin/index.ts +19 -5
- package/typescript/core/functions/index.ts +83 -0
- package/typescript/core/index.ts +6 -0
- package/typescript/core/types/index.ts +4 -0
- package/typescript/core/types/plugin.ts +19 -0
- package/typescript/core/types/result.ts +29 -0
- package/typescript/core/types/statement.ts +47 -0
- package/typescript/core/types/value.ts +29 -0
- package/typescript/index.ts +8 -1
- package/typescript/pkg/devalang_core.d.ts +4 -0
- package/typescript/pkg/devalang_core.ts +49 -0
- package/typescript/scripts/copy-wasm-dts.ts +41 -0
- package/typescript/scripts/postinstall.ts +85 -0
- package/typescript/scripts/version/bump.ts +0 -1
- package/typescript/scripts/version/fetch.ts +1 -6
- package/typescript/scripts/version/index.ts +0 -1
- package/docs/COMMANDS.md +0 -85
- package/docs/CONFIG.md +0 -30
- package/docs/SYNTAX.md +0 -210
- package/out-tsc/bin/devalang.exe +0 -0
- package/out-tsc/scripts/postbuild.js +0 -11
- package/rust/cli/build.rs +0 -137
- package/rust/cli/check.rs +0 -117
- package/rust/cli/play.rs +0 -193
- package/rust/config/loader.rs +0 -13
- package/rust/core/audio/engine.rs +0 -126
- package/rust/core/parser/handler/identifier.rs +0 -262
- package/rust/core/shared/duration.rs +0 -8
- package/rust/core/shared/mod.rs +0 -2
- package/rust/core/shared/value.rs +0 -18
- package/rust/core/utils/validation.rs +0 -35
- package/rust/utils/file.rs +0 -35
- package/rust/utils/signature.rs +0 -17
- package/rust/utils/version.rs +0 -15
- package/typescript/scripts/postbuild.ts +0 -8
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
use serde::{Deserialize, Serialize};
|
|
2
|
+
use toml::Value as TomlValue;
|
|
3
|
+
|
|
4
|
+
use crate::TelemetrySettings;
|
|
5
|
+
|
|
6
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
7
|
+
pub struct PluginExport {
|
|
8
|
+
pub name: String,
|
|
9
|
+
pub kind: String,
|
|
10
|
+
/// Optional default value provided by the plugin manifest (keeps toml::Value to preserve types)
|
|
11
|
+
#[serde(default)]
|
|
12
|
+
pub default: Option<TomlValue>,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
16
|
+
pub struct PluginInfo {
|
|
17
|
+
pub author: String,
|
|
18
|
+
pub name: String,
|
|
19
|
+
/// Optional version string when available from a plugin file
|
|
20
|
+
#[serde(default)]
|
|
21
|
+
pub version: Option<String>,
|
|
22
|
+
/// Optional human-friendly description
|
|
23
|
+
#[serde(default)]
|
|
24
|
+
pub description: Option<String>,
|
|
25
|
+
pub exports: Vec<PluginExport>,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// --- Config types (centralised) ------------------------------------------
|
|
29
|
+
|
|
30
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
31
|
+
pub struct ProjectConfig {
|
|
32
|
+
pub defaults: ProjectConfigDefaults,
|
|
33
|
+
pub banks: Option<Vec<ProjectConfigBankEntry>>,
|
|
34
|
+
pub plugins: Option<Vec<ProjectConfigPluginEntry>>,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
38
|
+
pub struct ProjectConfigDefaults {
|
|
39
|
+
pub entry: Option<String>,
|
|
40
|
+
pub output: Option<String>,
|
|
41
|
+
pub watch: Option<bool>,
|
|
42
|
+
pub repeat: Option<bool>,
|
|
43
|
+
pub debug: Option<bool>,
|
|
44
|
+
pub compress: Option<bool>,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
48
|
+
pub struct ProjectConfigBankEntry {
|
|
49
|
+
pub path: String,
|
|
50
|
+
pub version: Option<String>,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
54
|
+
pub struct ProjectConfigPluginEntry {
|
|
55
|
+
pub path: String,
|
|
56
|
+
pub version: Option<String>,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
60
|
+
pub struct PluginEntry {
|
|
61
|
+
pub path: String,
|
|
62
|
+
#[serde(default)]
|
|
63
|
+
pub version: String,
|
|
64
|
+
#[serde(default)]
|
|
65
|
+
pub author: String,
|
|
66
|
+
#[serde(default)]
|
|
67
|
+
pub access: String,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[derive(Serialize, Deserialize, Default, Debug)]
|
|
71
|
+
pub struct UserSettings {
|
|
72
|
+
pub session: String,
|
|
73
|
+
pub telemetry: TelemetrySettings,
|
|
74
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
use serde::{Deserialize, Serialize};
|
|
2
|
+
|
|
3
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
4
|
+
pub enum TelemetryErrorLevel {
|
|
5
|
+
#[default]
|
|
6
|
+
None,
|
|
7
|
+
Warning,
|
|
8
|
+
Critical,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
#[derive(Debug)]
|
|
12
|
+
pub enum TelemetrySendError {
|
|
13
|
+
Http(String),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
17
|
+
pub struct TelemetryProjectInfo {
|
|
18
|
+
pub config: Option<TelemetryProjectInfoConfig>,
|
|
19
|
+
pub stats: Option<TelemetryProjectInfoStats>,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
23
|
+
pub struct TelemetryProjectInfoStats {
|
|
24
|
+
pub counts: TelemetryProjectInfoStatsCounts,
|
|
25
|
+
pub features: TelemetryProjectInfoStatsFeatures,
|
|
26
|
+
pub audio: TelemetryProjectInfoStatsAudio,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
30
|
+
pub struct TelemetryProjectInfoStatsCounts {
|
|
31
|
+
pub nb_files: usize,
|
|
32
|
+
pub nb_modules: usize,
|
|
33
|
+
pub nb_lines: usize,
|
|
34
|
+
pub nb_banks: usize,
|
|
35
|
+
pub nb_plugins: usize,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
39
|
+
pub struct TelemetryProjectInfoStatsFeatures {
|
|
40
|
+
pub uses_imports: bool,
|
|
41
|
+
pub uses_functions: bool,
|
|
42
|
+
pub uses_groups: bool,
|
|
43
|
+
pub uses_automations: bool,
|
|
44
|
+
pub uses_loops: bool,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
48
|
+
pub struct TelemetryProjectInfoStatsAudio {
|
|
49
|
+
pub avg_bpm: Option<u32>,
|
|
50
|
+
pub has_synths: bool,
|
|
51
|
+
pub has_samples: bool,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
55
|
+
pub struct TelemetryProjectInfoConfig {
|
|
56
|
+
pub entry_defined: bool,
|
|
57
|
+
pub output_defined: bool,
|
|
58
|
+
pub watch_defined: bool,
|
|
59
|
+
pub repeat_defined: bool,
|
|
60
|
+
pub debug_defined: bool,
|
|
61
|
+
pub compress_defined: bool,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
|
|
65
|
+
pub struct TelemetryEvent {
|
|
66
|
+
pub uuid: String,
|
|
67
|
+
pub cli_version: String,
|
|
68
|
+
pub os: String,
|
|
69
|
+
pub command: Vec<String>,
|
|
70
|
+
pub project_info: Option<TelemetryProjectInfo>,
|
|
71
|
+
pub error_level: TelemetryErrorLevel,
|
|
72
|
+
pub error_message: Option<String>,
|
|
73
|
+
pub exit_code: Option<i32>,
|
|
74
|
+
pub timestamp: String,
|
|
75
|
+
pub duration: u64,
|
|
76
|
+
pub success: bool,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#[derive(Serialize, Deserialize, Default, Debug)]
|
|
80
|
+
pub struct TelemetrySettings {
|
|
81
|
+
pub uuid: String,
|
|
82
|
+
pub stats: bool,
|
|
83
|
+
pub level: String,
|
|
84
|
+
pub enabled: bool,
|
|
85
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "devalang_utils"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Utility functions and types for Devalang"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
authors = ["Devaloop <contact@devaloop.com>"]
|
|
7
|
+
edition = "2024"
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
devalang_types = { path = "../types", version = "0.0.2" }
|
|
11
|
+
serde = { version = "1.0", features = ["derive"] }
|
|
12
|
+
serde_json = "1.0"
|
|
13
|
+
include_dir = "0.7"
|
|
14
|
+
notify = "6.1"
|
|
15
|
+
zip = "4.3.0"
|
|
16
|
+
|
|
17
|
+
[dependencies.crossterm]
|
|
18
|
+
version = "0.27"
|
|
19
|
+
optional = true
|
|
20
|
+
|
|
21
|
+
[dependencies.indicatif]
|
|
22
|
+
version = "0.17"
|
|
23
|
+
optional = true
|
|
24
|
+
|
|
25
|
+
[features]
|
|
26
|
+
cli = ["crossterm", "indicatif"]
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
use super::logger::{LogLevel, Logger};
|
|
2
|
+
use devalang_types::{ErrorResult, Severity, StackFrame, Statement, StatementKind, Value};
|
|
3
|
+
use std::collections::HashMap;
|
|
4
|
+
|
|
5
|
+
pub fn collect_errors_recursively(statements: &[Statement]) -> Vec<ErrorResult> {
|
|
6
|
+
let mut errors: Vec<ErrorResult> = Vec::new();
|
|
7
|
+
|
|
8
|
+
for stmt in statements {
|
|
9
|
+
match &stmt.kind {
|
|
10
|
+
StatementKind::Unknown => {
|
|
11
|
+
errors.push(ErrorResult {
|
|
12
|
+
message: format!("Unknown statement at line {}:{}", stmt.line, stmt.column),
|
|
13
|
+
line: stmt.line,
|
|
14
|
+
column: stmt.column,
|
|
15
|
+
severity: Severity::Warning,
|
|
16
|
+
stack: vec![StackFrame {
|
|
17
|
+
module: None,
|
|
18
|
+
context: Some("Unknown".to_string()),
|
|
19
|
+
line: stmt.line,
|
|
20
|
+
column: stmt.column,
|
|
21
|
+
}],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
StatementKind::Error { message } => {
|
|
25
|
+
errors.push(ErrorResult {
|
|
26
|
+
message: message.clone(),
|
|
27
|
+
line: stmt.line,
|
|
28
|
+
column: stmt.column,
|
|
29
|
+
severity: Severity::Critical,
|
|
30
|
+
stack: vec![StackFrame {
|
|
31
|
+
module: None,
|
|
32
|
+
context: Some("Error".to_string()),
|
|
33
|
+
line: stmt.line,
|
|
34
|
+
column: stmt.column,
|
|
35
|
+
}],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
StatementKind::Loop => {
|
|
39
|
+
if let Some(body_statements) = extract_loop_body_statements(&stmt.value) {
|
|
40
|
+
let nested = collect_errors_recursively(body_statements);
|
|
41
|
+
errors.extend(nested.into_iter().map(|mut e| {
|
|
42
|
+
e.stack.insert(
|
|
43
|
+
0,
|
|
44
|
+
StackFrame {
|
|
45
|
+
module: None,
|
|
46
|
+
context: Some("loop".to_string()),
|
|
47
|
+
line: stmt.line,
|
|
48
|
+
column: stmt.column,
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
e
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
_ => {}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
errors
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn extract_loop_body_statements(value: &Value) -> Option<&[Statement]> {
|
|
63
|
+
if let Value::Map(map) = value {
|
|
64
|
+
if let Some(Value::Block(statements)) = map.get("body") {
|
|
65
|
+
return Some(statements);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
None
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
pub fn partition_errors(errors: Vec<ErrorResult>) -> (Vec<ErrorResult>, Vec<ErrorResult>) {
|
|
72
|
+
let mut warnings = Vec::new();
|
|
73
|
+
let mut criticals = Vec::new();
|
|
74
|
+
for e in errors {
|
|
75
|
+
match e.severity {
|
|
76
|
+
Severity::Warning => warnings.push(e),
|
|
77
|
+
Severity::Critical => criticals.push(e),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
(warnings, criticals)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub fn log_errors_with_stack(prefix: &str, warnings: &[ErrorResult], criticals: &[ErrorResult]) {
|
|
84
|
+
let logger = Logger::new();
|
|
85
|
+
if !warnings.is_empty() {
|
|
86
|
+
logger.log_message(
|
|
87
|
+
LogLevel::Warning,
|
|
88
|
+
&format!("{}: {} warning(s)", prefix, warnings.len()),
|
|
89
|
+
);
|
|
90
|
+
for w in warnings {
|
|
91
|
+
logger.log_message(LogLevel::Warning, &format!("- {}", w.message));
|
|
92
|
+
if let Some(frame) = w.stack.first() {
|
|
93
|
+
let module = frame.module.clone().unwrap_or_default();
|
|
94
|
+
logger.log_message(
|
|
95
|
+
LogLevel::Debug,
|
|
96
|
+
&format!(
|
|
97
|
+
" ↳ {}:{}:{} {}",
|
|
98
|
+
module,
|
|
99
|
+
frame.line,
|
|
100
|
+
frame.column,
|
|
101
|
+
frame.context.clone().unwrap_or_default()
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if w.stack.len() > 1 {
|
|
106
|
+
for (i, f) in w.stack.iter().enumerate().skip(1) {
|
|
107
|
+
let module = f.module.clone().unwrap_or_default();
|
|
108
|
+
logger.log_message(
|
|
109
|
+
LogLevel::Debug,
|
|
110
|
+
&format!(
|
|
111
|
+
" #{} {}:{}:{} {}",
|
|
112
|
+
i,
|
|
113
|
+
module,
|
|
114
|
+
f.line,
|
|
115
|
+
f.column,
|
|
116
|
+
f.context.clone().unwrap_or_default()
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if !criticals.is_empty() {
|
|
124
|
+
logger.log_message(
|
|
125
|
+
LogLevel::Error,
|
|
126
|
+
&format!("{}: {} critical error(s)", prefix, criticals.len()),
|
|
127
|
+
);
|
|
128
|
+
for c in criticals {
|
|
129
|
+
logger.log_message(LogLevel::Error, &format!("- {}", c.message));
|
|
130
|
+
if let Some(frame) = c.stack.first() {
|
|
131
|
+
let module = frame.module.clone().unwrap_or_default();
|
|
132
|
+
logger.log_message(
|
|
133
|
+
LogLevel::Error,
|
|
134
|
+
&format!(
|
|
135
|
+
" ↳ {}:{}:{} {}",
|
|
136
|
+
module,
|
|
137
|
+
frame.line,
|
|
138
|
+
frame.column,
|
|
139
|
+
frame.context.clone().unwrap_or_default()
|
|
140
|
+
),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if c.stack.len() > 1 {
|
|
144
|
+
for (i, f) in c.stack.iter().enumerate().skip(1) {
|
|
145
|
+
let module = f.module.clone().unwrap_or_default();
|
|
146
|
+
logger.log_message(
|
|
147
|
+
LogLevel::Error,
|
|
148
|
+
&format!(
|
|
149
|
+
" #{} {}:{}:{} {}",
|
|
150
|
+
i,
|
|
151
|
+
module,
|
|
152
|
+
f.line,
|
|
153
|
+
f.column,
|
|
154
|
+
f.context.clone().unwrap_or_default()
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
pub fn collect_all_errors_with_modules(
|
|
164
|
+
modules: &HashMap<String, Vec<Statement>>,
|
|
165
|
+
) -> Vec<ErrorResult> {
|
|
166
|
+
let mut all = Vec::new();
|
|
167
|
+
for (module_path, stmts) in modules {
|
|
168
|
+
let mut errs = collect_errors_recursively(stmts);
|
|
169
|
+
for e in errs.iter_mut() {
|
|
170
|
+
if e.stack.is_empty() {
|
|
171
|
+
e.stack.push(StackFrame {
|
|
172
|
+
module: Some(module_path.clone()),
|
|
173
|
+
context: None,
|
|
174
|
+
line: e.line,
|
|
175
|
+
column: e.column,
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
if e.stack[0].module.is_none() {
|
|
179
|
+
e.stack[0].module = Some(module_path.clone());
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
all.extend(errs);
|
|
184
|
+
}
|
|
185
|
+
all
|
|
186
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
pub mod
|
|
2
|
-
pub mod
|
|
3
|
-
pub mod
|
|
4
|
-
pub mod
|
|
5
|
-
pub mod
|
|
6
|
-
pub mod
|
|
1
|
+
pub mod error;
|
|
2
|
+
pub mod file;
|
|
3
|
+
pub mod first_usage;
|
|
4
|
+
pub mod logger;
|
|
5
|
+
pub mod path;
|
|
6
|
+
pub mod signature;
|
|
7
|
+
pub mod spinner;
|
|
8
|
+
pub mod version;
|
|
9
|
+
pub mod watcher;
|