it would be nice to enable a way to provide a custom gulpfile name/path, like:
gulp --gulpfile my/custom/file.js
affected code:
https://github.com/gulpjs/gulp/blob/master/bin/gulp.js#L117
grunt handles that nicely
thoughts?
:+1:
Why? What's the usecase?
application with two layers and two separate gulpfiles
shared main folder, split assets
currently working with grunt on such setup
separation is for readability and split of concerns
also, custom path might be needed - as it is in this case
/config
/layer1
/gulpfile.js
/layer2
/gulpfile.js
I'd also like to switch between multiple gulpfiles.
@stryju would you be able to send a PR regarding this?
well, if there are no other points against that - @sindresorhus ? - sure, i could take a look into that
sadly, won't be able to do this today and tomorrow (ork work) :worried:
@stryju it's not really priority -- nice to have
had a go, but before i do a PR i need to fix a few things that i'm stuck on...
https://github.com/stryju/gulp/commit/be504fe86fc311fda7e40bd580a7a2990cf31b26
--base change the CWD for the gulpfile itself? [1][1] currently, when executing with custom base, the path resolving didn't work as expected...
dir structure:
---
/config
/dirs.json
/test-gulp.js
/node_modules
package.json
// /config/test-gulp.js:
// ...
require('./config/dirs.js');
//...
when tried to execute gulp --gulpfile config/test-gulp.js and in the test-gulp.js i get an error.
while i expect the /config/dirs.json being loaded via test-gulp.js, it tries to resolve the path realtive to itself, so /config/config/dirs.json
any feedback would be really appreciated :)
/cc @Contra
@stryju IMO, if I was editing test-gulp.js, and have a line with require('./config/dirs.json');, I expect this to be relative to the cwd of the file I'm editing. So the correct way would be require('./dirs.json');.
@stryju gulp has nothing to do with paths in require - that's all node. the require path is always relative to the file requiring it
Grunt provides grunt.file.setBase(...), quoted below:
Change grunt's current working directory (CWD). By default, all file paths are relative to the Gruntfile. This works just like the --base command-line option.
Conforming with grunt would be a reasonable approach, especially for those switching to gulp from Grunt. On the other hand, I think if this feature comes to gulp, the behavior should be the opposite of what Grunt does. The current working directory should be set to where gulp is run from, rather than relative to where the gulpfile is located. I think this is more intuitive, in the sense that:
"I am running
gulp, using the configuration found in thisgulpfile, located at the specified directory."
In either case, there should be some corollary gulp.setBase(...).
@Polytonic The cwd is already the directory of the gulp file. A custom gulpfile is one thing but setBase? Why not just use process.chdir if you need to change the cwd? gulp is a tiny set of utilities to help facilitate builds + a small CLI for triggering tasks. I'm not interested in adding a bunch of complexity for edge cases
well, in that case, all we need is test coverage ;-)
gulpfile and base options seem to work just fine then
@Contra, that's fair. I wasn't sure what the cwd would be set to if a --gulpfile option was added, but as long as I can change the working directory so I don't have to set relative paths for all my globs, then I'm fine with however the option ends up being implemented.
@Polytonic one of the benefits of being a simple node lib is that you aren't locked into anything weird. process.chdir to your hearts content
Are you trying to look up folders or down folders for a gulpfile?
there's the --base option, but still, it is relative to gulpfile's location - that was the issue i was facing :)
@stryju There is no CLI option --base - there is only -v and --require <module name>
i added it along with the gulpfile option ;-)
did you check the previous comments and the source for PR? ;-) https://github.com/stryju/gulp/commit/be504fe86fc311fda7e40bd580a7a2990cf31b26
All of this seems outside of the scope of gulp. You can use gulp.env and some logic to do it yourself. Close?
@phated i don't think that specifying a different path to gulpfile itself is out of gulp's scope :)
Without implicitly changing the working directory, it doesn't make sense. If the flag is confined to executing in the same cwd as run from, then it could be within scope. People should be using process.chdir to change the working directory, as per my recipe PR. Most people expect --gulpfile to use the new directory as base, which is why I think it is the wrong solution. I added a recipe until/if it gets added.
your recipe doesn't provide a custom path for it - just nests the dependency... in the end, you still need a gulpfile.js file, which beats the purpose of this feature
It doesn't defeat the purpose because you can specify shared tasks in the
main file and pull in unique parts with the option. It leads to less code
duplication, which your solution doesn't.
On Jan 13, 2014 1:35 AM, "tomasz stryjewski" [email protected]
wrote:
your recipe doesn't provide a custom path for it - just nests the
dependency... in the end, you still need a gulpfile.js file, which beats
the purpose of this feature—
Reply to this email directly or view it on GitHubhttps://github.com/gulpjs/gulp/issues/122#issuecomment-32151888
.
main purpose of this feature was not to require the gulpfile.js filename...
@stryju can you tell us what you are trying to do and not what you want done so we can creatively solve the problem in a different way? Info about your project structure would be useful
ok, will try to put it as plain+simple as possible
i have a directory structure:
/root
/assets
/images
/scripts
/styles
/config
/custom-gulpfile.js
/other-gulpfile.js
/paths.json
/public
/images
/scripts
/styles
i want to be able to run gulp --gulpfile config/custom-gulpfile.js and gulpfile --gulpfile config/other-gulpfile.js from the /root folder, not the /root/config folder
current implementation requires gulpfile.js filename
@stryju okay so you want multiple gulpfiles in the same folder - i see now
doesn't have to be multiple gulpfiles - i just want the flexibility to define a custom path/name for gulpfile :)
like https://github.com/stryju/gulp/blob/be504fe86fc311fda7e40bd580a7a2990cf31b26/bin/gulp.js#L124
@phated make it so
so we ended up with
in order to use a custom gulpfile, you need to have a
gulpfile.jsin the "root" folder
while the purpose of this feature was to have an ability to specify a custom gulpfile filename...
:unamused:
No I still think it should be supported - @phated's recipe is useful for cases where you have a root dir that needs to reach down to subdirs but not for what you are doing
:+1:
@Polytonic one of the benefits of being a simple node lib is that you aren't locked into anything weird. process.chdir to your hearts content
@Contra: Yep, sorry. I wasn't clear. As long as I have some control over the cwd, e.g. process.chdir, then I'm happy. I just wasn't sure which cwd gulp was running under, per @stryju use-case comment, three days ago.
Are you trying to look up folders or down folders for a gulpfile?
Not quite sure what you mean by this, but my directory structure looks somewhat like the following:
/project
/app_a
/scripts
/gulpfile_a.js
/app_b
/styles
/gulpfile_b.js
/shared
/images
I'd like to run multiple gulpfiles located in different subdirectories, presumably also changing the cwd to the project root.
:clap: :)
Slick. That was fast.
--base should be --cwd instead, as per IRC discussion.
@phated send PR?
It appears that it was implemented on Jan 13th (https://github.com/gulpjs/gulp/commit/2db00754f4e5c7c36be7545209a480bc75594565), but then removed on Feb 4th (https://github.com/gulpjs/gulp/commit/761da2990427b5cbd7aaee26448cb61a2edc3db7)
Was it intentionally removed or just an oversight? Any plans on adding this back in?
Pretty sure this is taken care of by https://www.npmjs.org/package/liftoff
Ahh, so it was. My apologies for bringing up an old issue :)
I change my gulp file path from root to my public folder by using
gulp --gulpfile public/gulpfile.js
it works fine first time but when i run gulp again. it still not found the new path
Although current file work towards problem is solved. But I would recommend for a more organized code structure to be in the main directory.