Skip to content

Instantly share code, notes, and snippets.

@igorvieira
Last active September 25, 2017 12:49
Show Gist options
  • Save igorvieira/8ae6b6d007008414c75b34ad3aeb3428 to your computer and use it in GitHub Desktop.
Save igorvieira/8ae6b6d007008414c75b34ad3aeb3428 to your computer and use it in GitHub Desktop.
Convert files html.slim for html.erb
const { exec } = require('child_process')
const fs = require('fs')
const rl = require('readline')
const i = rl.createInterface(
process.stdin,
process.stdout,
null
);
const filterFiles = (file) =>
file.split(".")
.slice(0,-1).join(".")
.split(".").slice(0,-1)
.join(".") || file + ""
const removeSlimFile = (path,file) => {
exec(`rm -rf ${path}/${file}.html.slim`, (err) => {
if(err) console.log(err)
else console.log('File removed')
})
}
const readFile = (path) => {
fs.readdir(path, (err, files) => {
files.forEach(file => {
const newFile = filterFiles(file)
exec(`slimrb -e ${path}/${newFile}.html.slim > ${path}/${newFile}.html.erb`,
() => {
if(err) console.log(err)
else removeSlimFile(path,newFile)
})
});
})
}
i.question("paste the directory path:", (path) => {
readFile(path)
i.close();
process.stdin.destroy();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment