nicosantangelo / sublime-gulp

Run Gulp tasks and use snippets from Sublime Text
https://sublime-gulp.nicosantangelo.com/
MIT License
155 stars 18 forks source link

Support for gulpfile.js directory #34

Closed dkebler closed 9 years ago

dkebler commented 9 years ago

There is a (new?) way to organize tasks in separate file within a gulpfile.js directory as it is done here

https://github.com/greypants/gulp-starter/tree/2.0

Is sublime gulp going to support this? In which case it has to first look for index.js within gulpfile.js directory and then within the "tasks" subdirectory pointed to from index.js wherein is found individual and default task files?

nicosantangelo commented 9 years ago

I didn't know this was possible! I'll give it a try, listing the gulpfile.js dir and checking every file name it's definitely doable.

do you know if gulpfile.js/ is always on the root path?

dkebler commented 9 years ago

Here is an article with more details https://github.com/gulpjs/gulp/blob/master/docs/recipes/split-tasks-across-multiple-files.md

So one scenerio is you have a gulpfile.js in the root that points to a "tasks" directory, using the require-dir plugin. https://github.com/gulpjs/gulp/blob/master/docs/recipes/split-tasks-across-multiple-files.md

In the project I linked they do things slightly different. They use a gulpfile.js directory with index.js file in its root acting in the same capacity as gulpfile.js file in the project root. It works but I could not find any documentation at the gulpjs github or web. So I assume that in this secenerio the gulpfile.js directory MUST be in the root of the project just like the gulpfile.js file has been. Apparently gulp when it doesn't find a gulpfile.js in the root looks for a directory of the same and an index.js therein. (would appreciate if anyone finds documentation for this they post link here)

In either case you need to discover the tasks path by parsing the line

requireDir('./gulp-tasks');

then you could walk throught all the .js task files and collect the tasks for your plugin.

On Wed, Jul 8, 2015 at 6:19 AM, Nicolás Santángelo <notifications@github.com

wrote:

I didn't know this was possible! I'll give it a try, listing the gulpfile.js dir and checking every file name it's definitely doable.

do you know if gulpfile.js/ is always in the root path?

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-119575957 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

Got it! Thanks a lot for the info, I'll let you know how it goes

dkebler commented 9 years ago

Any progress toward this enhancement? Anything I might be able to do to help although I know node.js not python.

nicosantangelo commented 9 years ago

Yes!, but I had a tough time finding some free time this month and I'm currenty on vacation. I'll get to it (and all Version 5) as soon as I can; Sorry.

When I have a 'working' version it will be a huge help if you can test it :)

nicosantangelo commented 9 years ago

Hello again! Just a heads up, I have a working version for ST3 in OSX, I'm currently testing on Windows and ST2 so I can upload this by the end of the week. But, the only limitation is that for this to work your gulp CLI version should be 3.7.0 or higher.

I hope that's not a problem

dkebler commented 9 years ago

I am running latest gulp cli.

Do you have what you are working on in a branch in a github repo? If so I can test it on ST3 in linux for you.

BTW despite any documentation I could find it seems if node expects a particular file like gulpfile.js it is happy to accept a directory of the same name with an index.js file therein. This then is the convention just it is done with packages with node_modules.

So if there is not a gulpfile.js with a require-dir setting the a tasks directory then there must be a gulpfile.js directory with a index.js file therein which then would contain the require-dir module that sets the actual task directory. So those are the two cases you'd have to deal with it seems.

On Mon, Aug 10, 2015 at 8:00 PM, Nicolás Santángelo < notifications@github.com> wrote:

Hello again! Just a heads up, I have a working version for ST3 in OSX, I'm currently testing on Windows and ST2 so I can upload this by the end of the week. But, the only limitation is that for this to work your gulp CLI version should be 3.7.0 or higher.

I hope that's not a problem

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-129686941 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

Because I didn't want to deal with different cases I just use gulp --tasks-simple to list the tasks for me, so I just have to parse the result. The downside is that it won't work on gulp 3.6.0 (which is really old) and that it won't show the dependencies, but it has the huge advantage of not having issues with the project structure.

