IndigoUnited / automaton

Task automation tool built in JavaScript
http://indigounited.com/automaton
MIT License
214 stars 10 forks source link

Working dir #53

Closed satazor closed 11 years ago

satazor commented 11 years ago

At the moment, all operations made within tasks are relative to where automaton runs. Deep tasks have to use __dirname to perform operations with files referenced relatively. While this is an issue, only task devs will have to worry about it. I think we shouldn't do any magic regarding this. Still project level autofiles, specially the ones located in tasks/ folder will suffer from this problem. If they try to specify files to cp, they will have to specify it relative to the project directory and not relative to the task itself.

Grunt makes the working directory relative to the gruntfile. I think that we should do the same, but we would have to do process.chdir. This is not actually good when automaton is being used programatically, unless we document it well or we spawn a fork to actually run automaton tasks.

marcooliveira commented 11 years ago

I think we should keep in mind that this is still nodejs, and users know that any operation is based on the cwd. If this is not the desired behaviour, users can use the filter to do whatever they need to the paths. I'm open to discussion, but I still haven't seen a strong reason why we should be making magic.

satazor commented 11 years ago

@marcooliveira The problem is that project level tasks usually use relative references. The process.cwd() is usually the project root directory but if one tries to do cd tasks && automaton some_task.js, then strange things might happen. Grunt makes the process.cwd() always the path of the gruntfile (think of it as our root autofile) which solves this issue.

marcooliveira commented 11 years ago

What if the user tries to run automaton mkdir test? What would make sense to you? In this case, the autofile is within automaton itself, and if we make the autofile location the working dir, then the user will have created a test folder inside automaton, instead on the actual current working dir. This is a bit confusing.

satazor commented 11 years ago

I see your point. What about making an attribute of the task itself, living next to name and description. Grunt actually makes this a config option, called base.

marcooliveira commented 11 years ago

Although that solves the issue, might lead to inconsistencies in task behaviour, since some developers might use __dirname, other process.cwd(). This issue is only real when a user does something, like you said, cd tasks && automaton some_task.js. cd is change dir, so the user is effectively changing the working dir. If he meant to run the task from the current dir, he should have done automaton tasks/some_task.js.

My opinion on this, is that this is nodejs, and people need to understand that they are running nodejs, not some magic code. If they need a stronger way to reference a file, without any annoyance of relative paths, they can always use absolute paths.

I'm still open to discuss this further, but haven't seen any strong reason why we should do something else.

satazor commented 11 years ago

This kind of issues will be mitigated with #30. We can reopen this if necessary later on. Right @marcooliveira ?

marcooliveira commented 11 years ago

Yep! Fine with me, don't see this as a real issue yet. Let's wait for some feedback from the community, and see if it applies. Closing for now.