Skip to content

Commit

Permalink
fix(cli): allow lagon dev without arguments (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz authored Feb 22, 2023
1 parent 066c24e commit 8e70413
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-mugs-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/cli': patch
---

`lagon dev --env PATH` is relative to the root
5 changes: 5 additions & 0 deletions .changeset/ten-wolves-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/cli': patch
---

Allow using `lagon dev` without any argument to use the current directory configuration
15 changes: 10 additions & 5 deletions crates/cli/src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use notify::{Config, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
use pathdiff::diff_paths;
use std::collections::HashMap;
use std::convert::Infallible;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Mutex;
Expand Down Expand Up @@ -53,11 +53,14 @@ fn init_logger() -> Result<(), SetLoggerError> {
Ok(())
}

fn parse_environment_variables(env: Option<PathBuf>) -> Result<HashMap<String, String>> {
fn parse_environment_variables(
root: &Path,
env: Option<PathBuf>,
) -> Result<HashMap<String, String>> {
let mut environment_variables = HashMap::new();

if let Some(path) = env {
let envfile = EnvFile::new(path)?;
let envfile = EnvFile::new(root.join(path))?;

for (key, value) in envfile.store {
environment_variables.insert(key, value);
Expand Down Expand Up @@ -181,14 +184,16 @@ async fn handle_request(
}

pub async fn dev(
path: PathBuf,
path: Option<PathBuf>,
client: Option<PathBuf>,
public_dir: Option<PathBuf>,
port: Option<u16>,
hostname: Option<String>,
env: Option<PathBuf>,
allow_code_generation: bool,
) -> Result<()> {
let path = path.unwrap_or_else(|| PathBuf::from("."));

if !path.exists() {
return Err(anyhow!("File or directory not found"));
}
Expand Down Expand Up @@ -236,7 +241,7 @@ pub async fn dev(
.as_ref()
.map(|assets| root.join(assets));
let server_content = Arc::clone(&content);
let environment_variables = parse_environment_variables(env)?;
let environment_variables = parse_environment_variables(&root, env)?;
let isolate_lock = Arc::new(Mutex::new(None));
let server_isolate_lock = Arc::clone(&isolate_lock);
let pool = LocalPoolHandle::new(1);
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum Commands {
Dev {
/// Path to a file or a directory containing a Function
#[clap(value_parser)]
path: PathBuf,
path: Option<PathBuf>,
/// Path to a client-side script
#[clap(short, long, value_parser)]
client: Option<PathBuf>,
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/pages/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ This command accepts the following arguments and options:
Examples:

```bash
# Run a local dev server on the current directory
# Run a local dev server in the current directory
lagon dev
# Run a local dev server with a file entrypoint and some assets
lagon dev ./server.tsx --public ./assets
# Run a local dev server inside the my-project directory using a custom port
lagon dev ./my-project --port 56565
# Run a local dev server with a client file and some assets
lagon dev ./server.tsx --client App.tsx --public ./assets
```

### `lagon build`
Expand Down

1 comment on commit 8e70413

@vercel
Copy link

@vercel vercel bot commented on 8e70413 Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./packages/docs

lagon-docs.vercel.app
docs-git-main-lagon.vercel.app
docs.lagon.app
docs-lagon.vercel.app

Please sign in to comment.