2017-02-16 52 views
0

我現在有一個非常奇怪的問題。Grunt - 無法在PowerShell之後讀取Json文件ConvertTo-Json

我正在創建我的grunt-cache-breaker使用的文件列表。我生成使用此PowerShell腳本文件的列表:

$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path 

$file = @{} 

#GET HTML FILES 
$Dir = get-childitem $ScriptDir\Helix -recurse 
$file = $Dir | where {$_.extension -eq ".html" } | % {$_.FullName} 
#END 

$file | convertto-jSon | out-file $ScriptDir\htmlfiles.json 

這就產生了一個文件,包含像這樣

[ 
    "C:\\test\test1.html", 
    "C:\\test\test1.html", 
    "C:\\test\test1.html" 
] 

我緩存斷路器代碼:

module.exports = function(grunt) { 
grunt.initConfig({ 
    listOfHtmlPaths: grunt.file.readJSON('htmlfiles.json'), 
    cachebreaker: { 
     dev: { 
      options: { 
       match: ['.js', '.css', 'min.css'], 
       src: 
       { path: 'Helix/**/*' } 
      }, 
     files: 
      { src: ['<%= listOfHtmlPaths %>'], } 
     }, 
    }, 
}); 
grunt.loadNpmTasks('grunt-cache-breaker'); 
grunt.registerTask('default', ['cachebreaker']); 
}; 

我跑後PowerShell然後運行Grunt,但我得到以下錯誤:

錯誤:Unab解析「bustAFile.json」文件(Unexpected token?)。

如果我將bustAFile.json的全部內容複製到新的記事本文件中,則完全不需要保存它。有用。

是Poweshell添加一些奇怪的編碼,我看不到?

回答

0

迫使ASCII編碼的PowerShell來輸出固定我的問題

$file | convertto-jSon -Compress | out-file $ScriptDir\bustAFile.json -encoding ascii 

看來,JSON解析時咕嚕無法讀取其他編碼。