Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# changelog

## 0.7.1

* Watch gobblefile again when deleted (happens in editors which rename old files as backups)

## 0.7.0

* Switch to pathwatcher
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ messages = {
return 'gobblefile changed. restarting server';
},

GOBBLEFILE_DELETED: function () {
return 'gobblefile deleted or moved away. trying to read again';
},

MERGE_START: function ( x ) {
return chalk.bold( x.id ) + ' running...';
},
Expand Down
21 changes: 16 additions & 5 deletions lib/watchOrServe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ module.exports = function ( gobblefile, getTask ) {
resuming;

resume();
logger.info({message: 'gobblefile is ' + gobblefile});
function watch () {
pathwatcher.watch( gobblefile, type => {

pathwatcher.watch( gobblefile, type => {
if ( type === 'change' ) restart();
});
if ( type === 'change' ) {
logger.info({ code: 'GOBBLEFILE_CHANGED' });
return restart();
}

if ( type === 'delete' ) {
logger.info({ code: 'GOBBLEFILE_DELETED' });
return setTimeout( watch, 2000 );
Copy link
Contributor

Choose a reason for hiding this comment

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

what about a setInterval that gets cancelled once the file exists again? Or, equivalently...

function checkGobbleFileExists () {
  fs.exists( gobblefile, exists => exists ? restart() : setTimeout( checkGobbleFileExists, 100 ) );
}

// ...
if ( type === 'delete' ) {
  logger.info({ code: 'GOBBLEFILE_DELETED' });
  return setTimeout( checkGobbleFileExists, 100 );
}

That way you don't have to wait 2 seconds each time the editor saves. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a strong opinion about this particular bit. Waiting 2 seconds works reliably for my use case, but I can see the appeal of checking for the gobblefile in a loop.

}
});
}

watch();

function restart () {
if ( resuming ) return;

logger.info({ code: 'GOBBLEFILE_CHANGED' });

process.env.GOBBLE_RESET_UID = 'reset';

if ( task ) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gobble-cli",
"description": "Command line interface for gobble",
"version": "0.7.0",
"version": "0.7.1",
"author": "Rich Harris",
"license": "MIT",
"repository": "https://github.com/gobblejs/gobble-cli",
Expand Down