Skip to content

Instantly share code, notes, and snippets.

@rbtsolis
Created October 2, 2017 16:25
Show Gist options
  • Save rbtsolis/a051b04975baed3e3ea8c821b98c00ac to your computer and use it in GitHub Desktop.
Save rbtsolis/a051b04975baed3e3ea8c821b98c00ac to your computer and use it in GitHub Desktop.
var fs = require('fs'),
path = require('path');
function watchStyles(sourcefile, destinationfolder) {
var exec = require('child_process').exec;
var cmd = `stylus -c -u nib -w ${sourcefile} -o ${destinationfolder}`;
exec(cmd, function(error, stdout, stderr) {
if (stdout) {
console.log(stdout);
return;
}
if (stderr) {
console.log(stderr);
return;
}
});
}
function getDirectories(srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
}
//var directories = getDirectories(__dirname);
var directories = [
'apps',
'static',
'templates'
];
function fromDir(directory, startPath, filter){
if (!fs.existsSync(startPath)){
return;
}
var files = fs.readdirSync(startPath);
for(var i=0;i<files.length;i++){
var filename = path.join(startPath,files[i]);
var stat = fs.lstatSync(filename);
if (stat.isDirectory()){
fromDir(filename, filename, filter); //recurse
}
else if (filename.indexOf(filter)>=0) {
console.log("-------------");
console.log(filename);
//console.log(`${directory.replace('stylus','')}css/`)
console.log("-------------")
watchStyles(filename,`${directory.replace('stylus','')}css/`);
};
};
};
for(let directory of directories)
{
fromDir(`${__dirname}/${directory}/`,`${__dirname}/${directory}/`,'.styl');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment