Merge branch 'master' into templates

This commit is contained in:
Demonthos authored and GitHub committed 2022-10-02 07:12:14 -05:00
commit 46d46b139a
11 files changed
+47 -40

No files matched your search

+5 -2
View File
@@ -12,12 +12,15 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
include: include:
- target: x86_64-pc-windows-gnu - target: x86_64-unknown-linux-gnu
archive: zip archive: tar.gz tar.xz
- target: x86_64-unknown-linux-musl - target: x86_64-unknown-linux-musl
archive: tar.gz tar.xz archive: tar.gz tar.xz
- target: x86_64-apple-darwin - target: x86_64-apple-darwin
archive: tar.gz tar.xz
- target: x86_64-pc-windows-gnu
archive: zip archive: zip
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
- name: Compile and release - name: Compile and release
+3 -2
View File
@@ -2,9 +2,10 @@ name: github pages
on: on:
push: push:
paths:
- docs/**
branches: branches:
- main - main
pull_request:
jobs: jobs:
deploy: deploy:
@@ -30,4 +31,4 @@ jobs:
target-folder: docs/nightly/cli target-folder: docs/nightly/cli
repository-name: dioxuslabs/docsite repository-name: dioxuslabs/docsite
clean: false clean: false
token: ${{ secrets.DEPLOY_KEY }} # let's pretend I don't need it for now token: ${{ secrets.DEPLOY_KEY }} # let's pretend I don't need it for now
+1 -1
View File
@@ -40,7 +40,7 @@ impl Build {
crate::builder::build_desktop(&crate_config, false)?; crate::builder::build_desktop(&crate_config, false)?;
} }
_ => { _ => {
return custom_error!("Unsoppurt platform target."); return custom_error!("Unsupported platform target.");
} }
} }
+1 -2
View File
@@ -16,8 +16,7 @@ impl Clean {
.output()?; .output()?;
if !output.status.success() { if !output.status.success() {
log::error!("Cargo clean failed."); return custom_error!("Cargo clean failed.");
return Ok(());
} }
let out_dir = crate_config let out_dir = crate_config
+1 -2
View File
@@ -17,8 +17,7 @@ pub struct Create {
impl Create { impl Create {
pub fn create(self) -> Result<()> { pub fn create(self) -> Result<()> {
if Self::name_vaild_check(self.name.clone()) { if Self::name_vaild_check(self.name.clone()) {
log::error!("❗Unsupported project name."); return custom_error!("❗Unsupported project name.");
return Ok(());
} }
let project_path = PathBuf::from(&self.name); let project_path = PathBuf::from(&self.name);
+1 -1
View File
@@ -22,7 +22,7 @@ use std::{
fs::{remove_dir_all, File}, fs::{remove_dir_all, File},
io::{Read, Write}, io::{Read, Write},
path::PathBuf, path::PathBuf,
process::{exit, Command, Stdio}, process::{Command, Stdio},
}; };
/// Build, bundle, & ship your Dioxus app. /// Build, bundle, & ship your Dioxus app.
+5 -8
View File
@@ -30,15 +30,14 @@ impl Tool {
if let Some(v) = tools::tools_path().to_str() { if let Some(v) = tools::tools_path().to_str() {
println!("{}", v); println!("{}", v);
} else { } else {
log::error!("Tools path get failed."); return custom_error!("Tools path get failed.");
} }
} }
Tool::Add { name } => { Tool::Add { name } => {
let tool_list = tools::tool_list(); let tool_list = tools::tool_list();
if !tool_list.contains(&name.as_str()) { if !tool_list.contains(&name.as_str()) {
log::error!("Tool {name} not found."); return custom_error!("Tool {name} not found.");
return Ok(());
} }
let target_tool = tools::Tool::from_str(&name).unwrap(); let target_tool = tools::Tool::from_str(&name).unwrap();
@@ -49,17 +48,15 @@ impl Tool {
log::info!("Start to download tool package..."); log::info!("Start to download tool package...");
if let Err(e) = target_tool.download_package().await { if let Err(e) = target_tool.download_package().await {
log::error!("Tool download failed: {e}"); return custom_error!("Tool download failed: {e}");
return Ok(());
} }
log::info!("Start to install tool package..."); log::info!("Start to install tool package...");
if let Err(e) = target_tool.install_package().await { if let Err(e) = target_tool.install_package().await {
log::error!("Tool install failed: {e}"); return custom_error!("Tool install failed: {e}");
return Ok(());
} }
log::info!("Tool {name} install successfully!"); log::info!("Tool {name} installed successfully!");
} }
} }
Ok(()) Ok(())
+3 -6
View File
@@ -27,14 +27,11 @@ impl Translate {
} = self; } = self;
let contents = match file { let contents = match file {
Some(input) => std::fs::read_to_string(&input).unwrap_or_else(|e| { Some(input) => std::fs::read_to_string(&input)
log::error!("Cloud not read input file: {}.", e); .map_err(|e| Error::CustomError(format!("Could not read input file: {e}.")))?,
exit(0);
}),
None => { None => {
if atty::is(atty::Stream::Stdin) { if atty::is(atty::Stream::Stdin) {
log::error!("No input file, source, or stdin to translate from."); return custom_error!("No input file, source, or stdin to translate from.");
exit(0);
} }
let mut buffer = String::new(); let mut buffer = String::new();
+1 -1
View File
@@ -63,7 +63,7 @@ impl From<hyper::Error> for Error {
#[macro_export] #[macro_export]
macro_rules! custom_error { macro_rules! custom_error {
($msg:literal $(,)?) => { ($msg:literal $(,)?) => {
Err(Error::CustomError($msg.to_string())) Err(Error::CustomError(format!($msg)))
}; };
($err:expr $(,)?) => { ($err:expr $(,)?) => {
Err(Error::from($err)) Err(Error::from($err))
+8
View File
@@ -1,5 +1,6 @@
use clap::Parser; use clap::Parser;
use dioxus_cli::*; use dioxus_cli::*;
use std::process::exit;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@@ -10,42 +11,49 @@ async fn main() -> Result<()> {
Commands::Translate(opts) => { Commands::Translate(opts) => {
if let Err(e) = opts.translate() { if let Err(e) = opts.translate() {
log::error!("🚫 Translate failed: {}", e); log::error!("🚫 Translate failed: {}", e);
exit(1);
} }
} }
Commands::Build(opts) => { Commands::Build(opts) => {
if let Err(e) = opts.build() { if let Err(e) = opts.build() {
log::error!("🚫 Build project failed: {}", e); log::error!("🚫 Build project failed: {}", e);
exit(1);
} }
} }
Commands::Clean(opts) => { Commands::Clean(opts) => {
if let Err(e) = opts.clean() { if let Err(e) = opts.clean() {
log::error!("🚫 Clean project failed: {}", e); log::error!("🚫 Clean project failed: {}", e);
exit(1);
} }
} }
Commands::Serve(opts) => { Commands::Serve(opts) => {
if let Err(e) = opts.serve().await { if let Err(e) = opts.serve().await {
log::error!("🚫 Serve startup failed: {}", e); log::error!("🚫 Serve startup failed: {}", e);
exit(1);
} }
} }
Commands::Create(opts) => { Commands::Create(opts) => {
if let Err(e) = opts.create() { if let Err(e) = opts.create() {
log::error!("🚫 Create project failed: {}", e); log::error!("🚫 Create project failed: {}", e);
exit(1);
} }
} }
Commands::Config(opts) => { Commands::Config(opts) => {
if let Err(e) = opts.config() { if let Err(e) = opts.config() {
log::error!("config error: {}", e); log::error!("config error: {}", e);
exit(1);
} }
} }
Commands::Tool(opts) => { Commands::Tool(opts) => {
if let Err(e) = opts.tool().await { if let Err(e) = opts.tool().await {
log::error!("tool error: {}", e); log::error!("tool error: {}", e);
exit(1);
} }
} }
} }
+18 -15
View File
@@ -105,14 +105,15 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
if chrono::Local::now().timestamp() > last_update_time { if chrono::Local::now().timestamp() > last_update_time {
// Give time for the change to take effect before reading the file // Give time for the change to take effect before reading the file
std::thread::sleep(std::time::Duration::from_millis(100)); std::thread::sleep(std::time::Duration::from_millis(100));
let mut updated = false;
if let Ok(evt) = evt { if let Ok(evt) = evt {
let mut messages = Vec::new(); let mut messages = Vec::new();
let mut needs_rebuild = false; let mut needs_rebuild = false;
for path in evt.paths.clone() { for path in evt.paths.clone() {
let mut file = File::open(path.clone()).unwrap();
if path.extension().map(|p| p.to_str()).flatten() != Some("rs") { if path.extension().map(|p| p.to_str()).flatten() != Some("rs") {
continue; continue;
} }
let mut file = File::open(path.clone()).unwrap();
let mut src = String::new(); let mut src = String::new();
file.read_to_string(&mut src).expect("Unable to read file"); file.read_to_string(&mut src).expect("Unable to read file");
// find changes to the rsx in the file // find changes to the rsx in the file
@@ -120,6 +121,7 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
let mut last_file_rebuild = last_file_rebuild.lock().unwrap(); let mut last_file_rebuild = last_file_rebuild.lock().unwrap();
if let Some(old_str) = last_file_rebuild.map.get(&path) { if let Some(old_str) = last_file_rebuild.map.get(&path) {
if let Ok(old) = syn::parse_file(&old_str) { if let Ok(old) = syn::parse_file(&old_str) {
updated = true;
match find_rsx(&syntax, &old) { match find_rsx(&syntax, &old) {
DiffResult::CodeChanged => { DiffResult::CodeChanged => {
needs_rebuild = true; needs_rebuild = true;
@@ -207,7 +209,9 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
let _ = hot_reload_tx.send(msg); let _ = hot_reload_tx.send(msg);
} }
} }
last_update_time = chrono::Local::now().timestamp(); if updated {
last_update_time = chrono::Local::now().timestamp();
}
} }
}, },
notify::Config::default(), notify::Config::default(),
@@ -435,19 +439,18 @@ pub struct PrettierOptions {
} }
fn print_console_info(port: u16, config: &CrateConfig, options: PrettierOptions) { fn print_console_info(port: u16, config: &CrateConfig, options: PrettierOptions) {
print!(
"{}", if let Ok(native_clearseq) = Command::new(if cfg!(target_os = "windows") {
String::from_utf8_lossy( "cls"
&Command::new(if cfg!(target_os = "windows") { } else {
"cls" "clear"
} else { })
"clear" .output() {
}) print!("{}", String::from_utf8_lossy(&native_clearseq.stdout));
.output() } else {
.map(|output| output.stdout) // Try ANSI-Escape characters
.unwrap_or_default() print!("\x1b[2J\x1b[H");
) }
);
// for path in &changed { // for path in &changed {
// let path = path // let path = path