If you can test it, it's on this branch: version-5/gulpfile-dir-support. If you're using Package Control you'll have to clone the project manually.

Thanks a lot!

dkebler commented 9 years ago

I didn't know that gulp had such a cl switch, nice

I will try out the branch. Maybe later today.

FYI it took about 10 seconds first time to list my tasks so it's not particularly fast (maybe 10 secs) but it does list all my tasks. Seems fast on rerun so maybe results are put in a cache?

When (how often) do you intend to call/parse this? Every time the plugin runs a particular task might be problematic. So on install, when sublime opens a project/folder, maybe schedule every so often during idle? Then provide a command to run it manually?? It's not often that someone will add a new gulp task or remove an old one, only when like me currently, one is specifically working on their workflow gulp tasks which generally don't change from project to project once established.

On Tue, Aug 11, 2015 at 9:47 AM, Nicolás Santángelo < notifications@github.com> wrote:

Because I didn't want to deal with different cases I just use gulp --tasks-simple to list the tasks for me, so I just have to parse the result. The downside is that it won't work on gulp 3.6.0 (which is really old) and that it won't show the dependencies, but it has the huge advantage of not having issues with the project structure.

If you can test it, it's on this branch: version-5/gulpfile-dir-support https://github.com/NicoSantangelo/sublime-gulp/tree/version-5/gulpfile-dir-support. If you're using Package Control you'll have to clone the project manually.

Thanks a lot!

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-129964570 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

Wow 10 seconds is a lot :/ I'll check to see if where the bottleneck is, my local version takes around 5secs with https://github.com/greypants/gulp-starter/tree/2.0 . I'm afraid that If the problem is gulp --tasks-simple there's not much I can do.

When (how often) do you intend to call/parse this?

The old version does a SHA1 against the gulpfile.js itself to check the cache which works fine (if the file changes, the cache gets updated).

If the gulpfile is a dir, the idea is to create a SHA from every file (tasks and index). Right now I'm checking against a SHA1 of the directory using stat, so the cache will be regenerated only if the files on the root of the gulpfile.js dir change.

dkebler commented 9 years ago

in my workflow which I took from another starter repo the gulpfile.js directory has two subdirectories tasks and config. So in my case looking at the root of gulpfile.js directory would not trigger this unless the SHA1 includes subdirectory sizes.

Check out my repo to see the setup. https://github.com/dkebler/Hugo-Sass-Bower-Gulp-S3-Starter

On Tue, Aug 11, 2015 at 11:39 AM, Nicolás Santángelo < notifications@github.com> wrote:

Wow 10 seconds is a lot :/ I'll check to see if where the bottleneck is, my local version takes around 5secs with https://github.com/greypants/gulp-starter/tree/2.0 . I'm afraid that If the problem is gulp --tasks-simple there's not much I can do.

When (how often) do you intend to call/parse this?

The old version does a SHA1 against the gulpfile.js itself to check the cache.

If the gulpfile is a dir, the idea is to create a SHA from every file ( tasks and index). Right now I'm checking against a SHA1 of the directory using stat, so the cache will be regenerated only if the files on the root of the gulpfile.js dir change.

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-130008878 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

Hmm, makes sense. I'll add the check, update the branch and let you know!

dkebler commented 9 years ago

Yea it's running.

I cleared the cache a few times and it takes about 3 seconds each time to rebuild, so for some reason it's faster than when I did it from the command line.

So thanks for this enhancement!

In gratitude I'll put together a PR with with (context) menu additions for your commands to make it easier and more convenient to start the commands. I haven't looked but does your gulp command support a task argument so users could make a custom menu choice to run a specific task? I suppose one could just set up a cl call like any other program although that would lack the stdout in the console.

I'll even do a few additions to the read.me to make usage a bit clearer and include info on the new gulpfile directory support.

Want to do that to this branch or start another off the master?


