tvooo / sublime-grunt

Moved to https://github.com/sptndc/sublime-grunt
296 stars 35 forks source link

Gruntfile not found issue #77

Closed derpoho closed 5 years ago

derpoho commented 10 years ago

Having an issue with your plugin. Grunt Execution via Terminal works as expected. But your plugin gives me this error. Can`t get around this, any suggestions?

Using Sublime Text 3 on a Mac.

untitled_ _wpmodules_io

syymza commented 10 years ago

I have a similar problem whenever the Gruntfile.js file is not in one of the root folders.

apertureless commented 10 years ago

Yep same here. It's super annoying :/

parachute-dev commented 10 years ago

same here - Gruntfile.js in a sub directory of the project - this error appears - if in root, it'll run fine.

svossen commented 10 years ago

My gruntfile is also located in a sub folder. I would love the see the possibility to use this plugin when the gruntfile is not located in the root folder.

Now I have to open a second Sublime window for my theme folder to make this plugin work. Another option is to add the theme folder the root folder project. This way the gruntfile can be found.

TheComputerDude commented 10 years ago

Having the same issue as well. Here is my file tree starting at the root folder in sublime: TheArtDepartment\wp-content\themes\twocgroovybaby

Update: I promoted twocgroovybaby as project folder and the issue was resolved. As svovven also said, it would be nice to have the plugin look in all sub folders.

ncoquelet commented 9 years ago

As @TheComputerDude, add the folder that contains gruntfile to the project with "Add Folder to Projet ..." resolve this problem. It works with a sub folder like an outside folder :)

ghost commented 9 years ago

I'm not sure I understand how this issue is resolved. Could I get some clarification on this matter?

ncoquelet commented 9 years ago

On the top menu, go to Project, then "Add folder to project ...", choose the folder that contains your gruntfile and that's it, grunt plugin now find your grunt config.

ghost commented 9 years ago

Thanks for the explanation!

aolin480 commented 9 years ago

So how can we specify the folder where the gruntfile.js is located. The author says you can specify it, but does anyone know what to put in the project settings? Let's say my folder in sublime is local.mydomain.com and under that I have the standard wp-admin, wp-content, wp-includes. In my project settings, this doesn't work.

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "C:\\www\\local.mydomain.com"
        }
    ],
    "settings":
    [
        {
            "gruntfile_paths":
            [
                "/wp-content/themes/MY_THEME"
            ]
        }
    ]
}
tvooo commented 9 years ago

Hi @aolin480, the path you entered starts with a slash "/", but in Unix terminology this means "root folder of the system". I don't know how Windows handles it (you are apparently on Windows), but I would suggest you try "wp-content\themes\MY_THEME". You can also try it with two backslashes each, as in the path above.

aolin480 commented 9 years ago

@tvooo thanks for the explanation. You are correct, on the path as well as the escaped backslashes. Thanks for the help!

martijnvreeken commented 9 years ago

@tvooo Thanks for writing the Sublime Grunt plugin! I have one issue though. (same as @aolin480 actually). My project file is: { "folders": [ { "path": "/var/www/[project]/html" } ], "settings": [ { "gruntfile_paths": [ "wp-content/themes/bridge-child" ] } ] } But this config does not find my Gruntfile.js (which is in the bridge-child theme folder, obviuously) I am on an Ubuntu machine. Thanks in advance for your help.

tvooo commented 9 years ago

Have you tried to use the full path?

"settings": [ { "gruntfile_paths": [ "/var/www/[project]/html/wp-content/themes/bridge-child" ] } ]

Not smooth, but might work.

martijnvreeken commented 9 years ago

Hi Tim,

Tried it. Tried everything :-) But no, didn't work. It's a weird issue.

Regards, Martijn

On Feb 25, 2015 5:09 PM, Tim von Oldenburg notifications@github.com wrote:

Have you tried to use the full path?

"settings": [ { "gruntfile_paths": [ "/var/www/[project]/html/wp-content/themes/bridge-child" ] } ]

Not smooth, but might work.

Reply to this email directly or view it on GitHubhttps://github.com/tvooo/sublime-grunt/issues/77#issuecomment-75988528.

rtpHarry commented 9 years ago

@aolin480 can you give any further advice as to how you solved this issue?

I'm on Windows in Sublime 2.

I have tried a million different ways to solve this issue including:

  1. no slash as the start
  2. no slash at the end
  3. partial paths
  4. the full path with the folder
  5. all of the above combinations with forward slashes and double escaped backward slashes
  6. restarting sublime in between goes

Alternatively can anyone suggest how to augment this plugin with some kind of logging so we can see what folders / combinations it's actually trying.

It feels like the folder search isn't recursive as the only way I have managed to get this working is to drag a second folder into the root of the project which contains the gruntfile. At that point it starts working straight away.

rtpHarry commented 9 years ago

I did some further research into this, turns out using print() will dump stuff to the Sublime Console (View -> Show Console).

I added this line into the list_gruntfiles method in main.py:

def list_gruntfiles(self):
    self.grunt_files = []
    self.folders = []
    print(self.window.folders()); 

My added line is the last one in the snippet. It output this (slightly neutered to remove project info):

[u'E:\\example\\WordPress\\themes\\www\\example\\htdocs', u'E:\\example\\WordPress\\themes\\www\\example\\htdocs\\wp-content\\themes\\example']

Which are just two top level folders in the project currently. This means that it definitely isn't recursively searching your project folders, at least not in Sublime 2 on Windows 8.1.

rtpHarry commented 9 years ago

Ok I'm pretty pleased with myself as I've never written a line of Python before but I think I've fixed this bug :)

I'll post a pull request for it to get reviewed but the new code looks like this:

def list_gruntfiles(self):
    self.grunt_files = []
    self.folders = []        
    for f in self.window.folders():
        self.folders.append(f)
        for root, dirnames, filenames in os.walk(f):
            for gruntfilename in ['Gruntfile.js', 'Gruntfile.coffee']:
                for filename in fnmatch.filter(filenames, gruntfilename):
                    self.grunt_files.append(os.path.join(root, filename))
    if len(self.grunt_files) > 0:
        if len(self.grunt_files) == 1:
            self.choose_file(0)
        else:
            self.window.show_quick_panel(self.grunt_files, self.choose_file)
    else:
        sublime.error_message("Gruntfile.js or Gruntfile.coffee not found!")

And it's working great for me now!

rtpHarry commented 9 years ago

Final note: I created the pull request on the master branch. The code was slightly different to the copy I got when I used Sublime Package Control to import this package several hours ago.

I've already spent several hours being distracted by this so I'm not investigating any further but if you're trying to fix this yourself then please double check and don't just blindly copy paste whole blocks of code in.

The pull request is here https://github.com/tvooo/sublime-grunt/pull/94

tvooo commented 9 years ago

Hi @rtpHarry, thanks for all your work. We decided not to make the folder search recursive, because many users are working with npm, and the node_modules folder would contain a shitload of Gruntfiles they'd not be interested in using with the plugin. So that's why we opted for the config file option instead. However, it's a shame it's not working for you, and really weird.

I will investigate why the code of your Package Control sublime-grunt installation differs from the one in master. Maybe I need to create a new tag.

rtpHarry commented 9 years ago

@tvooo yes when I did get it working there were a lot of other gruntfiles but mine was at the top so I ignored the rest :)

personally if you are going to go down the configurable items I would make a filter to exclude the package folders and a configuration item to reallow them if required. Its your project though and I appreciate you want to make your own decisions with your project. This is just feedback.

My reason for this is that as developer that works on a lot of projects I want the path of least resistance. I want it to just work for 90% of the scenarios. I can't set something in the global settings as there is no placeholder I can inject into the path to account for the fact the theme name changes between projects. This means I have to go in and manually add the setting each new project. The configuration required is not discoverable without searching it out. It also seems that a different path is needed depending on the developers platform.

With regards to the code differences between the package and the repo, this is what I did to install it:

  1. Installed package control using the steps here: https://packagecontrol.io/installation#st2
  2. Installed your package by searching for Grunt within Sublime Package Control

Hope you manage to pinpoint where the issue is arising with that one.

rtpHarry commented 9 years ago

I was thinking about this issue and another way to solve it.

What if your initial gruntfile search works as it currently does, shallow, but there is an extra option added to the bottom of the menu "Search all folders" which does a recursive search. If you select one out of the "search all folders" menu then it automatically adds that path to the configuration and includes it in the next search.

It solves a couple of the problems: the main grunt command isn't littered with all the node packages, you can discover the others without having to read the docs and add paths, you don't have to worry about encoding the path correctly on windows.

An issue that it still doesn't solve would be that the paths are still platform specific so putting any of them in project settings files could cause problems with other members of the team.

mihirgokani007 commented 9 years ago

I was finding the same issue in Sublime 3. My project setup is as follows:

I tried adding "settings" with all combinations as also tried by others, including what is specified in documentation:

{
    "folders": [
        {"path": "root\\src"}
    ],
    "settings": {
        "gruntfile_paths": ["D:\\Work\\root"]
    }
}

But unfortunately, it didn't work for me either. So I looked into the code and found this line:

return sublime.active_window().active_view().settings().get('SublimeGrunt', {}).get('gruntfile_paths', global_settings.get('gruntfile_paths', []))

Apparently, there's one more nested property SublimeGrunt that we need to include in the settings. So I tried the following:

{
    "folders": [
        {"path": "root\\src"}
    ],
    "settings": {
        "SublimeGrunt": {
            "gruntfile_paths": ["D:\\Work\\root"]
        }
    }
}

And viola! That worked! HTH others finding the same issue, until it gets fixed or gets added to the documentation :)

@tvooo I haven't tried on SL2 but it seems that @rtpHarry is finding this on SL2 too. So this might be just a missing doc, if not a bug. Can we get this added to the docs as a workaround?

tvooo commented 5 years ago

Repository was moved to https://github.com/sptndc/sublime-grunt Please re-file any issues that still exist.