Skip to content

Commit ea1af29

Browse files
committed
feat (language): 增加 NodeJS
1 parent 4fcc0f9 commit ea1af29

File tree

6 files changed

+86
-3
lines changed

6 files changed

+86
-3
lines changed

public/icons/nodejs.svg

Lines changed: 26 additions & 0 deletions
Loading

src-tauri/src/plugins/manager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use super::{LanguagePlugin, PluginConfig, python2::Python2Plugin, python3::Python3Plugin};
1+
use super::{
2+
LanguagePlugin, PluginConfig, nodejs::NodeJSPlugin, python2::Python2Plugin,
3+
python3::Python3Plugin,
4+
};
25
use std::collections::HashMap;
36

47
pub struct PluginManager {
@@ -11,6 +14,7 @@ impl PluginManager {
1114

1215
plugins.insert("python2".to_string(), Box::new(Python2Plugin));
1316
plugins.insert("python3".to_string(), Box::new(Python3Plugin));
17+
plugins.insert("nodejs".to_string(), Box::new(NodeJSPlugin));
1418

1519
Self { plugins }
1620
}

src-tauri/src/plugins/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ pub trait LanguagePlugin: Send + Sync {
315315

316316
// 重新导出子模块
317317
pub mod manager;
318+
pub mod nodejs;
318319
pub mod python2;
319320
pub mod python3;
321+
320322
pub use manager::PluginManager;

src-tauri/src/plugins/nodejs.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use super::{LanguagePlugin, PluginConfig};
2+
3+
pub struct NodeJSPlugin;
4+
5+
impl LanguagePlugin for NodeJSPlugin {
6+
fn get_order(&self) -> i32 {
7+
3
8+
}
9+
10+
fn get_language_name(&self) -> &'static str {
11+
"NodeJS"
12+
}
13+
14+
fn get_language_key(&self) -> &'static str {
15+
"nodejs"
16+
}
17+
18+
fn get_file_extension(&self) -> String {
19+
self.get_config()
20+
.map(|config| config.extension.clone())
21+
.unwrap_or_else(|| "js".to_string())
22+
}
23+
24+
fn get_version_args(&self) -> Vec<&'static str> {
25+
vec!["--version"]
26+
}
27+
28+
fn get_path_command(&self) -> String {
29+
"console.log(process.execPath)".to_string()
30+
}
31+
32+
fn get_default_config(&self) -> PluginConfig {
33+
PluginConfig {
34+
enabled: true,
35+
language: String::from("nodejs"),
36+
before_compile: None,
37+
extension: String::from("js"),
38+
execute_home: None,
39+
run_command: Option::from(String::from("node $filename")),
40+
after_compile: None,
41+
template: None,
42+
timeout: Some(30),
43+
}
44+
}
45+
46+
fn get_default_command(&self) -> String {
47+
self.get_config()
48+
.and_then(|config| config.run_command)
49+
.unwrap_or_else(|| "node".to_string())
50+
}
51+
}

src/components/Settings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<Modal v-model:show="isVisible" title="设置" size="4xl" :close-on-backdrop="false" :close-on-esc="false" @close="closeSettings">
2+
<Modal v-model:show="isVisible" title="设置" size="4xl" :content-class="['min-h-[60vh]']" :close-on-backdrop="false" :close-on-esc="false" @close="closeSettings">
33
<Tabs v-model="activeTab"
44
type="card"
55
size="md"

src/components/setting/Language.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{ `语言 [ ${ tab.label } ] 配置` }}
88
</h3>
99

10-
<Tabs v-model="activeTab" type="card" size="md" :tabs="tabsData">
10+
<Tabs v-model="activeTab" type="card" size="md" :tabs="tabsData" :nav-class="['w-full', 'justify-center']">
1111
<template #general>
1212
<div class="space-y-4">
1313
<div>

0 commit comments

Comments
 (0)