Robert-W / grunt-ftp-push

Deploy files to an FTP server as part of your Grunt workflow.
MIT License
39 stars 14 forks source link

creating folders for nested files #17

Closed navFooh closed 9 years ago

navFooh commented 9 years ago

When you want to upload a file that's nested several folders deep, for example: 'scripts/vendor/requirejs/require.js', the containing folders are not created correctly.

In order to create the parent folders correctly, it seems you have to include:

src: [
    'scripts',
    'scripts/vendor',
    'scripts/vendor/requirejs',
    'scripts/vendor/requirejs/require.js'
]

Is this expected behavior or are there tricks to make this work correctly?

Cheers, Thijs

Robert-W commented 9 years ago

It should handle that automatically and you should not have to do anything special to make it work. Which version are you on? There was a bug in the older version which would cause that to error out and not upload but I believe it was resolved in recent builds. If your on the latest version (0.2.6 I believe) and this is still happening I will take a look.

navFooh commented 9 years ago

I'm on 0.2.6, but seem to have that problem. It works when the folders already exist on the server, but when I select a new folder as 'dest' and include:

src: [
    'scripts/vendor/requirejs/require.js'
]

I get: capture

If I use:

src: [
    'scripts',
    'scripts/vendor',
    'scripts/vendor/requirejs',
    'scripts/vendor/requirejs/require.js'
]

I get: capture2

Thanks for the quick response, would be great if you could have a look! Very nice and clean plugin otherwise.

Robert-W commented 9 years ago

Ok, Ill take a look and post here once I can find something.

Robert-W commented 9 years ago

Alright I think I have a fix for you, if your up for testing this patch out I will put the instructions below, if not, I plan on pushing to git later tonight and publishing to npm sometime tomorrow after some more testing so you can grab the latest from either once its pushed.

Here is the patch if your interested, in your node_modules directory, look for grunt-ftp-push/tasks/ftp_push.js around line 102 in the createDirectoriesForDestination function

replace the following:


fileObjects.forEach(function (fileItem) {
  if (fileItem.dest) {
    // Prepare the destination, then push into array for processing
    preparedDestination = destination + normalizeDir(fileItem.dest);
    destinations.push(preparedDestination);
  }
});

with this:


fileObjects.forEach(function (fileItem) {
      if (fileItem.dest) {
        // Prepare the destination, then push into array for processing
        preparedDestination = destination + normalizeDir(fileItem.dest);
        destinations.push(preparedDestination);
      } else {
        // Prepare the destination, then push into array for processing
        preparedDestination = destination + fileItem.path;
        destinations.push(preparedDestination);
      }
    });
navFooh commented 9 years ago

Hi Robert, just tested it and works perfectly now. Thanks!

Robert-W commented 9 years ago

Great thanks The patch is up now on npm.