Skip to content

Commit c4c7b5b

Browse files
✨ Support entry files in dev/ as well as src/.
1 parent ad94a2c commit c4c7b5b

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

src/lustre/dev.gleam

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,14 @@ directories are always watched and do not need to be specified here.
483483
proxy_to(flags) |> result.unwrap(""),
484484
))
485485

486-
let entry = case entries {
487-
[] -> project.name
488-
[entry, ..] -> entry
489-
}
486+
use entry <- result.try(case entries {
487+
[] -> Ok(project.name)
488+
[entry, ..] ->
489+
case project.exists(project, entry) {
490+
True -> Ok(entry)
491+
False -> Error(error.UnknownGleamModule(name: entry))
492+
}
493+
})
490494

491495
use tailwind_entry <- result.try(case tailwind.detect(project, entry) {
492496
Ok(tailwind.HasTailwindEntry) -> Ok(Some(entry))

src/lustre_dev_tools/dev/live_reload.gleam

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,18 @@ pub fn start(
8989
mist.continue(Nil)
9090
}
9191

92-
mist.Custom(watcher.BuildError(reason:)) -> {
93-
let message = ansi.strip(error.explain(reason))
94-
95-
let _ =
96-
json.object([
97-
#("type", json.string("error")),
98-
#("message", json.string(message)),
99-
])
100-
|> json.to_string
101-
|> mist.send_text_frame(connection, _)
92+
mist.Custom(watcher.BuildError) -> {
93+
let _ = case booklet.get(error) {
94+
Some(reason) ->
95+
json.object([
96+
#("type", json.string("error")),
97+
#("message", json.string(ansi.strip(error.explain(reason)))),
98+
])
99+
|> json.to_string
100+
|> mist.send_text_frame(connection, _)
101+
102+
None -> Ok(Nil)
103+
}
102104

103105
mist.continue(Nil)
104106
}

src/lustre_dev_tools/dev/watcher.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub type Watcher =
3535
pub type Event {
3636
Change(in: String, path: String)
3737
Styles
38-
BuildError(reason: Error)
38+
BuildError
3939
}
4040

4141
//
@@ -271,7 +271,7 @@ fn start_build_actor(
271271
)
272272

273273
group_registry.members(watcher, "watch")
274-
|> list.each(process.send(_, BuildError(reason:)))
274+
|> list.each(process.send(_, BuildError))
275275

276276
actor.continue(Waiting(self:))
277277
}

src/lustre_dev_tools/project.gleam

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ fn find_root(path: String) -> String {
123123
pub fn exists(project: Project, module: String) -> Bool {
124124
case simplifile.is_file(filepath.join(project.src, module <> ".gleam")) {
125125
Ok(True) -> True
126-
Ok(False) | Error(_) -> False
126+
Ok(False) | Error(_) ->
127+
simplifile.is_file(filepath.join(project.dev, module <> ".gleam"))
128+
|> result.unwrap(False)
127129
}
128130
}

0 commit comments

Comments
 (0)