Created
May 27, 2016 13:29
-
-
Save IgorHalfeld/87209e3c14cf34f66c663d6125f313d8 to your computer and use it in GitHub Desktop.
Generate file with Sass Placeholders reading of one directory
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
'use strict'; | |
const fs = require('fs'); | |
function readDir(path) { | |
return new Promise( (resolve, reject) => { | |
fs.readdir(path, (err, data) => err ? reject(err) : resolve(data)); | |
}); | |
}; | |
function createFile(files, path) { | |
return new Promise( (resolve, reject) => { | |
files.forEach(file => { | |
let value = `%${file.replace('.svg', '')} {\n\ \tbackground-image: url('${path}/${file}');\n}\n\n`; | |
file = file.replace('.svg', ''); | |
fs.writeFile(`${path}/_icons.scss`, value, {flag: 'a+'}, err => err ? reject(err) : resolve(`\tCreated!`)); | |
}); | |
}); | |
} | |
readDir('icons') | |
.then(files => { | |
createFile(files, 'icons') | |
.then(success => { | |
console.log(' '); | |
console.log(success); | |
console.log(' '); | |
}) | |
.catch(err => { | |
throw new Error(err); | |
}); | |
}) | |
.catch(err => { | |
throw new Error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment