Skip to content

Instantly share code, notes, and snippets.

@IgorVieira IgorVieira/convert.js
Last active Sep 25, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.