2014-04-15 114 views
2

當試圖將用戶私鑰傳遞給grunt-ssh時,我希望每個開發者都能夠在Gruntfile中加載的Gruntsetting.json中設置服務器密鑰,如下所示:將變量文件名傳遞給grunt.file.read

settings: grunt.file.readJSON('Gruntsettings.json'), 

    sshexec: { 
     test: { 
      command: 'uptime', 
      options: { 
       privateKey: grunt.file.read('<%- settings.keyPath %>'), 
       host: '<%= settings.host %>', 
       username: '<%= settings.username %>' 
      } 
     }, 
    } 

然而,當我在grunt.file.read語句中使用的keyPath設置我得到的錯誤:

Error: Unable to read "<%- settings.keyPath %>" file (Error code: ENOENT). 

是否有可能從讀JSON文件回到另一個讀取命令傳遞變量?

回答

3

展開privateKey模板中包含的文件讀取方法調用:

settings: grunt.file.readJSON('Gruntsettings.json'), 

sshexec: { 
    test: { 
     command: 'uptime', 
     options: { 
      privateKey: '<%= grunt.file.read(settings.keyPath) %>', 
      host: '<%= settings.host %>', 
      username: '<%= settings.username %>' 
     } 
    }, 
}