1
I am creating an app with Angularjs where I need to do a "mapping" of the system folder structure, so when it is necessary to make some change in the structure I just change this file and not the whole system.
To do that, I thought I’d ride a .config that would return an object with all the directories in my app. The directory structure is something like this:
app/
|- controllers/
|- cad/
|- directives/
|- views/
The problem is that if I write directory by directory it’s not working yet so I thought I could create an object with the multi-level structure and then return another object already with the mounted directories, something like:
var path = {
app: {
controllers:{
cad: ""
},
directives: "",
views:""
}
}
So from this variable I would return an object with all the "mappings" available based on the object, like this:
return {
app:{
_: "app/"
controllers: {
_: "app/controllers/",
cad: "app/controllers/cad/"
},
directives: {
_:"app/directives/"
},
views: {
_:"app/views/"
}
}
}
The problem is that I’m not being able to think about how to do this function so that it enters at all levels and assembles this structure. Does anyone have any matter of recursive functions or any solution?
what you want to do is something to read the file-Structure and pass it to an object ? If yes, and you are using Node, you can do this with the
fs.readdir
where each folder is pushed to the object and the value of that key is the full-path of it. The trick here is to recur in case you have N folders inside folders, but it’s not Rocket Science :)– MoshMage
is something similar to this but I don’t use Node. my app is about Cordova and to maintain a design pattern I need this kind of control
– LeandroLuk
All right, I just googled "Cordova readdir," but I got a really cool link that might help you with your quest - even just a little
– MoshMage
A key value wouldn’t be enough?
– Felipe Assunção