eol-converter-cli
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "eol-converter-cli", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Newline converter CLI for simple CRLF -> LF (and reverse) convertions of multiple files.", | ||
@@ -10,3 +10,3 @@ "main": "src/index.js", | ||
"scripts": { | ||
"eolConverter": "node src/index.js" | ||
"start": "node src/index.js" | ||
}, | ||
@@ -13,0 +13,0 @@ "keywords": [ |
@@ -5,8 +5,8 @@ #!/usr/bin/env node | ||
const eol = require('eol') | ||
const glob = require("glob") | ||
const glob = require('glob') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const argv = process.argv; | ||
const inputFiles = argv[argv.length - 1] | ||
const argv = process.argv | ||
const inputFilesGlob = argv[argv.length - 1] | ||
const isWarmup = argv[argv.length - 2] === 'warmup' | ||
@@ -16,8 +16,11 @@ const isCrlf = argv[argv.length - 2] === 'crlf' | ||
const dir = process.cwd() | ||
console.log('Running in directory ' + dir) | ||
console.log('Files GLOB regex: ' + inputFiles) | ||
console.log(isWarmup ? 'WARMUP: will only list files, no action will be performed - run `convertToLF` to do conversion' : '') | ||
console.log('Files GLOB regex: ' + inputFilesGlob) | ||
console.log(isWarmup | ||
? 'WARMUP: will only list files, no action will be performed' | ||
: 'Converting to ' + (isCrlf ? 'CRLF' : 'LF')) | ||
console.log('---') | ||
glob(inputFiles, null, function (er, files) { | ||
glob(inputFilesGlob, null, function (er, files) { | ||
if (!files || files.length === 0) { | ||
@@ -28,13 +31,14 @@ return console.error('ERROR: no files found') | ||
console.log(fileName) | ||
if (!isWarmup) { | ||
try { | ||
const file = fs.readFileSync(path.join(dir, fileName)) | ||
const converted = isCrlf ? eol.crlf(file.toString()) : eol.lf(file.toString()) | ||
fs.writeFileSync(fileName, converted); | ||
} catch (error) { | ||
console.warn(error) | ||
} | ||
if (isWarmup) { | ||
return; | ||
} | ||
try { | ||
const fileContent = fs.readFileSync(path.join(dir, fileName)).toString() | ||
const convertFn = (isCrlf ? eol.crlf : eol.lf).bind(eol) | ||
fs.writeFileSync(fileName, convertFn(fileContent)) | ||
} catch (error) { | ||
console.warn(error) | ||
} | ||
}) | ||
console.log('---') | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13880
9
36