deploy button
This commit is contained in:
Generated
+3
-2
@@ -1156,6 +1156,7 @@ dependencies = [
|
|||||||
"markdown",
|
"markdown",
|
||||||
"rfd",
|
"rfd",
|
||||||
"serde",
|
"serde",
|
||||||
|
"tempfile",
|
||||||
"thiserror 2.0.16",
|
"thiserror 2.0.16",
|
||||||
"tinyrand",
|
"tinyrand",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -3128,9 +3129,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.21.0"
|
version = "3.23.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "15b61f8f20e3a6f7e0649d825294eaf317edce30f82cf6026e7e4cb9222a7d1e"
|
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ axum = "0.8.4"
|
|||||||
tokio = { version = "1.47.1", features = ["full"] }
|
tokio = { version = "1.47.1", features = ["full"] }
|
||||||
tinyrand = "0.5.0"
|
tinyrand = "0.5.0"
|
||||||
clipboard-rs = "0.3.0"
|
clipboard-rs = "0.3.0"
|
||||||
|
tempfile = "3.23.0"
|
||||||
|
|
||||||
[package.metadata.bundle]
|
[package.metadata.bundle]
|
||||||
identifier = "org.geekfu.fleen"
|
identifier = "org.geekfu.fleen"
|
||||||
|
|||||||
+31
-1
@@ -32,7 +32,11 @@ pub enum FleenError {
|
|||||||
#[error("Target dir is invalid (can't contain the app dir or vice versa)")]
|
#[error("Target dir is invalid (can't contain the app dir or vice versa)")]
|
||||||
TargetDir,
|
TargetDir,
|
||||||
#[error("IO error: {0}")]
|
#[error("IO error: {0}")]
|
||||||
Io(#[from] io::Error)
|
Io(#[from] io::Error),
|
||||||
|
#[error("Deploy script missing! Create _scripts/deploy.sh")]
|
||||||
|
ScriptMissing,
|
||||||
|
#[error("Deploy script error:\n\n{0}")]
|
||||||
|
DeployError(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -279,6 +283,32 @@ impl FleenApp {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn build_and_deploy(&self) -> Result<String, FleenError> {
|
||||||
|
let output_dir = tempfile::tempdir().map_err(|_| TargetDir)?;
|
||||||
|
self.build_site(&output_dir.path())?; // Attempt to build the site somewhere
|
||||||
|
|
||||||
|
let deploy_script_path = self.root.join("_scripts/deploy.sh");
|
||||||
|
if !deploy_script_path.exists() {
|
||||||
|
Err(FleenError::ScriptMissing)
|
||||||
|
} else {
|
||||||
|
let mut command = Command::new(deploy_script_path);
|
||||||
|
command.current_dir(output_dir.path()); // don't consume dir!
|
||||||
|
match command.output() {
|
||||||
|
Ok(output) => {
|
||||||
|
let output = String::from_utf8(output.stdout).unwrap_or("Error reading deploy script output".to_string());
|
||||||
|
if command.status().unwrap().success() {
|
||||||
|
Ok(output)
|
||||||
|
} else {
|
||||||
|
Err(FleenError::DeployError(output))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
Err(FleenError::DeployError(e.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
+21
-3
@@ -39,6 +39,7 @@ struct TempMessage {
|
|||||||
struct FleenUi {
|
struct FleenUi {
|
||||||
app: Option<FleenApp>,
|
app: Option<FleenApp>,
|
||||||
error: Option<FleenError>,
|
error: Option<FleenError>,
|
||||||
|
message: Option<String>,
|
||||||
selected_file: Option<String>,
|
selected_file: Option<String>,
|
||||||
dialog_mode: Option<DialogMode>,
|
dialog_mode: Option<DialogMode>,
|
||||||
server_handle: Option<JoinHandle<()>>,
|
server_handle: Option<JoinHandle<()>>,
|
||||||
@@ -51,6 +52,7 @@ impl Default for FleenUi {
|
|||||||
Self {
|
Self {
|
||||||
app: None,
|
app: None,
|
||||||
error: None,
|
error: None,
|
||||||
|
message: None,
|
||||||
selected_file: None,
|
selected_file: None,
|
||||||
dialog_mode: None,
|
dialog_mode: None,
|
||||||
server_handle: None,
|
server_handle: None,
|
||||||
@@ -103,11 +105,17 @@ impl FleenUi {
|
|||||||
});
|
});
|
||||||
ui.column(width, |ui| self.server_controls(ui));
|
ui.column(width, |ui| self.server_controls(ui));
|
||||||
ui.column(width, |ui| {
|
ui.column(width, |ui| {
|
||||||
if ui.add_fill_width(Button::green("Build site...")).clicked() &&
|
if ui.add_fill_width(Button::green("Build and deploy")).clicked() {
|
||||||
|
match self.app.as_ref().unwrap().build_and_deploy() {
|
||||||
|
Ok(output) => { self.message = Some(format!("Site built and deployed:\n\n{}", output)) }
|
||||||
|
Err(err) => { self.error = Some(err) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.add_fill_width(Button::blue("Build site...")).clicked() &&
|
||||||
let Some(path) = rfd::FileDialog::new().pick_folder() {
|
let Some(path) = rfd::FileDialog::new().pick_folder() {
|
||||||
match self.app.as_ref().unwrap().build_site(&path) {
|
match self.app.as_ref().unwrap().build_site(&path) {
|
||||||
// TODO some kind of temporary notification thing
|
Ok(()) => { self.message = Some("Site built successfully".to_string()) }
|
||||||
Ok(()) => { println!("Yay!") }
|
|
||||||
Err(err) => { self.error = Some(err) }
|
Err(err) => { self.error = Some(err) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,6 +366,16 @@ impl eframe::App for FleenUi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(message) = &self.message {
|
||||||
|
let message = message.clone();
|
||||||
|
egui::Window::new("FYI").collapsible(false).resizable(false).show(ctx, |ui| {
|
||||||
|
ui.label(message);
|
||||||
|
if ui.button("Thanks!").clicked() {
|
||||||
|
self.message = None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(TempMessage { created, .. }) = &self.image_message
|
if let Some(TempMessage { created, .. }) = &self.image_message
|
||||||
&& *created < Instant::now() - Duration::from_secs(2) {
|
&& *created < Instant::now() - Duration::from_secs(2) {
|
||||||
self.image_message = None
|
self.image_message = None
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Make this be a script that will deploy your site. Assume it'll be run from the
|
||||||
|
# path of the built site, that the build succeeded, and that anything written to
|
||||||
|
# stdout will be displayed in a dialog.
|
||||||
|
|
||||||
|
# Example:
|
||||||
|
# rsync -r . root@example.com:/var/www/html 2>&1 && echo "Site deployed!"
|
||||||
|
|
||||||
|
echo "Edit _scripts/deploy.sh to set up deploy script"
|
||||||
Reference in New Issue
Block a user