【问题标题】:FTP using bash script with Grunt Task Manager使用带有 Grunt 任务管理器的 bash 脚本的 FTP
【发布时间】:2023-03-08 01:31:01
【问题描述】:

我正在尝试使用 Grunt 将文件从本地发行版构建到生产环境。我已经通过 bash 文件进行了测试,并且可以正常工作。我只是无法使用 grunt 运行它。

在我的 grunt 文件中:

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

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

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

我在命令行尝试grunt deploy,得到以下错误:

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

我在命令行尝试grunt exec,得到以下错误:

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.

ftp.sh 文件与Gruntfile.js 位于同一目录中。

如何配置它以便我可以运行 grunt deploy 并运行 bash 脚本?

【问题讨论】:

    标签: node.js bash ftp gruntjs grunt-exec


    【解决方案1】:

    这里有几个可供尝试的选项....

    选项 1

    假设 grunt-exec 允许运行 shell 脚本(...它不是我以前使用过的包!)重新配置 Gruntfile.js 如下:

    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']);
    };
    

    注意

    1. exec.ftpupload.command 的更改 - 现在包括 ./ 路径前缀,正如您提到的:

      ftp.sh 文件与 Gruntfile.js 位于同一目录中。

    2. 已注册的deploy 任务中的别名任务列表现在使用分号表示法,即exec:ftpupload

    选项 2

    如果选项 1 因任何原因失败,请使用 grunt-shell 而不是 grunt-exec

    1. 通过运行卸载 grunt-exec$ npm un -D grunt-exec

    2. 通过运行安装 grunt-shell$ npm i -D grunt-shell

    3. grunt-shell 使用了一个名为 load-grunt-tasks 的软件包,因此您也需要通过运行以下命令来安装它:$ npm i -D load-grunt-tasks

    4. 如下配置您的Gruntfile.js

    module.exports = function(grunt) {
    
        grunt.initConfig( {
    
            shell: {
                ftpupload: {
                    command: './ftp.sh'
                }
            }
        });
    
        require('load-grunt-tasks')(grunt);
    
        grunt.registerTask('deploy', ['shell:ftpupload']);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 2013-08-30
      • 1970-01-01
      相关资源
      最近更新 更多