Last active
November 8, 2016 11:52
-
-
Save Matheus-de-Souza/cbe217e82b887737877bfa41a85f31a2 to your computer and use it in GitHub Desktop.
This file contains 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
// Tem que instalar antes o plugin de clipboard com | |
// npm install copy-paste | |
var fs = require('fs'), | |
ncp = require("copy-paste"); | |
var arquivo_entrada = __dirname + '/index.html'; | |
var arquivo_saida = __dirname + '/output.html'; | |
var copiar_para_clipboard = true; | |
fs.readFile(arquivo_entrada, 'utf8', function (err,data) { | |
if (err) { | |
console.log(err); | |
} else { | |
var trimmed_data = data; | |
trimmed_data = trimmed_data.replace(/\t/g, " "); | |
trimmed_data = trimmed_data.replace(/\r\n/g, " "); | |
trimmed_data = trimmed_data.replace(/\s+/g, " "); | |
// console.log(data); | |
// console.log(trimmed_data); | |
if (copiar_para_clipboard) { | |
ncp.copy(trimmed_data, function () { | |
console.log('Copiado para o clipboard!'); | |
}) ; | |
} else { | |
fs.writeFile(arquivo_saida, trimmed_data, function(err) { | |
if(err) { | |
console.log(err); | |
} else { | |
console.log("Arquivo salvo!"); | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment