jakejs / jake

JavaScript build tool, similar to Make or Rake. Built to work with Node.js.
http://jakejs.com
Apache License 2.0
1.97k stars 190 forks source link

jake.orignal_dir #300

Closed navneetgarg123 closed 7 years ago

navneetgarg123 commented 9 years ago

is there an equivalent to rake's Rake.original_dir?

i.e. is there a way to know the calling directory of the jake invocation?

welearnednothing commented 8 years ago

There's no equivalent to Rake.original_dir in the Jake API, however Node itself can provide that info. There are a few options, each with different caveats, but they should cover all needs:

  1. __dirname: Returns the path to the Jakefile that is currently executing. This means if the file is in another directory (using the -f flag or it's in jakelib, for instance), that directory will be returned - not the directory jake was called from.
  2. process.cwd(): Returns the path that Jake was executed from. However, if the --directory flag was used, that directory will be returned. Sometimes desirable, sometimes not.
  3. process.env['PWD']: This will return the directory Jake was actually called from, even if the --directory flag was used or the file resides in another directory.

Given that these cover all use cases and are idiomatic Node, I'd lean towards not expanding the Jake API to include that info and encourage people use the underlying Node APIs.

navneetgarg123 commented 8 years ago

A very well put together response. Thank you! I agree - no need to extend the API if it's part of core Node.