Created
May 8, 2020 02:51
-
-
Save mraiguo/4016f6e446a9cf0bdd84ee2d74bffe29 to your computer and use it in GitHub Desktop.
处理window下换行符问题
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
const fg = require('fast-glob') | |
const { | |
crlf, chkcrlf, LF | |
} = require('crlf-normalize') | |
function checkLRForBinFile() { | |
console.log() | |
console.log('检查`bin`中的是否非LR格式') | |
fg.sync( | |
['packages/*/bin/*.js'], | |
{ ignore: ['**/node_modules'] } | |
).forEach((file) => { | |
const filePath = path.resolve(__dirname, file) | |
console.log(filePath) | |
const fileContent = fs.readFileSync(filePath, { | |
encoding: 'utf-8' | |
}) | |
console.log(fileContent) | |
if (chkcrlf(fileContent).crlf) { | |
console.error('Bin入口文件', filePath, '为CRLF, 将自动修正') | |
const fixedContent = crlf(fileContent, LF) | |
fs.writeFileSync(filePath, fixedContent, { | |
encoding: 'utf-8' | |
}) | |
} | |
}) | |
console.log('检查完成') | |
} | |
checkLRForBinFile() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment