Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Created May 27, 2016 13:29
Show Gist options
  • Save IgorHalfeld/87209e3c14cf34f66c663d6125f313d8 to your computer and use it in GitHub Desktop.
Save IgorHalfeld/87209e3c14cf34f66c663d6125f313d8 to your computer and use it in GitHub Desktop.
Generate file with Sass Placeholders reading of one directory
'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