0

I am trying to FTP files from local distribution build to production using Grunt. I have tested by bash file and it works. I just can't get it to run using grunt.

In my grunt file:

/*global module:false*/
module.exports = function(grunt) {

    grunt.initConfig( {
        ...
        exec: {
            ftpupload: {
                command: 'ftp.sh'
            }
        }
    } );

    grunt.loadNpmTasks('grunt-exec');
    grunt.registerTask('deploy', ['ftpupload']);
};

I try grunt deploy at the command line and get the following error:

Warning: Task "ftpupload" not found. Use --force to continue.

I try grunt exec at the command line and get the following error:

Running "exec:ftpupload" (exec) task
>> /bin/sh: ftp.sh: command not found
>> Exited with code: 127.
>> Error executing child process: Error: Process exited with code 127.
Warning: Task "exec:ftpupload" failed. Use --force to continue.

The ftp.sh file resides in the same directory as Gruntfile.js.

How can I configure it so that I can run grunt deploy and have the bash script run?

MoreScratch
  • 2,933
  • 6
  • 34
  • 65

1 Answers1

0

Here are a couple of options to try....

Option 1

Assuming that grunt-exec allows a shell script to be run (...it's not a package I've used before!) reconfigure the Gruntfile.js as follows:

module.exports = function(grunt) {

    grunt.initConfig( {

        exec: {
            ftpupload: {
                command: './ftp.sh' // 1. prefix the command with ./
            }
        }
    } );

    grunt.loadNpmTasks('grunt-exec');

    // 2. Note the use of the colon notation exec:ftpupload
    grunt.registerTask('deploy', ['exec:ftpupload']);
};

Note

  1. The change to the exec.ftpupload.command - it now includes a ./ path prefix, as you mention:

    ftp.sh file resides in the same directory as Gruntfile.js.

  2. The alias Task List in the registered deploy Task now utilizes the semicolon notation, i.e. exec:ftpupload

Option 2

If Option 1 fails for whatever reason use grunt-shell instead of grunt-exec.

  1. Uninstall grunt-exec by running: $ npm un -D grunt-exec

  2. Install grunt-shell by running: $ npm i -D grunt-shell

  3. grunt-shell utilizes a package named load-grunt-tasks, so you'll need to install that too by running: $ npm i -D load-grunt-tasks

  4. Configure your Gruntfile.js as follows:

module.exports = function(grunt) {

    grunt.initConfig( {

        shell: {
            ftpupload: {
                command: './ftp.sh'
            }
        }
    });

    require('load-grunt-tasks')(grunt);

    grunt.registerTask('deploy', ['shell:ftpupload']);
};
RobC
  • 22,977
  • 20
  • 73
  • 80