diff --git a/public/icons/nodejs.svg b/public/icons/nodejs.svg new file mode 100644 index 0000000..70baf5d --- /dev/null +++ b/public/icons/nodejs.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src-tauri/src/plugins/manager.rs b/src-tauri/src/plugins/manager.rs index ad74146..fce254c 100644 --- a/src-tauri/src/plugins/manager.rs +++ b/src-tauri/src/plugins/manager.rs @@ -1,4 +1,7 @@ -use super::{LanguagePlugin, PluginConfig, python2::Python2Plugin, python3::Python3Plugin}; +use super::{ + LanguagePlugin, PluginConfig, nodejs::NodeJSPlugin, python2::Python2Plugin, + python3::Python3Plugin, +}; use std::collections::HashMap; pub struct PluginManager { @@ -11,6 +14,7 @@ impl PluginManager { plugins.insert("python2".to_string(), Box::new(Python2Plugin)); plugins.insert("python3".to_string(), Box::new(Python3Plugin)); + plugins.insert("nodejs".to_string(), Box::new(NodeJSPlugin)); Self { plugins } } diff --git a/src-tauri/src/plugins/mod.rs b/src-tauri/src/plugins/mod.rs index a1ff9de..304944e 100644 --- a/src-tauri/src/plugins/mod.rs +++ b/src-tauri/src/plugins/mod.rs @@ -315,6 +315,8 @@ pub trait LanguagePlugin: Send + Sync { // 重新导出子模块 pub mod manager; +pub mod nodejs; pub mod python2; pub mod python3; + pub use manager::PluginManager; diff --git a/src-tauri/src/plugins/nodejs.rs b/src-tauri/src/plugins/nodejs.rs new file mode 100644 index 0000000..26303ff --- /dev/null +++ b/src-tauri/src/plugins/nodejs.rs @@ -0,0 +1,51 @@ +use super::{LanguagePlugin, PluginConfig}; + +pub struct NodeJSPlugin; + +impl LanguagePlugin for NodeJSPlugin { + fn get_order(&self) -> i32 { + 3 + } + + fn get_language_name(&self) -> &'static str { + "Node.js" + } + + fn get_language_key(&self) -> &'static str { + "nodejs" + } + + fn get_file_extension(&self) -> String { + self.get_config() + .map(|config| config.extension.clone()) + .unwrap_or_else(|| "js".to_string()) + } + + fn get_version_args(&self) -> Vec<&'static str> { + vec!["--version"] + } + + fn get_path_command(&self) -> String { + "console.log(process.execPath)".to_string() + } + + fn get_default_config(&self) -> PluginConfig { + PluginConfig { + enabled: true, + language: String::from("nodejs"), + before_compile: None, + extension: String::from("js"), + execute_home: None, + run_command: Option::from(String::from("node $filename")), + after_compile: None, + template: None, + timeout: Some(30), + } + } + + fn get_default_command(&self) -> String { + self.get_config() + .and_then(|config| config.run_command) + .unwrap_or_else(|| "node".to_string()) + } +} diff --git a/src/components/Settings.vue b/src/components/Settings.vue index c6cf322..eedc6a8 100644 --- a/src/components/Settings.vue +++ b/src/components/Settings.vue @@ -1,5 +1,5 @@