如何使用grunt-svninfo配置多个svninfo对象?

时间:2013-12-18 11:53:16

标签: gruntjs

我需要有两个不同svn存储库的svninfo对象。应用程序的svn信息应存储在对象svninfo_app中,elstr存储库(外部)的svn信息应存储在svninfo_elstr中:

  • 回购应用的信息 - > svninfo_app
  • repo elstr的信息 - > svninfo_elstr

我的Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    svninfo: {
      options: {
        output: 'svninfo_app',
        cwd: '.'
      },
      elstr: {
        options: {
          output: 'svninfo_elstr',
          cwd: './public/jslib/elstr/2.0.dev'
        }
      }
    },
    svn_export: {
      dev: {
        options: {
          repository: '<%= svninfo_elstr.url %>',
          output: 'deploy/'
        }
      }
    }
  });
  // https://npmjs.org/package/grunt-svninfo
  grunt.loadNpmTasks('grunt-svninfo');
  grunt.loadNpmTasks('grunt-svn-export');      
  // Default task.
  grunt.registerTask('default', ['svninfo','svn_export']);   
};

返回警告并中止:

Running "svninfo" task
SVN info fetched (rev: 4)

Running "svn_export:dev" (svn_export) task
Warning: An error occurred while processing a template (Cannot read property 'url' of undefined). Use --force to continue.

Aborted due to warnings.

对象svninfo_elstr未定义。为什么这个? 如何使用grunt-svninfo配置多个svninfo对象?

2 个答案:

答案 0 :(得分:1)

现在我找到了一个有效的解决方案。以下Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    svninfo: {
      options: {
        output: 'svninfo_app',
        cwd: '.',
        elstrCwd: './public/jslib/elstr/2.0.dev'
      }
    }
  });

  // https://npmjs.org/package/grunt-svninfo
  grunt.loadNpmTasks('grunt-svninfo');
  // Default task.
  grunt.registerTask('default', ['svninfo','svninfo:svninfo_elstr:elstrCwd']);
};

返回

Running "svninfo" task
SVN info fetched (rev: 5)

Running "svninfo:svninfo_elstr:elstrCwd" (svninfo) task
SVN info fetched (rev: 305)

Done, without errors.

必须注册两个任务:

  1. 'svninfo' - &gt;使用默认选项
  2. 将信息返回到对象svninfo_app
  3. 'svninfo:svninfo_elstr:elstrCwd' - &gt;使用选项elstrCwd
  4. 将信息返回到对象svninfo_elstr

答案 1 :(得分:0)

嗯,没有名为svninfo_elstr的属性,正如错误消息所示。您的Grunt配置没有任何svninfo_elstr属性。

  

如何使用grunt-svninfo配置多个svninfo对象?

使用您想要更详细的内容更新帖子可能会有所帮助吗?例如。没有<%= %>的东西会是什么样子?