Skip to content

Instantly share code, notes, and snippets.

@Matheus-de-Souza
Last active November 8, 2016 11:52
Show Gist options
  • Save Matheus-de-Souza/cbe217e82b887737877bfa41a85f31a2 to your computer and use it in GitHub Desktop.
Save Matheus-de-Souza/cbe217e82b887737877bfa41a85f31a2 to your computer and use it in GitHub Desktop.
// 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