(Just thinking now about another small enhancement related to having menu items. At the same time as building the task list to also generate the json for a corresponding set of menu items. Then users could right click go to gulp and then there would be submenu of all the tasks. This would also make it nice for them to move the menu item (in the json) to where ever they might want it. Shall I start a new issue for that?)

On Tue, Aug 11, 2015 at 12:46 PM, David Kebler d@kebler.net wrote:

in my workflow which I took from another starter repo the gulpfile.js directory has two subdirectories tasks and config. So in my case looking at the root of gulpfile.js directory would not trigger this unless the SHA1 includes subdirectory sizes.

Check out my repo to see the setup. https://github.com/dkebler/Hugo-Sass-Bower-Gulp-S3-Starter

On Tue, Aug 11, 2015 at 11:39 AM, Nicolás Santángelo < notifications@github.com> wrote:

Wow 10 seconds is a lot :/ I'll check to see if where the bottleneck is, my local version takes around 5secs with https://github.com/greypants/gulp-starter/tree/2.0 . I'm afraid that If the problem is gulp --tasks-simple there's not much I can do.

When (how often) do you intend to call/parse this?

The old version does a SHA1 against the gulpfile.js itself to check the cache.

If the gulpfile is a dir, the idea is to create a SHA from every file ( tasks and index). Right now I'm checking against a SHA1 of the directory using stat, so the cache will be regenerated only if the files on the root of the gulpfile.js dir change.

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-130008878 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

That would be awesome! (specially the README updates)

I think it would be best if you can do it out of that branch, version-5/gulpfile-dir-support, so I can merge it without worrying and then merge into master later. And you can run a specific task via keybinding ( https://github.com/NicoSantangelo/sublime-gulp#bind-specific-tasks ) but right now you have to specify the name when you write the keybinding. Running arbitrary tasks is on the roadmap :) ( https://github.com/NicoSantangelo/sublime-gulp/issues/39 ).

dkebler commented 9 years ago

might be several days before I have a PR but will do.

On Tue, Aug 11, 2015 at 8:40 PM, Nicolás Santángelo < notifications@github.com> wrote:

That would be awesome! (specially the README updates)

I think it would be best if you can do it out of that branch, version-5/gulpfile-dir-support, so I can merge it without worrying and then merge into master later. And you can run a specific task via keybinding ( https://github.com/NicoSantangelo/sublime-gulp#bind-specific-tasks ) but right now you have to specify the name when you write the keybinding. Running arbitrary tasks is on the roadmap :) ( #39 https://github.com/NicoSantangelo/sublime-gulp/issues/39 ).

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-130149724 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

No problem! If you have any issues with the context, the README update is really helpful. I think I'll have this particular feature by Friday but I don't have that much of a rush to ship it.

dkebler commented 9 years ago

Just letting you know I am getting closer to a PR. Working on the readme today. As you asked I'm doing it in that gulpfile-dir-support branch. Might have it later today or tomorrow.

On Wed, Aug 12, 2015 at 1:43 PM, Nicolás Santángelo < notifications@github.com> wrote:

No problem! If you have any issues with the context, the README update is really helpful. I think I'll have this particular feature by Friday but I don't have that much of a rush to ship it.

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-130442077 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

Awesome! I had to make some changes but the the branch now supports Windows and ST2 so after your PR we can make a release :)

dkebler commented 9 years ago

Are your last changes in that branch at github? If so I will sync your last changes with my repo before pushing it all to the PR.

On Tue, Aug 18, 2015 at 1:39 PM, Nicolás Santángelo < notifications@github.com> wrote:

Awesome! I had to make some changes but the the branch now supports Windows and ST2 so after your PR we can make a release :)

— Reply to this email directly or view it on GitHub https://github.com/NicoSantangelo/sublime-gulp/issues/34#issuecomment-132343832 .

Cheers, Cuidate, TTFN http://www.youtube.com/watch?v=5Gu50vq5ux4 David

nicosantangelo commented 9 years ago

Yup! it's all there

nicosantangelo commented 9 years ago

Version 5 is up! If you have any problems let me know ( @ mention me and I'll reopen this issue).

Thanks a lot for all the help.