Comparing version
45
index.js
var cSpawn = require('child_process').spawn; | ||
var os = require('os').type(); | ||
module.exports = spawn; | ||
exports = module.exports = spawn; | ||
function spawn(command, args, options) { | ||
if (os === 'Windows_NT') { | ||
if (os === 'Windows_NT') { | ||
if (command === 'rm') { | ||
command = 'rmdir'; | ||
if (args[0] === '-rf' || args[0] == '-fr') { | ||
args[0] = '/q'; | ||
args.unshift('/s'); | ||
} | ||
if (args[0] === '-f') { | ||
args[0] = '/q'; | ||
} | ||
if (args[0] === '-r') { | ||
args[0] = '/s'; | ||
} | ||
} | ||
args = args || []; | ||
@@ -48,2 +61,30 @@ options = options || {}; | ||
return out; | ||
} | ||
var fs = require('fs'); | ||
var join = require('path').join; | ||
exports.transformDir = transformDir; | ||
function transformDir(dirname, options) { | ||
options = options || {}; | ||
var dir = fs.readdirSync(dirname); | ||
dir.forEach(function (child) { | ||
if (fs.statSync(join(dirname, child)).isDirectory()) { | ||
if (child !== 'node_modules' && child !== '.git') { | ||
transformDir(join(dirname, child), options); | ||
} | ||
} else { | ||
transform(join(dirname, child), options); | ||
} | ||
}); | ||
} | ||
exports.transform = transform; | ||
function transform(file, options) { | ||
options = options || {}; | ||
var content = fs.readFileSync(file, 'utf8').toString(); | ||
if (/\r\n/g.test(content)) { | ||
console.warn('converting ' + file); | ||
if (!options.preview) fs.writeFileSync(file, content.replace(/\r\n/g, '\n'), 'utf8'); | ||
} | ||
} |
{ | ||
"name": "win-fork", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Spawn for node.js but in a way that works regardless of which OS you're using", | ||
@@ -12,6 +12,13 @@ "main": "index.js", | ||
"win-spawn": "./bin/win-spawn", | ||
"win-fork": "./bin/win-spawn" | ||
"win-fork": "./bin/win-spawn", | ||
"win-line-endings": "./bin/win-line-endings" | ||
}, | ||
"devDependencies": { | ||
"win-spawn": "*" | ||
}, | ||
"scripts": { | ||
"prepublish": "win-line-endings" | ||
}, | ||
"author": "ForbesLindesay", | ||
"license": "BSD" | ||
} |
@@ -20,2 +20,12 @@ # win-spawn | ||
You can also transform all the line endings in a directory from `\r\n` to `\n` just by running: | ||
$ win-line-endings | ||
You can preview the changes by running: | ||
$ win-line-endings -p | ||
It will ignore `node_modules` and `.git` by default, but is not clever enough to recognise binary files yet. | ||
### API | ||
@@ -22,0 +32,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
4729
49.79%6
20%79
92.68%39
34.48%1
Infinity%3
50%