Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs, handle, path, tree, yaml, marked;

fs = require('fs');
jsyaml = require('js-yaml');
marked = require('marked'); // markdown processor
marked = require('marked'); // markdown processor
path = require('path');
var util = require('gulp-util');

Expand All @@ -21,7 +21,7 @@ var generateTree = function(param){
var stream = through.obj(function (file, enc, callback) {

/* File passed in */

var parsedFile = tree(patternsPath)


Expand All @@ -33,7 +33,7 @@ var generateTree = function(param){
/**
* If patternsPath doesnt exist
*/

fs.stat(patternsPath, function(err, stats){
if(err && erro.errno == 34){
this.emit('error', new PluginError('gulp-tree', 'Patterns directory doesnt exist'));
Expand All @@ -44,48 +44,45 @@ var generateTree = function(param){
/**
* Write the file
*/

fs.stat(jsonPath, function(err, stats){

if(err && err.errno == 34){

fs.mkdir(jsonPath)

}
})
try {
fs.mkdirSync(jsonPath);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}

var files = [];

for(var i = 0; i< s.length; i++){

if(s[i].children && s[i].children.length){

files.push(jsonPath+ '/' + s[i].slug + '.json')

fs.writeFile(jsonPath + '/'+ s[i].slug+".json", JSON.stringify(s[i].children, null, 4), function(err){
if(err) {
console.log(err);
} else {

console.log("Generated json in " + jsonPath);
}
})
})
}


}

return files;





});

var excludedExtension = ['.png', '.jpg', '.git', '.jpeg', '.gif', '.html'];
var tree = function(root){

var info, ring;
root = root.replace(/\/+$/, "");
if (fs.existsSync(root)) {
Expand All @@ -102,23 +99,23 @@ var generateTree = function(param){

if (ring.isDirectory()) {

var children = fs.readdirSync(root)
var children = fs.readdirSync(root)

var filtered = children.filter(function(c){

var filepath = root + '/' + c,
isFile = fs.lstatSync(filepath).isFile(),
content = true;

if(isFile && fs.readFileSync(filepath) == ""){
content = false
}

return c != '.DS_Store' && excludedExtension.indexOf(path.extname(c)) == -1 && content

})

delete(info.path)
delete(info.path)

info.children = filtered.map(function(child) {
return tree(root + '/' + child);
Expand All @@ -129,15 +126,15 @@ var generateTree = function(param){

var contents = fs.readFileSync(root, {encoding: 'utf8'});
var extname = path.extname(root);

var re = /^(-{3}(?:\n|\r)([\w\W]+?)-{3})?([\w\W]*)*/
, results = re.exec(contents.trim())
, conf = {}
, yamlOrJson;
, yamlOrJson;

if((yamlOrJson = results[2])) {
if(yamlOrJson.charAt(0) === '{') {

if(yamlOrJson.charAt(0) === '{') {
conf = JSON.parse(yamlOrJson);
} else {
conf = jsyaml.load(yamlOrJson);
Expand All @@ -148,30 +145,30 @@ var generateTree = function(param){

info.name = conf.name
}else{

return true;
}


/**
* Add meta variables
*/

info.meta = {};

for(var key in conf){
if(key != "name" && key != "description"){
if(conf.hasOwnProperty(key)){
info.meta[key] = conf[key]
}
info.meta[key] = conf[key]
}
}
}

if(Object.keys(info.meta).length < 1){
delete(info.meta)
}


} else if (ring.isSymbolicLink()) {
info.type = 'link';
} else {
Expand All @@ -185,8 +182,8 @@ var generateTree = function(param){

}

module.exports = generateTree;
module.exports = generateTree;

} else if (ring.isSymbolicLink()) {
info.type = 'link';
} else {
Expand Down