Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some extra context for transforms and support single file gobbling #29

Merged
merged 3 commits into from
Jan 6, 2015

Conversation

evs-chris
Copy link
Contributor

There are no tests (yet?) - RFC

This is a combo of #23 and #24.

#23 Single file

If the gobbled target is a single file, the Source creates a temporary directory and assigns it as the dir. A watch is placed on the dir as usual, but one is also set on the file. When the file changes, sander copies the new file into the temp dir, which triggers the watch on dir as usual.

I wasn't really sure where to put the temp dir, since there could be one of three different .gobble* directories in play during any given run. The session.config is not available at Source creation time, so I went with .gobble-tmp for now.

#24 Context

There are a couple of additions to the contexts for transforms:

  • It adds env to the context with which transforms are called.
  • It also adds a log function that triggers an info event to be emitted for the cli (or whatever, I suppose) to log. It has a plain text/format overload along with the straight pass-through object flavor. The text overload keeps the progress pills popping.
  • It adds sander to the context for transforms and to the main gobble export. Sander is so darned convenient for moving files about, which a lot of directory transforms and gobblefiles need to do. Exposing gobbles sander makes it that much more convenient.

There is a PR on gobble-cli to help with logging. gobblejs/gobble-cli#5

by creating a .gobble-tmp directory with a generated directory per file
then watching the given file and copying it to the generated directory when it changes
@Rich-Harris
Copy link
Contributor

Love all this. I'd assumed that individual file watching would require a new node type with a much of almost-duplicated code, but once again you came up with a smarter way.

The session.config is not available at Source creation time, so I went with .gobble-tmp for now.

Yeah, it's kind of awkward that it's not, though I don't immediately see a better way. Using GOBBLE_COMMAND provides a workaround, though it would mean that API (as opposed to CLI) users would be second class. Maybe the file watcher's dir shouldn't be resolved until the task has begun. Hmm.

Should probably have some tests - will try and add some tonight or tomorrow unless you beat me to it.

@evs-chris
Copy link
Contributor Author

I just pushed a commit that defers watcher dir creation to task start. I got a little tangled up around what start and ready do, but I think this is reasonably correct.

Also, a test :)

it( 'should gracefully handle source nodes that appear twice (#19)', function ( done ) {
var timesToRun = 100;

this.timeout( 10000 );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I bumped this because it completes in just over the default 2 second timeout most of the time on my machine.

@Rich-Harris
Copy link
Contributor

LGTM. Merging

Rich-Harris added a commit that referenced this pull request Jan 6, 2015
Add some extra context for transforms and support single file gobbling
@Rich-Harris Rich-Harris merged commit 743b2cf into gobblejs:master Jan 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants