cobalt-org / cobalt.rs

Static site generator written in Rust
cobalt-org.github.io/
Apache License 2.0
1.37k stars 104 forks source link

Watch command loops endlessly #170

Closed nokaa closed 6 years ago

nokaa commented 7 years ago

I ran cobalt watch on my project and then ran cd /my/project/dir in another terminal. Cobalt starts to endlessly rebuild the project.

Work around: add an ignore for your dest folder, like

ignore: ["build/*"]
staaas commented 7 years ago

@nokaa what version of cobalt are you using? a similar issue was fixed in 0.4

nokaa commented 7 years ago

I am using 0.4.0. I installed cobalt from crates.io a few days ago.

LucioFranco commented 7 years ago

@nokaa what is in your .cobalt.yml?

nokaa commented 7 years ago
rss: rss.xml
name: name
description: description
link: https://example.com

I'm pretty sure this was happening without a .cobalt.yml though.

LucioFranco commented 7 years ago

@nokaa So it might be picking up a change in the folder you are running it from. Maybe try and add an ignore to the config to ignore the files that are changing and causing it to rebuild. If that is not the case. What OS are you on?

nokaa commented 7 years ago

It looks as though this only happens if I have a .git folder. My shell displays the current status of a git repository; so my guess is that it causes some change in one of the .git files.

Adding ignore: [.git/] to my config doesn't seem to do anything.

LucioFranco commented 7 years ago

@nokaa try ignore: ".git/*"

nokaa commented 7 years ago

That didn't work. I can try building from source and debugging it in a couple days if you'd like.

nokaa commented 7 years ago

I happened to find out today that the correct ignore syntax would be ignore: [".git/*"], which solves this issue.

mrkgnao commented 7 years ago

I just created a Cobalt site locally and have the same problem without having changed anything in .cobalt.yml whenever I run cobalt watch from inside the Cobalt site directory.

Running it from a different location triggers a full rebuild (I understand incremental builds aren't there yet), but is there any way to get watch to work without cding out elsewhere (or writing a wrapper script, etc.)?

epage commented 7 years ago

Let me see if I understand.

When you run cobalt watch from inside the same directory as your .cobalt.yml, your project endlessly rebuilds?

And if your run cobalt watch -c <PATH.YML> from a different location, it doesn't endlessly loop but rebuilds when it is supposed to?

What version of cobalt? What does your .cobalt.yml look like?

mrkgnao commented 7 years ago

@epage sorry for the slow response. Yes, the behavior is exactly as you describe it. I think the ignore functionality isn't working properly.

I just tried this with a new Cobalt site, and it's the same behavior.

<*> cobalt init coblog
[warn]   No .cobalt.yml file found in current directory, using default config.
[info]   Created new project at coblog
<*> cd coblog
<*> tree
.
├── build
│   ├── index.html
│   └── posts
│       └── post-1.html
├── index.liquid
├── _layouts
│   ├── default.liquid
│   └── post.liquid
└── posts
    └── post-1.md

I compiled Cobalt from master last week:

<*> cobalt -V
Cobalt 0.7.2

I have the default .cobalt.yml:

<*> cat .cobalt.yml
name: cobalt blog
source: "."
dest: "build"
ignore:
  - .git/*
  - build/*

Here is what happens when I compile from within the site directory:

<*> cobalt watch -s . -d "build"
[info]   Using config file .cobalt.yml
[info]   Building from . into build
[info]   Created build/posts/post-1.html
[info]   Created build/index.html
[info]   Copying remaining assets
[info]   Build successful
[info]   Serving "build" through static file server
[info]   Watching "." for changes
[info]   Server Listening on 127.0.0.1:3000
[info]   Ctrl-c to stop the server

< here I edited posts/post-1.md >

[info]   Building from . into build
[info]   Created build/index.html
[info]   Copying remaining assets
[info]   Build successful
[info]   Building from . into build
[info]   Created build/posts/post-1.html
[info]   Created build/index.html
[info]   Copying remaining assets
[info]   Build successful
[info]   Building from . into build
[info]   Created build/posts/post-1.html
[info]   Created build/index.html
[info]   Copying remaining assets
[info]   Build successful
...
eliassotodo commented 7 years ago

I am having the same issue.

After installing cobalt 0.7.2 with cargo and running cobalt serve in the root directory of the project I get the same output as @mrkgnao. Mine .cobalt.yml is also the same as his...

epage commented 7 years ago

Yeah, I re-did how watch triggers rebuilds and forgot to protect against this case!

The fun of me testing things by having my destination outside of the project folder.

epage commented 7 years ago

@nokaa I edited your posting of the issue to include the workaround (ignore the build directory) though we should fix this in cobalt itself.

epage commented 7 years ago

@mrkgnao, you have an attempt at the work around, not sure why it isn't working.

ignore:
  - .git/*
  - build/*

I know I've had to play some with the ignore syntax (trying just build, build/*, build/**, etc). I really need to better understand gitignore and how to properly use burntsushi's Gitignore code to make sure the syntax is right. And then figure out how to communicate what to do clearly :)

mre commented 7 years ago

So here's a workaround that I use on macOS until the issue is resolved:

# Start server in background
cobalt serve &
# Watch for changes in the "blog" directory and trigger a build
fswatch -0 -d blog | xargs -0 -n1 sh -c 'cobalt build'

What's cool about it is, that you can combine that with a browser refresh after every change. I've created a script to refresh the current tab on Firefox from the commandline:

activate application "Firefox"
tell application "System Events" to keystroke "r" using command down

Then, I've created a Makefile with the following content:

dev:
    pkill cobalt
    cobalt serve &
    fswatch -0 -d blog | xargs -0 -n1 sh -c 'cobalt build && osascript refresh-firefox.scpt'
.PHONY: dev

I start it with make dev. This way, whenever I change a blog entry, it shows a fresh version in my browser. 😎